1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) *
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. *
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. *
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 ***************************************************************************/
20 #ifndef DOLPHINCONTROLLER_H
21 #define DOLPHINCONTROLLER_H
23 #include <dolphinview.h>
25 #include <QtCore/QObject>
26 #include <libdolphin_export.h>
28 class QAbstractItemView
;
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
40 * @brief Acts as mediator between the abstract Dolphin view and the view
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:
51 * QAbstractItemView* view = new DolphinIconsView(parent, controller);
52 * controller->setItemView(view);
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()
64 * - handleKeyPressEvent()
66 * - emitViewportEntered()
67 * - replaceUrlByClipboard()
70 * The communication of the abstract view to the view implementations is done by:
72 * - setShowHiddenFiles()
74 * - indicateActivationChange()
77 class LIBDOLPHINPRIVATE_EXPORT DolphinController
: public QObject
82 explicit DolphinController(DolphinView
* dolphinView
);
83 virtual ~DolphinController();
86 * Allows read access for the view implementation to the abstract
89 const DolphinView
* dolphinView() const;
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.
97 void setUrl(const KUrl
& url
);
98 const KUrl
& url() const;
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.
105 void setItemView(QAbstractItemView
* view
);
107 QAbstractItemView
* itemView() const;
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).
117 void triggerUrlChangeRequest(const KUrl
& url
);
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. It is possible to define a custom list of actions for
125 * the context menu by \a customActions.
127 void triggerContextMenuRequest(const QPoint
& pos
,
128 const QList
<QAction
*>& customActions
= QList
<QAction
*>());
131 * Requests an activation of the view and emits the signal
132 * activated(). This method should be invoked by the view implementation
133 * if e. g. a mouse click on the view has been done.
134 * After the activation has been changed, the view implementation
135 * might listen to the activationChanged() signal.
137 void requestActivation();
140 * Indicates that URLs are dropped above a destination. This method
141 * should be invoked by the view implementation. The abstract Dolphin view
142 * will start the corresponding action (copy, move, link).
143 * @param destItem Item of the destination (can be null, see KFileItem::isNull()).
144 * @param destPath Path of the destination.
145 * @param event Drop event
147 void indicateDroppedUrls(const KFileItem
& destItem
,
148 const KUrl
& destPath
,
152 * Informs the abstract Dolphin view about a sorting change done inside
153 * the view implementation. This method should be invoked by the view
154 * implementation (e. g. the details view uses this method in combination
155 * with the details header).
157 void indicateSortingChange(DolphinView::Sorting sorting
);
160 * Informs the abstract Dolphin view about a sort order change done inside
161 * the view implementation. This method should be invoked by the view
162 * implementation (e. g. the details view uses this method in combination
163 * with the details header).
165 void indicateSortOrderChange(Qt::SortOrder order
);
168 * Informs the abstract Dolphin view about an additional information change
169 * done inside the view implementation. This method should be invoked by the
170 * view implementation (e. g. the details view uses this method in combination
171 * with the details header).
173 void indicateAdditionalInfoChange(const KFileItemDelegate::InformationList
& info
);
176 * Informs the view implementation about a change of the activation
177 * state and is invoked by the abstract Dolphin view. The signal
178 * activationChanged() is emitted.
180 void indicateActivationChange(bool active
);
183 * Sets the zoom level to \a level and emits the signal zoomLevelChanged().
184 * It must be assured that the used level is inside the range
185 * DolphinController::zoomLevelMinimum() and
186 * DolphinController::zoomLevelMaximum().
187 * Is invoked by the abstract Dolphin view.
189 void setZoomLevel(int level
);
190 int zoomLevel() const;
193 * Tells the view implementation to zoom out by emitting the signal zoomOut()
194 * and is invoked by the abstract Dolphin view.
196 void triggerZoomOut();
199 * Should be invoked in each view implementation whenever a key has been
200 * pressed. If the selection model of \a view is not empty and
201 * the return key has been pressed, the selected items will get triggered.
203 void handleKeyPressEvent(QKeyEvent
* event
);
206 * Replaces the URL of the abstract Dolphin view with the content
207 * of the clipboard as URL. If the clipboard contains no text,
208 * nothing will be done.
210 void replaceUrlByClipboard();
212 /** Emits the signal hideToolTip(). */
213 void emitHideToolTip();
216 * Emits the signal itemTriggered() for the item \a item.
217 * The method can be used by the view implementations to
218 * trigger an item directly without mouse interaction.
219 * If the item triggering is done by the mouse, it is recommended
220 * to use QAbstractItemView::triggerItem(), as this will check
221 * the used mouse buttons to execute the correct action.
223 void emitItemTriggered(const KFileItem
& item
);
226 * Returns the file item for the proxy index \a index of the view \a view.
228 KFileItem
itemForIndex(const QModelIndex
& index
) const;
232 * Emits the signal itemTriggered() if the file item for the index \a index
233 * is not null and the left mouse button has been pressed. If the item is
234 * null, the signal itemEntered() is emitted.
235 * The method should be invoked by the view implementations whenever the
236 * user has triggered an item with the mouse (see
237 * QAbstractItemView::clicked() or QAbstractItemView::doubleClicked()).
239 void triggerItem(const QModelIndex
& index
);
242 * Emits the signal tabRequested(), if the file item for the index \a index
243 * represents a directory and when the middle mouse button has been pressed.
244 * The method should be invoked by the controller parent.
246 void requestTab(const QModelIndex
& index
);
249 * Emits the signal itemEntered() if the file item for the index \a index
250 * is not null. The method should be invoked by the controller parent
251 * whenever the mouse cursor is above an item.
253 void emitItemEntered(const QModelIndex
& index
);
256 * Emits the signal viewportEntered(). The method should be invoked by
257 * the controller parent whenever the mouse cursor is above the viewport.
259 void emitViewportEntered();
263 * Is emitted if the URL for the Dolphin controller has been changed
266 void urlChanged(const KUrl
& url
);
269 * Is emitted if the view implementation requests a changing of the current
270 * URL to \a url (see triggerUrlChangeRequest()).
272 void requestUrlChange(const KUrl
& url
);
275 * Is emitted if a context menu should be opened (see triggerContextMenuRequest()).
276 * The abstract Dolphin view connects to this signal and will open the context menu.
277 * @param pos Position relative to the view widget where the
278 * context menu should be opened. It is recommended
279 * to get the corresponding model index from
281 * @param customActions List of actions that is added to the context menu when
282 * the menu is opened above the viewport.
284 void requestContextMenu(const QPoint
& pos
, QList
<QAction
*> customActions
);
287 * Is emitted if the view has been activated by e. g. a mouse click.
288 * The abstract Dolphin view connects to this signal to know the
289 * destination view for the menu actions.
294 * Is emitted if URLs have been dropped to the destination
295 * path \a destPath. If the URLs have been dropped above an item of
296 * the destination path, the item is indicated by \a destItem
297 * (can be null, see KFileItem::isNull()).
299 void urlsDropped(const KFileItem
& destItem
,
300 const KUrl
& destPath
,
304 * Is emitted if the sorting has been changed to \a sorting by
305 * the view implementation (see indicateSortingChanged().
306 * The abstract Dolphin view connects to
307 * this signal to update its menu action.
309 void sortingChanged(DolphinView::Sorting sorting
);
312 * Is emitted if the sort order has been changed to \a order
313 * by the view implementation (see indicateSortOrderChanged().
314 * The abstract Dolphin view connects
315 * to this signal to update its menu actions.
317 void sortOrderChanged(Qt::SortOrder order
);
320 * Is emitted if the additional info has been changed to \a info
321 * by the view implementation. The abstract Dolphin view connects
322 * to this signal to update its menu actions.
324 void additionalInfoChanged(const KFileItemDelegate::InformationList
& info
);
327 * Is emitted if the activation state has been changed to \a active
328 * by the abstract Dolphin view.
329 * The view implementation might connect to this signal if custom
330 * updates are required in this case.
332 void activationChanged(bool active
);
335 * Is emitted if the item \a item should be triggered. The abstract
336 * Dolphin view connects to this signal. If the item represents a directory,
337 * the directory is opened. On a file the corresponding application is opened.
338 * The item is null (see KFileItem::isNull()), when clicking on the viewport itself.
340 void itemTriggered(const KFileItem
& item
);
343 * Is emitted if the mouse cursor has entered the item
344 * given by \a index (see emitItemEntered()).
345 * The abstract Dolphin view connects to this signal.
347 void itemEntered(const KFileItem
& item
);
350 * Is emitted if a new tab should be opened for the URL \a url.
352 void tabRequested(const KUrl
& url
);
355 * Is emitted if the mouse cursor has entered
356 * the viewport (see emitViewportEntered().
357 * The abstract Dolphin view connects to this signal.
359 void viewportEntered();
362 * Is emitted if the view should change the zoom to \a level. The view implementation
363 * must connect to this signal if it supports zooming.
365 void zoomLevelChanged(int level
);
368 * Is emitted if the abstract view should hide an open tooltip.
373 void updateMouseButtonState();
377 static Qt::MouseButtons m_mouseButtons
; // TODO: this is a workaround until Qt-issue 176832 has been fixed
379 DolphinView
* m_dolphinView
;
380 QAbstractItemView
* m_itemView
;
383 inline const DolphinView
* DolphinController::dolphinView() const
385 return m_dolphinView
;
388 inline const KUrl
& DolphinController::url() const
393 inline QAbstractItemView
* DolphinController::itemView() const
398 inline int DolphinController::zoomLevel() const