diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-04-16 03:52:26 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-04-16 03:52:26 +0200 |
commit | 52e846df87ab370e5754d17e6d6931a32211ccb5 (patch) | |
tree | 08fc0afb526649a3c0d25e6c8761dc27c4dd136a /Applications | |
parent | 04500c1ae29c8ae5b59b8850b88afe1844548dce (diff) | |
download | serenity-52e846df87ab370e5754d17e6d6931a32211ccb5.zip |
VisualBuilder: Make it possible to move widgets to front/back.
Diffstat (limited to 'Applications')
-rw-r--r-- | Applications/VisualBuilder/VBForm.cpp | 24 | ||||
-rw-r--r-- | Applications/VisualBuilder/VBForm.h | 2 | ||||
-rw-r--r-- | Applications/VisualBuilder/VBWidget.cpp | 2 |
3 files changed, 18 insertions, 10 deletions
diff --git a/Applications/VisualBuilder/VBForm.cpp b/Applications/VisualBuilder/VBForm.cpp index bedcf849a9..8cc53728b0 100644 --- a/Applications/VisualBuilder/VBForm.cpp +++ b/Applications/VisualBuilder/VBForm.cpp @@ -36,9 +36,15 @@ VBForm::VBForm(const String& name, GWidget* parent) m_widgets.append(move(groupbox1)); 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("Item 2", [] (auto&) { dbgprintf("Item 2 activated!\n"); })); - set_context_menu(move(context_menu)); + context_menu->add_action(GAction::create("Move to front", [this] (auto&) { + if (m_selected_widget) + 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) @@ -86,12 +92,10 @@ bool VBForm::is_selected(const VBWidget& widget) const VBWidget* VBForm::widget_at(const Point& position) { - for (int i = m_widgets.size() - 1; i >= 0; --i) { - auto& widget = *m_widgets[i]; - if (widget.rect().contains(position)) - return &widget; - } - return nullptr; + auto* gwidget = child_at(position); + if (!gwidget) + return nullptr; + return m_gwidget_map.get(gwidget); } void VBForm::grabber_mousedown_event(GMouseEvent& event, VBWidget& widget, Direction grabber) @@ -118,7 +122,7 @@ void VBForm::mousedown_event(GMouseEvent& event) } return; } - if (event.button() == GMouseButton::Left) { + if (event.button() == GMouseButton::Left || event.button() == GMouseButton::Right) { m_selected_widget = widget->make_weak_ptr(); m_transform_event_origin = event.position(); m_transform_widget_origin_rect = widget->rect(); diff --git a/Applications/VisualBuilder/VBForm.h b/Applications/VisualBuilder/VBForm.h index 10d858157d..d9cc55df0e 100644 --- a/Applications/VisualBuilder/VBForm.h +++ b/Applications/VisualBuilder/VBForm.h @@ -5,6 +5,7 @@ #include "VBWidget.h" class VBForm : public GWidget { + friend class VBWidget; public: explicit VBForm(const String& name, GWidget* parent = nullptr); virtual ~VBForm() override; @@ -38,6 +39,7 @@ private: int m_grid_size { 5 }; bool m_should_snap_to_grid { true }; Vector<Retained<VBWidget>> m_widgets; + HashMap<GWidget*, VBWidget*> m_gwidget_map; WeakPtr<VBWidget> m_selected_widget; Point m_transform_event_origin; Rect m_transform_widget_origin_rect; diff --git a/Applications/VisualBuilder/VBWidget.cpp b/Applications/VisualBuilder/VBWidget.cpp index e77ba3b2bd..af473b6d09 100644 --- a/Applications/VisualBuilder/VBWidget.cpp +++ b/Applications/VisualBuilder/VBWidget.cpp @@ -18,10 +18,12 @@ VBWidget::VBWidget(VBWidgetType type, VBForm& form) , m_property_model(VBWidgetPropertyModel::create(*this)) { m_gwidget = VBWidgetRegistry::build_gwidget(type, &form, m_properties); + m_form.m_gwidget_map.set(m_gwidget, this); } VBWidget::~VBWidget() { + m_form.m_gwidget_map.remove(m_gwidget); } Rect VBWidget::rect() const |