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 setVerticalScrollMode(QListView::ScrollPerPixel
);
47 setHorizontalScrollMode(QListView::ScrollPerPixel
);
49 viewport()->setAttribute(Qt::WA_Hover
);
51 QPalette palette
= viewport()->palette();
52 palette
.setColor(viewport()->backgroundRole(), Qt::transparent
);
53 viewport()->setPalette(palette
);
55 KFileItemDelegate
* delegate
= new KFileItemDelegate(this);
56 setItemDelegate(delegate
);
59 SidebarTreeView::~SidebarTreeView()
63 bool SidebarTreeView::event(QEvent
* event
)
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
);
77 else if (event
->type() == QEvent::UpdateRequest
) {
78 // a wheel movement will scroll 1 item
79 if (model()->rowCount() > 0) {
80 verticalScrollBar()->setSingleStep(sizeHintForRow(0) / 3);
83 else if (event
->type() == QEvent::MetaCall
) {
84 resizeColumnToContents(DolphinModel::Name
);
87 return QTreeView::event(event
);
90 void SidebarTreeView::startDrag(Qt::DropActions supportedActions
)
92 DragAndDropHelper::startDrag(this, supportedActions
);
95 void SidebarTreeView::dragEnterEvent(QDragEnterEvent
* event
)
97 QTreeView::dragEnterEvent(event
);
99 if (event
->mimeData()->hasUrls()) {
100 event
->acceptProposedAction();
106 void SidebarTreeView::dragLeaveEvent(QDragLeaveEvent
* event
)
108 QTreeView::dragLeaveEvent(event
);
110 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
112 setDirtyRegion(m_dropRect
);
115 void SidebarTreeView::dragMoveEvent(QDragMoveEvent
* event
)
117 QTreeView::dragMoveEvent(event
);
119 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
120 const QModelIndex index
= indexAt(event
->pos());
121 setDirtyRegion(m_dropRect
);
122 m_dropRect
= visualRect(index
);
123 setDirtyRegion(m_dropRect
);
125 if (event
->mimeData()->hasUrls()) {
126 // accept url drops, independently from the destination item
127 event
->acceptProposedAction();
131 void SidebarTreeView::dropEvent(QDropEvent
* event
)
133 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
134 if (urls
.isEmpty()) {
135 QTreeView::dropEvent(event
);
137 event
->acceptProposedAction();
138 const QModelIndex index
= indexAt(event
->pos());
139 if (index
.isValid()) {
140 emit
urlsDropped(urls
, index
);
146 void SidebarTreeView::paintEvent(QPaintEvent
* event
)
148 QTreeView::paintEvent(event
);
150 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
152 const QBrush
& brush
= palette().brush(QPalette::Normal
, QPalette::Highlight
);
153 DragAndDropHelper::drawHoverIndication(this, m_dropRect
, brush
);
157 #include "sidebartreeview.moc"