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 "dolphincontroller.h"
23 #include "dolphinmodel.h"
24 #include "draganddrophelper.h"
26 #include <kfileitemdelegate.h>
29 #include <QHeaderView>
32 PanelTreeView::PanelTreeView(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 // make the background transparent and apply the window-text color
50 // to the text color, so that enough contrast is given for all color
52 QPalette p
= palette();
53 p
.setColor(QPalette::Active
, QPalette::Text
, p
.color(QPalette::Active
, QPalette::WindowText
));
54 p
.setColor(QPalette::Inactive
, QPalette::Text
, p
.color(QPalette::Inactive
, QPalette::WindowText
));
55 p
.setColor(QPalette::Disabled
, QPalette::Text
, p
.color(QPalette::Disabled
, QPalette::WindowText
));
57 viewport()->setAutoFillBackground(false);
59 KFileItemDelegate
* delegate
= new KFileItemDelegate(this);
60 setItemDelegate(delegate
);
63 PanelTreeView::~PanelTreeView()
67 bool PanelTreeView::event(QEvent
* event
)
69 switch (event
->type()) {
71 // hide all columns except of the 'Name' column
72 hideColumn(DolphinModel::Size
);
73 hideColumn(DolphinModel::ModifiedTime
);
74 hideColumn(DolphinModel::Permissions
);
75 hideColumn(DolphinModel::Owner
);
76 hideColumn(DolphinModel::Group
);
77 hideColumn(DolphinModel::Type
);
78 hideColumn(DolphinModel::Rating
);
79 hideColumn(DolphinModel::Tags
);
84 // TODO: The opening/closing animation of subtrees flickers in combination with the
85 // panel when using the Oxygen style. As workaround the animation is turned off:
89 case QEvent::UpdateRequest
:
90 // a wheel movement will scroll 1 item
91 if (model()->rowCount() > 0) {
92 verticalScrollBar()->setSingleStep(sizeHintForRow(0) / 3);
100 return KTreeView::event(event
);
103 void PanelTreeView::startDrag(Qt::DropActions supportedActions
)
105 DragAndDropHelper::instance().startDrag(this, supportedActions
);
108 void PanelTreeView::dragEnterEvent(QDragEnterEvent
* event
)
110 KTreeView::dragEnterEvent(event
);
111 if (event
->mimeData()->hasUrls()) {
112 event
->acceptProposedAction();
116 void PanelTreeView::dragLeaveEvent(QDragLeaveEvent
* event
)
118 KTreeView::dragLeaveEvent(event
);
119 setDirtyRegion(m_dropRect
);
122 void PanelTreeView::dragMoveEvent(QDragMoveEvent
* event
)
124 KTreeView::dragMoveEvent(event
);
126 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
127 const QModelIndex index
= indexAt(event
->pos());
128 setDirtyRegion(m_dropRect
);
129 m_dropRect
= visualRect(index
);
130 setDirtyRegion(m_dropRect
);
132 if (event
->mimeData()->hasUrls()) {
133 // accept url drops, independently from the destination item
134 event
->acceptProposedAction();
138 void PanelTreeView::dropEvent(QDropEvent
* event
)
140 const QModelIndex index
= indexAt(event
->pos());
141 if (index
.isValid()) {
142 emit
urlsDropped(index
, event
);
144 KTreeView::dropEvent(event
);
147 #include "paneltreeview.moc"