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 Allows to control Dolphin views and to react on state changes.
38 * One instance of a DolphinController can be assigned to a variable number of
39 * Dolphin views (DolphinIconsView, DolphinDetailsView) by passing it in
43 * DolphinController* controller = new DolphinController(parent);
44 * DolphinDetailsView* detailsView = new DolphinDetailsView(parent, controller);
45 * DolphinIconsView* iconsView = new DolphinIconsView(parent, controller);
48 * The Dolphin view assures that the controller gets informed about selection changes,
49 * when an item should be triggered and a lot more. The controller emits the corresponding signals
50 * so that the receiver may react on those changes.
52 class LIBDOLPHINPRIVATE_EXPORT DolphinController
: public QObject
57 explicit DolphinController(QObject
* parent
);
58 virtual ~DolphinController();
60 /** Sets the URL to \a url and emits the signal urlChanged(). */
61 void setUrl(const KUrl
& url
);
62 const KUrl
& url() const;
64 void triggerContextMenuRequest(const QPoint
& pos
);
66 void triggerActivation();
68 void indicateDroppedUrls(const KUrl::List
& urls
,
70 const QModelIndex
& destIndex
,
73 void indicateSortingChange(DolphinView::Sorting sorting
);
75 void indicateSortOrderChange(Qt::SortOrder order
);
77 void setShowPreview(bool show
);
78 bool showPreview() const;
80 void setAdditionalInfoCount(int count
);
81 bool additionalInfoCount() const;
84 void setZoomInPossible(bool possible
);
85 bool isZoomInPossible() const;
87 void triggerZoomOut();
88 void setZoomOutPossible(bool possible
);
89 bool isZoomOutPossible() const;
91 // TODO: remove this method when the issue #160611 is solved in Qt 4.4
92 static void drawHoverIndication(QWidget
* widget
,
98 * Emits the signal itemTriggered(). The method should be invoked by the
99 * controller parent whenever the user has triggered an item. */
100 void triggerItem(const QModelIndex
& index
);
103 * Emits the signal itemEntered(). The method should be invoked by
104 * the controller parent whenever the mouse cursor is above an item.
106 void emitItemEntered(const QModelIndex
& index
);
109 * Emits the signal viewportEntered(). The method should be invoked by
110 * the controller parent whenever the mouse cursor is above the viewport.
112 void emitViewportEntered();
116 * Is emitted if the URL for the Dolphin controller has been changed
119 void urlChanged(const KUrl
& url
);
122 * Is emitted if a context menu should be opened.
123 * @param pos Position relative to the view widget where the
124 * context menu should be opened. It is recommended
125 * to get the corresponding model index from
128 void requestContextMenu(const QPoint
& pos
);
131 * Is emitted if the view has been activated by e. g. a mouse click.
136 * Is emitted if the URLs \a urls have been dropped to the destination
137 * path \a destPath. If the URLs have been dropped above an item of
138 * the destination path, the item is indicated by \a destIndex.
139 * \a source indicates the widget where the dragging has been started from.
141 void urlsDropped(const KUrl::List
& urls
,
142 const KUrl
& destPath
,
143 const QModelIndex
& destIndex
,
146 /** Is emitted if the sorting has been changed to \a sorting. */
147 void sortingChanged(DolphinView::Sorting sorting
);
149 /** Is emitted if the sort order has been changed to \a sort order. */
150 void sortOrderChanged(Qt::SortOrder order
);
153 * Is emitted if the state for showing previews has been
154 * changed to \a show.
156 void showPreviewChanged(bool show
);
159 * Is emitted if the number of additional informations has been
160 * changed to \a count.
162 void additionalInfoCountChanged(int count
);
165 * Is emitted if the item with the index \a index should be triggered.
166 * Usually triggering on a directory opens the directory, triggering
167 * on a file opens the corresponding application.
168 * Emitted with an invalid \a index when clicking on the viewport itself.
170 void itemTriggered(const QModelIndex
& index
);
173 * Is emitted if the mouse cursor has entered the item
176 void itemEntered(const QModelIndex
& index
);
179 * Is emitted if the mouse cursor has entered
181 void viewportEntered();
183 /** Is emitted if the view should zoom in. */
186 /** Is emitted if the view should zoom out. */
191 bool m_zoomInPossible
;
192 bool m_zoomOutPossible
;
193 int m_additionalInfoCount
;
197 inline const KUrl
& DolphinController::url() const
202 inline bool DolphinController::showPreview() const
204 return m_showPreview
;
207 inline bool DolphinController::additionalInfoCount() const
209 return m_additionalInfoCount
;
212 inline void DolphinController::setZoomInPossible(bool possible
)
214 m_zoomInPossible
= possible
;
217 inline bool DolphinController::isZoomInPossible() const
219 return m_zoomInPossible
;
222 inline void DolphinController::setZoomOutPossible(bool possible
)
224 m_zoomOutPossible
= possible
;
227 inline bool DolphinController::isZoomOutPossible() const
229 return m_zoomOutPossible
;