mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 15:47:42 +00:00
VisualBuilder: Add some widget-specific properties.
This commit is contained in:
parent
3674bb9429
commit
c98bbff0cb
5 changed files with 66 additions and 25 deletions
|
@ -4,6 +4,13 @@
|
||||||
#include "VBWidgetRegistry.h"
|
#include "VBWidgetRegistry.h"
|
||||||
#include "VBWidgetPropertyModel.h"
|
#include "VBWidgetPropertyModel.h"
|
||||||
#include <LibGUI/GPainter.h>
|
#include <LibGUI/GPainter.h>
|
||||||
|
#include <LibGUI/GLabel.h>
|
||||||
|
#include <LibGUI/GButton.h>
|
||||||
|
#include <LibGUI/GScrollBar.h>
|
||||||
|
#include <LibGUI/GSpinBox.h>
|
||||||
|
#include <LibGUI/GTextEditor.h>
|
||||||
|
#include <LibGUI/GGroupBox.h>
|
||||||
|
#include <LibGUI/GProgressBar.h>
|
||||||
|
|
||||||
VBWidget::VBWidget(VBWidgetType type, VBForm& form)
|
VBWidget::VBWidget(VBWidgetType type, VBForm& form)
|
||||||
: m_type(type)
|
: m_type(type)
|
||||||
|
@ -80,23 +87,63 @@ void VBWidget::for_each_property(Function<void(VBProperty&)> callback)
|
||||||
|
|
||||||
void VBWidget::synchronize_properties()
|
void VBWidget::synchronize_properties()
|
||||||
{
|
{
|
||||||
property_by_name("width")->set_value(m_gwidget->width());
|
property("width").set_value(m_gwidget->width());
|
||||||
property_by_name("height")->set_value(m_gwidget->height());
|
property("height").set_value(m_gwidget->height());
|
||||||
property_by_name("x")->set_value(m_gwidget->x());
|
property("x").set_value(m_gwidget->x());
|
||||||
property_by_name("y")->set_value(m_gwidget->y());
|
property("y").set_value(m_gwidget->y());
|
||||||
property_by_name("visible")->set_value(m_gwidget->is_visible());
|
property("visible").set_value(m_gwidget->is_visible());
|
||||||
property_by_name("enabled")->set_value(m_gwidget->is_enabled());
|
property("enabled").set_value(m_gwidget->is_enabled());
|
||||||
property_by_name("tooltip")->set_value(m_gwidget->tooltip());
|
property("tooltip").set_value(m_gwidget->tooltip());
|
||||||
property_by_name("background_color")->set_value(m_gwidget->background_color());
|
property("background_color").set_value(m_gwidget->background_color());
|
||||||
property_by_name("foreground_color")->set_value(m_gwidget->foreground_color());
|
property("foreground_color").set_value(m_gwidget->foreground_color());
|
||||||
|
|
||||||
|
if (m_type == VBWidgetType::GLabel) {
|
||||||
|
auto& widget = *static_cast<GLabel*>(m_gwidget);
|
||||||
|
property("text").set_value(widget.text());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_type == VBWidgetType::GButton) {
|
||||||
|
auto& widget = *static_cast<GButton*>(m_gwidget);
|
||||||
|
property("caption").set_value(widget.caption());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_type == VBWidgetType::GScrollBar) {
|
||||||
|
auto& widget = *static_cast<GScrollBar*>(m_gwidget);
|
||||||
|
property("min").set_value(widget.min());
|
||||||
|
property("max").set_value(widget.max());
|
||||||
|
property("value").set_value(widget.value());
|
||||||
|
property("step").set_value(widget.step());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_type == VBWidgetType::GSpinBox) {
|
||||||
|
auto& widget = *static_cast<GSpinBox*>(m_gwidget);
|
||||||
|
property("min").set_value(widget.min());
|
||||||
|
property("max").set_value(widget.max());
|
||||||
|
property("value").set_value(widget.value());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_type == VBWidgetType::GProgressBar) {
|
||||||
|
auto& widget = *static_cast<GProgressBar*>(m_gwidget);
|
||||||
|
property("min").set_value(widget.min());
|
||||||
|
property("max").set_value(widget.max());
|
||||||
|
property("value").set_value(widget.value());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_type == VBWidgetType::GTextEditor) {
|
||||||
|
auto& widget = *static_cast<GTextEditor*>(m_gwidget);
|
||||||
|
property("text").set_value(widget.text());
|
||||||
|
property("ruler_visible").set_value(widget.is_ruler_visible());
|
||||||
|
}
|
||||||
|
|
||||||
m_property_model->update();
|
m_property_model->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
VBProperty* VBWidget::property_by_name(const String& name)
|
VBProperty& VBWidget::property(const String& name)
|
||||||
{
|
{
|
||||||
for (auto& property : m_properties) {
|
for (auto& prop : m_properties) {
|
||||||
if (property->name() == name)
|
if (prop->name() == name)
|
||||||
return property.ptr();
|
return *prop;
|
||||||
}
|
}
|
||||||
return nullptr;
|
m_properties.append(make<VBProperty>(name, GVariant()));
|
||||||
|
return *m_properties.last();
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,8 +44,7 @@ public:
|
||||||
|
|
||||||
GWidget* gwidget() { return m_gwidget; }
|
GWidget* gwidget() { return m_gwidget; }
|
||||||
|
|
||||||
const VBProperty* property_by_name(const String&) const;
|
VBProperty& property(const String&);
|
||||||
VBProperty* property_by_name(const String&);
|
|
||||||
|
|
||||||
void for_each_property(Function<void(VBProperty&)>);
|
void for_each_property(Function<void(VBProperty&)>);
|
||||||
|
|
||||||
|
|
|
@ -82,14 +82,5 @@ GWidget* VBWidgetRegistry::build_gwidget(VBWidgetType type, GWidget* parent, Vec
|
||||||
properties.append(move(property));
|
properties.append(move(property));
|
||||||
};
|
};
|
||||||
add_property("class", to_class_name(type), true);
|
add_property("class", to_class_name(type), true);
|
||||||
add_property("width");
|
|
||||||
add_property("height");
|
|
||||||
add_property("x");
|
|
||||||
add_property("y");
|
|
||||||
add_property("visible");
|
|
||||||
add_property("enabled");
|
|
||||||
add_property("tooltip");
|
|
||||||
add_property("background_color");
|
|
||||||
add_property("foreground_color");
|
|
||||||
return gwidget;
|
return gwidget;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,8 @@ public:
|
||||||
void set_value(int);
|
void set_value(int);
|
||||||
|
|
||||||
int value() const { return m_value; }
|
int value() const { return m_value; }
|
||||||
|
int min() const { return m_min; }
|
||||||
|
int max() const { return m_max; }
|
||||||
|
|
||||||
String caption() const { return m_caption; }
|
String caption() const { return m_caption; }
|
||||||
void set_caption(const String& caption) { m_caption = caption; }
|
void set_caption(const String& caption) { m_caption = caption; }
|
||||||
|
|
|
@ -13,6 +13,8 @@ public:
|
||||||
int value() const { return m_value; }
|
int value() const { return m_value; }
|
||||||
void set_value(int);
|
void set_value(int);
|
||||||
|
|
||||||
|
int min() const { return m_min; }
|
||||||
|
int max() const { return m_max; }
|
||||||
void set_range(int min, int max);
|
void set_range(int min, int max);
|
||||||
|
|
||||||
Function<void(int value)> on_change;
|
Function<void(int value)> on_change;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue