File indexing completed on 2024-06-23 05:03:10

0001 /***************************************************************************
0002  * SPDX-FileCopyrightText: 2022 S. MANKOWSKI stephane@mankowski.fr
0003  * SPDX-FileCopyrightText: 2022 G. DE BURE support@mankowski.fr
0004  * SPDX-License-Identifier: GPL-3.0-or-later
0005  ***************************************************************************/
0006 #ifndef SKGUNDOREDOPLUGIN_H
0007 #define SKGUNDOREDOPLUGIN_H
0008 /** @file
0009  * This file is a plugin for undo and redo operation.
0010 *
0011 * @author Stephane MANKOWSKI / Guillaume DE BURE
0012  */
0013 #include "skginterfaceplugin.h"
0014 #include "ui_skgundoredopluginwidget_pref.h"
0015 
0016 class QAction;
0017 class KToolBarPopupAction;
0018 class QMenu;
0019 
0020 /**
0021  * This file is a plugin for undo and redo operation
0022  */
0023 class SKGUndoRedoPlugin : public SKGInterfacePlugin
0024 {
0025     Q_OBJECT
0026     Q_INTERFACES(SKGInterfacePlugin)
0027 
0028 public:
0029     /**
0030      * Default Constructor
0031      */
0032     explicit SKGUndoRedoPlugin(QWidget* iWidget, QObject* iParent, const QVariantList& iArg);
0033 
0034     /**
0035      * Default Destructor
0036      */
0037     ~SKGUndoRedoPlugin() override;
0038 
0039     /**
0040      * Called to initialise the plugin
0041      * @param iDocument the main document
0042      * @return true if the plugin is compatible with the document
0043      */
0044     bool setupActions(SKGDocument* iDocument) override;
0045 
0046     /**
0047      * Must be modified to refresh widgets after a modification.
0048      */
0049     void refresh() override;
0050 
0051     /**
0052      * Initialize the preferences. This is use full for settings stored in the document
0053      */
0054     virtual void initPreferences() override;
0055 
0056     /**
0057      * The preference widget of the plugin.
0058      * @return The preference widget of the plugin
0059      */
0060     QWidget* getPreferenceWidget() override;
0061 
0062     /**
0063      * The preference skeleton of the plugin.
0064      * @return The preference skeleton of the plugin
0065      */
0066     KConfigSkeleton* getPreferenceSkeleton() override;
0067 
0068     /**
0069      * This function is called when preferences have been modified. Must be used to save some parameters into the document.
0070      * A transaction is already opened
0071      * @return an object managing the error.
0072      *   @see SKGError
0073      */
0074     SKGError savePreferences() const override;
0075 
0076     /**
0077      * The title of the plugin.
0078      * @return The title of the plugin
0079      */
0080     QString title() const override;
0081 
0082     /**
0083      * The icon of the plugin.
0084      * @return The icon of the plugin
0085      */
0086     QString icon() const override;
0087 
0088     /**
0089      * The toolTip of the plugin.
0090      * @return The toolTip of the plugin
0091      */
0092     QString toolTip() const override;
0093 
0094     /**
0095      * The tips list of the plugin.
0096      * @return The tips list of the plugin
0097      */
0098     QStringList tips() const override;
0099 
0100     /**
0101      * Must be implemented to set the position of the plugin.
0102      * @return integer value between 0 and 999 (default = 999)
0103      */
0104     int getOrder() const override;
0105 
0106     /**
0107      * The dock widget of the plugin.
0108      * @return The dock widget of the plugin
0109      */
0110     QDockWidget* getDockWidget() override;
0111 
0112     /**
0113      * The advice list of the plugin.
0114      * @return The advice list of the plugin
0115      */
0116     SKGAdviceList advice(const QStringList& iIgnoredAdvice) override;
0117 
0118     /**
0119      * Must be implemented to execute the automatic correction for the advice.
0120      * @param iAdviceIdentifier the identifier of the advice
0121      * @param iSolution the identifier of the possible solution
0122      * @return an object managing the error. MUST return ERR_NOTIMPL if iAdviceIdentifier is not known
0123      *   @see SKGError
0124      */
0125     SKGError executeAdviceCorrection(const QString& iAdviceIdentifier, int iSolution) override;
0126 
0127 private Q_SLOTS:
0128     void onUndoSave();
0129     void onUndo();
0130     void onRedo();
0131     void onClearHistory();
0132 
0133     void onShowUndoMenu();
0134     void onShowRedoMenu();
0135 private:
0136     Q_DISABLE_COPY(SKGUndoRedoPlugin)
0137 
0138     QAction* m_undoSaveAction;
0139     KToolBarPopupAction* m_undoAction;
0140     KToolBarPopupAction* m_redoAction;
0141 
0142     QMenu* m_undoMenu;
0143     QMenu* m_redoMenu;
0144 
0145 
0146     SKGDocument* m_currentDocument;
0147     QDockWidget* m_dockWidget;
0148 
0149     Ui::skgundoredoplugin_pref ui{};
0150 };
0151 
0152 #endif  // SKGDEBUGPLUGIN_H