]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphincontroller.h
Refactored DolphinColumnWidget so that it does not need a hierarchical KDirLister...
[dolphin.git] / src / dolphincontroller.h
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) *
3 * *
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. *
8 * *
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. *
13 * *
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 ***************************************************************************/
19
20 #ifndef DOLPHINCONTROLLER_H
21 #define DOLPHINCONTROLLER_H
22
23 #include <dolphinview.h>
24 #include <kurl.h>
25 #include <QtCore/QObject>
26 #include <libdolphin_export.h>
27
28 class KUrl;
29 class QBrush;
30 class QModelIndex;
31 class QPoint;
32 class QRect;
33 class QWidget;
34
35 /**
36 * @brief Allows to control Dolphin views and to react on state changes.
37 *
38 * One instance of a DolphinController can be assigned to a variable number of
39 * Dolphin views (DolphinIconsView, DolphinDetailsView) by passing it in
40 * the constructor:
41 *
42 * \code
43 * DolphinController* controller = new DolphinController(parent);
44 * DolphinDetailsView* detailsView = new DolphinDetailsView(parent, controller);
45 * DolphinIconsView* iconsView = new DolphinIconsView(parent, controller);
46 * \endcode
47 *
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.
51 */
52 class LIBDOLPHINPRIVATE_EXPORT DolphinController : public QObject
53 {
54 Q_OBJECT
55
56 public:
57 explicit DolphinController(QObject* parent);
58 virtual ~DolphinController();
59
60 /** Sets the URL to \a url and emits the signal urlChanged(). */
61 void setUrl(const KUrl& url);
62 const KUrl& url() const;
63
64 void triggerContextMenuRequest(const QPoint& pos);
65
66 void triggerActivation();
67
68 void indicateDroppedUrls(const KUrl::List& urls,
69 const KUrl& destPath,
70 const QModelIndex& destIndex,
71 QWidget* source);
72
73 void indicateSortingChange(DolphinView::Sorting sorting);
74
75 void indicateSortOrderChange(Qt::SortOrder order);
76
77 void setShowHiddenFiles(bool show);
78 bool showHiddenFiles() const;
79
80 void setShowPreview(bool show);
81 bool showPreview() const;
82
83 void setAdditionalInfoCount(int count);
84 bool additionalInfoCount() const;
85
86 void triggerZoomIn();
87 void setZoomInPossible(bool possible);
88 bool isZoomInPossible() const;
89
90 void triggerZoomOut();
91 void setZoomOutPossible(bool possible);
92 bool isZoomOutPossible() const;
93
94 // TODO: remove this method when the issue #160611 is solved in Qt 4.4
95 static void drawHoverIndication(QWidget* widget,
96 const QRect& bounds,
97 const QBrush& brush);
98
99 public slots:
100 /**
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);
104
105 /**
106 * Emits the signal itemEntered(). The method should be invoked by
107 * the controller parent whenever the mouse cursor is above an item.
108 */
109 void emitItemEntered(const KFileItem& item);
110
111 /**
112 * Emits the signal viewportEntered(). The method should be invoked by
113 * the controller parent whenever the mouse cursor is above the viewport.
114 */
115 void emitViewportEntered();
116
117 signals:
118 /**
119 * Is emitted if the URL for the Dolphin controller has been changed
120 * to \a url.
121 */
122 void urlChanged(const KUrl& url);
123
124 /**
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
129 * this position.
130 */
131 void requestContextMenu(const QPoint& pos);
132
133 /**
134 * Is emitted if the view has been activated by e. g. a mouse click.
135 */
136 void activated();
137
138 /**
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.
143 */
144 void urlsDropped(const KUrl::List& urls,
145 const KUrl& destPath,
146 const QModelIndex& destIndex,
147 QWidget* source);
148
149 /** Is emitted if the sorting has been changed to \a sorting. */
150 void sortingChanged(DolphinView::Sorting sorting);
151
152 /** Is emitted if the sort order has been changed to \a sort order. */
153 void sortOrderChanged(Qt::SortOrder order);
154
155 /**
156 * Is emitted if the state for showing hidden files has been
157 * changed to \a show.
158 */
159 void showHiddenFilesChanged(bool show);
160
161 /**
162 * Is emitted if the state for showing previews has been
163 * changed to \a show.
164 */
165 void showPreviewChanged(bool show);
166
167 /**
168 * Is emitted if the number of additional informations has been
169 * changed to \a count.
170 */
171 void additionalInfoCountChanged(int count);
172
173 /**
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.
178 */
179 void itemTriggered(const QModelIndex& index);
180
181 /**
182 * Is emitted if the mouse cursor has entered the item
183 * given by \a index.
184 */
185 void itemEntered(const KFileItem& item);
186
187 /**
188 * Is emitted if the mouse cursor has entered
189 * the viewport. */
190 void viewportEntered();
191
192 /** Is emitted if the view should zoom in. */
193 void zoomIn();
194
195 /** Is emitted if the view should zoom out. */
196 void zoomOut();
197
198 private:
199 bool m_showHiddenFiles;
200 bool m_showPreview;
201 bool m_zoomInPossible;
202 bool m_zoomOutPossible;
203 int m_additionalInfoCount;
204 KUrl m_url;
205 };
206
207 inline const KUrl& DolphinController::url() const
208 {
209 return m_url;
210 }
211
212 inline bool DolphinController::showHiddenFiles() const
213 {
214 return m_showHiddenFiles;
215 }
216
217 inline bool DolphinController::showPreview() const
218 {
219 return m_showPreview;
220 }
221
222 inline bool DolphinController::additionalInfoCount() const
223 {
224 return m_additionalInfoCount;
225 }
226
227 inline void DolphinController::setZoomInPossible(bool possible)
228 {
229 m_zoomInPossible = possible;
230 }
231
232 inline bool DolphinController::isZoomInPossible() const
233 {
234 return m_zoomInPossible;
235 }
236
237 inline void DolphinController::setZoomOutPossible(bool possible)
238 {
239 m_zoomOutPossible = possible;
240 }
241
242 inline bool DolphinController::isZoomOutPossible() const
243 {
244 return m_zoomOutPossible;
245 }
246
247 #endif