]> cloud.milkyroute.net Git - dolphin.git/blob - src/views/dolphinviewactionhandler.h
Add Reset Zoom Level action inside View menu
[dolphin.git] / src / views / dolphinviewactionhandler.h
1 /***************************************************************************
2 * Copyright (C) 2008 by David Faure <faure@kde.org> *
3 * Copyright (C) 2012 by Peter Penz <peter.penz19@gmail.com> *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
20
21
22 #ifndef DOLPHINVIEWACTIONHANDLER_H
23 #define DOLPHINVIEWACTIONHANDLER_H
24
25 #include "dolphin_export.h"
26 #include "views/dolphinview.h"
27
28 #include <QObject>
29
30 class KToggleAction;
31 class QAction;
32 class QActionGroup;
33 class DolphinView;
34 class KActionCollection;
35
36 /**
37 * @short Handles all actions for DolphinView
38 *
39 * The action handler owns all the actions and slots related to DolphinView,
40 * but the view that it acts upon can be switched to another one
41 * (this is used in the case of split views).
42 *
43 * The purpose of this class is also to share this code between DolphinMainWindow
44 * and DolphinPart.
45 *
46 * @see DolphinView
47 * @see DolphinMainWindow
48 * @see DolphinPart
49 */
50 class DOLPHIN_EXPORT DolphinViewActionHandler : public QObject
51 {
52 Q_OBJECT
53
54 public:
55 explicit DolphinViewActionHandler(KActionCollection* collection, QObject* parent);
56
57 /**
58 * Sets the view that this action handler should work on.
59 */
60 void setCurrentView(DolphinView* view);
61
62 /**
63 * Returns the view that this action handler should work on.
64 */
65 DolphinView* currentView();
66
67 /**
68 * Returns the name of the action for the current viewmode
69 */
70 QString currentViewModeActionName() const;
71
72 /**
73 * Returns m_actionCollection
74 */
75 KActionCollection* actionCollection();
76
77 public Q_SLOTS:
78 /**
79 * Update all actions in the 'View' menu, i.e. those that depend on the
80 * settings in the current view.
81 */
82 void updateViewActions();
83
84 Q_SIGNALS:
85 /**
86 * Emitted by DolphinViewActionHandler when the user triggered an action.
87 * This is only used for clearing the statusbar in DolphinMainWindow.
88 */
89 void actionBeingHandled();
90
91 /**
92 * Emitted if the user requested creating a new directory by the F10 key.
93 * The receiver of the signal (DolphinMainWindow or DolphinPart) invokes
94 * the method createDirectory of their KNewFileMenu instance.
95 */
96 void createDirectoryTriggered();
97
98 private Q_SLOTS:
99 /**
100 * Emitted when the user requested a change of view mode
101 */
102 void slotViewModeActionTriggered(QAction*);
103
104 /**
105 * Let the user input a name for the selected item(s) and trigger
106 * a renaming afterwards.
107 */
108 void slotRename();
109
110 /**
111 * Moves the selected items of the active view to the trash.
112 * This methods adds "shift means del" handling.
113 */
114 void slotTrashActivated();
115
116 /**
117 * Deletes the selected items of the active view.
118 */
119 void slotDeleteItems();
120
121 /**
122 * Switches between showing a preview of the file content and showing the icon.
123 */
124 void togglePreview(bool);
125
126 /** Updates the state of the 'Show preview' menu action. */
127 void slotPreviewsShownChanged(bool shown);
128
129 /** Increases the size of the current set view mode. */
130 void zoomIn();
131
132 /** Decreases the size of the current set view mode. */
133 void zoomOut();
134
135 /** Resets the size of the current set view mode to default. */
136 void zoomReset();
137
138 /** Switches between a separate sorting and a mixed sorting of files and folders. */
139 void toggleSortFoldersFirst();
140
141 /**
142 * Updates the state of the 'Sort Ascending/Descending' action.
143 */
144 void slotSortOrderChanged(Qt::SortOrder order);
145
146 /**
147 * Updates the state of the 'Sort Folders First' action.
148 */
149 void slotSortFoldersFirstChanged(bool foldersFirst);
150
151 /**
152 * Updates the state of the 'Sort by' actions.
153 */
154 void slotSortRoleChanged(const QByteArray& role);
155
156 /**
157 * Updates the state of the 'Zoom In' and 'Zoom Out' actions.
158 */
159 void slotZoomLevelChanged(int current, int previous);
160
161 /**
162 * Switches on or off the displaying of additional information
163 * as specified by \a action.
164 */
165 void toggleVisibleRole(QAction* action);
166
167 /**
168 * Changes the sorting of the current view.
169 */
170 void slotSortTriggered(QAction*);
171
172 /**
173 * Updates the state of the 'Additional Information' actions.
174 */
175 void slotVisibleRolesChanged(const QList<QByteArray>& current,
176 const QList<QByteArray>& previous);
177
178 /**
179 * Switches between sorting by groups or not.
180 */
181 void toggleGroupedSorting(bool);
182
183 /**
184 * Updates the state of the 'Categorized sorting' menu action.
185 */
186 void slotGroupedSortingChanged(bool sortCategorized);
187
188 /**
189 * Switches between showing and hiding of hidden marked files
190 */
191 void toggleShowHiddenFiles(bool);
192
193 /**
194 * Updates the state of the 'Show hidden files' menu action.
195 */
196 void slotHiddenFilesShownChanged(bool shown);
197
198 /**
199 * Updates the state of the 'Create Folder...' action.
200 */
201 void slotWriteStateChanged(bool isFolderWritable);
202
203 /**
204 * Opens the view properties dialog, which allows to modify the properties
205 * of the currently active view.
206 */
207 void slotAdjustViewProperties();
208
209 /**
210 * Connected to the "properties" action.
211 * Opens the properties dialog for the selected items of the
212 * active view. The properties dialog shows information
213 * like name, size and permissions.
214 */
215 void slotProperties();
216
217 private:
218 /**
219 * Create all the actions.
220 * This is called only once (by the constructor)
221 */
222 void createActions();
223
224 /**
225 * Creates an action-group out of all roles from KFileItemModel.
226 * Dependent on the group-prefix either a radiobutton-group is
227 * created for sorting (prefix is "sort_by_") or a checkbox-group
228 * is created for additional information (prefix is "show_").
229 * The changes of actions are reported to slotSortTriggered() or
230 * toggleAdditionalInfo().
231 */
232 QActionGroup* createFileItemRolesActionGroup(const QString& groupPrefix);
233
234 /**
235 * Returns the "switch to icons mode" action.
236 * Helper method for createActions();
237 */
238 KToggleAction* iconsModeAction();
239
240 /**
241 * Returns the "switch to compact mode" action.
242 * Helper method for createActions();
243 */
244 KToggleAction* compactModeAction();
245
246 /**
247 * Returns the "switch to details mode" action.
248 * Helper method for createActions();
249 */
250 KToggleAction* detailsModeAction();
251
252 KActionCollection* m_actionCollection;
253 DolphinView* m_currentView;
254
255 QHash<QByteArray, KToggleAction*> m_sortByActions;
256 QHash<QByteArray, KToggleAction*> m_visibleRoles;
257 };
258
259 #endif /* DOLPHINVIEWACTIONHANDLER_H */