1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date        : 2013-04-29
7  * Description : digiKam XML GUI window
8  *
9  * Copyright (C) 2013-2021 by Gilles Caulier <caulier dot gilles at gmail dot com>
10  *
11  * This program is free software; you can redistribute it
12  * and/or modify it under the terms of the GNU General
13  * Public License as published by the Free Software Foundation;
14  * either version 2, or (at your option)
15  * any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * ============================================================ */
23 
24 #ifndef DIGIKAM_DXML_GUI_WINDOW_H
25 #define DIGIKAM_DXML_GUI_WINDOW_H
26 
27 // Qt includes
28 
29 #include <QWidget>
30 #include <QObject>
31 #include <QAction>
32 #include <QWindow>
33 
34 // KDE includes
35 
36 #include <kxmlguiwindow.h>
37 
38 // Local includes
39 
40 #include "digikam_export.h"
41 #include "digikam_config.h"
42 #include "dlogoaction.h"
43 #include "dinfointerface.h"
44 #include "dpluginaction.h"
45 #include "dpluginloader.h"
46 
47 class QEvent;
48 
49 class KToolBar;
50 class KConfigGroup;
51 
52 namespace Digikam
53 {
54 
55 /**
56  * Optional parts which can be hidden or not from managed window configuration panel
57  */
58 enum FullScreenOptions
59 {
60     FS_TOOLBARS   = 0x00000001,                                                ///< Manage Tools bar in full-screen mode.
61     FS_THUMBBAR   = 0x00000002,                                                ///< Manage Thumb bar in full-screen mode.
62     FS_SIDEBARS   = 0x00000004,                                                ///< Manage Side bars in full-screen mode.
63     FS_STATUSBAR  = 0x00000008,                                                ///< Manage Status bar in full-screen mode.
64     FS_NONE       = 0x00000010,                                                ///< No full-screen options.
65 
66     FS_ALBUMGUI   = FS_TOOLBARS | FS_THUMBBAR | FS_SIDEBARS | FS_STATUSBAR,    ///< Album GUI Config.
67     FS_EDITOR     = FS_TOOLBARS | FS_THUMBBAR | FS_SIDEBARS | FS_STATUSBAR,    ///< Image Editor Config.
68     FS_LIGHTTABLE = FS_TOOLBARS | FS_SIDEBARS | FS_STATUSBAR,                  ///< Light Table Config.
69     FS_IMPORTUI   = FS_TOOLBARS | FS_THUMBBAR | FS_SIDEBARS | FS_STATUSBAR     ///< Import UI Config.
70 };
71 
72 enum StdActionType
73 {
74     StdCopyAction = 0,
75     StdPasteAction,
76     StdCutAction,
77     StdQuitAction,
78     StdCloseAction,
79     StdZoomInAction,
80     StdZoomOutAction,
81     StdOpenAction,
82     StdSaveAction,
83     StdSaveAsAction,
84     StdRevertAction,
85     StdBackAction,
86     StdForwardAction
87 };
88 
89 static const QString s_configFullScreenHideToolBarsEntry(QLatin1String("FullScreen Hide ToolBars"));
90 static const QString s_configFullScreenHideThumbBarEntry(QLatin1String("FullScreen Hide ThumbBar"));
91 static const QString s_configFullScreenHideSideBarsEntry(QLatin1String("FullScreen Hide SideBars"));
92 static const QString s_configFullScreenHideStatusBarEntry(QLatin1String("FullScreen Hide StatusBar"));
93 
94 /**
95  * Data container to use in managed window.
96  */
97 class DIGIKAM_EXPORT DXmlGuiWindow : public KXmlGuiWindow
98 {
99     Q_OBJECT
100 
101 public:
102 
103     explicit DXmlGuiWindow(QWidget* const parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
104     ~DXmlGuiWindow() override;
105 
106     /**
107      * Manage config group name used by window instance to get/set settings from config file
108      */
109     void setConfigGroupName(const QString& name);
110     QString configGroupName() const;
111 
112     /**
113      * Create common actions to setup all digiKam main windows.
114      */
115     void createSettingsActions();
116 
117     /**
118      * Create common actions from Help menu for all digiKam main windows.
119      */
120     void createHelpActions(bool coreOptions = true);
121 
122     /**
123      * Cleanup unwanted actions from action collection.
124      */
125     void cleanupActions();
126 
127     /**
128      * Create common actions to handle side-bar through keyboard shortcuts.
129      */
130     void createSidebarActions();
131 
132     /**
133      * Set full-screen options to managed window
134      */
135     void setFullScreenOptions(int options);
136 
137     /**
138      * Create Full-screen action to action collection instance from managed window
139      * set through setManagedWindow(). This action is connected to slotToggleFullScreen() slot.
140      * 'name' is action name used in KDE UI rc file.
141      */
142     void createFullScreenAction(const QString& name);
143 
144     /**
145      * Read full-screen settings from KDE config file.
146      */
147     void readFullScreenSettings(const KConfigGroup& group);
148 
149     /**
150      * Return true if managed window is currently in Full Screen Mode.
151      */
152     bool fullScreenIsActive() const;
153 
154     /**
155      * Return all actions from internal collection.
156      */
157     QList<QAction*> allActions() const;
158 
159 public:
160 
161     /**
162      * Register all generic plugins action to this instance.
163      * Call registerExtraPluginsActions() to plug oter kind of plugins in GUI.
164      */
165     void registerPluginsActions();
registerExtraPluginsActions(QString &)166     virtual void registerExtraPluginsActions(QString& /*dom*/) {};
167 
168     /**
169      * Return the interface instance to access to items information.
170      */
171     virtual DInfoInterface* infoIface(DPluginAction* const ac) = 0;
172 
173 public:
174 
175     static void openHandbook();
176     static void restoreWindowSize(QWindow* const win, const KConfigGroup& group);
177     static void saveWindowSize(QWindow* const win, KConfigGroup& group);
178 
179     static QAction* buildStdAction(StdActionType type,
180                                    const QObject* const recvr,
181                                    const char* const slot,
182                                    QObject* const parent);
183 
184     /**
185      * If we have some local breeze icon resource, prefer it.
186      */
187     static void setupIconTheme();
188 
189 protected:
190 
191     DLogoAction* m_animLogo;
192 
193 protected:
194 
195     QAction* showMenuBarAction()   const;
196     QAction* showStatusBarAction() const;
197 
198     /**
199      * Call this method from your main window to show keyboard shortcut config dialog
200      * with an extra action collection to configure. This method is called by slotEditKeys()
201      * which can be re-implement in child class for cutomization.
202      */
203     void editKeyboardShortcuts(KActionCollection* const extraac = nullptr, const QString& actitle = QString());
204 
205     void closeEvent(QCloseEvent* e)            override;
206     void keyPressEvent(QKeyEvent* e)           override;
207     bool eventFilter(QObject* obj, QEvent* ev) override;
208 
209     /**
210      * Re-implement this method if you want to manage sidebars visibility in full-screen mode.
211      * By default this method do nothing.
212      */
213     virtual void showSideBars(bool visible);
214 
215     /**
216      * Re-implement this method if you want to manage thumbbar visibility in full-screen mode.
217      * By default this method do nothing.
218      */
219     virtual void showThumbBar(bool visible);
220 
221     /**
222      * Re-implement this method if you want to manage customized view visibility in full-screen mode.
223      * This method is called by switchWindowToFullScreen(). By default this method do nothing.
224      */
225     virtual void customizedFullScreenMode(bool set);
226 
227     /**
228      * Re-implement this method if managed window has a thumbbar. This must return visibility state of it.
229      */
230     virtual bool thumbbarVisibility() const;
231 
232 private Q_SLOTS:
233 
234     void slotToggleFullScreen(bool);
235     void slotShowMenuBar();
236     void slotShowStatusBar();
237     void slotConfNotifications();
238     void slotConfToolbars();
239     void slotNewToolbarConfig();
240 
241     void slotRawCameraList();
242     void slotSolidHardwareList();
243     void slotDonateMoney();
244     void slotRecipesBook();
245     void slotContribute();
246     void slotHelpContents();
247 
248     /**
249      * Slots for common Help Actions
250      */
slotOnlineVersionCheck()251     virtual void slotOnlineVersionCheck()      {};
slotComponentsInfo()252     virtual void slotComponentsInfo()          {};
slotDBStat()253     virtual void slotDBStat()                  {};
254 
255     /**
256      * Slots for common Sidebar Actions
257      */
slotToggleLeftSideBar()258     virtual void slotToggleLeftSideBar()       {};
slotToggleRightSideBar()259     virtual void slotToggleRightSideBar()      {};
slotPreviousLeftSideBarTab()260     virtual void slotPreviousLeftSideBarTab()  {};
slotNextLeftSideBarTab()261     virtual void slotNextLeftSideBarTab()      {};
slotPreviousRightSideBarTab()262     virtual void slotPreviousRightSideBarTab() {};
slotNextRightSideBarTab()263     virtual void slotNextRightSideBarTab()     {};
264 
265     /**
266      * Slots for common Settings actions
267      */
slotEditKeys()268     virtual void slotEditKeys()                { editKeyboardShortcuts(); };
269     virtual void slotSetup() = 0;
270 
271 private:
272 
273     /**
274      * Used by slotToggleFullScreen() to switch tool-bar visibility in managed window
275      */
276     void showToolBars(bool visible);
277 
278     /**
279      * Return main tool bar instance created in managed window.
280      */
281     KToolBar* mainToolBar() const;
282 
283 private:
284 
285     class Private;
286     Private* const d;
287 };
288 
289 } // namespace Digikam
290 
291 #endif // DIGIKAM_DXML_GUI_WINDOW_H
292