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 "paneltreeview.h"
22 #include "dolphinviewcontroller.h"
23 #include "dolphinmodel.h"
24 #include "draganddrophelper.h"
25 #include "viewmodecontroller.h"
27 #include <kfileitemdelegate.h>
30 #include <QHeaderView>
33 PanelTreeView::PanelTreeView(QWidget
* parent
) :
37 setUniformRowHeights(true);
38 setSelectionMode(QAbstractItemView::SingleSelection
);
39 setEditTriggers(QAbstractItemView::NoEditTriggers
);
40 setSortingEnabled(true);
41 setFrameStyle(QFrame::NoFrame
);
42 setDragDropMode(QAbstractItemView::DragDrop
);
43 setDropIndicatorShown(false);
45 setVerticalScrollMode(QListView::ScrollPerPixel
);
46 setHorizontalScrollMode(QListView::ScrollPerPixel
);
48 viewport()->setAttribute(Qt::WA_Hover
);
50 // make the background transparent and apply the window-text color
51 // to the text color, so that enough contrast is given for all color
53 QPalette p
= palette();
54 p
.setColor(QPalette::Active
, QPalette::Text
, p
.color(QPalette::Active
, QPalette::WindowText
));
55 p
.setColor(QPalette::Inactive
, QPalette::Text
, p
.color(QPalette::Inactive
, QPalette::WindowText
));
56 p
.setColor(QPalette::Disabled
, QPalette::Text
, p
.color(QPalette::Disabled
, QPalette::WindowText
));
58 viewport()->setAutoFillBackground(false);
60 KFileItemDelegate
* delegate
= new KFileItemDelegate(this);
61 setItemDelegate(delegate
);
64 PanelTreeView::~PanelTreeView()
68 bool PanelTreeView::event(QEvent
* event
)
70 switch (event
->type()) {
72 // Hide all columns except of the 'Name' column
73 for (int i
= DolphinModel::Name
+ 1; i
< DolphinModel::ExtraColumnCount
; ++i
) {
80 // TODO: The opening/closing animation of subtrees flickers in combination with the
81 // panel when using the Oxygen style. As workaround the animation is turned off:
85 case QEvent::UpdateRequest
:
86 // a wheel movement will scroll 1 item
87 if (model()->rowCount() > 0) {
88 verticalScrollBar()->setSingleStep(sizeHintForRow(0) / 3);
96 return KTreeView::event(event
);
99 void PanelTreeView::startDrag(Qt::DropActions supportedActions
)
101 DragAndDropHelper::instance().startDrag(this, supportedActions
);
104 void PanelTreeView::dragEnterEvent(QDragEnterEvent
* event
)
106 KTreeView::dragEnterEvent(event
);
107 if (event
->mimeData()->hasUrls()) {
108 event
->acceptProposedAction();
112 void PanelTreeView::dragLeaveEvent(QDragLeaveEvent
* event
)
114 KTreeView::dragLeaveEvent(event
);
115 setDirtyRegion(m_dropRect
);
118 void PanelTreeView::dragMoveEvent(QDragMoveEvent
* event
)
120 KTreeView::dragMoveEvent(event
);
122 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
123 const QModelIndex index
= indexAt(event
->pos());
124 setDirtyRegion(m_dropRect
);
125 m_dropRect
= visualRect(index
);
126 setDirtyRegion(m_dropRect
);
128 if (event
->mimeData()->hasUrls()) {
129 // accept url drops, independently from the destination item
130 event
->acceptProposedAction();
134 void PanelTreeView::dropEvent(QDropEvent
* event
)
136 const QModelIndex index
= indexAt(event
->pos());
137 if (index
.isValid()) {
138 emit
urlsDropped(index
, event
);
140 KTreeView::dropEvent(event
);
143 #include "paneltreeview.moc"