]>
cloud.milkyroute.net Git - dolphin.git/blob - src/dolphindetailsview.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz *
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. *
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. *
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 ***************************************************************************/
21 #include "dolphindetailsview.h"
23 #include "dolphincontroller.h"
24 #include "dolphinsortfilterproxymodel.h"
25 #include "viewproperties.h"
28 #include <kdirmodel.h>
29 #include <QHeaderView>
31 DolphinDetailsView::DolphinDetailsView(QWidget
* parent
, DolphinController
* controller
) :
33 m_controller(controller
)
35 assert(controller
!= 0);
38 setRootIsDecorated(false);
39 setSortingEnabled(true);
40 setUniformRowHeights(true);
42 const ViewProperties
props(controller
->url());
43 setSortIndicatorSection(props
.sorting());
44 setSortIndicatorOrder(props
.sortOrder());
46 connect(header(), SIGNAL(sectionClicked(int)),
47 this, SLOT(synchronizeSortingState(int)));
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
)));
54 connect(this, SIGNAL(clicked(const QModelIndex
&)),
55 controller
, SLOT(triggerItem(const QModelIndex
&)));
58 DolphinDetailsView::~DolphinDetailsView()
62 bool DolphinDetailsView::event(QEvent
* event
)
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
);
74 return QTreeView::event(event
);
76 QStyleOptionViewItem
DolphinDetailsView::viewOptions() const
78 return QTreeView::viewOptions();
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;
91 void DolphinDetailsView::contextMenuEvent(QContextMenuEvent
* event
)
93 QTreeView::contextMenuEvent(event
);
94 m_controller
->triggerContextMenuRequest(event
->pos());
97 void DolphinDetailsView::mouseReleaseEvent(QMouseEvent
* event
)
99 QTreeView::mouseReleaseEvent(event
);
100 m_controller
->triggerActivation();
103 void DolphinDetailsView::dragEnterEvent(QDragEnterEvent
* event
)
105 if (event
->mimeData()->hasUrls()) {
106 event
->acceptProposedAction();
110 void DolphinDetailsView::dropEvent(QDropEvent
* event
)
112 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
113 if (urls
.isEmpty() || (event
->source() == this)) {
114 QTreeView::dropEvent(event
);
117 event
->acceptProposedAction();
118 m_controller
->indicateDroppedUrls(urls
, event
->pos());
122 void DolphinDetailsView::setSortIndicatorSection(DolphinView::Sorting sorting
)
124 QHeaderView
* headerView
= header();
125 headerView
->setSortIndicator(sorting
, headerView
->sortIndicatorOrder());
128 void DolphinDetailsView::setSortIndicatorOrder(Qt::SortOrder sortOrder
)
130 QHeaderView
* headerView
= header();
131 headerView
->setSortIndicator(headerView
->sortIndicatorSection(), sortOrder
);
134 void DolphinDetailsView::synchronizeSortingState(int column
)
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
);
144 #include "dolphindetailsview.moc"