1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz19@gmail.com> *
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 <KFileItemDelegate>
26 #include <QHeaderView>
29 PanelTreeView::PanelTreeView(QWidget
* parent
) :
33 setUniformRowHeights(true);
34 setSelectionMode(QAbstractItemView::SingleSelection
);
35 setEditTriggers(QAbstractItemView::NoEditTriggers
);
36 setSortingEnabled(true);
37 setFrameStyle(QFrame::NoFrame
);
38 setDragDropMode(QAbstractItemView::DragDrop
);
39 setDropIndicatorShown(false);
41 setVerticalScrollMode(QListView::ScrollPerPixel
);
42 setHorizontalScrollMode(QListView::ScrollPerPixel
);
44 viewport()->setAttribute(Qt::WA_Hover
);
46 // make the background transparent and apply the window-text color
47 // to the text color, so that enough contrast is given for all color
49 QPalette p
= palette();
50 p
.setColor(QPalette::Active
, QPalette::Text
, p
.color(QPalette::Active
, QPalette::WindowText
));
51 p
.setColor(QPalette::Inactive
, QPalette::Text
, p
.color(QPalette::Inactive
, QPalette::WindowText
));
52 p
.setColor(QPalette::Disabled
, QPalette::Text
, p
.color(QPalette::Disabled
, QPalette::WindowText
));
54 viewport()->setAutoFillBackground(false);
56 KFileItemDelegate
* delegate
= new KFileItemDelegate(this);
57 setItemDelegate(delegate
);
60 PanelTreeView::~PanelTreeView()
64 bool PanelTreeView::event(QEvent
* event
)
66 switch (event
->type()) {
68 // Hide all columns except of the 'Name' column
69 /*for (int i = DolphinModel::Name + 1; i < DolphinModel::ExtraColumnCount; ++i) {
76 // TODO: The opening/closing animation of subtrees flickers in combination with the
77 // panel when using the Oxygen style. As workaround the animation is turned off:
81 case QEvent::UpdateRequest
:
82 // a wheel movement will scroll 1 item
83 if (model()->rowCount() > 0) {
84 verticalScrollBar()->setSingleStep(sizeHintForRow(0) / 3);
92 return KTreeView::event(event
);
95 void PanelTreeView::startDrag(Qt::DropActions supportedActions
)
97 Q_UNUSED(supportedActions
);
98 //DragAndDropHelper::instance().startDrag(this, supportedActions);
101 void PanelTreeView::dragEnterEvent(QDragEnterEvent
* event
)
103 KTreeView::dragEnterEvent(event
);
104 if (event
->mimeData()->hasUrls()) {
105 event
->acceptProposedAction();
109 void PanelTreeView::dragLeaveEvent(QDragLeaveEvent
* event
)
111 KTreeView::dragLeaveEvent(event
);
112 setDirtyRegion(m_dropRect
);
115 void PanelTreeView::dragMoveEvent(QDragMoveEvent
* event
)
117 KTreeView::dragMoveEvent(event
);
119 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
120 const QModelIndex index
= indexAt(event
->pos());
121 setDirtyRegion(m_dropRect
);
122 m_dropRect
= visualRect(index
);
123 setDirtyRegion(m_dropRect
);
125 if (event
->mimeData()->hasUrls()) {
126 // accept url drops, independently from the destination item
127 event
->acceptProposedAction();
131 void PanelTreeView::dropEvent(QDropEvent
* event
)
133 const QModelIndex index
= indexAt(event
->pos());
134 if (index
.isValid()) {
135 emit
urlsDropped(index
, event
);
137 KTreeView::dropEvent(event
);
140 #include "paneltreeview.moc"