]> cloud.milkyroute.net Git - dolphin.git/blob - src/sidebartreeview.cpp
assure that the width of the name-column cannot get too small when decreasing the...
[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
25 #include <kfileitemdelegate.h>
26 #include <QKeyEvent>
27 #include <QPainter>
28 #include <QHeaderView>
29
30 SidebarTreeView::SidebarTreeView(QWidget* parent) :
31 QTreeView(parent),
32 m_dragging(false)
33 {
34 setAcceptDrops(true);
35 setUniformRowHeights(true);
36 setSelectionMode(QAbstractItemView::SingleSelection);
37 setEditTriggers(QAbstractItemView::NoEditTriggers);
38 setSortingEnabled(true);
39 setFrameStyle(QFrame::NoFrame);
40 setDragDropMode(QAbstractItemView::DragDrop);
41 setDropIndicatorShown(false);
42 setAutoExpandDelay(300);
43 // TODO: enable ScrollPerPixel again as soon as a Qt-patch
44 // is supplied which fixes a possible crash
45 // (see http://lists.kde.org/?l=kde-core-devel&m=119077433611662&w=2)
46 //setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
47 //setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
48
49 viewport()->setAttribute(Qt::WA_Hover);
50
51 QPalette palette = viewport()->palette();
52 palette.setColor(viewport()->backgroundRole(), Qt::transparent);
53 viewport()->setPalette(palette);
54
55 KFileItemDelegate* delegate = new KFileItemDelegate(this);
56 setItemDelegate(delegate);
57 }
58
59 SidebarTreeView::~SidebarTreeView()
60 {
61 }
62
63 bool SidebarTreeView::event(QEvent* event)
64 {
65 if (event->type() == QEvent::Polish) {
66 // hide all columns except of the 'Name' column
67 hideColumn(DolphinModel::Size);
68 hideColumn(DolphinModel::ModifiedTime);
69 hideColumn(DolphinModel::Permissions);
70 hideColumn(DolphinModel::Owner);
71 hideColumn(DolphinModel::Group);
72 hideColumn(DolphinModel::Type);
73 hideColumn(DolphinModel::Rating);
74 hideColumn(DolphinModel::Tags);
75 header()->hide();
76 }
77
78 return QTreeView::event(event);
79 }
80
81 void SidebarTreeView::dragEnterEvent(QDragEnterEvent* event)
82 {
83 if (event->mimeData()->hasUrls()) {
84 event->acceptProposedAction();
85 }
86 QTreeView::dragEnterEvent(event);
87 m_dragging = true;
88 }
89
90 void SidebarTreeView::dragLeaveEvent(QDragLeaveEvent* event)
91 {
92 QTreeView::dragLeaveEvent(event);
93
94 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
95 m_dragging = false;
96 setDirtyRegion(m_dropRect);
97 }
98
99 void SidebarTreeView::dragMoveEvent(QDragMoveEvent* event)
100 {
101 QTreeView::dragMoveEvent(event);
102
103 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
104 const QModelIndex index = indexAt(event->pos());
105 setDirtyRegion(m_dropRect);
106 m_dropRect = visualRect(index);
107 setDirtyRegion(m_dropRect);
108 }
109
110 void SidebarTreeView::dropEvent(QDropEvent* event)
111 {
112 const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
113 if (urls.isEmpty()) {
114 QTreeView::dropEvent(event);
115 } else {
116 event->acceptProposedAction();
117 const QModelIndex index = indexAt(event->pos());
118 if (index.isValid()) {
119 emit urlsDropped(urls, index);
120 }
121 }
122 m_dragging = false;
123 }
124
125 void SidebarTreeView::paintEvent(QPaintEvent* event)
126 {
127 QTreeView::paintEvent(event);
128
129 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
130 if (m_dragging) {
131 const QBrush& brush = palette().brush(QPalette::Normal, QPalette::Highlight);
132 DolphinController::drawHoverIndication(viewport(), m_dropRect, brush);
133 }
134 }
135
136 #include "sidebartreeview.moc"