]>
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 "dolphinmainwindow.h"
24 #include "dolphinsortfilterproxymodel.h"
25 #include "dolphinview.h"
26 #include "viewproperties.h"
29 #include <kdirmodel.h>
30 #include <QHeaderView>
32 DolphinDetailsView::DolphinDetailsView(DolphinView
* parent
) :
39 setRootIsDecorated(false);
40 setSortingEnabled(true);
41 setUniformRowHeights(true);
43 const ViewProperties
props(parent
->url());
44 setSortIndicatorSection(props
.sorting());
45 setSortIndicatorOrder(props
.sortOrder());
47 connect(header(), SIGNAL(sectionClicked(int)),
48 this, SLOT(synchronizeSortingState(int)));
50 connect(parent
, SIGNAL(sortingChanged(DolphinView::Sorting
)),
51 this, SLOT(setSortIndicatorSection(DolphinView::Sorting
)));
52 connect(parent
, SIGNAL(sortOrderChanged(Qt::SortOrder
)),
53 this, SLOT(setSortIndicatorOrder(Qt::SortOrder
)));
56 DolphinDetailsView::~DolphinDetailsView()
60 bool DolphinDetailsView::event(QEvent
* event
)
62 if (event
->type() == QEvent::Polish
) {
63 // Assure that by respecting the available width that:
64 // - the 'Name' column is stretched as large as possible
65 // - the remaining columns are as small as possible
66 QHeaderView
* headerView
= header();
67 headerView
->setStretchLastSection(false);
68 headerView
->setResizeMode(QHeaderView::ResizeToContents
);
69 headerView
->setResizeMode(0, QHeaderView::Stretch
);
72 return QTreeView::event(event
);
74 QStyleOptionViewItem
DolphinDetailsView::viewOptions() const
76 return QTreeView::viewOptions();
78 // TODO: the view options should been read from the settings;
79 // the following code is just for testing...
80 //QStyleOptionViewItem options = QTreeView::viewOptions();
81 //options.decorationAlignment = Qt::AlignRight;
82 //options.decorationPosition = QStyleOptionViewItem::Right;
83 //options.decorationSize = QSize(100, 100);
84 //options.showDecorationSelected = true;
85 //options.state = QStyle::State_MouseOver;
89 void DolphinDetailsView::contextMenuEvent(QContextMenuEvent
* event
)
91 QTreeView::contextMenuEvent(event
);
95 const QModelIndex index
= indexAt(event
->pos());
96 if (index
.isValid()) {
97 item
= m_dolphinView
->fileItem(index
);
100 m_dolphinView
->openContextMenu(item
, event
->globalPos());
103 void DolphinDetailsView::mouseReleaseEvent(QMouseEvent
* event
)
105 QTreeView::mouseReleaseEvent(event
);
106 m_dolphinView
->declareViewActive();
109 void DolphinDetailsView::dragEnterEvent(QDragEnterEvent
* event
)
111 if (event
->mimeData()->hasUrls()) {
112 event
->acceptProposedAction();
116 void DolphinDetailsView::dropEvent(QDropEvent
* event
)
118 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
119 if (!urls
.isEmpty()) {
120 event
->acceptProposedAction();
122 // TODO: handle dropping above a directory
124 const KUrl
& destination
= m_dolphinView
->url();
125 m_dolphinView
->mainWindow()->dropUrls(urls
, destination
);
129 void DolphinDetailsView::setSortIndicatorSection(DolphinView::Sorting sorting
)
131 QHeaderView
* headerView
= header();
132 headerView
->setSortIndicator(sorting
, headerView
->sortIndicatorOrder());
135 void DolphinDetailsView::setSortIndicatorOrder(Qt::SortOrder sortOrder
)
137 QHeaderView
* headerView
= header();
138 headerView
->setSortIndicator(headerView
->sortIndicatorSection(), sortOrder
);
141 void DolphinDetailsView::synchronizeSortingState(int column
)
143 // The sorting has already been changed in QTreeView if this slot is
144 // invoked, but Dolphin was not informed about this. This is bypassed by changing
145 // the sorting and sort order to a temporary other value and readjust it again.
146 DolphinView::Sorting sorting
= DolphinSortFilterProxyModel::sortingForColumn(column
);
147 const Qt::SortOrder sortOrder
= header()->sortIndicatorOrder();
149 // temporary adjust the sorting and sort order to different values...
150 const DolphinView::Sorting tempSorting
= (sorting
== DolphinView::SortByName
) ?
151 DolphinView::SortBySize
:
152 DolphinView::SortByName
;
153 m_dolphinView
->setSorting(tempSorting
);
154 const Qt::SortOrder tempSortOrder
= (sortOrder
== Qt::Ascending
) ?
155 Qt::Descending
: Qt::Ascending
;
156 m_dolphinView
->setSortOrder(tempSortOrder
);
158 // ... so that setting them again results in storing the new setting.
159 m_dolphinView
->setSorting(sorting
);
160 m_dolphinView
->setSortOrder(sortOrder
);
163 #include "dolphindetailsview.moc"