]> cloud.milkyroute.net Git - dolphin.git/blob - src/sidebartreeview.cpp
SVN_SILENT made messages (.desktop file)
[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 QTreeView(parent),
34 m_dragging(false)
35 {
36 setAcceptDrops(true);
37 setUniformRowHeights(true);
38 setSelectionMode(QAbstractItemView::SingleSelection);
39 setEditTriggers(QAbstractItemView::NoEditTriggers);
40 setSortingEnabled(true);
41 setFrameStyle(QFrame::NoFrame);
42 setDragDropMode(QAbstractItemView::DragDrop);
43 setDropIndicatorShown(false);
44 setAutoExpandDelay(300);
45
46 // TODO: Remove this check when 4.3.2 is released and KDE requires it... this
47 // check avoids a division by zero happening on versions before 4.3.1.
48 // Right now KDE in theory can be shipped with Qt 4.3.0 and above.
49 // ereslibre
50 #if (QT_VERSION >= QT_VERSION_CHECK(4, 3, 2) || defined(QT_KDE_QT_COPY))
51 setVerticalScrollMode(QListView::ScrollPerPixel);
52 setHorizontalScrollMode(QListView::ScrollPerPixel);
53 #endif
54
55 viewport()->setAttribute(Qt::WA_Hover);
56
57 QPalette palette = viewport()->palette();
58 palette.setColor(viewport()->backgroundRole(), Qt::transparent);
59 viewport()->setPalette(palette);
60
61 KFileItemDelegate* delegate = new KFileItemDelegate(this);
62 setItemDelegate(delegate);
63 }
64
65 SidebarTreeView::~SidebarTreeView()
66 {
67 }
68
69 bool SidebarTreeView::event(QEvent* event)
70 {
71 if (event->type() == QEvent::Polish) {
72 // hide all columns except of the 'Name' column
73 hideColumn(DolphinModel::Size);
74 hideColumn(DolphinModel::ModifiedTime);
75 hideColumn(DolphinModel::Permissions);
76 hideColumn(DolphinModel::Owner);
77 hideColumn(DolphinModel::Group);
78 hideColumn(DolphinModel::Type);
79 hideColumn(DolphinModel::Rating);
80 hideColumn(DolphinModel::Tags);
81 header()->hide();
82 }
83 // TODO: Remove this check when 4.3.2 is released and KDE requires it... this
84 // check avoids a division by zero happening on versions before 4.3.1.
85 // Right now KDE in theory can be shipped with Qt 4.3.0 and above.
86 // ereslibre
87 #if (QT_VERSION >= QT_VERSION_CHECK(4, 3, 2) || defined(QT_KDE_QT_COPY))
88 else if (event->type() == QEvent::UpdateRequest) {
89 // a wheel movement will scroll 1 item
90 if (model()->rowCount() > 0) {
91 verticalScrollBar()->setSingleStep(sizeHintForRow(0) / 3);
92 }
93 }
94 #endif
95
96 return QTreeView::event(event);
97 }
98
99 void SidebarTreeView::startDrag(Qt::DropActions supportedActions)
100 {
101 DragAndDropHelper::startDrag(this, supportedActions);
102 }
103
104 void SidebarTreeView::dragEnterEvent(QDragEnterEvent* event)
105 {
106 if (event->mimeData()->hasUrls()) {
107 event->acceptProposedAction();
108 }
109 QTreeView::dragEnterEvent(event);
110 m_dragging = true;
111 }
112
113 void SidebarTreeView::dragLeaveEvent(QDragLeaveEvent* event)
114 {
115 QTreeView::dragLeaveEvent(event);
116
117 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
118 m_dragging = false;
119 setDirtyRegion(m_dropRect);
120 }
121
122 void SidebarTreeView::dragMoveEvent(QDragMoveEvent* event)
123 {
124 QTreeView::dragMoveEvent(event);
125
126 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
127 const QModelIndex index = indexAt(event->pos());
128 setDirtyRegion(m_dropRect);
129 m_dropRect = visualRect(index);
130 setDirtyRegion(m_dropRect);
131 }
132
133 void SidebarTreeView::dropEvent(QDropEvent* event)
134 {
135 const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
136 if (urls.isEmpty()) {
137 QTreeView::dropEvent(event);
138 } else {
139 event->acceptProposedAction();
140 const QModelIndex index = indexAt(event->pos());
141 if (index.isValid()) {
142 emit urlsDropped(urls, index);
143 }
144 }
145 m_dragging = false;
146 }
147
148 void SidebarTreeView::paintEvent(QPaintEvent* event)
149 {
150 QTreeView::paintEvent(event);
151
152 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
153 if (m_dragging) {
154 const QBrush& brush = palette().brush(QPalette::Normal, QPalette::Highlight);
155 DragAndDropHelper::drawHoverIndication(viewport(), m_dropRect, brush);
156 }
157 }
158
159 #include "sidebartreeview.moc"