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