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"
24 #include "draganddrophelper.h"
26 #include <kfileitemdelegate.h>
29 #include <QHeaderView>
32 SidebarTreeView::SidebarTreeView(QWidget
* parent
) :
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 setAutoExpandDelay(300);
46 // TODO: Remove this check when 4.3.2 is released and KDE requires it... this
47 // check avoids a division by zero happening on versions before 4.3.1.
48 // Right now KDE in theory can be shipped with Qt 4.3.0 and above.
50 #if (QT_VERSION >= QT_VERSION_CHECK(4, 3, 2) || defined(QT_KDE_QT_COPY))
51 setVerticalScrollMode(QListView::ScrollPerPixel
);
52 setHorizontalScrollMode(QListView::ScrollPerPixel
);
55 viewport()->setAttribute(Qt::WA_Hover
);
57 QPalette palette
= viewport()->palette();
58 palette
.setColor(viewport()->backgroundRole(), Qt::transparent
);
59 viewport()->setPalette(palette
);
61 KFileItemDelegate
* delegate
= new KFileItemDelegate(this);
62 setItemDelegate(delegate
);
65 SidebarTreeView::~SidebarTreeView()
69 bool SidebarTreeView::event(QEvent
* event
)
71 if (event
->type() == 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::Rating
);
80 hideColumn(DolphinModel::Tags
);
83 else if (event
->type() == QEvent::UpdateRequest
) {
84 // TODO: Remove this check when 4.3.2 is released and KDE requires it... this
85 // check avoids a division by zero happening on versions before 4.3.1.
86 // Right now KDE in theory can be shipped with Qt 4.3.0 and above.
88 #if (QT_VERSION >= QT_VERSION_CHECK(4, 3, 2) || defined(QT_KDE_QT_COPY))
89 // a wheel movement will scroll 1 item
90 if (model()->rowCount() > 0) {
91 verticalScrollBar()->setSingleStep(sizeHintForRow(0) / 3);
95 else if (event
->type() == QEvent::MetaCall
) {
96 resizeColumnToContents(DolphinModel::Name
);
99 return QTreeView::event(event
);
102 void SidebarTreeView::startDrag(Qt::DropActions supportedActions
)
104 DragAndDropHelper::startDrag(this, supportedActions
);
107 void SidebarTreeView::dragEnterEvent(QDragEnterEvent
* event
)
109 if (event
->mimeData()->hasUrls()) {
110 event
->acceptProposedAction();
112 QTreeView::dragEnterEvent(event
);
116 void SidebarTreeView::dragLeaveEvent(QDragLeaveEvent
* event
)
118 QTreeView::dragLeaveEvent(event
);
120 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
122 setDirtyRegion(m_dropRect
);
125 void SidebarTreeView::dragMoveEvent(QDragMoveEvent
* event
)
127 QTreeView::dragMoveEvent(event
);
129 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
130 const QModelIndex index
= indexAt(event
->pos());
131 setDirtyRegion(m_dropRect
);
132 m_dropRect
= visualRect(index
);
133 setDirtyRegion(m_dropRect
);
136 void SidebarTreeView::dropEvent(QDropEvent
* event
)
138 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
139 if (urls
.isEmpty()) {
140 QTreeView::dropEvent(event
);
142 event
->acceptProposedAction();
143 const QModelIndex index
= indexAt(event
->pos());
144 if (index
.isValid()) {
145 emit
urlsDropped(urls
, index
);
151 void SidebarTreeView::paintEvent(QPaintEvent
* event
)
153 QTreeView::paintEvent(event
);
155 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
157 const QBrush
& brush
= palette().brush(QPalette::Normal
, QPalette::Highlight
);
158 DragAndDropHelper::drawHoverIndication(this, m_dropRect
, brush
);
162 #include "sidebartreeview.moc"