1 /***************************************************************************
2 * Copyright (C) 2010 by Peter Penz <peter.penz@gmx.at> *
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. *
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. *
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 ***************************************************************************/
20 #ifndef DOLPHINVIEWCONTROLLER_H
21 #define DOLPHINVIEWCONTROLLER_H
23 #include <views/dolphinview.h>
26 #include <libdolphin_export.h>
28 class QAbstractItemView
;
34 * @brief Allows the view mode implementations (DolphinIconsView, DolphinDetailsView, DolphinColumnView)
35 * to do a limited control of the DolphinView.
37 * The DolphinView connects to the signals of DolphinViewController to react on changes
38 * that have been triggered by the view mode implementations. The view mode implementations
39 * have read access to the whole DolphinView by DolphinViewController::view(). Limited control of the
40 * DolphinView by the view mode implementations are defined by the public DolphinViewController methods.
42 class LIBDOLPHINPRIVATE_EXPORT DolphinViewController
: public QObject
47 explicit DolphinViewController(DolphinView
* dolphinView
);
48 virtual ~DolphinViewController();
51 * Allows read access for the view mode implementation
54 const DolphinView
* view() const;
57 * Requests the DolphinView to change the URL to \p url. The signal
58 * urlChangeRequested will be emitted.
60 void requestUrlChange(const KUrl
& url
);
63 * Changes the current view mode implementation where the controller is working.
64 * This is only necessary for views like the column view, where internally
65 * several QAbstractItemView instances are used.
67 void setItemView(QAbstractItemView
* view
);
68 QAbstractItemView
* itemView() const;
71 * Requests a context menu for the position \a pos. DolphinView
72 * takes care itself to get the selected items depending from
73 * \a pos. It is possible to define a custom list of actions for
74 * the context menu by \a customActions.
76 void triggerContextMenuRequest(const QPoint
& pos
,
77 const QList
<QAction
*>& customActions
= QList
<QAction
*>());
80 * Requests an activation of the DolphinView and emits the signal
81 * activated(). This method should be invoked by the view mode implementation
82 * if e. g. a mouse click on the view has been done.
84 void requestActivation();
87 * Indicates that URLs are dropped above a destination. The DolphinView
88 * will start the corresponding action (copy, move, link).
89 * @param destItem Item of the destination (can be null, see KFileItem::isNull()).
90 * @param event Drop event
92 void indicateDroppedUrls(const KFileItem
& destItem
, QDropEvent
* event
);
95 * Informs the DolphinView about a sorting change done inside
96 * the view mode implementation.
98 void indicateSortingChange(DolphinView::Sorting sorting
);
101 * Informs the DolphinView about a sort order change done inside
102 * the view mode implementation.
104 void indicateSortOrderChange(Qt::SortOrder order
);
107 * Informs the DolphinView about a change between separate sorting
108 * (with folders first) and mixed sorting of files and folders done inside
109 * the view mode implementation.
111 void indicateSortFoldersFirstChange(bool foldersFirst
);
114 * Informs the DolphinView about an additional information change
115 * done inside the view mode implementation.
117 void indicateAdditionalInfoChange(const KFileItemDelegate::InformationList
& info
);
120 * Sets the available version control actions. Is called by the view
121 * mode implementation as soon as the DolphinView has requested them by the signal
122 * requestVersionControlActions().
124 void setVersionControlActions(QList
<QAction
*> actions
);
127 * Emits the signal requestVersionControlActions(). The view mode implementation
128 * listens to the signal and will invoke a DolphinViewController::setVersionControlActions()
129 * and the result will be returned.
131 QList
<QAction
*> versionControlActions(const KFileItemList
& items
);
134 * Must be be invoked in each view mode implementation whenever a key has been
135 * pressed. If the selection model of \a view is not empty and
136 * the return key has been pressed, the selected items will get triggered.
138 void handleKeyPressEvent(QKeyEvent
* event
);
141 * Replaces the URL of the DolphinView with the content
142 * of the clipboard as URL. If the clipboard contains no text,
143 * nothing will be done.
145 void replaceUrlByClipboard();
148 * Requests the view mode implementation to hide tooltips.
150 void requestToolTipHiding();
153 * Emits the signal itemTriggered() for the item \a item.
154 * The method can be used by the view mode implementations to
155 * trigger an item directly without mouse interaction.
156 * If the item triggering is done by the mouse, it is recommended
157 * to use DolphinViewController::triggerItem(), as this will check
158 * the used mouse buttons to execute the correct action.
160 void emitItemTriggered(const KFileItem
& item
);
163 * Returns the file item for the proxy index \a index of the DolphinView.
165 KFileItem
itemForIndex(const QModelIndex
& index
) const;
169 * Emits the signal itemTriggered() if the file item for the index \a index
170 * is not null and the left mouse button has been pressed. If the item is
171 * null, the signal itemEntered() is emitted.
172 * The method should be invoked by the view mode implementations whenever the
173 * user has triggered an item with the mouse (see
174 * QAbstractItemView::clicked() or QAbstractItemView::doubleClicked()).
176 void triggerItem(const QModelIndex
& index
);
179 * Emits the signal tabRequested(), if the file item for the index \a index
180 * represents a directory and when the middle mouse button has been pressed.
182 void requestTab(const QModelIndex
& index
);
185 * Emits the signal itemEntered() if the file item for the index \a index
186 * is not null. The method should be invoked by the view mode implementation
187 * whenever the mouse cursor is above an item.
189 void emitItemEntered(const QModelIndex
& index
);
192 * Emits the signal viewportEntered(). The method should be invoked by
193 * the view mode implementation whenever the mouse cursor is above the viewport.
195 void emitViewportEntered();
198 void urlChangeRequested(const KUrl
& url
);
201 * Is emitted if a context menu should be opened (see triggerContextMenuRequest()).
202 * @param pos Position relative to the view widget where the
203 * context menu should be opened. It is recommended
204 * to get the corresponding model index from
206 * @param customActions List of actions that is added to the context menu when
207 * the menu is opened above the viewport.
209 void requestContextMenu(const QPoint
& pos
, QList
<QAction
*> customActions
);
212 * Is emitted if the view has been activated by e. g. a mouse click.
217 * Is emitted if URLs have been dropped to the destination
218 * path \a destPath. If the URLs have been dropped above an item of
219 * the destination path, the item is indicated by \a destItem
220 * (can be null, see KFileItem::isNull()).
222 void urlsDropped(const KFileItem
& destItem
,
223 const KUrl
& destPath
,
227 * Is emitted if the sorting has been changed to \a sorting by
228 * the view mode implementation (see indicateSortingChanged().
229 * The DolphinView connects to
230 * this signal to update its menu action.
232 void sortingChanged(DolphinView::Sorting sorting
);
235 * Is emitted if the sort order has been changed to \a order
236 * by the view mode implementation (see indicateSortOrderChanged().
237 * The DolphinView connects
238 * to this signal to update its menu actions.
240 void sortOrderChanged(Qt::SortOrder order
);
243 * Is emitted if 'sort folders first' has been changed to \a foldersFirst
244 * by the view mode implementation (see indicateSortOrderChanged().
245 * The DolphinView connects
246 * to this signal to update its menu actions.
248 void sortFoldersFirstChanged(bool foldersFirst
);
251 * Is emitted if the additional info has been changed to \a info
252 * by the view mode implementation. The DolphinView connects
253 * to this signal to update its menu actions.
255 void additionalInfoChanged(const KFileItemDelegate::InformationList
& info
);
258 * Is emitted if the item \a item should be triggered. The abstract
259 * Dolphin view connects to this signal. If the item represents a directory,
260 * the directory is opened. On a file the corresponding application is opened.
261 * The item is null (see KFileItem::isNull()), when clicking on the viewport itself.
263 void itemTriggered(const KFileItem
& item
);
266 * Is emitted if the mouse cursor has entered the item
267 * given by \a index (see emitItemEntered()).
269 void itemEntered(const KFileItem
& item
);
272 * Is emitted if a new tab should be opened for the URL \a url.
274 void tabRequested(const KUrl
& url
);
277 * Is emitted if the mouse cursor has entered
278 * the viewport (see emitViewportEntered()).
280 void viewportEntered();
283 * Is emitted, if DolphinViewController::requestToolTipHiding() is invoked
284 * and requests to hide all tooltips.
289 * Is emitted if pending previews should be canceled (e. g. because of an URL change).
291 void cancelPreviews();
294 * Requests the view mode implementation to invoke DolphinViewController::setVersionControlActions(),
295 * so that they can be returned with DolphinViewController::versionControlActions() for
298 void requestVersionControlActions(const KFileItemList
& items
);
301 void updateMouseButtonState();
304 static Qt::MouseButtons m_mouseButtons
; // TODO: this is a workaround until Qt-issue 176832 has been fixed
306 DolphinView
* m_dolphinView
;
307 QAbstractItemView
* m_itemView
;
308 QList
<QAction
*> m_versionControlActions
;