1 // Copyright 2001-2018 Crytek GmbH / Crytek Group. All rights reserved.
5 #include "IEditorClassFactory.h"
6 #include "AutoRegister.h"
12 #include "EditorFramework/StateSerializable.h"
16 struct IViewPaneClass
: public IClassDesc
18 enum EDockingDirection
27 virtual ESystemClassID
SystemClassID() { return ESYSTEM_CLASS_VIEWPANE
; };
29 // Get view pane window runtime class.
30 virtual CRuntimeClass
* GetRuntimeClass() = 0;
32 // Return text for view pane title.
33 virtual const char* GetPaneTitle() = 0;
35 // Return true if only one pane at a time of time view class can be created.
36 virtual bool SinglePane() = 0;
38 //! Notifies the application if it should create an entry in the tools menu for this pane
39 virtual bool NeedsMenuItem() { return true; }
41 //! This method returns the tools menu path where the tool can be spawned from.
42 virtual const char* GetMenuPath() { return ""; }
44 //////////////////////////////////////////////////////////////////////////
45 // Creates a Qt QWidget for this ViewPane
46 virtual IPane
* CreatePane() const { return 0; };
49 class IPane
: public IStateSerializable
54 virtual QWidget
* GetWidget() = 0;
56 // Return preferable initial docking position for pane.
57 virtual IViewPaneClass::EDockingDirection
GetDockingDirection() const { return IViewPaneClass::DOCK_FLOAT
; }
59 // Return text for view pane title.
60 virtual const char* GetPaneTitle() const = 0;
63 virtual QRect
GetPaneRect() { return QRect(0, 0, 800, 500); }
65 // Get Minimal view size
66 virtual QSize
GetMinSize() { return QSize(0, 0); }
68 // Save transient state
69 virtual QVariantMap
GetState() const { return QVariantMap(); }
71 // Restore transient state
72 virtual void SetState(const QVariantMap
& state
) {}
75 virtual void LoadLayoutPersonalization() {}
78 virtual void SaveLayoutPersonalization() {}
82 class CDockableWidgetT
: public T
, public IPane
84 static_assert(std::is_base_of
<QWidget
, T
>::value
, "T has to be QWidget");
87 CDockableWidgetT(QWidget
* pParent
= nullptr) : T(pParent
)
89 QWidget::setAttribute(Qt::WA_DeleteOnClose
);
91 virtual ~CDockableWidgetT() {}
92 virtual QWidget
* GetWidget() override
{ return this; };
95 typedef CDockableWidgetT
<QWidget
> CDockableWidget
;
97 //DEPREACTED, DO NOT USE THIS, QMainWindow is not a suitable baseclass for a dockable pane
98 typedef CDockableWidgetT
<QMainWindow
> CDockableWindow
;
102 // Registers the QWidget pane so that it can be opened in the editor as a tool
103 #define REGISTER_VIEWPANE_FACTORY_AND_MENU_IMPL(widget, name, category, unique, menuPath, needsItem) \
104 class widget ## Pane : public IViewPaneClass \
106 virtual const char* ClassName() override { return name; } \
107 virtual const char* Category() { return category; } \
108 virtual bool NeedsMenuItem() { return needsItem; } \
109 virtual const char* GetMenuPath() { return menuPath; } \
110 virtual CRuntimeClass* GetRuntimeClass() { return 0; } \
111 virtual const char* GetPaneTitle() override { return name; } \
112 virtual bool SinglePane() override { return unique; } \
113 virtual IPane* CreatePane() const override { return new widget(); } \
115 REGISTER_CLASS_DESC(widget ## Pane);
118 #define REGISTER_VIEWPANE_FACTORY(widget, name, category, unique) \
119 REGISTER_VIEWPANE_FACTORY_AND_MENU_IMPL(widget, name, category, unique, "", true)
121 #define REGISTER_VIEWPANE_FACTORY_AND_MENU(widget, name, category, unique, menuPath) \
122 REGISTER_VIEWPANE_FACTORY_AND_MENU_IMPL(widget, name, category, unique, menuPath, true)
124 #define REGISTER_HIDDEN_VIEWPANE_FACTORY(widget, name, category, unique) \
125 REGISTER_VIEWPANE_FACTORY_AND_MENU_IMPL(widget, name, category, unique, "", false)