]>
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);
44 viewport()->setAttribute(Qt::WA_Hover
);
46 QPalette palette
= viewport()->palette();
47 palette
.setColor(viewport()->backgroundRole(), Qt::transparent
);
48 viewport()->setPalette(palette
);
50 KFileItemDelegate
* delegate
= new KFileItemDelegate(this);
51 setItemDelegate(delegate
);
54 SidebarTreeView::~SidebarTreeView()
58 bool SidebarTreeView::event(QEvent
* event
)
60 if (event
->type() == QEvent::Polish
) {
61 // hide all columns except of the 'Name' column
62 hideColumn(DolphinModel::Size
);
63 hideColumn(DolphinModel::ModifiedTime
);
64 hideColumn(DolphinModel::Permissions
);
65 hideColumn(DolphinModel::Owner
);
66 hideColumn(DolphinModel::Group
);
67 hideColumn(DolphinModel::Type
);
68 hideColumn(DolphinModel::Rating
);
69 hideColumn(DolphinModel::Tags
);
73 return QTreeView::event(event
);
76 void SidebarTreeView::dragEnterEvent(QDragEnterEvent
* event
)
78 if (event
->mimeData()->hasUrls()) {
79 event
->acceptProposedAction();
81 QTreeView::dragEnterEvent(event
);
85 void SidebarTreeView::dragLeaveEvent(QDragLeaveEvent
* event
)
87 QTreeView::dragLeaveEvent(event
);
89 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
91 setDirtyRegion(m_dropRect
);
94 void SidebarTreeView::dragMoveEvent(QDragMoveEvent
* event
)
96 QTreeView::dragMoveEvent(event
);
98 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
99 const QModelIndex index
= indexAt(event
->pos());
100 setDirtyRegion(m_dropRect
);
101 m_dropRect
= visualRect(index
);
102 setDirtyRegion(m_dropRect
);
105 void SidebarTreeView::dropEvent(QDropEvent
* event
)
107 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
108 if (urls
.isEmpty()) {
109 QTreeView::dropEvent(event
);
111 event
->acceptProposedAction();
112 const QModelIndex index
= indexAt(event
->pos());
113 if (index
.isValid()) {
114 emit
urlsDropped(urls
, index
);
120 void SidebarTreeView::paintEvent(QPaintEvent
* event
)
122 QTreeView::paintEvent(event
);
124 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
126 const QBrush
& brush
= palette().brush(QPalette::Normal
, QPalette::Highlight
);
127 DolphinController::drawHoverIndication(viewport(), m_dropRect
, brush
);
131 #include "sidebartreeview.moc"