]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphincontroller.h
start to simplify the DolphinController as preparation for the kparts DolphinViewWidg...
[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 QModelIndex;
30 class QPoint;
31
32 /**
33 * @brief Allows to control Dolphin views and to react on state changes.
34 *
35 * One instance of a DolphinController can be assigned to a variable number of
36 * Dolphin views (DolphinIconsView, DolphinDetailsView) by passing it in
37 * the constructor:
38 *
39 * \code
40 * DolphinController* controller = new DolphinController(parent);
41 * DolphinDetailsView* detailsView = new DolphinDetailsView(parent, controller);
42 * DolphinIconsView* iconsView = new DolphinIconsView(parent, controller);
43 * \endcode
44 *
45 * The Dolphin view assures that the controller gets informed about selection changes,
46 * when an item should be triggered and a lot more. The controller emits the corresponding signals
47 * so that the receiver may react on those changes.
48 */
49 class LIBDOLPHINPRIVATE_EXPORT DolphinController : public QObject
50 {
51 Q_OBJECT
52
53 public:
54 explicit DolphinController(QObject* parent);
55 virtual ~DolphinController();
56
57 inline void setUrl(const KUrl& url);
58 inline const KUrl& url() const;
59
60 void triggerContextMenuRequest(const QPoint& pos);
61
62 void triggerActivation();
63
64 void indicateDroppedUrls(const KUrl::List& urls,
65 const QModelIndex& index,
66 QWidget* source);
67
68 void indicateSortingChange(DolphinView::Sorting sorting);
69
70 void indicateSortOrderChange(Qt::SortOrder order);
71
72 void setShowPreview(bool show);
73 inline bool showPreview() const;
74
75 void setShowAdditionalInfo(bool show);
76 inline bool showAdditionalInfo() const;
77
78 void triggerZoomIn();
79 inline void setZoomInPossible(bool possible);
80 inline bool isZoomInPossible() const;
81
82 void triggerZoomOut();
83 inline void setZoomOutPossible(bool possible);
84 inline bool isZoomOutPossible() const;
85
86 public slots:
87 /**
88 * Emits the signal itemTriggered(). The method should be invoked by the
89 * controller parent whenever the user has triggered an item. */
90 void triggerItem(const QModelIndex& index);
91
92 /**
93 * Emits the signal itemEntered(). The method should be invoked by
94 * the controller parent whenever the mouse cursor is above an item.
95 */
96 void emitItemEntered(const QModelIndex& index);
97
98 /**
99 * Emits the signal viewportEntered(). The method should be invoked by
100 * the controller parent whenever the mouse cursor is above the viewport.
101 */
102 void emitViewportEntered();
103
104 signals:
105 /**
106 * Is emitted if a context menu should be opened.
107 * @param pos Position relative to the view widget where the
108 * context menu should be opened. It is recommended
109 * to get the corresponding model index from
110 * this position.
111 */
112 void requestContextMenu(const QPoint& pos);
113
114 /**
115 * Is emitted if the view has been activated by e. g. a mouse click.
116 */
117 void activated();
118
119 /**
120 * Is emitted if the URLs \a urls have been dropped to the index
121 * \a index. \a source indicates the widget where the dragging has
122 * been started from.
123 */
124 void urlsDropped(const KUrl::List& urls,
125 const QModelIndex& index,
126 QWidget* source);
127
128 /** Is emitted if the sorting has been changed to \a sorting. */
129 void sortingChanged(DolphinView::Sorting sorting);
130
131 /** Is emitted if the sort order has been changed to \a sort order. */
132 void sortOrderChanged(Qt::SortOrder order);
133
134 /**
135 * Is emitted if the state for showing previews has been
136 * changed to \a show.
137 */
138 void showPreviewChanged(bool show);
139
140 /**
141 * Is emitted if the state for showing additional info has been
142 * changed to \a show.
143 */
144 void showAdditionalInfoChanged(bool show);
145
146 /**
147 * Is emitted if the item with the index \a index should be triggered.
148 * Usually triggering on a directory opens the directory, triggering
149 * on a file opens the corresponding application.
150 */
151 void itemTriggered(const QModelIndex& index);
152
153 /**
154 * Is emitted if the mouse cursor has entered the item
155 * given by \a index.
156 */
157 void itemEntered(const QModelIndex& index);
158
159 /**
160 * Is emitted if the mouse cursor has entered
161 * the viewport. */
162 void viewportEntered();
163
164 /** Is emitted if the view should zoom in. */
165 void zoomIn();
166
167 /** Is emitted if the view should zoom out. */
168 void zoomOut();
169
170 private:
171 bool m_showPreview;
172 bool m_showAdditionalInfo;
173 bool m_zoomInPossible;
174 bool m_zoomOutPossible;
175 KUrl m_url;
176 };
177
178 void DolphinController::setUrl(const KUrl& url)
179 {
180 m_url = url;
181 }
182
183 const KUrl& DolphinController::url() const
184 {
185 return m_url;
186 }
187
188 bool DolphinController::showPreview() const
189 {
190 return m_showPreview;
191 }
192
193 bool DolphinController::showAdditionalInfo() const
194 {
195 return m_showAdditionalInfo;
196 }
197
198 void DolphinController::setZoomInPossible(bool possible)
199 {
200 m_zoomInPossible = possible;
201 }
202
203 bool DolphinController::isZoomInPossible() const
204 {
205 return m_zoomInPossible;
206 }
207
208 void DolphinController::setZoomOutPossible(bool possible)
209 {
210 m_zoomOutPossible = possible;
211 }
212
213 bool DolphinController::isZoomOutPossible() const
214 {
215 return m_zoomOutPossible;
216 }
217
218 #endif