kis_action.h 4.49 KB
Newer Older
1
/*
2
 *  SPDX-FileCopyrightText: 2013 Sven Langkamp <sven.langkamp@gmail.com>
3
 *
Samuel Gaist's avatar
Samuel Gaist committed
4
 *  SPDX-License-Identifier: GPL-2.0-or-later
5
6
7
8
9
 */

#ifndef KIS_ACTION_H
#define KIS_ACTION_H

10
#include <QWidgetAction>
11
#include <kritaui_export.h>
Halla Rempt's avatar
Halla Rempt committed
12
#include <kis_debug.h>
13
#include <QIcon>
14
class KisActionManager;
15

16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31


/**
 *  KisAction, inheriting from QWidgetAction, is a convenience class for GUI
 *  actions, with Krita's configuration system and GUI states. A widget like a
 *  "save" button may be enabled/disabled, hidden or shown depending on the
 *  state of the application, e.g. whether the image currently being viewed was
 *  modified since it was opened.
 *
 *  Copies of these actions are created for each MainWindow instance. They are
 *  owned by a KisActionManager, of which there is one for each MainWindow. Most
 *  of these instantiations happen inside the constructor for KisMainWindow as
 *  well as the various functions called in KisViewManager::setupManagers().
 *
 **/

32
class KRITAUI_EXPORT KisAction : public QWidgetAction
33
{
34
    Q_OBJECT
35
public:
36
37
38
39
40

    /**
     * If you re-order these, you must change the associated values in
     * krita.action and kritamenu.action!
     */
41
    enum ActivationFlag {
42
43
44
45
        NONE                        = 0x0000, ///< Always activate
        ACTIVE_IMAGE                = 0x0001, ///< Activate if there is at least one image
        MULTIPLE_IMAGES             = 0x0002, ///< Activate if there is more than one image open
        CURRENT_IMAGE_MODIFIED      = 0x0004, ///< Activate if the current image is modified
Halla Rempt's avatar
Halla Rempt committed
46
47
48
        ACTIVE_NODE                 = 0x0008, ///< Activate if there's an active node (layer or mask)
        ACTIVE_DEVICE               = 0x0010, ///< Activate if the active node has a paint device, i.e. there are pixels to be modified
        ACTIVE_LAYER                = 0x0020, ///< Activate if the current node is a layer (vector or pixel)
49
50
        ACTIVE_TRANSPARENCY_MASK    = 0x0040, ///< Activate if the current node is a transparency mask
        ACTIVE_SHAPE_LAYER          = 0x0080, ///< Activate if the current node is a vector layer
Yuri Chornoivan's avatar
Yuri Chornoivan committed
51
        PIXELS_SELECTED             = 0x0100, ///< Activate if any pixels are selected (with any kind of selection)
52
53
        SHAPES_SELECTED             = 0x0200, ///< Activate if any vector shape is selected
        ANY_SELECTION_WITH_PIXELS   = 0x0400, ///< ???
54
55
        PIXELS_IN_CLIPBOARD         = 0x0800, ///< Activate if the clipboard contains pixels
        SHAPES_IN_CLIPBOARD         = 0x1000, ///< Activate if the clipboard contains vector data
56
57
58
        NEVER_ACTIVATE              = 0x2000, ///< ???
        LAYERS_IN_CLIPBOARD         = 0x4000, ///< ???
        IMAGE_HAS_ANIMATION         = 0x8000, ///< Activate if the image has an animation
59
60
        SHAPE_SELECTION_WITH_SHAPES = 0x10000, ///< Activate there is a vector selection active
        PIXEL_SELECTION_WITH_PIXELS = 0x20000, ///< Activate there is a raster selection active
61
62
63
64
65
    };
    Q_DECLARE_FLAGS(ActivationFlags, ActivationFlag)

    enum ActivationCondition {
        NO_CONDITION = 0,
66
67
        ACTIVE_NODE_EDITABLE = 0x1,
        ACTIVE_NODE_EDITABLE_PAINT_DEVICE = 0x2,
68
69
        SELECTION_EDITABLE = 0x4,
        OPENGL_ENABLED = 0x8,
70
71
    };
    Q_DECLARE_FLAGS(ActivationConditions, ActivationCondition)
72

73
74
    explicit KisAction(QObject* parent = 0);
    KisAction(const QString& text, QObject* parent = 0);
75
    KisAction(const QIcon& icon, const QString& text, QObject* parent = 0);
76
    ~KisAction() override;
77

78
79
80
    void setDefaultShortcut(const QKeySequence & shortcut);
    QKeySequence defaultShortcut() const;

81
82
83
84
85
86
    void setActivationFlags(ActivationFlags flags);
    ActivationFlags activationFlags();

    void setActivationConditions(ActivationConditions conditions);
    ActivationConditions activationConditions();

87
88
89
    void setExcludedNodeTypes(const QStringList &nodeTypes);
    const QStringList& excludedNodeTypes() const;

90
91
    virtual void setActionEnabled(bool enabled);

92
93
94
95
96
   /**
    * Set operation id. This will used to run an operation in the KisActionManager
    */
    void setOperationID(const QString& id);

97
Q_SIGNALS:
98
99
    void sigEnableSlaves(bool value);

100
private Q_SLOTS:
101
    void slotTriggered();
102
    void slotChanged();
103

104
private:
105
106
107
108
109
110
111
112
113

    friend class KisActionManager;

    /**
     * Set the action manager. Only used by KisActionManager
     */
     void setActionManager(KisActionManager* actionManager);


114
    class Private;
115
116
117
118
119
120
121
122
    Private* const d;
};

Q_DECLARE_OPERATORS_FOR_FLAGS(KisAction::ActivationFlags)
Q_DECLARE_OPERATORS_FOR_FLAGS(KisAction::ActivationConditions)


#endif // KIS_ACTION_H