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>
36 * @brief Acts as mediator between the abstract Dolphin view and the view
39 * The abstract Dolphin view (see DolphinView) represents the parent of the controller.
40 * The controller is passed to the current view implementation
41 * (see DolphinIconsView, DolphinDetailsView and DolphinColumnView)
42 * by passing it in the constructor:
45 * DolphinController* controller = new DolphinController(parent);
46 * QAbstractItemView* view = new DolphinIconsView(parent, controller);
49 * The communication of the view implementations to the abstract view is done by:
50 * - triggerContextMenuRequest()
51 * - requestActivation()
52 * - indicateDroppedUrls()
53 * - indicateSortingChange()
54 * - indicateSortOrderChanged()
55 * - setZoomInPossible()
56 * - setZoomOutPossible()
59 * - emitViewportEntered()
61 * The communication of the abstract view to the view implementations is done by:
62 * - setShowHiddenFiles()
64 * - setAdditionalInfoCount()
65 * - indicateActivationChange()
69 class LIBDOLPHINPRIVATE_EXPORT DolphinController
: public QObject
74 explicit DolphinController(QObject
* parent
);
75 virtual ~DolphinController();
77 /** Sets the URL to \a url and emits the signal urlChanged(). */
78 void setUrl(const KUrl
& url
);
79 const KUrl
& url() const;
82 * Requests a context menu for the position \a pos. This method
83 * should be invoked by the view implementation when a context
84 * menu should be opened. The abstract Dolphin view itself
85 * takes care itself to get the selected items depending from
88 void triggerContextMenuRequest(const QPoint
& pos
);
91 * Requests an activation of the view and emits the signal
92 * activated(). This method should be invoked by the view implementation
93 * if e. g. a mouse click on the view has been done.
94 * After the activation has been changed, the view implementation
95 * might listen to the activationChanged() signal.
97 void requestActivation();
100 * Indicates that URLs are dropped above a destination. This method
101 * should be invoked by the view implementation. The abstract Dolphin view
102 * will start the corresponding action (copy, move, link).
103 * @param urls URLs that are dropped above a destination.
104 * @param destPath Path of the destination.
105 * @param destIndex Model index of the destination item.
106 * @param source Pointer to the view implementation which invoked this method.
108 void indicateDroppedUrls(const KUrl::List
& urls
,
109 const KUrl
& destPath
,
110 const QModelIndex
& destIndex
,
114 * Informs the abstract Dolphin view about a sorting change done inside
115 * the view implementation. This method should be invoked by the view
116 * implementation (e. g. the details view uses this method in combination
117 * with the details header).
119 void indicateSortingChange(DolphinView::Sorting sorting
);
122 * Informs the abstract Dolphin view about a sort order change done inside
123 * the view implementation. This method should be invoked by the view
124 * implementation (e. g. the details view uses this method in combination
125 * with the details header).
127 void indicateSortOrderChange(Qt::SortOrder order
);
130 * Informs the view implementation about a change of the show hidden files
131 * state and is invoked by the abstract Dolphin view.
132 * The signal showHiddenFilesChanged() is emitted.
134 void setShowHiddenFiles(bool show
);
135 bool showHiddenFiles() const;
138 * Informs the view implementation about a change of the show preview
139 * state and is invoked by the abstract Dolphin view.
140 * The signal showPreviewChanged() is emitted.
142 void setShowPreview(bool show
);
143 bool showPreview() const;
146 * Informs the view implementation about a change of the number of
147 * additional informations and is invoked by the abstract Dolphin view.
148 * The signal additionalInfoCountChanged() is emitted.
150 void setAdditionalInfoCount(int count
);
151 bool additionalInfoCount() const;
154 * Informs the view implementation about a change of the activation
155 * state and is invoked by the abstract Dolphin view. The signal
156 * activationChanged() is emitted.
158 void indicateActivationChange(bool active
);
161 * Tells the view implementation to zoom in by emitting the signal zoomIn()
162 * and is invoked by the abstract Dolphin view.
164 void triggerZoomIn();
167 * Is invoked by the view implementation to indicate whether a zooming in
168 * is possible. The abstract Dolphin view updates the corresponding menu
169 * action depending on this state.
171 void setZoomInPossible(bool possible
);
172 bool isZoomInPossible() const;
175 * Tells the view implementation to zoom out by emitting the signal zoomOut()
176 * and is invoked by the abstract Dolphin view.
178 void triggerZoomOut();
181 * Is invoked by the view implementation to indicate whether a zooming out
182 * is possible. The abstract Dolphin view updates the corresponding menu
183 * action depending on this state.
185 void setZoomOutPossible(bool possible
);
186 bool isZoomOutPossible() const;
188 // TODO: remove this method when the issue #160611 is solved in Qt 4.4
189 static void drawHoverIndication(QWidget
* widget
,
191 const QBrush
& brush
);
195 * Emits the signal itemTriggered(). The method should be invoked by the
196 * controller parent whenever the user has triggered an item. */
197 void triggerItem(const KFileItem
& item
);
200 * Emits the signal itemEntered(). The method should be invoked by
201 * the controller parent whenever the mouse cursor is above an item.
203 void emitItemEntered(const KFileItem
& item
);
206 * Emits the signal viewportEntered(). The method should be invoked by
207 * the controller parent whenever the mouse cursor is above the viewport.
209 void emitViewportEntered();
213 * Is emitted if the URL for the Dolphin controller has been changed
216 void urlChanged(const KUrl
& url
);
219 * Is emitted if a context menu should be opened (see triggerContextMenuRequest()).
220 * The abstract Dolphin view connects to this signal and will open the context menu.
221 * @param pos Position relative to the view widget where the
222 * context menu should be opened. It is recommended
223 * to get the corresponding model index from
226 void requestContextMenu(const QPoint
& pos
);
229 * Is emitted if the view has been activated by e. g. a mouse click.
230 * The abstract Dolphin view connects to this signal to know the
231 * destination view for the menu actions.
236 * Is emitted if the URLs \a urls have been dropped to the destination
237 * path \a destPath. If the URLs have been dropped above an item of
238 * the destination path, the item is indicated by \a destIndex.
239 * \a source indicates the widget where the dragging has been started from.
241 void urlsDropped(const KUrl::List
& urls
,
242 const KUrl
& destPath
,
243 const QModelIndex
& destIndex
,
247 * Is emitted if the sorting has been changed to \a sorting by
248 * the view implementation (see indicateSortingChanged().
249 * The abstract Dolphin view connects to
250 * this signal to update its menu action.
252 void sortingChanged(DolphinView::Sorting sorting
);
255 * Is emitted if the sort order has been changed to \a order
256 * by the view implementation (see indicateSortOrderChanged().
257 * The abstract Dolphin view connects
258 * to this signal to update its menu actions.
260 void sortOrderChanged(Qt::SortOrder order
);
263 * Is emitted if the state for showing hidden files has been
264 * changed to \a show by the abstract Dolphin view. The view
265 * implementation might connect to this signal if custom
266 * updates are required in this case.
268 void showHiddenFilesChanged(bool show
);
271 * Is emitted if the state for showing previews has been
272 * changed to \a show by the abstract Dolphin view.
273 * The view implementation might connect to this signal if custom
274 * updates are required in this case.
276 void showPreviewChanged(bool show
);
279 * Is emitted if the number of additional informations has been
280 * changed to \a count by the abstract Dolphin view.
281 * The view implementation might connect to this signal if custom
282 * updates are required in this case.
284 void additionalInfoCountChanged(int count
);
287 * Is emitted if the activation state has been changed to \a active
288 * by the abstract Dolphin view.
289 * The view implementation might connect to this signal if custom
290 * updates are required in this case.
292 void activationChanged(bool active
);
295 * Is emitted if the item \a item should be triggered. The abstract
296 * Dolphin view connects to this signal. If the item represents a directory,
297 * the directory is opened. On a file the corresponding application is opened.
298 * The item is null (see KFileItem::isNull()), when clicking on the viewport itself.
300 void itemTriggered(const KFileItem
& item
);
303 * Is emitted if the mouse cursor has entered the item
304 * given by \a index (see emitItemEntered()).
305 * The abstract Dolphin view connects to this signal.
307 void itemEntered(const KFileItem
& item
);
310 * Is emitted if the mouse cursor has entered
311 * the viewport (see emitViewportEntered().
312 * The abstract Dolphin view connects to this signal.
314 void viewportEntered();
317 * Is emitted if the view should zoom in. The view implementation
318 * must connect to this signal if it supports zooming.
323 * Is emitted if the view should zoom out. The view implementation
324 * must connect to this signal if it supports zooming.
329 bool m_showHiddenFiles
;
331 bool m_zoomInPossible
;
332 bool m_zoomOutPossible
;
333 int m_additionalInfoCount
;
337 inline const KUrl
& DolphinController::url() const
342 inline bool DolphinController::showHiddenFiles() const
344 return m_showHiddenFiles
;
347 inline bool DolphinController::showPreview() const
349 return m_showPreview
;
352 inline bool DolphinController::additionalInfoCount() const
354 return m_additionalInfoCount
;
357 inline void DolphinController::setZoomInPossible(bool possible
)
359 m_zoomInPossible
= possible
;
362 inline bool DolphinController::isZoomInPossible() const
364 return m_zoomInPossible
;
367 inline void DolphinController::setZoomOutPossible(bool possible
)
369 m_zoomOutPossible
= possible
;
372 inline bool DolphinController::isZoomOutPossible() const
374 return m_zoomOutPossible
;