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 resizeColumnToContents(DolphinModel::Name
);
86 // TODO: Remove this check when 4.3.2 is released and KDE requires it... this
87 // check avoids a division by zero happening on versions before 4.3.1.
88 // Right now KDE in theory can be shipped with Qt 4.3.0 and above.
90 #if (QT_VERSION >= QT_VERSION_CHECK(4, 3, 2) || defined(QT_KDE_QT_COPY))
91 // a wheel movement will scroll 1 item
92 if (model()->rowCount() > 0) {
93 verticalScrollBar()->setSingleStep(sizeHintForRow(0) / 3);
98 return QTreeView::event(event
);
101 void SidebarTreeView::startDrag(Qt::DropActions supportedActions
)
103 DragAndDropHelper::startDrag(this, supportedActions
);
106 void SidebarTreeView::dragEnterEvent(QDragEnterEvent
* event
)
108 if (event
->mimeData()->hasUrls()) {
109 event
->acceptProposedAction();
111 QTreeView::dragEnterEvent(event
);
115 void SidebarTreeView::dragLeaveEvent(QDragLeaveEvent
* event
)
117 QTreeView::dragLeaveEvent(event
);
119 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
121 setDirtyRegion(m_dropRect
);
124 void SidebarTreeView::dragMoveEvent(QDragMoveEvent
* event
)
126 QTreeView::dragMoveEvent(event
);
128 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
129 const QModelIndex index
= indexAt(event
->pos());
130 setDirtyRegion(m_dropRect
);
131 m_dropRect
= visualRect(index
);
132 setDirtyRegion(m_dropRect
);
135 void SidebarTreeView::dropEvent(QDropEvent
* event
)
137 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
138 if (urls
.isEmpty()) {
139 QTreeView::dropEvent(event
);
141 event
->acceptProposedAction();
142 const QModelIndex index
= indexAt(event
->pos());
143 if (index
.isValid()) {
144 emit
urlsDropped(urls
, index
);
150 void SidebarTreeView::paintEvent(QPaintEvent
* event
)
152 QTreeView::paintEvent(event
);
154 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
156 const QBrush
& brush
= palette().brush(QPalette::Normal
, QPalette::Highlight
);
157 DragAndDropHelper::drawHoverIndication(viewport(), m_dropRect
, brush
);
161 #include "sidebartreeview.moc"