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 <dolphinview.h>
25 #include <QtCore/QObject>
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 DolphinController 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 tree 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 destPath Path of the destination.
91 * @param event Drop event
93 void indicateDroppedUrls(const KFileItem
& destItem
,
98 * Informs the DolphinView about a sorting change done inside
99 * the view mode implementation.
101 void indicateSortingChange(DolphinView::Sorting sorting
);
104 * Informs the DolphinView about a sort order change done inside
105 * the view mode implementation.
107 void indicateSortOrderChange(Qt::SortOrder order
);
110 * Informs the DolphinView about a change between separate sorting
111 * (with folders first) and mixed sorting of files and folders done inside
112 * the view mode implementation.
114 void indicateSortFoldersFirstChange(bool foldersFirst
);
117 * Informs the DolphinView about an additional information change
118 * done inside the view mode implementation.
120 void indicateAdditionalInfoChange(const KFileItemDelegate::InformationList
& info
);
123 * Sets the available version control actions. Is called by the view
124 * mode implementation as soon as the DolphinView has requested them by the signal
125 * requestVersionControlActions().
127 void setVersionControlActions(QList
<QAction
*> actions
);
130 * Emits the signal requestVersionControlActions(). The view mode implementation
131 * listens to the signal and will invoke a DolphinViewController::setVersionControlActions()
132 * and the result will be returned.
134 QList
<QAction
*> versionControlActions(const KFileItemList
& items
);
137 * Must be be invoked in each view mode implementation whenever a key has been
138 * pressed. If the selection model of \a view is not empty and
139 * the return key has been pressed, the selected items will get triggered.
141 void handleKeyPressEvent(QKeyEvent
* event
);
144 * Replaces the URL of the DolphinView with the content
145 * of the clipboard as URL. If the clipboard contains no text,
146 * nothing will be done.
148 void replaceUrlByClipboard();
151 * Requests the view mode implementation to hide tooltips.
153 void requestToolTipHiding();
156 * Emits the signal itemTriggered() for the item \a item.
157 * The method can be used by the view mode implementations to
158 * trigger an item directly without mouse interaction.
159 * If the item triggering is done by the mouse, it is recommended
160 * to use DolphinViewController::triggerItem(), as this will check
161 * the used mouse buttons to execute the correct action.
163 void emitItemTriggered(const KFileItem
& item
);
166 * Returns the file item for the proxy index \a index of the DolphinView.
168 KFileItem
itemForIndex(const QModelIndex
& index
) const;
172 * Emits the signal itemTriggered() if the file item for the index \a index
173 * is not null and the left mouse button has been pressed. If the item is
174 * null, the signal itemEntered() is emitted.
175 * The method should be invoked by the view mode implementations whenever the
176 * user has triggered an item with the mouse (see
177 * QAbstractItemView::clicked() or QAbstractItemView::doubleClicked()).
179 void triggerItem(const QModelIndex
& index
);
182 * Emits the signal tabRequested(), if the file item for the index \a index
183 * represents a directory and when the middle mouse button has been pressed.
185 void requestTab(const QModelIndex
& index
);
188 * Emits the signal itemEntered() if the file item for the index \a index
189 * is not null. The method should be invoked by the view mode implementation
190 * whenever the mouse cursor is above an item.
192 void emitItemEntered(const QModelIndex
& index
);
195 * Emits the signal viewportEntered(). The method should be invoked by
196 * the view mode implementation whenever the mouse cursor is above the viewport.
198 void emitViewportEntered();
201 void urlChangeRequested(const KUrl
& url
);
204 * Is emitted if a context menu should be opened (see triggerContextMenuRequest()).
205 * @param pos Position relative to the view widget where the
206 * context menu should be opened. It is recommended
207 * to get the corresponding model index from
209 * @param customActions List of actions that is added to the context menu when
210 * the menu is opened above the viewport.
212 void requestContextMenu(const QPoint
& pos
, QList
<QAction
*> customActions
);
215 * Is emitted if the view has been activated by e. g. a mouse click.
220 * Is emitted if URLs have been dropped to the destination
221 * path \a destPath. If the URLs have been dropped above an item of
222 * the destination path, the item is indicated by \a destItem
223 * (can be null, see KFileItem::isNull()).
225 void urlsDropped(const KFileItem
& destItem
,
226 const KUrl
& destPath
,
230 * Is emitted if the sorting has been changed to \a sorting by
231 * the view mode implementation (see indicateSortingChanged().
232 * The DolphinView connects to
233 * this signal to update its menu action.
235 void sortingChanged(DolphinView::Sorting sorting
);
238 * Is emitted if the sort order has been changed to \a order
239 * by the view mode implementation (see indicateSortOrderChanged().
240 * The DolphinView connects
241 * to this signal to update its menu actions.
243 void sortOrderChanged(Qt::SortOrder order
);
246 * Is emitted if 'sort folders first' has been changed to \a foldersFirst
247 * by the view mode implementation (see indicateSortOrderChanged().
248 * The DolphinView connects
249 * to this signal to update its menu actions.
251 void sortFoldersFirstChanged(bool foldersFirst
);
254 * Is emitted if the additional info has been changed to \a info
255 * by the view mode implementation. The DolphinView connects
256 * to this signal to update its menu actions.
258 void additionalInfoChanged(const KFileItemDelegate::InformationList
& info
);
261 * Is emitted if the item \a item should be triggered. The abstract
262 * Dolphin view connects to this signal. If the item represents a directory,
263 * the directory is opened. On a file the corresponding application is opened.
264 * The item is null (see KFileItem::isNull()), when clicking on the viewport itself.
266 void itemTriggered(const KFileItem
& item
);
269 * Is emitted if the mouse cursor has entered the item
270 * given by \a index (see emitItemEntered()).
272 void itemEntered(const KFileItem
& item
);
275 * Is emitted if a new tab should be opened for the URL \a url.
277 void tabRequested(const KUrl
& url
);
280 * Is emitted if the mouse cursor has entered
281 * the viewport (see emitViewportEntered()).
283 void viewportEntered();
286 * Is emitted, if DolphinViewController::requestToolTipHiding() is invoked
287 * and requests to hide all tooltips.
292 * Is emitted if pending previews should be canceled (e. g. because of an URL change).
294 void cancelPreviews();
297 * Requests the view mode implementation to invoke DolphinViewController::setVersionControlActions(),
298 * so that they can be returned with DolphinViewController::versionControlActions() for
301 void requestVersionControlActions(const KFileItemList
& items
);
304 void updateMouseButtonState();
307 static Qt::MouseButtons m_mouseButtons
; // TODO: this is a workaround until Qt-issue 176832 has been fixed
309 DolphinView
* m_dolphinView
;
310 QAbstractItemView
* m_itemView
;
311 QList
<QAction
*> m_versionControlActions
;