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 #ifndef KIS_ACTION_H 0008 #define KIS_ACTION_H 0009 0010 #include <QWidgetAction> 0011 #include <kritaui_export.h> 0012 #include <kis_debug.h> 0013 #include <QIcon> 0014 class KisActionManager; 0015 0016 0017 0018 /** 0019 * KisAction, inheriting from QWidgetAction, is a convenience class for GUI 0020 * actions, with Krita's configuration system and GUI states. A widget like a 0021 * "save" button may be enabled/disabled, hidden or shown depending on the 0022 * state of the application, e.g. whether the image currently being viewed was 0023 * modified since it was opened. 0024 * 0025 * Copies of these actions are created for each MainWindow instance. They are 0026 * owned by a KisActionManager, of which there is one for each MainWindow. Most 0027 * of these instantiations happen inside the constructor for KisMainWindow as 0028 * well as the various functions called in KisViewManager::setupManagers(). 0029 * 0030 **/ 0031 0032 class KRITAUI_EXPORT KisAction : public QWidgetAction 0033 { 0034 Q_OBJECT 0035 public: 0036 0037 /** 0038 * If you re-order these, you must change the associated values in 0039 * krita.action and kritamenu.action! 0040 */ 0041 enum ActivationFlag { 0042 NONE = 0x0000, ///< Always activate 0043 ACTIVE_IMAGE = 0x0001, ///< Activate if there is at least one image 0044 MULTIPLE_IMAGES = 0x0002, ///< Activate if there is more than one image open 0045 CURRENT_IMAGE_MODIFIED = 0x0004, ///< Activate if the current image is modified 0046 ACTIVE_NODE = 0x0008, ///< Activate if there's an active node (layer or mask) 0047 ACTIVE_DEVICE = 0x0010, ///< Activate if the active node has a paint device, i.e. there are pixels to be modified 0048 ACTIVE_LAYER = 0x0020, ///< Activate if the current node is a layer (vector or pixel) 0049 ACTIVE_TRANSPARENCY_MASK = 0x0040, ///< Activate if the current node is a transparency mask 0050 ACTIVE_SHAPE_LAYER = 0x0080, ///< Activate if the current node is a vector layer 0051 PIXELS_SELECTED = 0x0100, ///< Activate if any pixels are selected (with any kind of selection) 0052 SHAPES_SELECTED = 0x0200, ///< Activate if any vector shape is selected 0053 ANY_SELECTION_WITH_PIXELS = 0x0400, ///< ??? 0054 PIXELS_IN_CLIPBOARD = 0x0800, ///< Activate if the clipboard contains pixels 0055 SHAPES_IN_CLIPBOARD = 0x1000, ///< Activate if the clipboard contains vector data 0056 NEVER_ACTIVATE = 0x2000, ///< ??? 0057 LAYERS_IN_CLIPBOARD = 0x4000, ///< ??? 0058 IMAGE_HAS_ANIMATION = 0x8000, ///< Activate if the image has an animation 0059 SHAPE_SELECTION_WITH_SHAPES = 0x10000, ///< Activate there is a vector selection active 0060 PIXEL_SELECTION_WITH_PIXELS = 0x20000, ///< Activate there is a raster selection active 0061 }; 0062 Q_DECLARE_FLAGS(ActivationFlags, ActivationFlag) 0063 0064 enum ActivationCondition { 0065 NO_CONDITION = 0, 0066 ACTIVE_NODE_EDITABLE = 0x1, 0067 ACTIVE_NODE_EDITABLE_PAINT_DEVICE = 0x2, 0068 SELECTION_EDITABLE = 0x4, 0069 OPENGL_ENABLED = 0x8, 0070 }; 0071 Q_DECLARE_FLAGS(ActivationConditions, ActivationCondition) 0072 0073 explicit KisAction(QObject* parent = 0); 0074 KisAction(const QString& text, QObject* parent = 0); 0075 KisAction(const QIcon& icon, const QString& text, QObject* parent = 0); 0076 ~KisAction() override; 0077 0078 void setDefaultShortcut(const QKeySequence & shortcut); 0079 QKeySequence defaultShortcut() const; 0080 0081 void setActivationFlags(ActivationFlags flags); 0082 ActivationFlags activationFlags(); 0083 0084 void setActivationConditions(ActivationConditions conditions); 0085 ActivationConditions activationConditions(); 0086 0087 void setExcludedNodeTypes(const QStringList &nodeTypes); 0088 const QStringList& excludedNodeTypes() const; 0089 0090 virtual void setActionEnabled(bool enabled); 0091 0092 /** 0093 * Set operation id. This will used to run an operation in the KisActionManager 0094 */ 0095 void setOperationID(const QString& id); 0096 0097 Q_SIGNALS: 0098 void sigEnableSlaves(bool value); 0099 0100 private Q_SLOTS: 0101 void slotTriggered(); 0102 void slotChanged(); 0103 0104 private: 0105 0106 friend class KisActionManager; 0107 0108 /** 0109 * Set the action manager. Only used by KisActionManager 0110 */ 0111 void setActionManager(KisActionManager* actionManager); 0112 0113 0114 class Private; 0115 Private* const d; 0116 }; 0117 0118 Q_DECLARE_OPERATORS_FOR_FLAGS(KisAction::ActivationFlags) 0119 Q_DECLARE_OPERATORS_FOR_FLAGS(KisAction::ActivationConditions) 0120 0121 0122 #endif // KIS_ACTION_H