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