]>
cloud.milkyroute.net Git - dolphin.git/blob - src/sidebartreeview.cpp
86f58c17f198a5e8fc332df2bf065c9a6117dacd
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>
31 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);
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())
78 verticalScrollBar()->setSingleStep(sizeHintForRow(0) / 3);
81 return QTreeView::event(event
);
84 void SidebarTreeView::dragEnterEvent(QDragEnterEvent
* event
)
86 if (event
->mimeData()->hasUrls()) {
87 event
->acceptProposedAction();
89 QTreeView::dragEnterEvent(event
);
93 void SidebarTreeView::dragLeaveEvent(QDragLeaveEvent
* event
)
95 QTreeView::dragLeaveEvent(event
);
97 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
99 setDirtyRegion(m_dropRect
);
102 void SidebarTreeView::dragMoveEvent(QDragMoveEvent
* event
)
104 QTreeView::dragMoveEvent(event
);
106 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
107 const QModelIndex index
= indexAt(event
->pos());
108 setDirtyRegion(m_dropRect
);
109 m_dropRect
= visualRect(index
);
110 setDirtyRegion(m_dropRect
);
113 void SidebarTreeView::dropEvent(QDropEvent
* event
)
115 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
116 if (urls
.isEmpty()) {
117 QTreeView::dropEvent(event
);
119 event
->acceptProposedAction();
120 const QModelIndex index
= indexAt(event
->pos());
121 if (index
.isValid()) {
122 emit
urlsDropped(urls
, index
);
128 void SidebarTreeView::paintEvent(QPaintEvent
* event
)
130 QTreeView::paintEvent(event
);
132 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
134 const QBrush
& brush
= palette().brush(QPalette::Normal
, QPalette::Highlight
);
135 DolphinController::drawHoverIndication(viewport(), m_dropRect
, brush
);
139 #include "sidebartreeview.moc"