]> cloud.milkyroute.net Git - dolphin.git/blob - src/panels/folders/paneltreeview.cpp
Respect Shift- and Control-key for the rubberband selection
[dolphin.git] / src / panels / folders / paneltreeview.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz19@gmail.com> *
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 PanelTreeView::PanelTreeView(QWidget* parent) :
30 KTreeView(parent)
31 {
32 setAcceptDrops(true);
33 setUniformRowHeights(true);
34 setSelectionMode(QAbstractItemView::SingleSelection);
35 setEditTriggers(QAbstractItemView::NoEditTriggers);
36 setSortingEnabled(true);
37 setFrameStyle(QFrame::NoFrame);
38 setDragDropMode(QAbstractItemView::DragDrop);
39 setDropIndicatorShown(false);
40
41 setVerticalScrollMode(QListView::ScrollPerPixel);
42 setHorizontalScrollMode(QListView::ScrollPerPixel);
43
44 viewport()->setAttribute(Qt::WA_Hover);
45
46 // make the background transparent and apply the window-text color
47 // to the text color, so that enough contrast is given for all color
48 // schemes
49 QPalette p = palette();
50 p.setColor(QPalette::Active, QPalette::Text, p.color(QPalette::Active, QPalette::WindowText));
51 p.setColor(QPalette::Inactive, QPalette::Text, p.color(QPalette::Inactive, QPalette::WindowText));
52 p.setColor(QPalette::Disabled, QPalette::Text, p.color(QPalette::Disabled, QPalette::WindowText));
53 setPalette(p);
54 viewport()->setAutoFillBackground(false);
55
56 KFileItemDelegate* delegate = new KFileItemDelegate(this);
57 setItemDelegate(delegate);
58 }
59
60 PanelTreeView::~PanelTreeView()
61 {
62 }
63
64 bool PanelTreeView::event(QEvent* event)
65 {
66 switch (event->type()) {
67 case QEvent::Polish:
68 // Hide all columns except of the 'Name' column
69 /*for (int i = DolphinModel::Name + 1; i < DolphinModel::ExtraColumnCount; ++i) {
70 hideColumn(i);
71 }
72 header()->hide();*/
73 break;
74
75 case QEvent::Show:
76 // TODO: The opening/closing animation of subtrees flickers in combination with the
77 // panel when using the Oxygen style. As workaround the animation is turned off:
78 setAnimated(false);
79 break;
80
81 case QEvent::UpdateRequest:
82 // a wheel movement will scroll 1 item
83 if (model()->rowCount() > 0) {
84 verticalScrollBar()->setSingleStep(sizeHintForRow(0) / 3);
85 }
86 break;
87
88 default:
89 break;
90 }
91
92 return KTreeView::event(event);
93 }
94
95 void PanelTreeView::startDrag(Qt::DropActions supportedActions)
96 {
97 Q_UNUSED(supportedActions);
98 //DragAndDropHelper::instance().startDrag(this, supportedActions);
99 }
100
101 void PanelTreeView::dragEnterEvent(QDragEnterEvent* event)
102 {
103 KTreeView::dragEnterEvent(event);
104 if (event->mimeData()->hasUrls()) {
105 event->acceptProposedAction();
106 }
107 }
108
109 void PanelTreeView::dragLeaveEvent(QDragLeaveEvent* event)
110 {
111 KTreeView::dragLeaveEvent(event);
112 setDirtyRegion(m_dropRect);
113 }
114
115 void PanelTreeView::dragMoveEvent(QDragMoveEvent* event)
116 {
117 KTreeView::dragMoveEvent(event);
118
119 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
120 const QModelIndex index = indexAt(event->pos());
121 setDirtyRegion(m_dropRect);
122 m_dropRect = visualRect(index);
123 setDirtyRegion(m_dropRect);
124
125 if (event->mimeData()->hasUrls()) {
126 // accept url drops, independently from the destination item
127 event->acceptProposedAction();
128 }
129 }
130
131 void PanelTreeView::dropEvent(QDropEvent* event)
132 {
133 const QModelIndex index = indexAt(event->pos());
134 if (index.isValid()) {
135 emit urlsDropped(index, event);
136 }
137 KTreeView::dropEvent(event);
138 }
139
140 #include "paneltreeview.moc"