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
) :
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 setVerticalScrollMode(QListView::ScrollPerPixel
);
46 setHorizontalScrollMode(QListView::ScrollPerPixel
);
48 viewport()->setAttribute(Qt::WA_Hover
);
50 QPalette palette
= viewport()->palette();
51 palette
.setColor(viewport()->backgroundRole(), Qt::transparent
);
52 viewport()->setPalette(palette
);
54 KFileItemDelegate
* delegate
= new KFileItemDelegate(this);
55 setItemDelegate(delegate
);
58 SidebarTreeView::~SidebarTreeView()
62 bool SidebarTreeView::event(QEvent
* event
)
64 if (event
->type() == QEvent::Polish
) {
65 // hide all columns except of the 'Name' column
66 hideColumn(DolphinModel::Size
);
67 hideColumn(DolphinModel::ModifiedTime
);
68 hideColumn(DolphinModel::Permissions
);
69 hideColumn(DolphinModel::Owner
);
70 hideColumn(DolphinModel::Group
);
71 hideColumn(DolphinModel::Type
);
72 hideColumn(DolphinModel::Rating
);
73 hideColumn(DolphinModel::Tags
);
76 else if (event
->type() == QEvent::UpdateRequest
) {
77 // a wheel movement will scroll 1 item
78 if (model()->rowCount() > 0) {
79 verticalScrollBar()->setSingleStep(sizeHintForRow(0) / 3);
82 else if (event
->type() == QEvent::MetaCall
) {
83 resizeColumnToContents(DolphinModel::Name
);
86 return QTreeView::event(event
);
89 void SidebarTreeView::startDrag(Qt::DropActions supportedActions
)
91 DragAndDropHelper::startDrag(this, supportedActions
);
94 void SidebarTreeView::dragEnterEvent(QDragEnterEvent
* event
)
96 QTreeView::dragEnterEvent(event
);
97 if (event
->mimeData()->hasUrls()) {
98 event
->acceptProposedAction();
102 void SidebarTreeView::dragLeaveEvent(QDragLeaveEvent
* event
)
104 QTreeView::dragLeaveEvent(event
);
105 setDirtyRegion(m_dropRect
);
108 void SidebarTreeView::dragMoveEvent(QDragMoveEvent
* event
)
110 QTreeView::dragMoveEvent(event
);
112 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
113 const QModelIndex index
= indexAt(event
->pos());
114 setDirtyRegion(m_dropRect
);
115 m_dropRect
= visualRect(index
);
116 setDirtyRegion(m_dropRect
);
118 if (event
->mimeData()->hasUrls()) {
119 // accept url drops, independently from the destination item
120 event
->acceptProposedAction();
124 void SidebarTreeView::dropEvent(QDropEvent
* event
)
126 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
127 if (urls
.isEmpty()) {
128 QTreeView::dropEvent(event
);
130 event
->acceptProposedAction();
131 const QModelIndex index
= indexAt(event
->pos());
132 if (index
.isValid()) {
133 emit
urlsDropped(urls
, index
);
138 #include "sidebartreeview.moc"