mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:47:44 +00:00
VisualBuilder: Make it possible to move widgets to front/back.
This commit is contained in:
parent
04500c1ae2
commit
52e846df87
3 changed files with 18 additions and 10 deletions
|
@ -36,9 +36,15 @@ VBForm::VBForm(const String& name, GWidget* parent)
|
||||||
m_widgets.append(move(groupbox1));
|
m_widgets.append(move(groupbox1));
|
||||||
|
|
||||||
auto context_menu = make<GMenu>("Context menu");
|
auto context_menu = make<GMenu>("Context menu");
|
||||||
context_menu->add_action(GAction::create("Item 1", [] (auto&) { dbgprintf("Item 1 activated!\n"); }));
|
context_menu->add_action(GAction::create("Move to front", [this] (auto&) {
|
||||||
context_menu->add_action(GAction::create("Item 2", [] (auto&) { dbgprintf("Item 2 activated!\n"); }));
|
if (m_selected_widget)
|
||||||
set_context_menu(move(context_menu));
|
m_selected_widget->gwidget()->move_to_front();
|
||||||
|
}));
|
||||||
|
context_menu->add_action(GAction::create("Move to back", [this] (auto&) {
|
||||||
|
if (m_selected_widget)
|
||||||
|
m_selected_widget->gwidget()->move_to_back();
|
||||||
|
}));
|
||||||
|
set_context_menu(move(context_menu), GWidget::ContextMenuMode::PassthroughMouseEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VBForm::insert_widget(VBWidgetType type)
|
void VBForm::insert_widget(VBWidgetType type)
|
||||||
|
@ -86,12 +92,10 @@ bool VBForm::is_selected(const VBWidget& widget) const
|
||||||
|
|
||||||
VBWidget* VBForm::widget_at(const Point& position)
|
VBWidget* VBForm::widget_at(const Point& position)
|
||||||
{
|
{
|
||||||
for (int i = m_widgets.size() - 1; i >= 0; --i) {
|
auto* gwidget = child_at(position);
|
||||||
auto& widget = *m_widgets[i];
|
if (!gwidget)
|
||||||
if (widget.rect().contains(position))
|
return nullptr;
|
||||||
return &widget;
|
return m_gwidget_map.get(gwidget);
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void VBForm::grabber_mousedown_event(GMouseEvent& event, VBWidget& widget, Direction grabber)
|
void VBForm::grabber_mousedown_event(GMouseEvent& event, VBWidget& widget, Direction grabber)
|
||||||
|
@ -118,7 +122,7 @@ void VBForm::mousedown_event(GMouseEvent& event)
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (event.button() == GMouseButton::Left) {
|
if (event.button() == GMouseButton::Left || event.button() == GMouseButton::Right) {
|
||||||
m_selected_widget = widget->make_weak_ptr();
|
m_selected_widget = widget->make_weak_ptr();
|
||||||
m_transform_event_origin = event.position();
|
m_transform_event_origin = event.position();
|
||||||
m_transform_widget_origin_rect = widget->rect();
|
m_transform_widget_origin_rect = widget->rect();
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "VBWidget.h"
|
#include "VBWidget.h"
|
||||||
|
|
||||||
class VBForm : public GWidget {
|
class VBForm : public GWidget {
|
||||||
|
friend class VBWidget;
|
||||||
public:
|
public:
|
||||||
explicit VBForm(const String& name, GWidget* parent = nullptr);
|
explicit VBForm(const String& name, GWidget* parent = nullptr);
|
||||||
virtual ~VBForm() override;
|
virtual ~VBForm() override;
|
||||||
|
@ -38,6 +39,7 @@ private:
|
||||||
int m_grid_size { 5 };
|
int m_grid_size { 5 };
|
||||||
bool m_should_snap_to_grid { true };
|
bool m_should_snap_to_grid { true };
|
||||||
Vector<Retained<VBWidget>> m_widgets;
|
Vector<Retained<VBWidget>> m_widgets;
|
||||||
|
HashMap<GWidget*, VBWidget*> m_gwidget_map;
|
||||||
WeakPtr<VBWidget> m_selected_widget;
|
WeakPtr<VBWidget> m_selected_widget;
|
||||||
Point m_transform_event_origin;
|
Point m_transform_event_origin;
|
||||||
Rect m_transform_widget_origin_rect;
|
Rect m_transform_widget_origin_rect;
|
||||||
|
|
|
@ -18,10 +18,12 @@ VBWidget::VBWidget(VBWidgetType type, VBForm& form)
|
||||||
, m_property_model(VBWidgetPropertyModel::create(*this))
|
, m_property_model(VBWidgetPropertyModel::create(*this))
|
||||||
{
|
{
|
||||||
m_gwidget = VBWidgetRegistry::build_gwidget(type, &form, m_properties);
|
m_gwidget = VBWidgetRegistry::build_gwidget(type, &form, m_properties);
|
||||||
|
m_form.m_gwidget_map.set(m_gwidget, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
VBWidget::~VBWidget()
|
VBWidget::~VBWidget()
|
||||||
{
|
{
|
||||||
|
m_form.m_gwidget_map.remove(m_gwidget);
|
||||||
}
|
}
|
||||||
|
|
||||||
Rect VBWidget::rect() const
|
Rect VBWidget::rect() const
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue