]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphincontroller.h
when clicking with the middle mouse button on a directory, a new tab should be opened
[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 QAbstractItemView;
29 class DolphinView;
30 class KUrl;
31 class QBrush;
32 class QPoint;
33 class QRect;
34 class QWidget;
35
36 // TODO: get rid of all the state duplications in the controller and allow read access
37 // to the Dolphin view for all view implementations
38
39 /**
40 * @brief Acts as mediator between the abstract Dolphin view and the view
41 * implementations.
42 *
43 * The abstract Dolphin view (see DolphinView) represents the parent of the controller.
44 * The lifetime of the controller is equal to the lifetime of the Dolphin view.
45 * The controller is passed to the current view implementation
46 * (see DolphinIconsView, DolphinDetailsView and DolphinColumnView)
47 * by passing it in the constructor and informing the controller about the change
48 * of the view implementation:
49 *
50 * \code
51 * QAbstractItemView* view = new DolphinIconsView(parent, controller);
52 * controller->setItemView(view);
53 * \endcode
54 *
55 * The communication of the view implementations to the abstract view is done by:
56 * - triggerContextMenuRequest()
57 * - requestActivation()
58 * - triggerUrlChangeRequest()
59 * - indicateDroppedUrls()
60 * - indicateSortingChange()
61 * - indicateSortOrderChanged()
62 * - setZoomInPossible()
63 * - setZoomOutPossible()
64 * - triggerItem()
65 * - handleKeyPressEvent()
66 * - emitItemEntered()
67 * - emitViewportEntered()
68 *
69 * The communication of the abstract view to the view implementations is done by:
70 * - setUrl()
71 * - setShowHiddenFiles()
72 * - setShowPreview()
73 * - indicateActivationChange()
74 * - triggerZoomIn()
75 * - triggerZoomOut()
76 */
77 class LIBDOLPHINPRIVATE_EXPORT DolphinController : public QObject
78 {
79 Q_OBJECT
80
81 public:
82 explicit DolphinController(DolphinView* dolphinView);
83 virtual ~DolphinController();
84
85 /**
86 * Allows read access for the the view implementation to the abstract
87 * Dolphin view.
88 */
89 const DolphinView* dolphinView() const;
90
91 /**
92 * Sets the URL to \a url and emits the signal urlChanged() if
93 * \a url is different for the current URL. This method should
94 * be invoked by the abstract Dolphin view whenever the current
95 * URL has been changed.
96 */
97 void setUrl(const KUrl& url);
98 const KUrl& url() const;
99
100 /**
101 * Changes the current item view where the controller is working. This
102 * is only necessary for views like the tree view, where internally
103 * several QAbstractItemView instances are used.
104 */
105 void setItemView(QAbstractItemView* view);
106
107 QAbstractItemView* itemView() const;
108
109 /**
110 * Allows a view implementation to request an URL change to \a url.
111 * The signal requestUrlChange() is emitted and the abstract Dolphin view
112 * will assure that the URL of the Dolphin Controller will be updated
113 * later. Invoking this method makes only sense if the view implementation
114 * shows a hierarchy of URLs and allows to change the URL within
115 * the view (e. g. this is the case in the column view).
116 */
117 void triggerUrlChangeRequest(const KUrl& url);
118
119 /**
120 * Requests a context menu for the position \a pos. This method
121 * should be invoked by the view implementation when a context
122 * menu should be opened. The abstract Dolphin view itself
123 * takes care itself to get the selected items depending from
124 * \a pos.
125 */
126 void triggerContextMenuRequest(const QPoint& pos);
127
128 /**
129 * Requests an activation of the view and emits the signal
130 * activated(). This method should be invoked by the view implementation
131 * if e. g. a mouse click on the view has been done.
132 * After the activation has been changed, the view implementation
133 * might listen to the activationChanged() signal.
134 */
135 void requestActivation();
136
137 /**
138 * Indicates that URLs are dropped above a destination. This method
139 * should be invoked by the view implementation. The abstract Dolphin view
140 * will start the corresponding action (copy, move, link).
141 * @param urls URLs that are dropped above a destination.
142 * @param destPath Path of the destination.
143 * @param destItem Destination item (can be null, see KFileItem::isNull()).
144 */
145 void indicateDroppedUrls(const KUrl::List& urls,
146 const KUrl& destPath,
147 const KFileItem& destItem);
148
149 /**
150 * Informs the abstract Dolphin view about a sorting change done inside
151 * the view implementation. This method should be invoked by the view
152 * implementation (e. g. the details view uses this method in combination
153 * with the details header).
154 */
155 void indicateSortingChange(DolphinView::Sorting sorting);
156
157 /**
158 * Informs the abstract Dolphin view about a sort order change done inside
159 * the view implementation. This method should be invoked by the view
160 * implementation (e. g. the details view uses this method in combination
161 * with the details header).
162 */
163 void indicateSortOrderChange(Qt::SortOrder order);
164
165 /**
166 * Informs the abstract Dolphin view about an additional information change
167 * done inside the view implementation. This method should be invoked by the
168 * view implementation (e. g. the details view uses this method in combination
169 * with the details header).
170 */
171 void indicateAdditionalInfoChange(const KFileItemDelegate::InformationList& info);
172
173 /**
174 * Informs the view implementation about a change of the activation
175 * state and is invoked by the abstract Dolphin view. The signal
176 * activationChanged() is emitted.
177 */
178 void indicateActivationChange(bool active);
179
180 /**
181 * Tells the view implementation to zoom in by emitting the signal zoomIn()
182 * and is invoked by the abstract Dolphin view.
183 */
184 void triggerZoomIn();
185
186 /**
187 * Is invoked by the view implementation to indicate whether a zooming in
188 * is possible. The abstract Dolphin view updates the corresponding menu
189 * action depending on this state.
190 */
191 void setZoomInPossible(bool possible);
192 bool isZoomInPossible() const;
193
194 /**
195 * Tells the view implementation to zoom out by emitting the signal zoomOut()
196 * and is invoked by the abstract Dolphin view.
197 */
198 void triggerZoomOut();
199
200 /**
201 * Is invoked by the view implementation to indicate whether a zooming out
202 * is possible. The abstract Dolphin view updates the corresponding menu
203 * action depending on this state.
204 */
205 void setZoomOutPossible(bool possible);
206 bool isZoomOutPossible() const;
207
208 /**
209 * Should be invoked in each view implementation whenever a key has been
210 * pressed. If the selection model of \a view is not empty and
211 * the return key has been pressed, the selected items will get triggered.
212 */
213 void handleKeyPressEvent(QKeyEvent* event);
214
215 /**
216 * Returns the file item for the proxy index \a index of the view \a view.
217 */
218 KFileItem itemForIndex(const QModelIndex& index) const;
219
220 public slots:
221 /**
222 * Emits the signal itemTriggered() if the file item for the index \a index
223 * is not null. The method should be invoked by the
224 * controller parent whenever the user has triggered an item.
225 */
226 void triggerItem(const QModelIndex& index);
227
228 /**
229 * Emits the signal itemEntered() if the file item for the index \a index
230 * is not null. The method should be invoked by the controller parent
231 * whenever the mouse cursor is above an item.
232 */
233 void emitItemEntered(const QModelIndex& index);
234
235 /**
236 * Emits the signal viewportEntered(). The method should be invoked by
237 * the controller parent whenever the mouse cursor is above the viewport.
238 */
239 void emitViewportEntered();
240
241 signals:
242 /**
243 * Is emitted if the URL for the Dolphin controller has been changed
244 * to \a url.
245 */
246 void urlChanged(const KUrl& url);
247
248 /**
249 * Is emitted if the view implementation requests a changing of the current
250 * URL to \a url (see triggerUrlChangeRequest()).
251 */
252 void requestUrlChange(const KUrl& url);
253
254 /**
255 * Is emitted if a context menu should be opened (see triggerContextMenuRequest()).
256 * The abstract Dolphin view connects to this signal and will open the context menu.
257 * @param pos Position relative to the view widget where the
258 * context menu should be opened. It is recommended
259 * to get the corresponding model index from
260 * this position.
261 */
262 void requestContextMenu(const QPoint& pos);
263
264 /**
265 * Is emitted if the view has been activated by e. g. a mouse click.
266 * The abstract Dolphin view connects to this signal to know the
267 * destination view for the menu actions.
268 */
269 void activated();
270
271 /**
272 * Is emitted if the URLs \a urls have been dropped to the destination
273 * path \a destPath. If the URLs have been dropped above an item of
274 * the destination path, the item is indicated by \a destItem
275 * (can be null, see KFileItem::isNull()).
276 */
277 void urlsDropped(const KUrl::List& urls,
278 const KUrl& destPath,
279 const KFileItem& destItem);
280
281 /**
282 * Is emitted if the sorting has been changed to \a sorting by
283 * the view implementation (see indicateSortingChanged().
284 * The abstract Dolphin view connects to
285 * this signal to update its menu action.
286 */
287 void sortingChanged(DolphinView::Sorting sorting);
288
289 /**
290 * Is emitted if the sort order has been changed to \a order
291 * by the view implementation (see indicateSortOrderChanged().
292 * The abstract Dolphin view connects
293 * to this signal to update its menu actions.
294 */
295 void sortOrderChanged(Qt::SortOrder order);
296
297 /**
298 * Is emitted if the additional info has been changed to \a info
299 * by the view implementation. The abstract Dolphin view connects
300 * to this signal to update its menu actions.
301 */
302 void additionalInfoChanged(const KFileItemDelegate::InformationList& info);
303
304 /**
305 * Is emitted if the activation state has been changed to \a active
306 * by the abstract Dolphin view.
307 * The view implementation might connect to this signal if custom
308 * updates are required in this case.
309 */
310 void activationChanged(bool active);
311
312 /**
313 * Is emitted if the item \a item should be triggered. The abstract
314 * Dolphin view connects to this signal. If the item represents a directory,
315 * the directory is opened. On a file the corresponding application is opened.
316 * The item is null (see KFileItem::isNull()), when clicking on the viewport itself.
317 */
318 void itemTriggered(const KFileItem& item);
319
320 /**
321 * Is emitted if the mouse cursor has entered the item
322 * given by \a index (see emitItemEntered()).
323 * The abstract Dolphin view connects to this signal.
324 */
325 void itemEntered(const KFileItem& item);
326
327 /**
328 * Is emitted if a new tab should be opened for the URL \a url.
329 */
330 void tabRequested(const KUrl& url);
331
332 /**
333 * Is emitted if the mouse cursor has entered
334 * the viewport (see emitViewportEntered().
335 * The abstract Dolphin view connects to this signal.
336 */
337 void viewportEntered();
338
339 /**
340 * Is emitted if the view should zoom in. The view implementation
341 * must connect to this signal if it supports zooming.
342 */
343 void zoomIn();
344
345 /**
346 * Is emitted if the view should zoom out. The view implementation
347 * must connect to this signal if it supports zooming.
348 */
349 void zoomOut();
350
351 private slots:
352 void updateOpenTabState();
353
354 private:
355 bool m_zoomInPossible;
356 bool m_zoomOutPossible;
357 bool m_openTab; // TODO: this is a workaround until Qt-issue 176832 has been fixed
358 KUrl m_url;
359 DolphinView* m_dolphinView;
360 QAbstractItemView* m_itemView;
361 };
362
363 inline const DolphinView* DolphinController::dolphinView() const
364 {
365 return m_dolphinView;
366 }
367
368 inline const KUrl& DolphinController::url() const
369 {
370 return m_url;
371 }
372
373 inline QAbstractItemView* DolphinController::itemView() const
374 {
375 return m_itemView;
376 }
377
378 inline void DolphinController::setZoomInPossible(bool possible)
379 {
380 m_zoomInPossible = possible;
381 }
382
383 inline bool DolphinController::isZoomInPossible() const
384 {
385 return m_zoomInPossible;
386 }
387
388 inline void DolphinController::setZoomOutPossible(bool possible)
389 {
390 m_zoomOutPossible = possible;
391 }
392
393 inline bool DolphinController::isZoomOutPossible() const
394 {
395 return m_zoomOutPossible;
396 }
397
398 #endif