]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphincontroller.h
Allow showing additional information like type, size and date in parallel for the...
[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 <QtCore/QObject>
26 #include <libdolphin_export.h>
27
28 class KUrl;
29 class QBrush;
30 class QModelIndex;
31 class QPoint;
32 class QRect;
33 class QWidget;
34
35 /**
36 * @brief Allows to control Dolphin views and to react on state changes.
37 *
38 * One instance of a DolphinController can be assigned to a variable number of
39 * Dolphin views (DolphinIconsView, DolphinDetailsView) by passing it in
40 * the constructor:
41 *
42 * \code
43 * DolphinController* controller = new DolphinController(parent);
44 * DolphinDetailsView* detailsView = new DolphinDetailsView(parent, controller);
45 * DolphinIconsView* iconsView = new DolphinIconsView(parent, controller);
46 * \endcode
47 *
48 * The Dolphin view assures that the controller gets informed about selection changes,
49 * when an item should be triggered and a lot more. The controller emits the corresponding signals
50 * so that the receiver may react on those changes.
51 */
52 class LIBDOLPHINPRIVATE_EXPORT DolphinController : public QObject
53 {
54 Q_OBJECT
55
56 public:
57 explicit DolphinController(QObject* parent);
58 virtual ~DolphinController();
59
60 /** Sets the URL to \a url and emits the signal urlChanged(). */
61 void setUrl(const KUrl& url);
62 const KUrl& url() const;
63
64 void triggerContextMenuRequest(const QPoint& pos);
65
66 void triggerActivation();
67
68 void indicateDroppedUrls(const KUrl::List& urls,
69 const KUrl& destPath,
70 const QModelIndex& destIndex,
71 QWidget* source);
72
73 void indicateSortingChange(DolphinView::Sorting sorting);
74
75 void indicateSortOrderChange(Qt::SortOrder order);
76
77 void setShowPreview(bool show);
78 bool showPreview() const;
79
80 void setAdditionalInfoCount(int count);
81 bool additionalInfoCount() const;
82
83 void triggerZoomIn();
84 void setZoomInPossible(bool possible);
85 bool isZoomInPossible() const;
86
87 void triggerZoomOut();
88 void setZoomOutPossible(bool possible);
89 bool isZoomOutPossible() const;
90
91 // TODO: remove this method when the issue #160611 is solved in Qt 4.4
92 static void drawHoverIndication(QWidget* widget,
93 const QRect& bounds,
94 const QBrush& brush);
95
96 public slots:
97 /**
98 * Emits the signal itemTriggered(). The method should be invoked by the
99 * controller parent whenever the user has triggered an item. */
100 void triggerItem(const QModelIndex& index);
101
102 /**
103 * Emits the signal itemEntered(). The method should be invoked by
104 * the controller parent whenever the mouse cursor is above an item.
105 */
106 void emitItemEntered(const QModelIndex& index);
107
108 /**
109 * Emits the signal viewportEntered(). The method should be invoked by
110 * the controller parent whenever the mouse cursor is above the viewport.
111 */
112 void emitViewportEntered();
113
114 signals:
115 /**
116 * Is emitted if the URL for the Dolphin controller has been changed
117 * to \a url.
118 */
119 void urlChanged(const KUrl& url);
120
121 /**
122 * Is emitted if a context menu should be opened.
123 * @param pos Position relative to the view widget where the
124 * context menu should be opened. It is recommended
125 * to get the corresponding model index from
126 * this position.
127 */
128 void requestContextMenu(const QPoint& pos);
129
130 /**
131 * Is emitted if the view has been activated by e. g. a mouse click.
132 */
133 void activated();
134
135 /**
136 * Is emitted if the URLs \a urls have been dropped to the destination
137 * path \a destPath. If the URLs have been dropped above an item of
138 * the destination path, the item is indicated by \a destIndex.
139 * \a source indicates the widget where the dragging has been started from.
140 */
141 void urlsDropped(const KUrl::List& urls,
142 const KUrl& destPath,
143 const QModelIndex& destIndex,
144 QWidget* source);
145
146 /** Is emitted if the sorting has been changed to \a sorting. */
147 void sortingChanged(DolphinView::Sorting sorting);
148
149 /** Is emitted if the sort order has been changed to \a sort order. */
150 void sortOrderChanged(Qt::SortOrder order);
151
152 /**
153 * Is emitted if the state for showing previews has been
154 * changed to \a show.
155 */
156 void showPreviewChanged(bool show);
157
158 /**
159 * Is emitted if the number of additional informations has been
160 * changed to \a count.
161 */
162 void additionalInfoCountChanged(int count);
163
164 /**
165 * Is emitted if the item with the index \a index should be triggered.
166 * Usually triggering on a directory opens the directory, triggering
167 * on a file opens the corresponding application.
168 * Emitted with an invalid \a index when clicking on the viewport itself.
169 */
170 void itemTriggered(const QModelIndex& index);
171
172 /**
173 * Is emitted if the mouse cursor has entered the item
174 * given by \a index.
175 */
176 void itemEntered(const QModelIndex& index);
177
178 /**
179 * Is emitted if the mouse cursor has entered
180 * the viewport. */
181 void viewportEntered();
182
183 /** Is emitted if the view should zoom in. */
184 void zoomIn();
185
186 /** Is emitted if the view should zoom out. */
187 void zoomOut();
188
189 private:
190 bool m_showPreview;
191 bool m_zoomInPossible;
192 bool m_zoomOutPossible;
193 int m_additionalInfoCount;
194 KUrl m_url;
195 };
196
197 inline const KUrl& DolphinController::url() const
198 {
199 return m_url;
200 }
201
202 inline bool DolphinController::showPreview() const
203 {
204 return m_showPreview;
205 }
206
207 inline bool DolphinController::additionalInfoCount() const
208 {
209 return m_additionalInfoCount;
210 }
211
212 inline void DolphinController::setZoomInPossible(bool possible)
213 {
214 m_zoomInPossible = possible;
215 }
216
217 inline bool DolphinController::isZoomInPossible() const
218 {
219 return m_zoomInPossible;
220 }
221
222 inline void DolphinController::setZoomOutPossible(bool possible)
223 {
224 m_zoomOutPossible = possible;
225 }
226
227 inline bool DolphinController::isZoomOutPossible() const
228 {
229 return m_zoomOutPossible;
230 }
231
232 #endif