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);
44 setVerticalScrollMode(QListView::ScrollPerPixel
);
45 setHorizontalScrollMode(QListView::ScrollPerPixel
);
47 viewport()->setAttribute(Qt::WA_Hover
);
49 QPalette palette
= viewport()->palette();
50 palette
.setColor(viewport()->backgroundRole(), Qt::transparent
);
51 viewport()->setPalette(palette
);
53 KFileItemDelegate
* delegate
= new KFileItemDelegate(this);
54 setItemDelegate(delegate
);
57 SidebarTreeView::~SidebarTreeView()
61 bool SidebarTreeView::event(QEvent
* event
)
63 if (event
->type() == QEvent::Polish
) {
64 // hide all columns except of the 'Name' column
65 hideColumn(DolphinModel::Size
);
66 hideColumn(DolphinModel::ModifiedTime
);
67 hideColumn(DolphinModel::Permissions
);
68 hideColumn(DolphinModel::Owner
);
69 hideColumn(DolphinModel::Group
);
70 hideColumn(DolphinModel::Type
);
71 hideColumn(DolphinModel::Rating
);
72 hideColumn(DolphinModel::Tags
);
75 else if (event
->type() == QEvent::UpdateRequest
) {
76 // a wheel movement will scroll 1 item
77 if (model()->rowCount() > 0) {
78 verticalScrollBar()->setSingleStep(sizeHintForRow(0) / 3);
82 return KTreeView::event(event
);
85 void SidebarTreeView::startDrag(Qt::DropActions supportedActions
)
87 DragAndDropHelper::startDrag(this, supportedActions
);
90 void SidebarTreeView::dragEnterEvent(QDragEnterEvent
* event
)
92 KTreeView::dragEnterEvent(event
);
93 if (event
->mimeData()->hasUrls()) {
94 event
->acceptProposedAction();
98 void SidebarTreeView::dragLeaveEvent(QDragLeaveEvent
* event
)
100 KTreeView::dragLeaveEvent(event
);
101 setDirtyRegion(m_dropRect
);
104 void SidebarTreeView::dragMoveEvent(QDragMoveEvent
* event
)
106 KTreeView::dragMoveEvent(event
);
108 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
109 const QModelIndex index
= indexAt(event
->pos());
110 setDirtyRegion(m_dropRect
);
111 m_dropRect
= visualRect(index
);
112 setDirtyRegion(m_dropRect
);
114 if (event
->mimeData()->hasUrls()) {
115 // accept url drops, independently from the destination item
116 event
->acceptProposedAction();
120 void SidebarTreeView::dropEvent(QDropEvent
* event
)
122 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
123 if (urls
.isEmpty()) {
124 KTreeView::dropEvent(event
);
126 event
->acceptProposedAction();
127 const QModelIndex index
= indexAt(event
->pos());
128 if (index
.isValid()) {
129 emit
urlsDropped(urls
, index
);
134 #include "sidebartreeview.moc"