File indexing completed on 2024-05-12 16:01:24
0001 /* 0002 * SPDX-FileCopyrightText: 2013 Sven Langkamp <sven.langkamp@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 0008 #ifndef KIS_ACTION_MANAGER_H 0009 #define KIS_ACTION_MANAGER_H 0010 0011 #include <kritaui_export.h> 0012 0013 #include <QPointer> 0014 0015 #include "KisView.h" 0016 0017 #include "kstandardaction.h" 0018 #include "kis_action_registry.h" 0019 #include "operations/kis_operation_configuration.h" 0020 0021 class KisViewManager; 0022 class KisAction; 0023 class KisOperationUIFactory; 0024 class KisOperation; 0025 0026 /** 0027 * @brief A KisActionManager class keeps track of KisActions. 0028 * These actions are always associated with the GUI. That means each MainWindow 0029 * will create its own duplicate of these actions. 0030 * 0031 * KisActionManager enables and disables actions, to grey out buttons according 0032 * to the state of the application. 0033 * 0034 * Some of the primitive actions (load/save and so on) are not defined as 0035 * KisActions, but instead KActions, automacially registered through KisKXMLGUI. 0036 * It tracks these actions through the KisKActionCollection owned by the window. 0037 * Ultimately it would be nice to unify these things more fully. 0038 * 0039 */ 0040 class KRITAUI_EXPORT KisActionManager : public QObject 0041 { 0042 Q_OBJECT 0043 public: 0044 KisActionManager(KisViewManager* viewManager, KisKActionCollection *actionCollection); 0045 ~KisActionManager() override; 0046 0047 void setView(QPointer<KisView> imageView); 0048 0049 /** 0050 * Add an existing action to the action manager. 0051 */ 0052 void addAction(const QString& name, KisAction* action); 0053 0054 /** 0055 * Stop managing an action. 0056 */ 0057 void takeAction(KisAction* action); 0058 0059 /** 0060 * Create a new KisAction. Looks up data from the .action data files. 0061 */ 0062 KisAction *createAction(const QString &name); 0063 0064 /** 0065 * Look up an action by name. 0066 */ 0067 KisAction *actionByName(const QString &name) const; 0068 0069 void registerOperationUIFactory(KisOperationUIFactory* factory); 0070 void registerOperation(KisOperation* operation); 0071 void runOperation(const QString &id); 0072 void runOperationFromConfiguration(KisOperationConfigurationSP config); 0073 0074 /** 0075 * Update actions handled by kis_action_manager to set enabled. 0076 * This is used to grey out buttons that can't be pressed. 0077 */ 0078 void updateGUI(); 0079 0080 /** 0081 * Create a KisAction based on a KStandardAction. The KStandardAction is deleted. 0082 */ 0083 KisAction *createStandardAction(KStandardAction::StandardAction, 0084 const QObject *receiver, const char *member); 0085 0086 static void safePopulateMenu(QMenu *menu, const QString &actionId, KisActionManager *actionManager); 0087 0088 private Q_SLOTS: 0089 void slotActionAddedToCollection(QAction *action); 0090 0091 private: 0092 void dumpActionFlags(); 0093 0094 class Private; 0095 Private* const d; 0096 }; 0097 0098 #endif // KIS_ACTION_MANAGER_H