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 setShowHiddenFiles(bool show
);
78 bool showHiddenFiles() const;
80 void setShowPreview(bool show
);
81 bool showPreview() const;
83 void setAdditionalInfoCount(int count
);
84 bool additionalInfoCount() const;
87 void setZoomInPossible(bool possible
);
88 bool isZoomInPossible() const;
90 void triggerZoomOut();
91 void setZoomOutPossible(bool possible
);
92 bool isZoomOutPossible() const;
94 // TODO: remove this method when the issue #160611 is solved in Qt 4.4
95 static void drawHoverIndication(QWidget
* widget
,
101 * Emits the signal itemTriggered(). The method should be invoked by the
102 * controller parent whenever the user has triggered an item. */
103 void triggerItem(const QModelIndex
& index
);
106 * Emits the signal itemEntered(). The method should be invoked by
107 * the controller parent whenever the mouse cursor is above an item.
109 void emitItemEntered(const KFileItem
& item
);
112 * Emits the signal viewportEntered(). The method should be invoked by
113 * the controller parent whenever the mouse cursor is above the viewport.
115 void emitViewportEntered();
119 * Is emitted if the URL for the Dolphin controller has been changed
122 void urlChanged(const KUrl
& url
);
125 * Is emitted if a context menu should be opened.
126 * @param pos Position relative to the view widget where the
127 * context menu should be opened. It is recommended
128 * to get the corresponding model index from
131 void requestContextMenu(const QPoint
& pos
);
134 * Is emitted if the view has been activated by e. g. a mouse click.
139 * Is emitted if the URLs \a urls have been dropped to the destination
140 * path \a destPath. If the URLs have been dropped above an item of
141 * the destination path, the item is indicated by \a destIndex.
142 * \a source indicates the widget where the dragging has been started from.
144 void urlsDropped(const KUrl::List
& urls
,
145 const KUrl
& destPath
,
146 const QModelIndex
& destIndex
,
149 /** Is emitted if the sorting has been changed to \a sorting. */
150 void sortingChanged(DolphinView::Sorting sorting
);
152 /** Is emitted if the sort order has been changed to \a sort order. */
153 void sortOrderChanged(Qt::SortOrder order
);
156 * Is emitted if the state for showing hidden files has been
157 * changed to \a show.
159 void showHiddenFilesChanged(bool show
);
162 * Is emitted if the state for showing previews has been
163 * changed to \a show.
165 void showPreviewChanged(bool show
);
168 * Is emitted if the number of additional informations has been
169 * changed to \a count.
171 void additionalInfoCountChanged(int count
);
174 * Is emitted if the item with the index \a index should be triggered.
175 * Usually triggering on a directory opens the directory, triggering
176 * on a file opens the corresponding application.
177 * Emitted with an invalid \a index when clicking on the viewport itself.
179 void itemTriggered(const QModelIndex
& index
);
182 * Is emitted if the mouse cursor has entered the item
185 void itemEntered(const KFileItem
& item
);
188 * Is emitted if the mouse cursor has entered
190 void viewportEntered();
192 /** Is emitted if the view should zoom in. */
195 /** Is emitted if the view should zoom out. */
199 bool m_showHiddenFiles
;
201 bool m_zoomInPossible
;
202 bool m_zoomOutPossible
;
203 int m_additionalInfoCount
;
207 inline const KUrl
& DolphinController::url() const
212 inline bool DolphinController::showHiddenFiles() const
214 return m_showHiddenFiles
;
217 inline bool DolphinController::showPreview() const
219 return m_showPreview
;
222 inline bool DolphinController::additionalInfoCount() const
224 return m_additionalInfoCount
;
227 inline void DolphinController::setZoomInPossible(bool possible
)
229 m_zoomInPossible
= possible
;
232 inline bool DolphinController::isZoomInPossible() const
234 return m_zoomInPossible
;
237 inline void DolphinController::setZoomOutPossible(bool possible
)
239 m_zoomOutPossible
= possible
;
242 inline bool DolphinController::isZoomOutPossible() const
244 return m_zoomOutPossible
;