File indexing completed on 2025-04-27 03:58:32

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2013-04-29
0007  * Description : digiKam XML GUI window
0008  *
0009  * SPDX-FileCopyrightText: 2013-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  *
0011  * SPDX-License-Identifier: GPL-2.0-or-later
0012  *
0013  * ============================================================ */
0014 
0015 #ifndef DIGIKAM_DXML_GUI_WINDOW_H
0016 #define DIGIKAM_DXML_GUI_WINDOW_H
0017 
0018 // Qt includes
0019 
0020 #include <QWidget>
0021 #include <QObject>
0022 #include <QAction>
0023 #include <QWindow>
0024 
0025 // KDE includes
0026 
0027 #include <kxmlguiwindow.h>
0028 
0029 // Local includes
0030 
0031 #include "digikam_export.h"
0032 #include "digikam_config.h"
0033 #include "dlogoaction.h"
0034 #include "dinfointerface.h"
0035 #include "dpluginaction.h"
0036 #include "dpluginloader.h"
0037 
0038 class QEvent;
0039 
0040 class KToolBar;
0041 class KConfigGroup;
0042 
0043 namespace Digikam
0044 {
0045 
0046 /**
0047  * Optional parts which can be hidden or not from managed window configuration panel
0048  */
0049 enum FullScreenOptions
0050 {
0051     FS_TOOLBARS   = 0x00000001,                                                ///< Manage Tools bar in full-screen mode.
0052     FS_THUMBBAR   = 0x00000002,                                                ///< Manage Thumb bar in full-screen mode.
0053     FS_SIDEBARS   = 0x00000004,                                                ///< Manage Side bars in full-screen mode.
0054     FS_STATUSBAR  = 0x00000008,                                                ///< Manage Status bar in full-screen mode.
0055     FS_NONE       = 0x00000010,                                                ///< No full-screen options.
0056 
0057     FS_ALBUMGUI   = FS_TOOLBARS | FS_THUMBBAR | FS_SIDEBARS | FS_STATUSBAR,    ///< Album GUI Config.
0058     FS_EDITOR     = FS_TOOLBARS | FS_THUMBBAR | FS_SIDEBARS | FS_STATUSBAR,    ///< Image Editor Config.
0059     FS_LIGHTTABLE = FS_TOOLBARS | FS_SIDEBARS | FS_STATUSBAR,                  ///< Light Table Config.
0060     FS_IMPORTUI   = FS_TOOLBARS | FS_THUMBBAR | FS_SIDEBARS | FS_STATUSBAR     ///< Import UI Config.
0061 };
0062 
0063 enum StdActionType
0064 {
0065     StdCopyAction = 0,
0066     StdPasteAction,
0067     StdCutAction,
0068     StdQuitAction,
0069     StdCloseAction,
0070     StdZoomInAction,
0071     StdZoomOutAction,
0072     StdOpenAction,
0073     StdSaveAction,
0074     StdSaveAsAction,
0075     StdRevertAction,
0076     StdBackAction,
0077     StdForwardAction
0078 };
0079 
0080 static const QString s_configFullScreenHideToolBarsEntry(QLatin1String("FullScreen Hide ToolBars"));
0081 static const QString s_configFullScreenHideThumbBarEntry(QLatin1String("FullScreen Hide ThumbBar"));
0082 static const QString s_configFullScreenHideSideBarsEntry(QLatin1String("FullScreen Hide SideBars"));
0083 static const QString s_configFullScreenHideStatusBarEntry(QLatin1String("FullScreen Hide StatusBar"));
0084 
0085 /**
0086  * Generi class to use with all main window.
0087  */
0088 class DIGIKAM_EXPORT DXmlGuiWindow : public KXmlGuiWindow
0089 {
0090     Q_OBJECT
0091 
0092 public:
0093 
0094     explicit DXmlGuiWindow(QWidget* const parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
0095     ~DXmlGuiWindow() override;
0096 
0097     /**
0098      * Manage config group name used by window instance to get/set settings from config file
0099      */
0100     void setConfigGroupName(const QString& name);
0101     QString configGroupName() const;
0102 
0103     void restoreWindowSize();
0104     void saveWindowSize();
0105 
0106     /**
0107      * Create common actions to setup all digiKam main windows.
0108      */
0109     void createSettingsActions();
0110 
0111     /**
0112      * Create common actions from Help menu for all digiKam main windows.
0113      */
0114     void createHelpActions(const QString& handbookSection, bool coreOptions = true);
0115 
0116     /**
0117      * Cleanup unwanted actions from action collection.
0118      */
0119     void cleanupActions();
0120 
0121     /**
0122      * Create common actions to handle side-bar through keyboard shortcuts.
0123      */
0124     void createSidebarActions();
0125 
0126     /**
0127      * Set full-screen options to managed window
0128      */
0129     void setFullScreenOptions(int options);
0130 
0131     /**
0132      * Create Full-screen action to action collection instance from managed window
0133      * set through setManagedWindow(). This action is connected to slotToggleFullScreen() slot.
0134      * 'name' is action name used in KDE UI rc file.
0135      */
0136     void createFullScreenAction(const QString& name);
0137 
0138     /**
0139      * Read full-screen settings from KDE config file.
0140      */
0141     void readFullScreenSettings(const KConfigGroup& group);
0142 
0143     /**
0144      * Return true if managed window is currently in Full Screen Mode.
0145      */
0146     bool fullScreenIsActive() const;
0147 
0148     /**
0149      * Return all actions from internal collection.
0150      */
0151     QList<QAction*> allActions() const;
0152 
0153 public:
0154 
0155     /**
0156      * Register all generic plugins action to this instance.
0157      * Call registerExtraPluginsActions() to plug other kind of plugins in GUI.
0158      */
0159     void registerPluginsActions();
0160     virtual void registerExtraPluginsActions(QString& /*dom*/) {};
0161 
0162     /**
0163      * Return the interface instance to access to items information.
0164      */
0165     virtual DInfoInterface* infoIface(DPluginAction* const ac) = 0;
0166 
0167 public:
0168 
0169     void unminimizeAndActivateWindow();
0170 
0171 public:
0172 
0173     static bool restoreWindowSize(QWindow* const win, const KConfigGroup& group);
0174     static void saveWindowSize(QWindow* const win, KConfigGroup& group);
0175     static void setGoodDefaultWindowSize(QWindow* const win);
0176 
0177     static QAction* buildStdAction(StdActionType type,
0178                                    const QObject* const recvr,
0179                                    const char* const slot,
0180                                    QObject* const parent);
0181 
0182     /**
0183      * If we have some local breeze icon resource, prefer it.
0184      */
0185     static void setupIconTheme();
0186 
0187 protected:
0188 
0189     DLogoAction* m_animLogo;
0190 
0191 protected:
0192 
0193     QAction* showMenuBarAction()   const;
0194     QAction* showStatusBarAction() const;
0195 
0196     /**
0197      * Call this method from your main window to show keyboard shortcut config dialog
0198      * with an extra action collection to configure. This method is called by slotEditKeys()
0199      * which can be re-implement in child class for cutomization.
0200      */
0201     void editKeyboardShortcuts(KActionCollection* const extraac = nullptr, const QString& actitle = QString());
0202 
0203     void showEvent(QShowEvent* e)              override;
0204     void closeEvent(QCloseEvent* e)            override;
0205     void keyPressEvent(QKeyEvent* e)           override;
0206     bool eventFilter(QObject* obj, QEvent* ev) override;
0207 
0208     /**
0209      * Re-implement this method if you want to manage sidebars visibility in full-screen mode.
0210      * By default this method do nothing.
0211      */
0212     virtual void showSideBars(bool visible);
0213 
0214     /**
0215      * Re-implement this method if you want to manage thumbbar visibility in full-screen mode.
0216      * By default this method do nothing.
0217      */
0218     virtual void showThumbBar(bool visible);
0219 
0220     /**
0221      * Re-implement this method if you want to manage customized view visibility in full-screen mode.
0222      * This method is called by switchWindowToFullScreen(). By default this method do nothing.
0223      */
0224     virtual void customizedFullScreenMode(bool set);
0225 
0226     /**
0227      * Re-implement this method if managed window has a thumbbar. This must return visibility state of it.
0228      */
0229     virtual bool thumbbarVisibility() const;
0230 
0231 protected Q_SLOTS:
0232 
0233     bool slotClose();
0234 
0235 private Q_SLOTS:
0236 
0237     void slotToggleFullScreen(bool);
0238     void slotShowMenuBar();
0239     void slotShowStatusBar();
0240     void slotConfNotifications();
0241     void slotConfToolbars();
0242     void slotNewToolbarConfig();
0243 
0244     void slotRawCameraList();
0245     void slotSolidHardwareList();
0246     void slotDonateMoney();
0247     void slotRecipesBook();
0248     void slotContribute();
0249     void slotHelpContents();
0250 
0251     /**
0252      * Slots for common Help Actions
0253      */
0254     virtual void slotOnlineVersionCheck()      {};
0255     virtual void slotComponentsInfo()          {};
0256     virtual void slotDBStat()                  {};
0257 
0258     /**
0259      * Slots for common Sidebar Actions
0260      */
0261     virtual void slotToggleLeftSideBar()       {};
0262     virtual void slotToggleRightSideBar()      {};
0263     virtual void slotPreviousLeftSideBarTab()  {};
0264     virtual void slotNextLeftSideBarTab()      {};
0265     virtual void slotPreviousRightSideBarTab() {};
0266     virtual void slotNextRightSideBarTab()     {};
0267 
0268     /**
0269      * Slots for common Settings actions
0270      */
0271     virtual void slotEditKeys()                { editKeyboardShortcuts(); };
0272     virtual void slotSetup() = 0;
0273 
0274 private:
0275 
0276     /**
0277      * Used by slotToggleFullScreen() to switch tool-bar visibility in managed window
0278      */
0279     void showToolBars(bool visible);
0280 
0281     /**
0282      * Return main tool bar instance created in managed window.
0283      */
0284     KToolBar* mainToolBar() const;
0285 
0286     /**
0287      * Common code to run before closing window.
0288      */
0289     void checkFullScreenBeforeClosing();
0290 
0291 private:
0292 
0293     bool m_winLoaded;
0294     bool m_maximized;
0295 
0296 private:
0297 
0298     class Private;
0299     Private* const d;
0300 };
0301 
0302 } // namespace Digikam
0303 
0304 #endif // DIGIKAM_DXML_GUI_WINDOW_H