]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphincontroller.h
Fixed some drag & drop issues:
[dolphin.git] / src / dolphincontroller.h
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
19
20 #ifndef DOLPHINCONTROLLER_H
21 #define DOLPHINCONTROLLER_H
22
23 #include <dolphinview.h>
24 #include <kurl.h>
25 #include <QObject>
26
27 class KUrl;
28 class QModelIndex;
29 class QPoint;
30
31 /**
32 * @brief Allows to control Dolphin views and to react on state changes.
33 *
34 * One instance of a DolphinController can be assigned to a variable number of
35 * Dolphin views (DolphinIconsView, DolphinDetailsView) by passing it in
36 * the constructor:
37 *
38 * \code
39 * DolphinController* controller = new DolphinController(parent);
40 * DolphinDetailsView* detailsView = new DolphinDetailsView(parent, controller);
41 * DolphinIconsView* iconsView = new DolphinIconsView(parent, controller);
42 * \endcode
43 *
44 * The Dolphin view assures that the controller gets informed about selection changes,
45 * when an item should be triggered and a lot more. The controller emits the corresponding signals
46 * so that the receiver may react on those changes.
47 */
48 class DolphinController : public QObject
49 {
50 Q_OBJECT
51
52 public:
53 explicit DolphinController(QObject* parent);
54 virtual ~DolphinController();
55
56 void setUrl(const KUrl& url) { m_url = url; }
57 const KUrl& url() const { return m_url; }
58
59 void triggerContextMenuRequest(const QPoint& pos);
60
61 void triggerActivation();
62
63 void indicateDroppedUrls(const KUrl::List& urls,
64 const QModelIndex& index,
65 QWidget* source);
66
67 void indicateSortingChange(DolphinView::Sorting sorting);
68
69 void indicateSortOrderChange(Qt::SortOrder order);
70
71 void setShowPreview(bool showPreview);
72 bool showPreview() const { return m_showPreview; }
73
74 void triggerZoomIn();
75 void setZoomInPossible(bool possible) { m_zoomInPossible = possible; }
76 bool isZoomInPossible() const { return m_zoomInPossible; }
77
78 void triggerZoomOut();
79 void setZoomOutPossible(bool possible) { m_zoomOutPossible = possible; }
80 bool isZoomOutPossible() const { return m_zoomOutPossible; }
81
82 public slots:
83 void triggerItem(const QModelIndex& index);
84 void indicateSelectionChange();
85
86 signals:
87 /**
88 * Is emitted if a context menu should be opened.
89 * @param pos Position relative to the view widget where the
90 * context menu should be opened. It is recommended
91 * to get the corresponding model index from
92 * this position.
93 */
94 void requestContextMenu(const QPoint& pos);
95
96 /**
97 * Is emitted if the view has been activated by e. g. a mouse click.
98 */
99 void activated();
100
101 /**
102 * Is emitted if the URLs \a urls have been dropped to the index
103 * \a index. \a source indicates the widget where the dragging has
104 * been started from.
105 */
106 void urlsDropped(const KUrl::List& urls,
107 const QModelIndex& index,
108 QWidget* source);
109
110 /** Is emitted if the sorting has been changed to \a sorting. */
111 void sortingChanged(DolphinView::Sorting sorting);
112
113 /** Is emitted if the sort order has been changed to \a sort order. */
114 void sortOrderChanged(Qt::SortOrder order);
115
116 /**
117 * Is emitted if the state for showing previews has been
118 * changed to \a showPreview.
119 */
120 void showPreviewChanged(bool showPreview);
121
122 /**
123 * Is emitted if the item with the index \a index should be triggered.
124 * Usually triggering on a directory opens the directory, triggering
125 * on a file opens the corresponding application.
126 */
127 void itemTriggered(const QModelIndex& index);
128
129 /** Is emitted if the selection has been changed by the user. */
130 void selectionChanged();
131
132 /** Is emitted if the view should zoom in. */
133 void zoomIn();
134
135 /** Is emitted if the view should zoom out. */
136 void zoomOut();
137
138 private:
139 bool m_showPreview;
140 bool m_zoomInPossible;
141 bool m_zoomOutPossible;
142 KUrl m_url;
143 };
144
145 #endif