vtkProperties
This commit is contained in:
110
app/gcompose/src/PropertyWidgets.h
Normal file
110
app/gcompose/src/PropertyWidgets.h
Normal file
@@ -0,0 +1,110 @@
|
||||
#ifndef PROPERTY_WIDGETS_H
|
||||
#define PROPERTY_WIDGETS_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QLabel>
|
||||
#include <QHBoxLayout>
|
||||
#include <QVBoxLayout>
|
||||
#include <QDoubleSpinBox>
|
||||
#include <QSpinBox>
|
||||
#include <QLineEdit>
|
||||
#include <QCheckBox>
|
||||
#include <QScrollArea>
|
||||
#include <map>
|
||||
#include <typeindex>
|
||||
#include <functional>
|
||||
|
||||
#include "Core/Property.h"
|
||||
#include "Core/Object.h"
|
||||
|
||||
namespace uLib {
|
||||
namespace Qt {
|
||||
|
||||
class PropertyWidgetBase : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
PropertyWidgetBase(PropertyBase* prop, QWidget* parent = nullptr);
|
||||
virtual ~PropertyWidgetBase();
|
||||
PropertyBase* getProperty() const { return m_BaseProperty; }
|
||||
|
||||
protected:
|
||||
PropertyBase* m_BaseProperty;
|
||||
QHBoxLayout* m_Layout;
|
||||
QLabel* m_Label;
|
||||
};
|
||||
|
||||
class DoublePropertyWidget : public PropertyWidgetBase {
|
||||
Q_OBJECT
|
||||
public:
|
||||
DoublePropertyWidget(Property<double>* prop, QWidget* parent = nullptr);
|
||||
virtual ~DoublePropertyWidget();
|
||||
private:
|
||||
Property<double>* m_Prop;
|
||||
QDoubleSpinBox* m_SpinBox;
|
||||
};
|
||||
|
||||
class FloatPropertyWidget : public PropertyWidgetBase {
|
||||
Q_OBJECT
|
||||
public:
|
||||
FloatPropertyWidget(Property<float>* prop, QWidget* parent = nullptr);
|
||||
virtual ~FloatPropertyWidget();
|
||||
private:
|
||||
Property<float>* m_Prop;
|
||||
QDoubleSpinBox* m_SpinBox;
|
||||
};
|
||||
|
||||
class IntPropertyWidget : public PropertyWidgetBase {
|
||||
Q_OBJECT
|
||||
public:
|
||||
IntPropertyWidget(Property<int>* prop, QWidget* parent = nullptr);
|
||||
virtual ~IntPropertyWidget();
|
||||
private:
|
||||
Property<int>* m_Prop;
|
||||
QSpinBox* m_SpinBox;
|
||||
};
|
||||
|
||||
class BoolPropertyWidget : public PropertyWidgetBase {
|
||||
Q_OBJECT
|
||||
public:
|
||||
BoolPropertyWidget(Property<bool>* prop, QWidget* parent = nullptr);
|
||||
virtual ~BoolPropertyWidget();
|
||||
private:
|
||||
Property<bool>* m_Prop;
|
||||
QCheckBox* m_CheckBox;
|
||||
};
|
||||
|
||||
class StringPropertyWidget : public PropertyWidgetBase {
|
||||
Q_OBJECT
|
||||
public:
|
||||
StringPropertyWidget(Property<std::string>* prop, QWidget* parent = nullptr);
|
||||
virtual ~StringPropertyWidget();
|
||||
private:
|
||||
Property<std::string>* m_Prop;
|
||||
QLineEdit* m_LineEdit;
|
||||
};
|
||||
|
||||
class PropertyEditor : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
PropertyEditor(QWidget* parent = nullptr);
|
||||
virtual ~PropertyEditor();
|
||||
void setObject(uLib::Object* obj, bool displayOnly = false);
|
||||
template<typename T>
|
||||
void registerFactory(std::function<QWidget*(PropertyBase*, QWidget*)> factory) {
|
||||
m_Factories[std::type_index(typeid(T))] = factory;
|
||||
}
|
||||
|
||||
private:
|
||||
void clear();
|
||||
uLib::Object* m_Object;
|
||||
QVBoxLayout* m_MainLayout;
|
||||
QScrollArea* m_ScrollArea;
|
||||
QWidget* m_Container;
|
||||
QVBoxLayout* m_ContainerLayout;
|
||||
std::map<std::type_index, std::function<QWidget*(PropertyBase*, QWidget*)>> m_Factories;
|
||||
};
|
||||
|
||||
} // namespace Qt
|
||||
} // namespace uLib
|
||||
|
||||
#endif // PROPERTY_WIDGETS_H
|
||||
Reference in New Issue
Block a user