1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
/***************************************************************************
* Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#include "paneltreeview.h"
#include "dolphincontroller.h"
#include "dolphinmodel.h"
#include "draganddrophelper.h"
#include <kfileitemdelegate.h>
#include <QKeyEvent>
#include <QPainter>
#include <QHeaderView>
#include <QScrollBar>
PanelTreeView::PanelTreeView(QWidget* parent) :
KTreeView(parent)
{
setAcceptDrops(true);
setUniformRowHeights(true);
setSelectionMode(QAbstractItemView::SingleSelection);
setEditTriggers(QAbstractItemView::NoEditTriggers);
setSortingEnabled(true);
setFrameStyle(QFrame::NoFrame);
setDragDropMode(QAbstractItemView::DragDrop);
setDropIndicatorShown(false);
setVerticalScrollMode(QListView::ScrollPerPixel);
setHorizontalScrollMode(QListView::ScrollPerPixel);
viewport()->setAttribute(Qt::WA_Hover);
// make the background transparent and apply the window-text color
// to the text color, so that enough contrast is given for all color
// schemes
QPalette p = palette();
p.setColor(QPalette::Active, QPalette::Text, p.color(QPalette::Active, QPalette::WindowText));
p.setColor(QPalette::Inactive, QPalette::Text, p.color(QPalette::Inactive, QPalette::WindowText));
p.setColor(QPalette::Disabled, QPalette::Text, p.color(QPalette::Disabled, QPalette::WindowText));
setPalette(p);
viewport()->setAutoFillBackground(false);
KFileItemDelegate* delegate = new KFileItemDelegate(this);
setItemDelegate(delegate);
}
PanelTreeView::~PanelTreeView()
{
}
bool PanelTreeView::event(QEvent* event)
{
switch (event->type()) {
case QEvent::Polish:
// hide all columns except of the 'Name' column
hideColumn(DolphinModel::Size);
hideColumn(DolphinModel::ModifiedTime);
hideColumn(DolphinModel::Permissions);
hideColumn(DolphinModel::Owner);
hideColumn(DolphinModel::Group);
hideColumn(DolphinModel::Type);
hideColumn(DolphinModel::Version);
header()->hide();
break;
case QEvent::Show:
// TODO: The opening/closing animation of subtrees flickers in combination with the
// panel when using the Oxygen style. As workaround the animation is turned off:
setAnimated(false);
break;
case QEvent::UpdateRequest:
// a wheel movement will scroll 1 item
if (model()->rowCount() > 0) {
verticalScrollBar()->setSingleStep(sizeHintForRow(0) / 3);
}
break;
default:
break;
}
return KTreeView::event(event);
}
void PanelTreeView::startDrag(Qt::DropActions supportedActions)
{
DragAndDropHelper::instance().startDrag(this, supportedActions);
}
void PanelTreeView::dragEnterEvent(QDragEnterEvent* event)
{
KTreeView::dragEnterEvent(event);
if (event->mimeData()->hasUrls()) {
event->acceptProposedAction();
}
}
void PanelTreeView::dragLeaveEvent(QDragLeaveEvent* event)
{
KTreeView::dragLeaveEvent(event);
setDirtyRegion(m_dropRect);
}
void PanelTreeView::dragMoveEvent(QDragMoveEvent* event)
{
KTreeView::dragMoveEvent(event);
// TODO: remove this code when the issue #160611 is solved in Qt 4.4
const QModelIndex index = indexAt(event->pos());
setDirtyRegion(m_dropRect);
m_dropRect = visualRect(index);
setDirtyRegion(m_dropRect);
if (event->mimeData()->hasUrls()) {
// accept url drops, independently from the destination item
event->acceptProposedAction();
}
}
void PanelTreeView::dropEvent(QDropEvent* event)
{
const QModelIndex index = indexAt(event->pos());
if (index.isValid()) {
emit urlsDropped(index, event);
}
KTreeView::dropEvent(event);
}
#include "paneltreeview.moc"
|