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