]> cloud.milkyroute.net Git - dolphin.git/blob - src/sidebartreeview.cpp
added missing copyright
[dolphin.git] / src / sidebartreeview.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
19
20 #include "sidebartreeview.h"
21
22 #include "dolphincontroller.h"
23 #include "dolphinmodel.h"
24 #include "draganddrophelper.h"
25
26 #include <kfileitemdelegate.h>
27 #include <QKeyEvent>
28 #include <QPainter>
29 #include <QHeaderView>
30 #include <QScrollBar>
31
32 SidebarTreeView::SidebarTreeView(QWidget* parent) :
33 KTreeView(parent)
34 {
35 setAcceptDrops(true);
36 setUniformRowHeights(true);
37 setSelectionMode(QAbstractItemView::SingleSelection);
38 setEditTriggers(QAbstractItemView::NoEditTriggers);
39 setSortingEnabled(true);
40 setFrameStyle(QFrame::NoFrame);
41 setDragDropMode(QAbstractItemView::DragDrop);
42 setDropIndicatorShown(false);
43
44 setVerticalScrollMode(QListView::ScrollPerPixel);
45 setHorizontalScrollMode(QListView::ScrollPerPixel);
46
47 viewport()->setAttribute(Qt::WA_Hover);
48
49 QPalette palette = viewport()->palette();
50 palette.setColor(viewport()->backgroundRole(), Qt::transparent);
51 viewport()->setPalette(palette);
52
53 KFileItemDelegate* delegate = new KFileItemDelegate(this);
54 setItemDelegate(delegate);
55 }
56
57 SidebarTreeView::~SidebarTreeView()
58 {
59 }
60
61 bool SidebarTreeView::event(QEvent* event)
62 {
63 if (event->type() == QEvent::Polish) {
64 // hide all columns except of the 'Name' column
65 hideColumn(DolphinModel::Size);
66 hideColumn(DolphinModel::ModifiedTime);
67 hideColumn(DolphinModel::Permissions);
68 hideColumn(DolphinModel::Owner);
69 hideColumn(DolphinModel::Group);
70 hideColumn(DolphinModel::Type);
71 hideColumn(DolphinModel::Rating);
72 hideColumn(DolphinModel::Tags);
73 header()->hide();
74 }
75 else if (event->type() == QEvent::UpdateRequest) {
76 // a wheel movement will scroll 1 item
77 if (model()->rowCount() > 0) {
78 verticalScrollBar()->setSingleStep(sizeHintForRow(0) / 3);
79 }
80 }
81
82 return KTreeView::event(event);
83 }
84
85 void SidebarTreeView::startDrag(Qt::DropActions supportedActions)
86 {
87 DragAndDropHelper::startDrag(this, supportedActions);
88 }
89
90 void SidebarTreeView::dragEnterEvent(QDragEnterEvent* event)
91 {
92 KTreeView::dragEnterEvent(event);
93 if (event->mimeData()->hasUrls()) {
94 event->acceptProposedAction();
95 }
96 }
97
98 void SidebarTreeView::dragLeaveEvent(QDragLeaveEvent* event)
99 {
100 KTreeView::dragLeaveEvent(event);
101 setDirtyRegion(m_dropRect);
102 }
103
104 void SidebarTreeView::dragMoveEvent(QDragMoveEvent* event)
105 {
106 KTreeView::dragMoveEvent(event);
107
108 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
109 const QModelIndex index = indexAt(event->pos());
110 setDirtyRegion(m_dropRect);
111 m_dropRect = visualRect(index);
112 setDirtyRegion(m_dropRect);
113
114 if (event->mimeData()->hasUrls()) {
115 // accept url drops, independently from the destination item
116 event->acceptProposedAction();
117 }
118 }
119
120 void SidebarTreeView::dropEvent(QDropEvent* event)
121 {
122 const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
123 if (urls.isEmpty()) {
124 KTreeView::dropEvent(event);
125 } else {
126 event->acceptProposedAction();
127 const QModelIndex index = indexAt(event->pos());
128 if (index.isValid()) {
129 emit urlsDropped(urls, index);
130 }
131 }
132 }
133
134 #include "sidebartreeview.moc"