File indexing completed on 2024-05-12 15:59:58
0001 /* 0002 * SPDX-FileCopyrightText: 2018 Boudewijn Rempt <boud@valdyas.org> 0003 * SPDX-FileCopyrightText: 2020 Agata Cacko <cacko.azh@gmail.com> 0004 * 0005 * SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 #ifndef TAGACTIONS_H 0008 #define TAGACTIONS_H 0009 0010 #include <QMenu> 0011 #include <QWidgetAction> 0012 #include <QLabel> 0013 #include <QLineEdit> 0014 #include <QPushButton> 0015 0016 #include <KoResource.h> 0017 0018 #include <KisTag.h> 0019 #include <KisTagModel.h> 0020 0021 #include <kritaresourcewidgets_export.h> 0022 0023 0024 // ########### Actions ########### 0025 /// 0026 /// \brief The SimpleExistingTagAction class defines an action that holds a resource and a tag 0027 /// 0028 /// This is mostly used in ContextMenu for the context menu actions displaying tags to tag or untag 0029 /// specific resource with a specific tag. 0030 /// 0031 class SimpleExistingTagAction : public QAction 0032 { 0033 Q_OBJECT 0034 public: 0035 explicit SimpleExistingTagAction(KoResourceSP resource, KisTagSP tag, QObject* parent = 0); 0036 ~SimpleExistingTagAction() override; 0037 0038 Q_SIGNALS: 0039 void triggered(KisTagSP tag, KoResourceSP resource); 0040 0041 protected Q_SLOTS: 0042 void onTriggered(); 0043 0044 private: 0045 /// 0046 /// \brief m_resource resource associated with the action 0047 /// 0048 KoResourceSP m_resource; 0049 /// 0050 /// \brief m_tag tag associated with the action 0051 /// 0052 KisTagSP m_tag; 0053 }; 0054 0055 0056 // ########### Line Edit Actions ########### 0057 // --------------------------- 0058 /** 0059 * A line edit QWidgetAction. 0060 * Default behavior: Closes its parent upon triggering. 0061 * This is a base for all tag/resources actions that needs a user text input 0062 * (for example create new tag or rename tag) 0063 */ 0064 0065 /// 0066 /// \brief The LineEditAction class defines an action with a user text input 0067 /// 0068 /// This is a base for all tag/resources actions that needs a user text input 0069 /// (for example create new tag or rename tag). 0070 /// By default it closes its parent upon triggering and clears the content, 0071 /// but it can be disabled. 0072 /// 0073 class KRITARESOURCEWIDGETS_EXPORT LineEditAction : public QWidgetAction 0074 { 0075 Q_OBJECT 0076 protected: 0077 LineEditAction(QObject* parent); 0078 0079 public: 0080 ~LineEditAction() override; 0081 void setIcon(const QIcon &icon); 0082 void setCloseParentOnTrigger(bool closeParent); 0083 bool closeParentOnTrigger(); 0084 0085 void setPlaceholderText(const QString& clickMessage); 0086 void setText(const QString& text); 0087 void setVisible(bool showAction); 0088 0089 protected Q_SLOTS: 0090 0091 /// 0092 /// \brief slotActionTriggered defines all behaviour expressed when the widget is triggered 0093 /// 0094 /// It contains logic for closing the widget and calls onTriggered() to make sure 0095 /// behaviours defined in classes inheriting LineEditAction are called. 0096 /// 0097 void slotActionTriggered(); 0098 0099 /// 0100 /// \brief onTriggered defines additional behaviour for the action 0101 /// 0102 /// This function is called in slotActionTriggered() *before* the widget is closed 0103 /// and cleared. 0104 /// 0105 virtual void onTriggered() {} 0106 0107 /// 0108 /// \brief userText getter for the text inside the edit box 0109 /// \return text inside edit box (user input) 0110 /// 0111 QString userText(); 0112 0113 private: 0114 bool m_closeParentOnTrigger; 0115 QLabel *m_label; 0116 QLineEdit *m_editBox; 0117 QPushButton *m_AddButton; 0118 }; 0119 0120 /// 0121 /// \brief The UserInputTagAction class defines an action with user text input that sends a signal with a simple QString 0122 /// 0123 /// It inherits all behaviour from LineEditAction. 0124 /// When triggered, it sends a signal with the content of the edit box. 0125 /// 0126 /// Usages: 0127 /// - Create a new tag 0128 /// - Rename a current tag (the responsibility to know which tag is current 0129 /// depends on the external widget like KisTagChooserWidget) 0130 /// 0131 class KRITARESOURCEWIDGETS_EXPORT UserInputTagAction : public LineEditAction 0132 { 0133 Q_OBJECT 0134 0135 public: 0136 explicit UserInputTagAction(QObject* parent); 0137 ~UserInputTagAction() override; 0138 0139 Q_SIGNALS: 0140 void triggered(const QString &newTagName); 0141 0142 protected Q_SLOTS: 0143 void onTriggered() override; 0144 }; 0145 0146 /// 0147 /// \brief The NewTagResourceAction class defines an action that sends a signal with QString and a saved resource 0148 /// 0149 /// It inherits all behaviours from LineEditAction. 0150 /// When triggered, it sends a signal with the content of the edit box as QString, and the saved resource. 0151 /// 0152 /// Usages: 0153 /// - Tag a resource 0154 /// - Untag a resource 0155 /// 0156 class NewTagResourceAction : public LineEditAction 0157 { 0158 Q_OBJECT 0159 0160 public: 0161 explicit NewTagResourceAction(KoResourceSP resource, QObject* parent); 0162 ~NewTagResourceAction() override; 0163 0164 void setResource(KoResourceSP resource); 0165 0166 Q_SIGNALS: 0167 void triggered(const QString &newTagName, KoResourceSP resource); 0168 0169 protected Q_SLOTS: 0170 0171 void onTriggered() override; 0172 0173 private: 0174 KoResourceSP m_resource; 0175 }; 0176 0177 // ########### Tag Comparer ########### 0178 0179 /// 0180 /// \brief The CompareWithOtherTagFunctor class defines a comparer for tags 0181 /// 0182 /// It contains a saved tag and can be used to determine if another tag is equal 0183 /// to the saved tag ("reference tag") or not. It can be used in stl list features 0184 /// like erase() etc. 0185 /// 0186 class CompareWithOtherTagFunctor 0187 { 0188 /// Tag to compare all other tags to 0189 KisTagSP m_referenceTag; 0190 0191 public: 0192 /// 0193 /// \brief CompareWithOtherTagFunctor defines a default constructor 0194 /// \param referenceTag a tag to compare all other tags to 0195 /// 0196 CompareWithOtherTagFunctor(KisTagSP referenceTag); 0197 0198 /// 0199 /// \brief operator () contains comparison logic 0200 /// \param otherTag a tag to compare with the reference tag 0201 /// \return 0202 /// 0203 bool operator()(KisTagSP otherTag); 0204 0205 /// 0206 /// \brief setReferenceTag sets a reference tag in the comparer 0207 /// \param referenceTag a tag that is used to compare other tags to 0208 /// 0209 void setReferenceTag(KisTagSP referenceTag); 0210 0211 /// 0212 /// \brief referenceTag is a getter for the reference tag 0213 /// \return a tag that is used to compare other tags to 0214 /// 0215 KisTagSP referenceTag(); 0216 0217 }; 0218 0219 0220 #endif // TAGACTIONS_H