File indexing completed on 2024-05-19 04:28:51

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         IMAGE_CAN_RESELECT          = 0x40000, ///< Activate there is a deselected selection in the image
0062     };
0063     Q_DECLARE_FLAGS(ActivationFlags, ActivationFlag)
0064 
0065     enum ActivationCondition {
0066         NO_CONDITION = 0,
0067         ACTIVE_NODE_EDITABLE = 0x1,
0068         ACTIVE_NODE_EDITABLE_PAINT_DEVICE = 0x2,
0069         SELECTION_EDITABLE = 0x4,
0070         OPENGL_ENABLED = 0x8,
0071     };
0072     Q_DECLARE_FLAGS(ActivationConditions, ActivationCondition)
0073 
0074     explicit KisAction(QObject* parent = 0);
0075     KisAction(const QString& text, QObject* parent = 0);
0076     KisAction(const QIcon& icon, const QString& text, QObject* parent = 0);
0077     ~KisAction() override;
0078 
0079     void setDefaultShortcut(const QKeySequence & shortcut);
0080     QKeySequence defaultShortcut() const;
0081 
0082     void setActivationFlags(ActivationFlags flags);
0083     ActivationFlags activationFlags();
0084 
0085     void setActivationConditions(ActivationConditions conditions);
0086     ActivationConditions activationConditions();
0087 
0088     void setExcludedNodeTypes(const QStringList &nodeTypes);
0089     const QStringList& excludedNodeTypes() const;
0090 
0091     virtual void setActionEnabled(bool enabled);
0092 
0093    /**
0094     * Set operation id. This will used to run an operation in the KisActionManager
0095     */
0096     void setOperationID(const QString& id);
0097 
0098 Q_SIGNALS:
0099     void sigEnableSlaves(bool value);
0100 
0101 private Q_SLOTS:
0102     void slotTriggered();
0103     void slotChanged();
0104 
0105 private:
0106 
0107     friend class KisActionManager;
0108 
0109     /**
0110      * Set the action manager. Only used by KisActionManager
0111      */
0112      void setActionManager(KisActionManager* actionManager);
0113 
0114 
0115     class Private;
0116     Private* const d;
0117 };
0118 
0119 Q_DECLARE_OPERATORS_FOR_FLAGS(KisAction::ActivationFlags)
0120 Q_DECLARE_OPERATORS_FOR_FLAGS(KisAction::ActivationConditions)
0121 
0122 
0123 #endif // KIS_ACTION_H