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
126 void triggerContextMenuRequest(const QPoint
& pos
);
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.
135 void requestActivation();
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 destItem Item of the destination (can be null, see KFileItem::isNull()).
142 * @param destPath Path of the destination.
143 * @param event Drop event
145 void indicateDroppedUrls(const KFileItem
& destItem
,
146 const KUrl
& destPath
,
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).
155 void indicateSortingChange(DolphinView::Sorting sorting
);
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).
163 void indicateSortOrderChange(Qt::SortOrder order
);
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).
171 void indicateAdditionalInfoChange(const KFileItemDelegate::InformationList
& info
);
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.
178 void indicateActivationChange(bool active
);
181 * Sets the zoom level to \a level and emits the signal zoomLevelChanged().
182 * It must be assured that the used level is inside the range
183 * DolphinController::zoomLevelMinimum() and
184 * DolphinController::zoomLevelMaximum().
185 * Is invoked by the abstract Dolphin view.
187 void setZoomLevel(int level
);
188 int zoomLevel() const;
191 * Tells the view implementation to zoom out by emitting the signal zoomOut()
192 * and is invoked by the abstract Dolphin view.
194 void triggerZoomOut();
197 * Should be invoked in each view implementation whenever a key has been
198 * pressed. If the selection model of \a view is not empty and
199 * the return key has been pressed, the selected items will get triggered.
201 void handleKeyPressEvent(QKeyEvent
* event
);
204 * Replaces the URL of the abstract Dolphin view with the content
205 * of the clipboard as URL. If the clipboard contains no text,
206 * nothing will be done.
208 void replaceUrlByClipboard();
210 /** Emits the signal hideToolTip(). */
211 void emitHideToolTip();
214 * Emits the signal itemTriggered() for the item \a item.
215 * The method can be used by the view implementations to
216 * trigger an item directly without mouse interaction.
217 * If the item triggering is done by the mouse, it is recommended
218 * to use QAbstractItemView::triggerItem(), as this will check
219 * the used mouse buttons to execute the correct action.
221 void emitItemTriggered(const KFileItem
& item
);
224 * Returns the file item for the proxy index \a index of the view \a view.
226 KFileItem
itemForIndex(const QModelIndex
& index
) const;
230 * Emits the signal itemTriggered() if the file item for the index \a index
231 * is not null and the left mouse button has been pressed. If the item is
232 * null, the signal itemEntered() is emitted.
233 * The method should be invoked by the view implementations whenever the
234 * user has triggered an item with the mouse (see
235 * QAbstractItemView::clicked() or QAbstractItemView::doubleClicked()).
237 void triggerItem(const QModelIndex
& index
);
240 * Emits the signal tabRequested(), if the file item for the index \a index
241 * represents a directory and when the middle mouse button has been pressed.
242 * The method should be invoked by the controller parent.
244 void requestTab(const QModelIndex
& index
);
247 * Emits the signal itemEntered() if the file item for the index \a index
248 * is not null. The method should be invoked by the controller parent
249 * whenever the mouse cursor is above an item.
251 void emitItemEntered(const QModelIndex
& index
);
254 * Emits the signal viewportEntered(). The method should be invoked by
255 * the controller parent whenever the mouse cursor is above the viewport.
257 void emitViewportEntered();
261 * Is emitted if the URL for the Dolphin controller has been changed
264 void urlChanged(const KUrl
& url
);
267 * Is emitted if the view implementation requests a changing of the current
268 * URL to \a url (see triggerUrlChangeRequest()).
270 void requestUrlChange(const KUrl
& url
);
273 * Is emitted if a context menu should be opened (see triggerContextMenuRequest()).
274 * The abstract Dolphin view connects to this signal and will open the context menu.
275 * @param pos Position relative to the view widget where the
276 * context menu should be opened. It is recommended
277 * to get the corresponding model index from
280 void requestContextMenu(const QPoint
& pos
);
283 * Is emitted if the view has been activated by e. g. a mouse click.
284 * The abstract Dolphin view connects to this signal to know the
285 * destination view for the menu actions.
290 * Is emitted if URLs have been dropped to the destination
291 * path \a destPath. If the URLs have been dropped above an item of
292 * the destination path, the item is indicated by \a destItem
293 * (can be null, see KFileItem::isNull()).
295 void urlsDropped(const KFileItem
& destItem
,
296 const KUrl
& destPath
,
300 * Is emitted if the sorting has been changed to \a sorting by
301 * the view implementation (see indicateSortingChanged().
302 * The abstract Dolphin view connects to
303 * this signal to update its menu action.
305 void sortingChanged(DolphinView::Sorting sorting
);
308 * Is emitted if the sort order has been changed to \a order
309 * by the view implementation (see indicateSortOrderChanged().
310 * The abstract Dolphin view connects
311 * to this signal to update its menu actions.
313 void sortOrderChanged(Qt::SortOrder order
);
316 * Is emitted if the additional info has been changed to \a info
317 * by the view implementation. The abstract Dolphin view connects
318 * to this signal to update its menu actions.
320 void additionalInfoChanged(const KFileItemDelegate::InformationList
& info
);
323 * Is emitted if the activation state has been changed to \a active
324 * by the abstract Dolphin view.
325 * The view implementation might connect to this signal if custom
326 * updates are required in this case.
328 void activationChanged(bool active
);
331 * Is emitted if the item \a item should be triggered. The abstract
332 * Dolphin view connects to this signal. If the item represents a directory,
333 * the directory is opened. On a file the corresponding application is opened.
334 * The item is null (see KFileItem::isNull()), when clicking on the viewport itself.
336 void itemTriggered(const KFileItem
& item
);
339 * Is emitted if the mouse cursor has entered the item
340 * given by \a index (see emitItemEntered()).
341 * The abstract Dolphin view connects to this signal.
343 void itemEntered(const KFileItem
& item
);
346 * Is emitted if a new tab should be opened for the URL \a url.
348 void tabRequested(const KUrl
& url
);
351 * Is emitted if the mouse cursor has entered
352 * the viewport (see emitViewportEntered().
353 * The abstract Dolphin view connects to this signal.
355 void viewportEntered();
358 * Is emitted if the view should change the zoom to \a level. The view implementation
359 * must connect to this signal if it supports zooming.
361 void zoomLevelChanged(int level
);
364 * Is emitted if the abstract view should hide an open tooltip.
369 void updateMouseButtonState();
373 static Qt::MouseButtons m_mouseButtons
; // TODO: this is a workaround until Qt-issue 176832 has been fixed
375 DolphinView
* m_dolphinView
;
376 QAbstractItemView
* m_itemView
;
379 inline const DolphinView
* DolphinController::dolphinView() const
381 return m_dolphinView
;
384 inline const KUrl
& DolphinController::url() const
389 inline QAbstractItemView
* DolphinController::itemView() const
394 inline int DolphinController::zoomLevel() const