]> cloud.milkyroute.net Git - dolphin.git/blob - src/panels/folders/paneltreeview.cpp
Use capitalized KDE includes
[dolphin.git] / src / panels / folders / paneltreeview.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 "paneltreeview.h"
21
22 #include <KFileItemDelegate>
23 #include <QListView>
24 #include <QKeyEvent>
25 #include <QPainter>
26 #include <QHeaderView>
27 #include <QScrollBar>
28
29 #include <views/dolphinmodel.h>
30 #include <views/draganddrophelper.h>
31
32 PanelTreeView::PanelTreeView(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 // make the background transparent and apply the window-text color
50 // to the text color, so that enough contrast is given for all color
51 // schemes
52 QPalette p = palette();
53 p.setColor(QPalette::Active, QPalette::Text, p.color(QPalette::Active, QPalette::WindowText));
54 p.setColor(QPalette::Inactive, QPalette::Text, p.color(QPalette::Inactive, QPalette::WindowText));
55 p.setColor(QPalette::Disabled, QPalette::Text, p.color(QPalette::Disabled, QPalette::WindowText));
56 setPalette(p);
57 viewport()->setAutoFillBackground(false);
58
59 KFileItemDelegate* delegate = new KFileItemDelegate(this);
60 setItemDelegate(delegate);
61 }
62
63 PanelTreeView::~PanelTreeView()
64 {
65 }
66
67 bool PanelTreeView::event(QEvent* event)
68 {
69 switch (event->type()) {
70 case QEvent::Polish:
71 // Hide all columns except of the 'Name' column
72 for (int i = DolphinModel::Name + 1; i < DolphinModel::ExtraColumnCount; ++i) {
73 hideColumn(i);
74 }
75 header()->hide();
76 break;
77
78 case QEvent::Show:
79 // TODO: The opening/closing animation of subtrees flickers in combination with the
80 // panel when using the Oxygen style. As workaround the animation is turned off:
81 setAnimated(false);
82 break;
83
84 case QEvent::UpdateRequest:
85 // a wheel movement will scroll 1 item
86 if (model()->rowCount() > 0) {
87 verticalScrollBar()->setSingleStep(sizeHintForRow(0) / 3);
88 }
89 break;
90
91 default:
92 break;
93 }
94
95 return KTreeView::event(event);
96 }
97
98 void PanelTreeView::startDrag(Qt::DropActions supportedActions)
99 {
100 DragAndDropHelper::instance().startDrag(this, supportedActions);
101 }
102
103 void PanelTreeView::dragEnterEvent(QDragEnterEvent* event)
104 {
105 KTreeView::dragEnterEvent(event);
106 if (event->mimeData()->hasUrls()) {
107 event->acceptProposedAction();
108 }
109 }
110
111 void PanelTreeView::dragLeaveEvent(QDragLeaveEvent* event)
112 {
113 KTreeView::dragLeaveEvent(event);
114 setDirtyRegion(m_dropRect);
115 }
116
117 void PanelTreeView::dragMoveEvent(QDragMoveEvent* event)
118 {
119 KTreeView::dragMoveEvent(event);
120
121 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
122 const QModelIndex index = indexAt(event->pos());
123 setDirtyRegion(m_dropRect);
124 m_dropRect = visualRect(index);
125 setDirtyRegion(m_dropRect);
126
127 if (event->mimeData()->hasUrls()) {
128 // accept url drops, independently from the destination item
129 event->acceptProposedAction();
130 }
131 }
132
133 void PanelTreeView::dropEvent(QDropEvent* event)
134 {
135 const QModelIndex index = indexAt(event->pos());
136 if (index.isValid()) {
137 emit urlsDropped(index, event);
138 }
139 KTreeView::dropEvent(event);
140 }
141
142 #include "paneltreeview.moc"