]>
cloud.milkyroute.net Git - dolphin.git/blob - src/sidebartreeview.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
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. *
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. *
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 ***************************************************************************/
20 #include "sidebartreeview.h"
22 #include "dolphincontroller.h"
23 #include "dolphinmodel.h"
25 #include <kfileitemdelegate.h>
28 #include <QHeaderView>
31 SidebarTreeView::SidebarTreeView(QWidget
* parent
) :
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 setAutoExpandDelay(300);
45 // TODO: Remove this check when 4.3.2 is released and KDE requires it... this
46 // check avoids a division by zero happening on versions before 4.3.1.
47 // Right now KDE in theory can be shipped with Qt 4.3.0 and above.
49 #if (QT_VERSION >= QT_VERSION_CHECK(4, 3, 2) || defined(QT_KDE_QT_COPY))
50 setVerticalScrollMode(QListView::ScrollPerPixel
);
51 setHorizontalScrollMode(QListView::ScrollPerPixel
);
54 viewport()->setAttribute(Qt::WA_Hover
);
56 QPalette palette
= viewport()->palette();
57 palette
.setColor(viewport()->backgroundRole(), Qt::transparent
);
58 viewport()->setPalette(palette
);
60 KFileItemDelegate
* delegate
= new KFileItemDelegate(this);
61 setItemDelegate(delegate
);
64 SidebarTreeView::~SidebarTreeView()
68 bool SidebarTreeView::event(QEvent
* event
)
70 if (event
->type() == QEvent::Polish
) {
71 // hide all columns except of the 'Name' column
72 hideColumn(DolphinModel::Size
);
73 hideColumn(DolphinModel::ModifiedTime
);
74 hideColumn(DolphinModel::Permissions
);
75 hideColumn(DolphinModel::Owner
);
76 hideColumn(DolphinModel::Group
);
77 hideColumn(DolphinModel::Type
);
78 hideColumn(DolphinModel::Rating
);
79 hideColumn(DolphinModel::Tags
);
82 // TODO: Remove this check when 4.3.2 is released and KDE requires it... this
83 // check avoids a division by zero happening on versions before 4.3.1.
84 // Right now KDE in theory can be shipped with Qt 4.3.0 and above.
86 #if (QT_VERSION >= QT_VERSION_CHECK(4, 3, 2) || defined(QT_KDE_QT_COPY))
87 else if (event
->type() == QEvent::UpdateRequest
) {
88 // a wheel movement will scroll 1 item
89 if (model()->rowCount() > 0) {
90 verticalScrollBar()->setSingleStep(sizeHintForRow(0) / 3);
95 return QTreeView::event(event
);
98 void SidebarTreeView::dragEnterEvent(QDragEnterEvent
* event
)
100 if (event
->mimeData()->hasUrls()) {
101 event
->acceptProposedAction();
103 QTreeView::dragEnterEvent(event
);
107 void SidebarTreeView::dragLeaveEvent(QDragLeaveEvent
* event
)
109 QTreeView::dragLeaveEvent(event
);
111 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
113 setDirtyRegion(m_dropRect
);
116 void SidebarTreeView::dragMoveEvent(QDragMoveEvent
* event
)
118 QTreeView::dragMoveEvent(event
);
120 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
121 const QModelIndex index
= indexAt(event
->pos());
122 setDirtyRegion(m_dropRect
);
123 m_dropRect
= visualRect(index
);
124 setDirtyRegion(m_dropRect
);
127 void SidebarTreeView::dropEvent(QDropEvent
* event
)
129 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
130 if (urls
.isEmpty()) {
131 QTreeView::dropEvent(event
);
133 event
->acceptProposedAction();
134 const QModelIndex index
= indexAt(event
->pos());
135 if (index
.isValid()) {
136 emit
urlsDropped(urls
, index
);
142 void SidebarTreeView::paintEvent(QPaintEvent
* event
)
144 QTreeView::paintEvent(event
);
146 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
148 const QBrush
& brush
= palette().brush(QPalette::Normal
, QPalette::Highlight
);
149 DolphinController::drawHoverIndication(viewport(), m_dropRect
, brush
);
153 #include "sidebartreeview.moc"