]>
cloud.milkyroute.net Git - dolphin.git/blob - src/sidebartreeview.cpp
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"
25 #include <kfileitemdelegate.h>
28 #include <QHeaderView>
30 SidebarTreeView::SidebarTreeView(QWidget
* parent
) :
35 setUniformRowHeights(true);
36 setSelectionMode(QAbstractItemView::SingleSelection
);
37 setEditTriggers(QAbstractItemView::NoEditTriggers
);
38 setSortingEnabled(true);
39 setFrameStyle(QFrame::NoFrame
);
40 setDragDropMode(QAbstractItemView::DragDrop
);
41 setDropIndicatorShown(false);
42 setAutoExpandDelay(300);
43 // TODO: enable ScrollPerPixel again as soon as a Qt-patch
44 // is supplied which fixes a possible crash
45 // (see http://lists.kde.org/?l=kde-core-devel&m=119077433611662&w=2)
46 //setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
47 //setVerticalScrollMode(QAbstractItemView::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
);
78 return QTreeView::event(event
);
81 void SidebarTreeView::dragEnterEvent(QDragEnterEvent
* event
)
83 if (event
->mimeData()->hasUrls()) {
84 event
->acceptProposedAction();
86 QTreeView::dragEnterEvent(event
);
90 void SidebarTreeView::dragLeaveEvent(QDragLeaveEvent
* event
)
92 QTreeView::dragLeaveEvent(event
);
94 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
96 setDirtyRegion(m_dropRect
);
99 void SidebarTreeView::dragMoveEvent(QDragMoveEvent
* event
)
101 QTreeView::dragMoveEvent(event
);
103 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
104 const QModelIndex index
= indexAt(event
->pos());
105 setDirtyRegion(m_dropRect
);
106 m_dropRect
= visualRect(index
);
107 setDirtyRegion(m_dropRect
);
110 void SidebarTreeView::dropEvent(QDropEvent
* event
)
112 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
113 if (urls
.isEmpty()) {
114 QTreeView::dropEvent(event
);
116 event
->acceptProposedAction();
117 const QModelIndex index
= indexAt(event
->pos());
118 if (index
.isValid()) {
119 emit
urlsDropped(urls
, index
);
125 void SidebarTreeView::paintEvent(QPaintEvent
* event
)
127 QTreeView::paintEvent(event
);
129 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
131 const QBrush
& brush
= palette().brush(QPalette::Normal
, QPalette::Highlight
);
132 DolphinController::drawHoverIndication(viewport(), m_dropRect
, brush
);
136 #include "sidebartreeview.moc"