]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphincontroller.h
selection model fixes
[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 inline 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 QModelIndex& index,
70 QWidget* source);
71
72 void indicateSortingChange(DolphinView::Sorting sorting);
73
74 void indicateSortOrderChange(Qt::SortOrder order);
75
76 void setShowPreview(bool show);
77 inline bool showPreview() const;
78
79 void setShowAdditionalInfo(bool show);
80 inline bool showAdditionalInfo() const;
81
82 void triggerZoomIn();
83 inline void setZoomInPossible(bool possible);
84 inline bool isZoomInPossible() const;
85
86 void triggerZoomOut();
87 inline void setZoomOutPossible(bool possible);
88 inline bool isZoomOutPossible() const;
89
90 // TODO: remove this method when the issue #160611 is solved in Qt 4.4
91 static void drawHoverIndication(QWidget* widget,
92 const QRect& bounds,
93 const QBrush& brush);
94
95 public slots:
96 /**
97 * Emits the signal itemTriggered(). The method should be invoked by the
98 * controller parent whenever the user has triggered an item. */
99 void triggerItem(const QModelIndex& index);
100
101 /**
102 * Emits the signal itemEntered(). The method should be invoked by
103 * the controller parent whenever the mouse cursor is above an item.
104 */
105 void emitItemEntered(const QModelIndex& index);
106
107 /**
108 * Emits the signal viewportEntered(). The method should be invoked by
109 * the controller parent whenever the mouse cursor is above the viewport.
110 */
111 void emitViewportEntered();
112
113 signals:
114 /**
115 * Is emitted if the URL for the Dolphin controller has been changed
116 * to \a url.
117 */
118 void urlChanged(const KUrl& url);
119
120 /**
121 * Is emitted if a context menu should be opened.
122 * @param pos Position relative to the view widget where the
123 * context menu should be opened. It is recommended
124 * to get the corresponding model index from
125 * this position.
126 */
127 void requestContextMenu(const QPoint& pos);
128
129 /**
130 * Is emitted if the view has been activated by e. g. a mouse click.
131 */
132 void activated();
133
134 /**
135 * Is emitted if the URLs \a urls have been dropped to the index
136 * \a index. \a source indicates the widget where the dragging has
137 * been started from.
138 */
139 void urlsDropped(const KUrl::List& urls,
140 const QModelIndex& index,
141 QWidget* source);
142
143 /** Is emitted if the sorting has been changed to \a sorting. */
144 void sortingChanged(DolphinView::Sorting sorting);
145
146 /** Is emitted if the sort order has been changed to \a sort order. */
147 void sortOrderChanged(Qt::SortOrder order);
148
149 /**
150 * Is emitted if the state for showing previews has been
151 * changed to \a show.
152 */
153 void showPreviewChanged(bool show);
154
155 /**
156 * Is emitted if the state for showing additional info has been
157 * changed to \a show.
158 */
159 void showAdditionalInfoChanged(bool show);
160
161 /**
162 * Is emitted if the item with the index \a index should be triggered.
163 * Usually triggering on a directory opens the directory, triggering
164 * on a file opens the corresponding application.
165 * Emitted with an invalid \a index when clicking on the viewport itself.
166 */
167 void itemTriggered(const QModelIndex& index);
168
169 /**
170 * Is emitted if the mouse cursor has entered the item
171 * given by \a index.
172 */
173 void itemEntered(const QModelIndex& index);
174
175 /**
176 * Is emitted if the mouse cursor has entered
177 * the viewport. */
178 void viewportEntered();
179
180 /** Is emitted if the view should zoom in. */
181 void zoomIn();
182
183 /** Is emitted if the view should zoom out. */
184 void zoomOut();
185
186 private:
187 bool m_showPreview;
188 bool m_showAdditionalInfo;
189 bool m_zoomInPossible;
190 bool m_zoomOutPossible;
191 KUrl m_url;
192 };
193
194 const KUrl& DolphinController::url() const
195 {
196 return m_url;
197 }
198
199 bool DolphinController::showPreview() const
200 {
201 return m_showPreview;
202 }
203
204 bool DolphinController::showAdditionalInfo() const
205 {
206 return m_showAdditionalInfo;
207 }
208
209 void DolphinController::setZoomInPossible(bool possible)
210 {
211 m_zoomInPossible = possible;
212 }
213
214 bool DolphinController::isZoomInPossible() const
215 {
216 return m_zoomInPossible;
217 }
218
219 void DolphinController::setZoomOutPossible(bool possible)
220 {
221 m_zoomOutPossible = possible;
222 }
223
224 bool DolphinController::isZoomOutPossible() const
225 {
226 return m_zoomOutPossible;
227 }
228
229 #endif