Plasma Engine  2.0
Loading...
Searching...
No Matches
BaseActions.h
1#pragma once
2
3#include <GuiFoundation/Action/Action.h>
4#include <GuiFoundation/GuiFoundationDLL.h>
5#include <QIcon>
6
8class PL_GUIFOUNDATION_DLL plNamedAction : public plAction
9{
10 PL_ADD_DYNAMIC_REFLECTION(plNamedAction, plAction);
11
12public:
13 plNamedAction(const plActionContext& context, const char* szName, const char* szIconPath)
14 : plAction(context)
15 , m_sName(szName)
16 , m_sIconPath(szIconPath)
17 {
18 }
19
20 const char* GetName() const { return m_sName; }
21
22 plStringView GetAdditionalDisplayString() { return m_sAdditionalDisplayString; }
23 void SetAdditionalDisplayString(plStringView sString, bool bTriggerUpdate = true)
24 {
25 m_sAdditionalDisplayString = sString;
26 if (bTriggerUpdate)
27 TriggerUpdate();
28 }
29
30 const char* GetIconPath() const { return m_sIconPath; }
31 void SetIconPath(const char* szIconPath) { m_sIconPath = szIconPath; }
32
33protected:
34 plString m_sName;
35 plString m_sAdditionalDisplayString; // to add some context to the current action
36 plString m_sIconPath;
37};
38
40class PL_GUIFOUNDATION_DLL plCategoryAction : public plAction
41{
42 PL_ADD_DYNAMIC_REFLECTION(plCategoryAction, plAction);
43
44public:
45 plCategoryAction(const plActionContext& context)
46 : plAction(context)
47 {
48 }
49
50 virtual void Execute(const plVariant& value) override{};
51};
52
54class PL_GUIFOUNDATION_DLL plMenuAction : public plNamedAction
55{
56 PL_ADD_DYNAMIC_REFLECTION(plMenuAction, plNamedAction);
57
58public:
59 plMenuAction(const plActionContext& context, const char* szName, const char* szIconPath)
60 : plNamedAction(context, szName, szIconPath)
61 {
62 }
63
64 virtual void Execute(const plVariant& value) override{};
65};
66
68class PL_GUIFOUNDATION_DLL plDynamicMenuAction : public plMenuAction
69{
70 PL_ADD_DYNAMIC_REFLECTION(plDynamicMenuAction, plMenuAction);
71
72public:
73 struct Item
74 {
75 enum class CheckMark
76 {
77 NotCheckable,
78 Unchecked,
79 Checked
80 };
81
82 struct ItemFlags
83 {
84 using StorageType = plUInt8;
85
86 enum Enum
87 {
88 Default = 0,
89 Separator = PL_BIT(0),
90 };
91 struct Bits
92 {
93 StorageType Separator : 1;
94 };
95 };
96
97 Item() { m_CheckState = CheckMark::NotCheckable; }
98
99 plString m_sDisplay;
100 QIcon m_Icon;
101 CheckMark m_CheckState;
102 plBitflags<ItemFlags> m_ItemFlags;
103 plVariant m_UserValue;
104 };
105
106 plDynamicMenuAction(const plActionContext& context, const char* szName, const char* szIconPath)
107 : plMenuAction(context, szName, szIconPath)
108 {
109 }
110 virtual void GetEntries(plHybridArray<Item, 16>& out_entries) = 0;
111};
112
114class PL_GUIFOUNDATION_DLL plDynamicActionAndMenuAction : public plDynamicMenuAction
115{
116 PL_ADD_DYNAMIC_REFLECTION(plDynamicActionAndMenuAction, plDynamicMenuAction);
117
118public:
119 plDynamicActionAndMenuAction(const plActionContext& context, const char* szName, const char* szIconPath);
120
121 bool IsEnabled() const { return m_bEnabled; }
122 void SetEnabled(bool bEnable, bool bTriggerUpdate = true)
123 {
124 m_bEnabled = bEnable;
125 if (bTriggerUpdate)
126 TriggerUpdate();
127 }
128
129 bool IsVisible() const { return m_bVisible; }
130 void SetVisible(bool bVisible, bool bTriggerUpdate = true)
131 {
132 m_bVisible = bVisible;
133 if (bTriggerUpdate)
134 TriggerUpdate();
135 }
136
137protected:
138 bool m_bEnabled;
139 bool m_bVisible;
140};
141
143class PL_GUIFOUNDATION_DLL plEnumerationMenuAction : public plDynamicMenuAction
144{
145 PL_ADD_DYNAMIC_REFLECTION(plEnumerationMenuAction, plDynamicMenuAction);
146
147public:
148 plEnumerationMenuAction(const plActionContext& context, const char* szName, const char* szIconPath);
149 void InitEnumerationType(const plRTTI* pEnumerationType);
150 virtual void GetEntries(plHybridArray<plDynamicMenuAction::Item, 16>& out_entries) override;
151 virtual plInt64 GetValue() const = 0;
152
153protected:
154 const plRTTI* m_pEnumerationType;
155};
156
158class PL_GUIFOUNDATION_DLL plButtonAction : public plNamedAction
159{
160 PL_ADD_DYNAMIC_REFLECTION(plButtonAction, plNamedAction);
161
162public:
163 plButtonAction(const plActionContext& context, const char* szName, bool bCheckable, const char* szIconPath);
164
165 bool IsEnabled() const { return m_bEnabled; }
166 void SetEnabled(bool bEnable, bool bTriggerUpdate = true)
167 {
168 m_bEnabled = bEnable;
169 if (bTriggerUpdate)
170 TriggerUpdate();
171 }
172
173 bool IsCheckable() const { return m_bCheckable; }
174 void SetCheckable(bool bCheckable, bool bTriggerUpdate = true)
175 {
176 m_bCheckable = bCheckable;
177 if (bTriggerUpdate)
178 TriggerUpdate();
179 }
180
181 bool IsChecked() const { return m_bChecked; }
182 void SetChecked(bool bChecked, bool bTriggerUpdate = true)
183 {
184 m_bChecked = bChecked;
185 if (bTriggerUpdate)
186 TriggerUpdate();
187 }
188
189 bool IsVisible() const { return m_bVisible; }
190 void SetVisible(bool bVisible, bool bTriggerUpdate = true)
191 {
192 m_bVisible = bVisible;
193 if (bTriggerUpdate)
194 TriggerUpdate();
195 }
196
197protected:
198 bool m_bCheckable;
199 bool m_bChecked;
200 bool m_bEnabled;
201 bool m_bVisible;
202};
203
204
205class PL_GUIFOUNDATION_DLL plSliderAction : public plNamedAction
206{
207 PL_ADD_DYNAMIC_REFLECTION(plSliderAction, plNamedAction);
208
209public:
210 plSliderAction(const plActionContext& context, const char* szName);
211
212 bool IsEnabled() const { return m_bEnabled; }
213 void SetEnabled(bool bEnable, bool bTriggerUpdate = true)
214 {
215 m_bEnabled = bEnable;
216 if (bTriggerUpdate)
217 TriggerUpdate();
218 }
219
220 bool IsVisible() const { return m_bVisible; }
221 void SetVisible(bool bVisible, bool bTriggerUpdate = true)
222 {
223 m_bVisible = bVisible;
224 if (bTriggerUpdate)
225 TriggerUpdate();
226 }
227
228 void GetRange(plInt32& out_iMin, plInt32& out_iMax) const
229 {
230 out_iMin = m_iMinValue;
231 out_iMax = m_iMaxValue;
232 }
233
234 void SetRange(plInt32 iMin, plInt32 iMax, bool bTriggerUpdate = true);
235
236 plInt32 GetValue() const { return m_iCurValue; }
237 void SetValue(plInt32 iVal, bool bTriggerUpdate = true);
238
239protected:
240 bool m_bEnabled;
241 bool m_bVisible;
242 plInt32 m_iMinValue;
243 plInt32 m_iMaxValue;
244 plInt32 m_iCurValue;
245};
Definition Action.h:111
Definition BaseActions.h:159
Definition BaseActions.h:41
Definition BaseActions.h:115
Definition BaseActions.h:69
Definition BaseActions.h:144
A hybrid array uses in-place storage to handle the first few elements without any allocation....
Definition HybridArray.h:12
Definition BaseActions.h:55
Definition BaseActions.h:9
This class holds information about reflected types. Each instance represents one type that is known t...
Definition RTTI.h:30
Definition BaseActions.h:206
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
plVariant is a class that can store different types of variables, which is useful in situations where...
Definition Variant.h:44
Definition Action.h:67
The plBitflags class allows you to work with type-safe bitflags.
Definition Bitflags.h:82
Definition BaseActions.h:83
Definition BaseActions.h:74