1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
|
/***************************************************************************
* Copyright (C) 2006 by Peter Penz ([email protected]) *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#ifndef DOLPHINCONTROLLER_H
#define DOLPHINCONTROLLER_H
#include <dolphinview.h>
#include <kurl.h>
#include <QtCore/QObject>
#include <libdolphin_export.h>
class DolphinView;
class KUrl;
class QBrush;
class QPoint;
class QRect;
class QWidget;
// TODO: get rid of all the state duplications in the controller and allow read access
// to the Dolphin view for all view implementations
/**
* @brief Acts as mediator between the abstract Dolphin view and the view
* implementations.
*
* The abstract Dolphin view (see DolphinView) represents the parent of the controller.
* The controller is passed to the current view implementation
* (see DolphinIconsView, DolphinDetailsView and DolphinColumnView)
* by passing it in the constructor:
*
* \code
* DolphinController* controller = new DolphinController(dolphinView);
* QAbstractItemView* view = new DolphinIconsView(parent, controller);
* \endcode
*
* The communication of the view implementations to the abstract view is done by:
* - triggerContextMenuRequest()
* - requestActivation()
* - triggerUrlChangeRequest()
* - indicateDroppedUrls()
* - indicateSortingChange()
* - indicateSortOrderChanged()
* - setZoomInPossible()
* - setZoomOutPossible()
* - triggerItem()
* - emitItemEntered()
* - emitViewportEntered()
*
* The communication of the abstract view to the view implementations is done by:
* - setUrl()
* - setShowHiddenFiles()
* - setShowPreview()
* - indicateActivationChange()
* - triggerZoomIn()
* - triggerZoomOut()
*/
class LIBDOLPHINPRIVATE_EXPORT DolphinController : public QObject
{
Q_OBJECT
public:
explicit DolphinController(DolphinView* dolphinView);
virtual ~DolphinController();
/**
* Allows read access for the the view implementation to the abstract
* Dolphin view.
*/
const DolphinView* dolphinView() const;
/**
* Sets the URL to \a url and emits the signal urlChanged() if
* \a url is different for the current URL. This method should
* be invoked by the abstract Dolphin view whenever the current
* URL has been changed.
*/
void setUrl(const KUrl& url);
const KUrl& url() const;
/**
* Allows a view implementation to request an URL change to \a url.
* The signal requestUrlChange() is emitted and the abstract Dolphin view
* will assure that the URL of the Dolphin Controller will be updated
* later. Invoking this method makes only sense if the view implementation
* shows a hierarchy of URLs and allows to change the URL within
* the view (e. g. this is the case in the column view).
*/
void triggerUrlChangeRequest(const KUrl& url);
/**
* Requests a context menu for the position \a pos. This method
* should be invoked by the view implementation when a context
* menu should be opened. The abstract Dolphin view itself
* takes care itself to get the selected items depending from
* \a pos.
*/
void triggerContextMenuRequest(const QPoint& pos);
/**
* Requests an activation of the view and emits the signal
* activated(). This method should be invoked by the view implementation
* if e. g. a mouse click on the view has been done.
* After the activation has been changed, the view implementation
* might listen to the activationChanged() signal.
*/
void requestActivation();
/**
* Indicates that URLs are dropped above a destination. This method
* should be invoked by the view implementation. The abstract Dolphin view
* will start the corresponding action (copy, move, link).
* @param urls URLs that are dropped above a destination.
* @param destPath Path of the destination.
* @param destItem Destination item (can be null, see KFileItem::isNull()).
*/
void indicateDroppedUrls(const KUrl::List& urls,
const KUrl& destPath,
const KFileItem& destItem);
/**
* Informs the abstract Dolphin view about a sorting change done inside
* the view implementation. This method should be invoked by the view
* implementation (e. g. the details view uses this method in combination
* with the details header).
*/
void indicateSortingChange(DolphinView::Sorting sorting);
/**
* Informs the abstract Dolphin view about a sort order change done inside
* the view implementation. This method should be invoked by the view
* implementation (e. g. the details view uses this method in combination
* with the details header).
*/
void indicateSortOrderChange(Qt::SortOrder order);
/**
* Informs the abstract Dolphin view about an additional information change
* done inside the view implementation. This method should be invoked by the
* view implementation (e. g. the details view uses this method in combination
* with the details header).
*/
void indicateAdditionalInfoChange(const KFileItemDelegate::InformationList& info);
/**
* Informs the view implementation about a change of the activation
* state and is invoked by the abstract Dolphin view. The signal
* activationChanged() is emitted.
*/
void indicateActivationChange(bool active);
/**
* Tells the view implementation to zoom in by emitting the signal zoomIn()
* and is invoked by the abstract Dolphin view.
*/
void triggerZoomIn();
/**
* Is invoked by the view implementation to indicate whether a zooming in
* is possible. The abstract Dolphin view updates the corresponding menu
* action depending on this state.
*/
void setZoomInPossible(bool possible);
bool isZoomInPossible() const;
/**
* Tells the view implementation to zoom out by emitting the signal zoomOut()
* and is invoked by the abstract Dolphin view.
*/
void triggerZoomOut();
/**
* Is invoked by the view implementation to indicate whether a zooming out
* is possible. The abstract Dolphin view updates the corresponding menu
* action depending on this state.
*/
void setZoomOutPossible(bool possible);
bool isZoomOutPossible() const;
public slots:
/**
* Emits the signal itemTriggered(). The method should be invoked by the
* controller parent whenever the user has triggered an item. */
void triggerItem(const KFileItem& item);
/**
* Emits the signal itemEntered(). The method should be invoked by
* the controller parent whenever the mouse cursor is above an item.
*/
void emitItemEntered(const KFileItem& item);
/**
* Emits the signal viewportEntered(). The method should be invoked by
* the controller parent whenever the mouse cursor is above the viewport.
*/
void emitViewportEntered();
signals:
/**
* Is emitted if the URL for the Dolphin controller has been changed
* to \a url.
*/
void urlChanged(const KUrl& url);
/**
* Is emitted if the view implementation requests a changing of the current
* URL to \a url (see triggerUrlChangeRequest()).
*/
void requestUrlChange(const KUrl& url);
/**
* Is emitted if a context menu should be opened (see triggerContextMenuRequest()).
* The abstract Dolphin view connects to this signal and will open the context menu.
* @param pos Position relative to the view widget where the
* context menu should be opened. It is recommended
* to get the corresponding model index from
* this position.
*/
void requestContextMenu(const QPoint& pos);
/**
* Is emitted if the view has been activated by e. g. a mouse click.
* The abstract Dolphin view connects to this signal to know the
* destination view for the menu actions.
*/
void activated();
/**
* Is emitted if the URLs \a urls have been dropped to the destination
* path \a destPath. If the URLs have been dropped above an item of
* the destination path, the item is indicated by \a destItem
* (can be null, see KFileItem::isNull()).
*/
void urlsDropped(const KUrl::List& urls,
const KUrl& destPath,
const KFileItem& destItem);
/**
* Is emitted if the sorting has been changed to \a sorting by
* the view implementation (see indicateSortingChanged().
* The abstract Dolphin view connects to
* this signal to update its menu action.
*/
void sortingChanged(DolphinView::Sorting sorting);
/**
* Is emitted if the sort order has been changed to \a order
* by the view implementation (see indicateSortOrderChanged().
* The abstract Dolphin view connects
* to this signal to update its menu actions.
*/
void sortOrderChanged(Qt::SortOrder order);
/**
* Is emitted if the additional info has been changed to \a info
* by the view implementation. The abstract Dolphin view connects
* to this signal to update its menu actions.
*/
void additionalInfoChanged(const KFileItemDelegate::InformationList& info);
/**
* Is emitted if the activation state has been changed to \a active
* by the abstract Dolphin view.
* The view implementation might connect to this signal if custom
* updates are required in this case.
*/
void activationChanged(bool active);
/**
* Is emitted if the item \a item should be triggered. The abstract
* Dolphin view connects to this signal. If the item represents a directory,
* the directory is opened. On a file the corresponding application is opened.
* The item is null (see KFileItem::isNull()), when clicking on the viewport itself.
*/
void itemTriggered(const KFileItem& item);
/**
* Is emitted if the mouse cursor has entered the item
* given by \a index (see emitItemEntered()).
* The abstract Dolphin view connects to this signal.
*/
void itemEntered(const KFileItem& item);
/**
* Is emitted if the mouse cursor has entered
* the viewport (see emitViewportEntered().
* The abstract Dolphin view connects to this signal.
*/
void viewportEntered();
/**
* Is emitted if the view should zoom in. The view implementation
* must connect to this signal if it supports zooming.
*/
void zoomIn();
/**
* Is emitted if the view should zoom out. The view implementation
* must connect to this signal if it supports zooming.
*/
void zoomOut();
private:
bool m_zoomInPossible;
bool m_zoomOutPossible;
KUrl m_url;
DolphinView* m_dolphinView;
};
inline const DolphinView* DolphinController::dolphinView() const
{
return m_dolphinView;
}
inline const KUrl& DolphinController::url() const
{
return m_url;
}
inline void DolphinController::setZoomInPossible(bool possible)
{
m_zoomInPossible = possible;
}
inline bool DolphinController::isZoomInPossible() const
{
return m_zoomInPossible;
}
inline void DolphinController::setZoomOutPossible(bool possible)
{
m_zoomOutPossible = possible;
}
inline bool DolphinController::isZoomOutPossible() const
{
return m_zoomOutPossible;
}
#endif
|