┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/views/dolphinviewcontroller.h
blob: 1ad8fab33b40b5b1dd4756050e90e79dc68c7cc2 (plain)
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
/***************************************************************************
 *   Copyright (C) 2010 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 DOLPHINVIEWCONTROLLER_H
#define DOLPHINVIEWCONTROLLER_H

#include <views/dolphinview.h>
#include <KUrl>
#include <QObject>
#include <libdolphin_export.h>

class QAbstractItemView;
class DolphinView;
class KUrl;
class QPoint;

/**
 * @brief Allows the view mode implementations (DolphinIconsView, DolphinDetailsView, DolphinColumnView)
 *        to do a limited control of the DolphinView.
 *
 * The DolphinView connects to the signals of DolphinViewController to react on changes
 * that have been triggered by the view mode implementations. The view mode implementations
 * have read access to the whole DolphinView by DolphinViewController::view(). Limited control of the
 * DolphinView by the view mode implementations are defined by the public DolphinViewController methods.
 */
class LIBDOLPHINPRIVATE_EXPORT DolphinViewController : public QObject
{
    Q_OBJECT

public:
    explicit DolphinViewController(DolphinView* dolphinView);
    virtual ~DolphinViewController();

    /**
     * Allows read access for the view mode implementation
     * to the DolphinView.
     */
    const DolphinView* view() const;

    /**
     * Requests the DolphinView to change the URL to \p url. The signal
     * urlChangeRequested will be emitted.
     */
    void requestUrlChange(const KUrl& url);

    /**
     * Changes the current view mode implementation where the controller is working.
     * This is only necessary for views like the column view, where internally
     * several QAbstractItemView instances are used.
     */
    void setItemView(QAbstractItemView* view);
    QAbstractItemView* itemView() const;

    /**
     * Requests a context menu for the position \a pos. DolphinView
     * takes care itself to get the selected items depending from
     * \a pos. It is possible to define a custom list of actions for
     * the context menu by \a customActions.
     */
    void triggerContextMenuRequest(const QPoint& pos,
                                   const QList<QAction*>& customActions = QList<QAction*>());

    /**
     * Requests an activation of the DolphinView and emits the signal
     * activated(). This method should be invoked by the view mode implementation
     * if e. g. a mouse click on the view has been done.
     */
    void requestActivation();

    /**
     * Indicates that URLs are dropped above a destination. The DolphinView
     * will start the corresponding action (copy, move, link).
     * @param destItem  Item of the destination (can be null, see KFileItem::isNull()).
     * @param event     Drop event
     */
    void indicateDroppedUrls(const KFileItem& destItem, QDropEvent* event);

    /**
     * Informs the DolphinView about a sorting change done inside
     * the view mode implementation.
     */
    void indicateSortingChange(DolphinView::Sorting sorting);

    /**
     * Informs the DolphinView about a sort order change done inside
     * the view mode implementation.
     */
    void indicateSortOrderChange(Qt::SortOrder order);

    /**
     * Informs the DolphinView about a change between separate sorting
     * (with folders first) and mixed sorting of files and folders done inside
     * the view mode implementation.
     */
    void indicateSortFoldersFirstChange(bool foldersFirst);

    /**
     * Informs the DolphinView about an additional information change
     * done inside the view mode implementation.
     */
    void indicateAdditionalInfoChange(const KFileItemDelegate::InformationList& info);

    /**
     * Sets the available version control actions. Is called by the view
     * mode implementation as soon as the DolphinView has requested them by the signal
     * requestVersionControlActions().
     */
    void setVersionControlActions(QList<QAction*> actions);

    /**
     * Emits the signal requestVersionControlActions(). The view mode implementation
     * listens to the signal and will invoke a DolphinViewController::setVersionControlActions()
     * and the result will be returned.
     */
    QList<QAction*> versionControlActions(const KFileItemList& items);

    /**
     * Must be be invoked in each view mode implementation whenever a key has been
     * pressed. If the selection model of \a view is not empty and
     * the return key has been pressed, the selected items will get triggered.
     */
    void handleKeyPressEvent(QKeyEvent* event);

    /**
     * Replaces the URL of the DolphinView  with the content
     * of the clipboard as URL. If the clipboard contains no text,
     * nothing will be done.
     */
    void replaceUrlByClipboard();

    /**
     * Requests the view mode implementation to hide tooltips.
     */
    void requestToolTipHiding();

    /**
     * Emits the signal itemTriggered() for the item \a item.
     * The method can be used by the view mode implementations to
     * trigger an item directly without mouse interaction.
     * If the item triggering is done by the mouse, it is recommended
     * to use DolphinViewController::triggerItem(), as this will check
     * the used mouse buttons to execute the correct action.
     */
    void emitItemTriggered(const KFileItem& item);

    /**
     * Returns the file item for the proxy index \a index of the DolphinView.
     */
    KFileItem itemForIndex(const QModelIndex& index) const;

public slots:
    /**
     * Emits the signal itemTriggered() if the file item for the index \a index
     * is not null and the left mouse button has been pressed. If the item is
     * null, the signal itemEntered() is emitted.
     * The method should be invoked by the view mode implementations whenever the
     * user has triggered an item with the mouse (see
     * QAbstractItemView::clicked() or QAbstractItemView::doubleClicked()).
     */
    void triggerItem(const QModelIndex& index);

    /**
     * Emits the signal tabRequested(), if the file item for the index \a index
     * represents a directory and when the middle mouse button has been pressed.
     */
    void requestTab(const QModelIndex& index);

    /**
     * Emits the signal itemEntered() if the file item for the index \a index
     * is not null. The method should be invoked by the view mode implementation
     * whenever the mouse cursor is above an item.
     */
    void emitItemEntered(const QModelIndex& index);

    /**
     * Emits the signal viewportEntered(). The method should be invoked by
     * the view mode implementation whenever the mouse cursor is above the viewport.
     */
    void emitViewportEntered();

signals:
    void urlChangeRequested(const KUrl& url);

    /**
     * Is emitted if a context menu should be opened (see triggerContextMenuRequest()).
     * @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.
     * @param customActions List of actions that is added to the context menu when
     *                      the menu is opened above the viewport.
     */
    void requestContextMenu(const QPoint& pos, QList<QAction*> customActions);

    /**
     * Is emitted if the view has been activated by e. g. a mouse click.
     */
    void activated();

    /**
     * Is emitted if 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 KFileItem& destItem,
                     const KUrl& destPath,
                     QDropEvent* event);

    /**
     * Is emitted if the sorting has been changed to \a sorting by
     * the view mode implementation (see indicateSortingChanged().
     * The DolphinView 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 mode implementation (see indicateSortOrderChanged().
     * The DolphinView connects
     * to this signal to update its menu actions.
     */
    void sortOrderChanged(Qt::SortOrder order);

    /**
     * Is emitted if 'sort folders first' has been changed to \a foldersFirst
     * by the view mode implementation (see indicateSortOrderChanged().
     * The DolphinView connects
     * to this signal to update its menu actions.
     */
    void sortFoldersFirstChanged(bool foldersFirst);

    /**
     * Is emitted if the additional info has been changed to \a info
     * by the view mode implementation. The DolphinView connects
     * to this signal to update its menu actions.
     */
    void additionalInfoChanged(const KFileItemDelegate::InformationList& info);

    /**
     * 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()).
     */
    void itemEntered(const KFileItem& item);

    /**
     * Is emitted if a new tab should be opened for the URL \a url.
     */
    void tabRequested(const KUrl& url);

    /**
     * Is emitted if the mouse cursor has entered
     * the viewport (see emitViewportEntered()).
     */
    void viewportEntered();

    /**
     * Is emitted, if DolphinViewController::requestToolTipHiding() is invoked
     * and requests to hide all tooltips.
     */
    void hideToolTip();

    /**
     * Is emitted if pending previews should be canceled (e. g. because of an URL change).
     */
    void cancelPreviews();

    /**
     * Requests the view mode implementation to invoke DolphinViewController::setVersionControlActions(),
     * so that they can be returned with DolphinViewController::versionControlActions() for
     * the DolphinView.
     */
    void requestVersionControlActions(const KFileItemList& items);

private slots:
    void updateMouseButtonState();

private:
    static Qt::MouseButtons m_mouseButtons; // TODO: this is a workaround until  Qt-issue 176832 has been fixed

    DolphinView* m_dolphinView;
    QAbstractItemView* m_itemView;
    QList<QAction*> m_versionControlActions;
};

#endif