]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphindetailsview.cpp
Reanimated drag & drop support again after introducing the DolphinController. It...
[dolphin.git] / src / dolphindetailsview.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz *
3 * peter.penz@gmx.at *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
20
21 #include "dolphindetailsview.h"
22
23 #include "dolphincontroller.h"
24 #include "dolphinsortfilterproxymodel.h"
25 #include "viewproperties.h"
26
27 #include <assert.h>
28 #include <kdirmodel.h>
29 #include <QHeaderView>
30
31 DolphinDetailsView::DolphinDetailsView(QWidget* parent, DolphinController* controller) :
32 QTreeView(parent),
33 m_controller(controller)
34 {
35 assert(controller != 0);
36
37 setAcceptDrops(true);
38 setRootIsDecorated(false);
39 setSortingEnabled(true);
40 setUniformRowHeights(true);
41
42 const ViewProperties props(controller->url());
43 setSortIndicatorSection(props.sorting());
44 setSortIndicatorOrder(props.sortOrder());
45
46 connect(header(), SIGNAL(sectionClicked(int)),
47 this, SLOT(synchronizeSortingState(int)));
48
49 connect(parent, SIGNAL(sortingChanged(DolphinView::Sorting)),
50 this, SLOT(setSortIndicatorSection(DolphinView::Sorting)));
51 connect(parent, SIGNAL(sortOrderChanged(Qt::SortOrder)),
52 this, SLOT(setSortIndicatorOrder(Qt::SortOrder)));
53
54 connect(this, SIGNAL(clicked(const QModelIndex&)),
55 controller, SLOT(triggerItem(const QModelIndex&)));
56 }
57
58 DolphinDetailsView::~DolphinDetailsView()
59 {
60 }
61
62 bool DolphinDetailsView::event(QEvent* event)
63 {
64 if (event->type() == QEvent::Polish) {
65 // Assure that by respecting the available width that:
66 // - the 'Name' column is stretched as large as possible
67 // - the remaining columns are as small as possible
68 QHeaderView* headerView = header();
69 headerView->setStretchLastSection(false);
70 headerView->setResizeMode(QHeaderView::ResizeToContents);
71 headerView->setResizeMode(0, QHeaderView::Stretch);
72 }
73
74 return QTreeView::event(event);
75 }
76 QStyleOptionViewItem DolphinDetailsView::viewOptions() const
77 {
78 return QTreeView::viewOptions();
79
80 // TODO: the view options should been read from the settings;
81 // the following code is just for testing...
82 //QStyleOptionViewItem options = QTreeView::viewOptions();
83 //options.decorationAlignment = Qt::AlignRight;
84 //options.decorationPosition = QStyleOptionViewItem::Right;
85 //options.decorationSize = QSize(100, 100);
86 //options.showDecorationSelected = true;
87 //options.state = QStyle::State_MouseOver;
88 //return options;
89 }
90
91 void DolphinDetailsView::contextMenuEvent(QContextMenuEvent* event)
92 {
93 QTreeView::contextMenuEvent(event);
94 m_controller->triggerContextMenuRequest(event->pos());
95 }
96
97 void DolphinDetailsView::mouseReleaseEvent(QMouseEvent* event)
98 {
99 QTreeView::mouseReleaseEvent(event);
100 m_controller->triggerActivation();
101 }
102
103 void DolphinDetailsView::dragEnterEvent(QDragEnterEvent* event)
104 {
105 if (event->mimeData()->hasUrls()) {
106 event->acceptProposedAction();
107 }
108 }
109
110 void DolphinDetailsView::dropEvent(QDropEvent* event)
111 {
112 const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
113 if (urls.isEmpty() || (event->source() == this)) {
114 QTreeView::dropEvent(event);
115 }
116 else {
117 event->acceptProposedAction();
118 m_controller->indicateDroppedUrls(urls, event->pos());
119 }
120 }
121
122 void DolphinDetailsView::setSortIndicatorSection(DolphinView::Sorting sorting)
123 {
124 QHeaderView* headerView = header();
125 headerView->setSortIndicator(sorting, headerView->sortIndicatorOrder());
126 }
127
128 void DolphinDetailsView::setSortIndicatorOrder(Qt::SortOrder sortOrder)
129 {
130 QHeaderView* headerView = header();
131 headerView->setSortIndicator(headerView->sortIndicatorSection(), sortOrder);
132 }
133
134 void DolphinDetailsView::synchronizeSortingState(int column)
135 {
136 // The sorting has already been changed in QTreeView if this slot is
137 // invoked, but Dolphin is not informed about this.
138 DolphinView::Sorting sorting = DolphinSortFilterProxyModel::sortingForColumn(column);
139 const Qt::SortOrder sortOrder = header()->sortIndicatorOrder();
140 m_controller->indicateSortingChange(sorting);
141 m_controller->indicateSortOrderChange(sortOrder);
142 }
143
144 #include "dolphindetailsview.moc"