]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphincontroller.h
f9f4f4e4716d05daec5469e8274ebe41ef251cfe
[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 <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 void setUrl(const KUrl& url)
58 {
59 m_url = url;
60 }
61 const KUrl& url() const
62 {
63 return m_url;
64 }
65
66 void triggerContextMenuRequest(const QPoint& pos);
67
68 void triggerActivation();
69
70 void indicateDroppedUrls(const KUrl::List& urls,
71 const QModelIndex& index,
72 QWidget* source);
73
74 void indicateSortingChange(DolphinView::Sorting sorting);
75
76 void indicateSortOrderChange(Qt::SortOrder order);
77
78 void setShowPreview(bool showPreview);
79 bool showPreview() const
80 {
81 return m_showPreview;
82 }
83
84 void triggerZoomIn();
85 void setZoomInPossible(bool possible)
86 {
87 m_zoomInPossible = possible;
88 }
89 bool isZoomInPossible() const
90 {
91 return m_zoomInPossible;
92 }
93
94 void triggerZoomOut();
95 void setZoomOutPossible(bool possible)
96 {
97 m_zoomOutPossible = possible;
98 }
99 bool isZoomOutPossible() const
100 {
101 return m_zoomOutPossible;
102 }
103
104 public slots:
105 void triggerItem(const QModelIndex& index);
106 void indicateSelectionChange();
107
108 signals:
109 /**
110 * Is emitted if a context menu should be opened.
111 * @param pos Position relative to the view widget where the
112 * context menu should be opened. It is recommended
113 * to get the corresponding model index from
114 * this position.
115 */
116 void requestContextMenu(const QPoint& pos);
117
118 /**
119 * Is emitted if the view has been activated by e. g. a mouse click.
120 */
121 void activated();
122
123 /**
124 * Is emitted if the URLs \a urls have been dropped to the index
125 * \a index. \a source indicates the widget where the dragging has
126 * been started from.
127 */
128 void urlsDropped(const KUrl::List& urls,
129 const QModelIndex& index,
130 QWidget* source);
131
132 /** Is emitted if the sorting has been changed to \a sorting. */
133 void sortingChanged(DolphinView::Sorting sorting);
134
135 /** Is emitted if the sort order has been changed to \a sort order. */
136 void sortOrderChanged(Qt::SortOrder order);
137
138 /**
139 * Is emitted if the state for showing previews has been
140 * changed to \a showPreview.
141 */
142 void showPreviewChanged(bool showPreview);
143
144 /**
145 * Is emitted if the item with the index \a index should be triggered.
146 * Usually triggering on a directory opens the directory, triggering
147 * on a file opens the corresponding application.
148 */
149 void itemTriggered(const QModelIndex& index);
150
151 /** Is emitted if the selection has been changed by the user. */
152 void selectionChanged();
153
154 /** Is emitted if the view should zoom in. */
155 void zoomIn();
156
157 /** Is emitted if the view should zoom out. */
158 void zoomOut();
159
160 private:
161 bool m_showPreview;
162 bool m_zoomInPossible;
163 bool m_zoomOutPossible;
164 KUrl m_url;
165 };
166
167 #endif