Plasma Engine  2.0
Loading...
Searching...
No Matches
PropertyBaseWidget.moc.h
1#pragma once
2
3#include <Foundation/Communication/Event.h>
4#include <Foundation/Containers/HybridArray.h>
5#include <GuiFoundation/GuiFoundationDLL.h>
6#include <GuiFoundation/PropertyGrid/Implementation/PropertyEventHandler.h>
7#include <QWidget>
8#include <ToolsFoundation/Object/DocumentObjectManager.h>
9#include <ToolsFoundation/Reflection/ReflectedType.h>
10
12class plQtTypeWidget;
13class QHBoxLayout;
14class QVBoxLayout;
15class QLabel;
16class QMenu;
17class QComboBox;
22class QMimeData;
25
27class PL_GUIFOUNDATION_DLL plQtPropertyWidget : public QWidget
28{
29 Q_OBJECT;
30
31public:
32 explicit plQtPropertyWidget();
33 virtual ~plQtPropertyWidget();
34
35 void Init(plQtPropertyGridWidget* pGrid, plObjectAccessorBase* pObjectAccessor, const plRTTI* pType, const plAbstractProperty* pProp);
36 const plAbstractProperty* GetProperty() const { return m_pProp; }
37
42 virtual void SetSelection(const plHybridArray<plPropertySelection, 8>& items);
43 const plHybridArray<plPropertySelection, 8>& GetSelection() const { return m_Items; }
44
46 virtual bool HasLabel() const { return true; }
47
49 virtual const char* GetLabel(plStringBuilder& ref_sTmp) const;
50
51 virtual void ExtendContextMenu(QMenu& ref_menu);
52
54 virtual void SetIsDefault(bool bIsDefault) { m_bIsDefault = bIsDefault; }
55
58 bool GetCommonVariantSubType(
59 const plHybridArray<plPropertySelection, 8>& items, const plAbstractProperty* pProperty, plVariantType::Enum& out_type);
60
61 plVariant GetCommonValue(const plHybridArray<plPropertySelection, 8>& items, const plAbstractProperty* pProperty);
62 void PrepareToDie();
63
65 virtual void SetReadOnly(bool bReadOnly = true);
66
67public:
68 static const plRTTI* GetCommonBaseType(const plHybridArray<plPropertySelection, 8>& items);
69 static QColor SetPaletteBackgroundColor(plColorGammaUB inputColor, QPalette& ref_palette);
70
71public Q_SLOTS:
72 void OnCustomContextMenu(const QPoint& pt);
73
74protected:
75 void Broadcast(plPropertyEvent::Type type);
76 void PropertyChangedHandler(const plPropertyEvent& ed);
77
78 virtual void OnInit() = 0;
79 bool IsUndead() const { return m_bUndead; }
80
81protected:
82 virtual void DoPrepareToDie() = 0;
83
84 virtual bool eventFilter(QObject* pWatched, QEvent* pEvent) override;
85
86 plQtPropertyGridWidget* m_pGrid = nullptr;
87 plObjectAccessorBase* m_pObjectAccessor = nullptr;
88 const plRTTI* m_pType = nullptr;
89 const plAbstractProperty* m_pProp = nullptr;
92
93private:
94 bool m_bUndead;
95};
96
97
99class PL_GUIFOUNDATION_DLL plQtUnsupportedPropertyWidget : public plQtPropertyWidget
100{
101 Q_OBJECT;
102
103public:
104 explicit plQtUnsupportedPropertyWidget(const char* szMessage = nullptr);
105
106protected:
107 virtual void OnInit() override;
108 virtual void DoPrepareToDie() override {}
109
110 QHBoxLayout* m_pLayout;
111 QLabel* m_pWidget;
112 plString m_sMessage;
113};
114
115
117class PL_GUIFOUNDATION_DLL plQtStandardPropertyWidget : public plQtPropertyWidget
118{
119 Q_OBJECT;
120
121public:
123
124 virtual void SetSelection(const plHybridArray<plPropertySelection, 8>& items) override;
125
126protected:
127 void BroadcastValueChanged(const plVariant& NewValue);
128 virtual void DoPrepareToDie() override {}
129
130 const plVariant& GetOldValue() const { return m_OldValue; }
131 virtual void InternalSetValue(const plVariant& value) = 0;
132
133protected:
134 plVariant m_OldValue;
135};
136
137
140class PL_GUIFOUNDATION_DLL plQtEmbeddedClassPropertyWidget : public plQtPropertyWidget
141{
142 Q_OBJECT;
143
144public:
147
148 virtual void SetSelection(const plHybridArray<plPropertySelection, 8>& items) override;
149
150protected:
151 void SetPropertyValue(const plAbstractProperty* pProperty, const plVariant& NewValue);
152
153 virtual void OnInit() override;
154 virtual void DoPrepareToDie() override;
155 virtual void OnPropertyChanged(const plString& sProperty) = 0;
156
157private:
158 void PropertyEventHandler(const plDocumentObjectPropertyEvent& e);
159 void CommandHistoryEventHandler(const plCommandHistoryEvent& e);
160 void FlushQueuedChanges();
161
162protected:
163 bool m_bTemporaryCommand = false;
164 const plRTTI* m_pResolvedType = nullptr;
166
167 plHybridArray<plString, 1> m_QueuedChanges;
168};
169
170
174class PL_GUIFOUNDATION_DLL plQtPropertyTypeWidget : public plQtPropertyWidget
175{
176 Q_OBJECT;
177
178public:
179 explicit plQtPropertyTypeWidget(bool bAddCollapsibleGroup = false);
180 virtual ~plQtPropertyTypeWidget();
181
182 virtual void SetSelection(const plHybridArray<plPropertySelection, 8>& items) override;
183 virtual bool HasLabel() const override { return false; }
184 virtual void SetIsDefault(bool bIsDefault) override;
185
186protected:
187 virtual void OnInit() override;
188 virtual void DoPrepareToDie() override;
189
190protected:
191 QVBoxLayout* m_pLayout;
192 plQtGroupBoxBase* m_pGroup;
193 QVBoxLayout* m_pGroupLayout;
194 plQtTypeWidget* m_pTypeWidget;
195};
196
198class PL_GUIFOUNDATION_DLL plQtPropertyPointerWidget : public plQtPropertyWidget
199{
200 Q_OBJECT;
201
202public:
203 explicit plQtPropertyPointerWidget();
205
206 virtual void SetSelection(const plHybridArray<plPropertySelection, 8>& items) override;
207 virtual bool HasLabel() const override { return false; }
208
209
210public Q_SLOTS:
211 void OnDeleteButtonClicked();
212
213protected:
214 virtual void OnInit() override;
215 void StructureEventHandler(const plDocumentObjectStructureEvent& e);
216 virtual void DoPrepareToDie() override;
217 void UpdateTitle(const plRTTI* pType = nullptr);
218
219protected:
220 QHBoxLayout* m_pLayout = nullptr;
221 plQtGroupBoxBase* m_pGroup = nullptr;
222 plQtAddSubElementButton* m_pAddButton = nullptr;
223 plQtElementGroupButton* m_pDeleteButton = nullptr;
224 QHBoxLayout* m_pGroupLayout = nullptr;
225 plQtTypeWidget* m_pTypeWidget = nullptr;
226};
227
228
230class PL_GUIFOUNDATION_DLL plQtPropertyContainerWidget : public plQtPropertyWidget
231{
232 Q_OBJECT;
233
234public:
237
238 virtual void SetSelection(const plHybridArray<plPropertySelection, 8>& items) override;
239 virtual bool HasLabel() const override { return false; }
240 virtual void SetIsDefault(bool bIsDefault) override;
241
242public Q_SLOTS:
243 void OnElementButtonClicked();
244 void OnDragStarted(QMimeData& ref_mimeData);
245 void OnContainerContextMenu(const QPoint& pt);
246 void OnCustomElementContextMenu(const QPoint& pt);
247
248protected:
249 struct Element
250 {
251 Element() = default;
252
253 Element(plQtGroupBoxBase* pSubGroup, plQtPropertyWidget* pWidget, plQtElementGroupButton* pHelpButton)
254 : m_pSubGroup(pSubGroup)
255 , m_pWidget(pWidget)
256 , m_pHelpButton(pHelpButton)
257 {
258 }
259
260 plQtGroupBoxBase* m_pSubGroup = nullptr;
261 plQtPropertyWidget* m_pWidget = nullptr;
262 plQtElementGroupButton* m_pHelpButton = nullptr;
263 };
264
265 virtual plQtGroupBoxBase* CreateElement(QWidget* pParent);
266 virtual plQtPropertyWidget* CreateWidget(plUInt32 index);
267 virtual Element& AddElement(plUInt32 index);
268 virtual void RemoveElement(plUInt32 index);
269 virtual void UpdateElement(plUInt32 index) = 0;
270 void UpdateElements();
271 virtual plUInt32 GetRequiredElementCount() const;
272 virtual void UpdatePropertyMetaState();
273
274 void Clear();
275 virtual void OnInit() override;
276
277 void DeleteItems(plHybridArray<plPropertySelection, 8>& items);
278 void MoveItems(plHybridArray<plPropertySelection, 8>& items, plInt32 iMove);
279 virtual void DoPrepareToDie() override;
280 virtual void dragEnterEvent(QDragEnterEvent* event) override;
281 virtual void dragMoveEvent(QDragMoveEvent* event) override;
282 virtual void dragLeaveEvent(QDragLeaveEvent* event) override;
283 virtual void dropEvent(QDropEvent* event) override;
284 virtual void paintEvent(QPaintEvent* event) override;
285 virtual void showEvent(QShowEvent* event) override;
286
287private:
288 bool updateDropIndex(QDropEvent* pEvent);
289
290protected:
291 QHBoxLayout* m_pLayout;
292 plQtGroupBoxBase* m_pGroup;
293 QVBoxLayout* m_pGroupLayout;
294 plQtAddSubElementButton* m_pAddButton = nullptr;
295 QPalette m_Pal;
296
297 mutable plHybridArray<plVariant, 16> m_Keys;
298 plDynamicArray<Element> m_Elements;
299 plInt32 m_iDropSource = -1;
300 plInt32 m_iDropTarget = -1;
301};
302
303
305{
306 Q_OBJECT;
307
308public:
311
312protected:
313 virtual plQtGroupBoxBase* CreateElement(QWidget* pParent) override;
314 virtual plQtPropertyWidget* CreateWidget(plUInt32 index) override;
315 virtual Element& AddElement(plUInt32 index) override;
316 virtual void RemoveElement(plUInt32 index) override;
317 virtual void UpdateElement(plUInt32 index) override;
318};
319
321{
322 Q_OBJECT;
323
324public:
327
328protected:
329 virtual void OnInit() override;
330 virtual void UpdateElement(plUInt32 index) override;
331
332 void StructureEventHandler(const plDocumentObjectStructureEvent& e);
333 void CommandHistoryEventHandler(const plCommandHistoryEvent& e);
334
335private:
336 bool m_bNeedsUpdate = false;
337};
338
339class PL_GUIFOUNDATION_DLL plQtVariantPropertyWidget : public plQtStandardPropertyWidget
340{
341 Q_OBJECT;
342
343public:
346
347protected:
348 virtual void OnInit() override;
349 virtual void InternalSetValue(const plVariant& value) override;
350 virtual void DoPrepareToDie() override;
351 void UpdateTypeListSelection(plVariantType::Enum type);
352 void ChangeVariantType(plVariantType::Enum type);
353
354 virtual plResult GetVariantTypeDisplayName(plVariantType::Enum type, plStringBuilder& out_sName) const;
355
356protected:
357 QVBoxLayout* m_pLayout = nullptr;
358 QComboBox* m_pTypeList = nullptr;
359 plQtPropertyWidget* m_pWidget = nullptr;
360 const plRTTI* m_pCurrentSubType = nullptr;
361};
This is the base interface for all properties in the reflection system. It provides enough informatio...
Definition AbstractProperty.h:150
A 8bit per channel unsigned normalized (values interpreted as 0-1) color storage format that represen...
Definition Color8UNorm.h:99
Definition DocumentObjectBase.h:11
Definition DynamicArray.h:81
A hybrid array uses in-place storage to handle the first few elements without any allocation....
Definition HybridArray.h:12
Definition ObjectAccessorBase.h:8
Definition AddSubElementButton.moc.h:12
Definition ElementGroupButton.moc.h:8
Base class for more 'advanced' property type widgets for Pointer or Class type properties....
Definition PropertyBaseWidget.moc.h:141
Definition GroupBoxBase.moc.h:10
Base class for all container properties.
Definition PropertyBaseWidget.moc.h:231
virtual bool HasLabel() const override
If this returns true (default), a QLabel is created and the text that GetLabel() returns is displayed...
Definition PropertyBaseWidget.moc.h:239
Definition PropertyGridWidget.moc.h:29
Used for property types that are pointers.
Definition PropertyBaseWidget.moc.h:199
virtual bool HasLabel() const override
If this returns true (default), a QLabel is created and the text that GetLabel() returns is displayed...
Definition PropertyBaseWidget.moc.h:207
Definition PropertyBaseWidget.moc.h:305
Definition PropertyBaseWidget.moc.h:321
plQtPropertyTypeContainerWidget()
*** plQtPropertyTypeContainerWidget ***
Definition PropertyBaseWidget.moc.h:175
virtual bool HasLabel() const override
If this returns true (default), a QLabel is created and the text that GetLabel() returns is displayed...
Definition PropertyBaseWidget.moc.h:183
Base class for all property widgets.
Definition PropertyBaseWidget.moc.h:28
bool m_bIsDefault
Whether the variable that the widget represents is currently set to the default value or has been mod...
Definition PropertyBaseWidget.moc.h:91
virtual bool HasLabel() const
If this returns true (default), a QLabel is created and the text that GetLabel() returns is displayed...
Definition PropertyBaseWidget.moc.h:46
virtual void SetIsDefault(bool bIsDefault)
Whether the variable that the widget represents is currently set to the default value or has been mod...
Definition PropertyBaseWidget.moc.h:54
Base class for most 'simple' property type widgets. Implements some of the standard functionality.
Definition PropertyBaseWidget.moc.h:118
Definition TypeWidget.moc.h:18
Fallback widget for all property types for which no other widget type is registered.
Definition PropertyBaseWidget.moc.h:100
Definition PropertyBaseWidget.moc.h:340
This class holds information about reflected types. Each instance represents one type that is known t...
Definition RTTI.h:30
plStringBuilder is a class that is meant for creating and modifying strings.
Definition StringBuilder.h:35
plVariant is a class that can store different types of variables, which is useful in situations where...
Definition Variant.h:44
Definition CommandHistory.h:31
Used by plDocumentObjectManager::m_PropertyEvents.
Definition DocumentObjectManager.h:77
Used by plDocumentObjectManager::m_StructureEvents.
Definition DocumentObjectManager.h:45
Definition PropertyEventHandler.h:10
Definition PropertyBaseWidget.moc.h:250
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54
Enum
This enum describes the type of data that is currently stored inside the variant. Note that changes t...
Definition VariantType.h:26