]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphindetailsview.cpp
Do a custom error handling in for the 'Create New...' submenu. Thanks to David for...
[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 #include "dolphinmainwindow.h"
23 #include "dolphinview.h"
24
25 #include <QHeaderView>
26
27 DolphinDetailsView::DolphinDetailsView(DolphinView* parent) :
28 QTreeView(parent),
29 m_parentView(parent)
30 {
31 setAcceptDrops(true);
32 setRootIsDecorated(false);
33 setSortingEnabled(true);
34 setUniformRowHeights(true);
35 }
36
37 DolphinDetailsView::~DolphinDetailsView()
38 {
39 }
40
41 bool DolphinDetailsView::event(QEvent* event)
42 {
43 if (event->type() == QEvent::Polish) {
44 // Assure that by respecting the available width that:
45 // - the 'Name' column is stretched as large as possible
46 // - the remaining columns are as small as possible
47 QHeaderView* headerView = header();
48 headerView->setStretchLastSection(false);
49 headerView->setResizeMode(QHeaderView::ResizeToContents);
50 headerView->setResizeMode(0, QHeaderView::Stretch);
51 }
52
53 return QTreeView::event(event);
54 }
55 QStyleOptionViewItem DolphinDetailsView::viewOptions() const
56 {
57 return QTreeView::viewOptions();
58
59 // TODO: the view options should been read from the settings;
60 // the following code is just for testing...
61 //QStyleOptionViewItem options = QTreeView::viewOptions();
62 //options.decorationAlignment = Qt::AlignRight;
63 //options.decorationPosition = QStyleOptionViewItem::Right;
64 //options.decorationSize = QSize(100, 100);
65 //options.showDecorationSelected = true;
66 //options.state = QStyle::State_MouseOver;
67 //return options;
68 }
69
70 void DolphinDetailsView::contextMenuEvent(QContextMenuEvent* event)
71 {
72 QTreeView::contextMenuEvent(event);
73
74 KFileItem* item = 0;
75
76 const QModelIndex index = indexAt(event->pos());
77 if (index.isValid()) {
78 item = m_parentView->fileItem(index);
79 }
80
81 m_parentView->openContextMenu(item, event->globalPos());
82 }
83
84 void DolphinDetailsView::mouseReleaseEvent(QMouseEvent* event)
85 {
86 QTreeView::mouseReleaseEvent(event);
87 m_parentView->declareViewActive();
88 }
89
90 void DolphinDetailsView::dragEnterEvent(QDragEnterEvent* event)
91 {
92 if (event->mimeData()->hasUrls()) {
93 event->acceptProposedAction();
94 }
95 }
96
97 void DolphinDetailsView::dropEvent(QDropEvent* event)
98 {
99 const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
100 if (!urls.isEmpty()) {
101 event->acceptProposedAction();
102
103 // TODO: handle dropping above a directory
104
105 const KUrl& destination = m_parentView->url();
106 m_parentView->mainWindow()->dropUrls(urls, destination);
107 }
108 }
109
110 #include "dolphindetailsview.moc"