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>
35 // TODO: get rid of all the state duplications in the controller and allow read access
36 // to the Dolphin view for all view implementations
39 * @brief Acts as mediator between the abstract Dolphin view and the view
42 * The abstract Dolphin view (see DolphinView) represents the parent of the controller.
43 * The controller is passed to the current view implementation
44 * (see DolphinIconsView, DolphinDetailsView and DolphinColumnView)
45 * by passing it in the constructor:
48 * DolphinController* controller = new DolphinController(dolphinView);
49 * QAbstractItemView* view = new DolphinIconsView(parent, controller);
52 * The communication of the view implementations to the abstract view is done by:
53 * - triggerContextMenuRequest()
54 * - requestActivation()
55 * - triggerUrlChangeRequest()
56 * - indicateDroppedUrls()
57 * - indicateSortingChange()
58 * - indicateSortOrderChanged()
59 * - setZoomInPossible()
60 * - setZoomOutPossible()
63 * - emitViewportEntered()
65 * The communication of the abstract view to the view implementations is done by:
67 * - setShowHiddenFiles()
69 * - indicateActivationChange()
73 class LIBDOLPHINPRIVATE_EXPORT DolphinController
: public QObject
78 explicit DolphinController(DolphinView
* dolphinView
);
79 virtual ~DolphinController();
82 * Allows read access for the the view implementation to the abstract
85 const DolphinView
* dolphinView() const;
88 * Sets the URL to \a url and emits the signal urlChanged() if
89 * \a url is different for the current URL. This method should
90 * be invoked by the abstract Dolphin view whenever the current
91 * URL has been changed.
93 void setUrl(const KUrl
& url
);
94 const KUrl
& url() const;
97 * Allows a view implementation to request an URL change to \a url.
98 * The signal requestUrlChange() is emitted and the abstract Dolphin view
99 * will assure that the URL of the Dolphin Controller will be updated
100 * later. Invoking this method makes only sense if the view implementation
101 * shows a hierarchy of URLs and allows to change the URL within
102 * the view (e. g. this is the case in the column view).
104 void triggerUrlChangeRequest(const KUrl
& url
);
107 * Requests a context menu for the position \a pos. This method
108 * should be invoked by the view implementation when a context
109 * menu should be opened. The abstract Dolphin view itself
110 * takes care itself to get the selected items depending from
113 void triggerContextMenuRequest(const QPoint
& pos
);
116 * Requests an activation of the view and emits the signal
117 * activated(). This method should be invoked by the view implementation
118 * if e. g. a mouse click on the view has been done.
119 * After the activation has been changed, the view implementation
120 * might listen to the activationChanged() signal.
122 void requestActivation();
125 * Indicates that URLs are dropped above a destination. This method
126 * should be invoked by the view implementation. The abstract Dolphin view
127 * will start the corresponding action (copy, move, link).
128 * @param urls URLs that are dropped above a destination.
129 * @param destPath Path of the destination.
130 * @param destItem Destination item (can be null, see KFileItem::isNull()).
131 * @param source Pointer to the view implementation which invoked this method.
133 void indicateDroppedUrls(const KUrl::List
& urls
,
134 const KUrl
& destPath
,
135 const KFileItem
& destItem
,
139 * Informs the abstract Dolphin view about a sorting change done inside
140 * the view implementation. This method should be invoked by the view
141 * implementation (e. g. the details view uses this method in combination
142 * with the details header).
144 void indicateSortingChange(DolphinView::Sorting sorting
);
147 * Informs the abstract Dolphin view about a sort order change done inside
148 * the view implementation. This method should be invoked by the view
149 * implementation (e. g. the details view uses this method in combination
150 * with the details header).
152 void indicateSortOrderChange(Qt::SortOrder order
);
155 * Informs the abstract Dolphin view about an additional information change
156 * done inside the view implementation. This method should be invoked by the
157 * view implementation (e. g. the details view uses this method in combination
158 * with the details header).
160 void indicateAdditionalInfoChange(const KFileItemDelegate::InformationList
& info
);
163 * Informs the view implementation about a change of the show preview
164 * state and is invoked by the abstract Dolphin view.
165 * The signal showPreviewChanged() is emitted.
167 void setShowPreview(bool show
);
168 bool showPreview() const;
171 * Informs the view implementation about a change of the activation
172 * state and is invoked by the abstract Dolphin view. The signal
173 * activationChanged() is emitted.
175 void indicateActivationChange(bool active
);
178 * Tells the view implementation to zoom in by emitting the signal zoomIn()
179 * and is invoked by the abstract Dolphin view.
181 void triggerZoomIn();
184 * Is invoked by the view implementation to indicate whether a zooming in
185 * is possible. The abstract Dolphin view updates the corresponding menu
186 * action depending on this state.
188 void setZoomInPossible(bool possible
);
189 bool isZoomInPossible() const;
192 * Tells the view implementation to zoom out by emitting the signal zoomOut()
193 * and is invoked by the abstract Dolphin view.
195 void triggerZoomOut();
198 * Is invoked by the view implementation to indicate whether a zooming out
199 * is possible. The abstract Dolphin view updates the corresponding menu
200 * action depending on this state.
202 void setZoomOutPossible(bool possible
);
203 bool isZoomOutPossible() const;
205 // TODO: remove this method when the issue #160611 is solved in Qt 4.4
206 static void drawHoverIndication(QWidget
* widget
,
208 const QBrush
& brush
);
212 * Emits the signal itemTriggered(). The method should be invoked by the
213 * controller parent whenever the user has triggered an item. */
214 void triggerItem(const KFileItem
& item
);
217 * Emits the signal itemEntered(). The method should be invoked by
218 * the controller parent whenever the mouse cursor is above an item.
220 void emitItemEntered(const KFileItem
& item
);
223 * Emits the signal viewportEntered(). The method should be invoked by
224 * the controller parent whenever the mouse cursor is above the viewport.
226 void emitViewportEntered();
230 * Is emitted if the URL for the Dolphin controller has been changed
233 void urlChanged(const KUrl
& url
);
236 * Is emitted if the view implementation requests a changing of the current
237 * URL to \a url (see triggerUrlChangeRequest()).
239 void requestUrlChange(const KUrl
& url
);
242 * Is emitted if a context menu should be opened (see triggerContextMenuRequest()).
243 * The abstract Dolphin view connects to this signal and will open the context menu.
244 * @param pos Position relative to the view widget where the
245 * context menu should be opened. It is recommended
246 * to get the corresponding model index from
249 void requestContextMenu(const QPoint
& pos
);
252 * Is emitted if the view has been activated by e. g. a mouse click.
253 * The abstract Dolphin view connects to this signal to know the
254 * destination view for the menu actions.
259 * Is emitted if the URLs \a urls have been dropped to the destination
260 * path \a destPath. If the URLs have been dropped above an item of
261 * the destination path, the item is indicated by \a destItem
262 * (can be null, see KFileItem::isNull()). \a source indicates
263 * the widget where the dragging has been started from.
265 void urlsDropped(const KUrl::List
& urls
,
266 const KUrl
& destPath
,
267 const KFileItem
& destItem
,
271 * Is emitted if the sorting has been changed to \a sorting by
272 * the view implementation (see indicateSortingChanged().
273 * The abstract Dolphin view connects to
274 * this signal to update its menu action.
276 void sortingChanged(DolphinView::Sorting sorting
);
279 * Is emitted if the sort order has been changed to \a order
280 * by the view implementation (see indicateSortOrderChanged().
281 * The abstract Dolphin view connects
282 * to this signal to update its menu actions.
284 void sortOrderChanged(Qt::SortOrder order
);
287 * Is emitted if the additional info has been changed to \a info
288 * by the view implementation. The abstract Dolphin view connects
289 * to this signal to update its menu actions.
291 void additionalInfoChanged(const KFileItemDelegate::InformationList
& info
);
294 * Is emitted if the state for showing previews has been
295 * changed to \a show by the abstract Dolphin view.
296 * The view implementation might connect to this signal if custom
297 * updates are required in this case.
299 void showPreviewChanged(bool show
);
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.
307 void activationChanged(bool active
);
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.
315 void itemTriggered(const KFileItem
& item
);
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.
322 void itemEntered(const KFileItem
& item
);
325 * Is emitted if the mouse cursor has entered
326 * the viewport (see emitViewportEntered().
327 * The abstract Dolphin view connects to this signal.
329 void viewportEntered();
332 * Is emitted if the view should zoom in. The view implementation
333 * must connect to this signal if it supports zooming.
338 * Is emitted if the view should zoom out. The view implementation
339 * must connect to this signal if it supports zooming.
345 bool m_zoomInPossible
;
346 bool m_zoomOutPossible
;
348 DolphinView
* m_dolphinView
;
351 inline const DolphinView
* DolphinController::dolphinView() const
353 return m_dolphinView
;
356 inline const KUrl
& DolphinController::url() const
361 inline bool DolphinController::showPreview() const
363 return m_showPreview
;
366 inline void DolphinController::setZoomInPossible(bool possible
)
368 m_zoomInPossible
= possible
;
371 inline bool DolphinController::isZoomInPossible() const
373 return m_zoomInPossible
;
376 inline void DolphinController::setZoomOutPossible(bool possible
)
378 m_zoomOutPossible
= possible
;
381 inline bool DolphinController::isZoomOutPossible() const
383 return m_zoomOutPossible
;