diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-09-17 21:22:15 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-09-17 22:17:28 +0200 |
commit | 9d460d55d1ff3070f578aef9326ecc425da68d7d (patch) | |
tree | 721eaa12e1012b5a1b6938e4dafd890cc9b29534 /DevTools | |
parent | 5e439bb3c88a269406b2a7617c6b3d116797f250 (diff) | |
download | serenity-9d460d55d1ff3070f578aef9326ecc425da68d7d.zip |
VisualBuilder: Don't allow moving/resizing widgets that are in a layout
Also paint these widgets' grabbers differently to make it stand out
visually which widgets have managed geometry. :^)
Diffstat (limited to 'DevTools')
-rw-r--r-- | DevTools/VisualBuilder/VBForm.cpp | 14 | ||||
-rw-r--r-- | DevTools/VisualBuilder/VBWidget.cpp | 12 | ||||
-rw-r--r-- | DevTools/VisualBuilder/VBWidget.h | 2 |
3 files changed, 26 insertions, 2 deletions
diff --git a/DevTools/VisualBuilder/VBForm.cpp b/DevTools/VisualBuilder/VBForm.cpp index bd9838ffc5..8e7ef948e0 100644 --- a/DevTools/VisualBuilder/VBForm.cpp +++ b/DevTools/VisualBuilder/VBForm.cpp @@ -96,7 +96,11 @@ void VBForm::second_paint_event(GPaintEvent& event) for (auto& widget : m_widgets) { if (widget.is_selected()) { for_each_direction([&](auto direction) { - painter.fill_rect(widget.grabber_rect(direction), Color::Black); + bool in_layout = widget.is_in_layout(); + auto grabber_rect = widget.grabber_rect(direction); + painter.fill_rect(grabber_rect, in_layout ? Color::White : Color::Black); + if (in_layout) + painter.draw_rect(grabber_rect, Color::Black); }); } } @@ -211,6 +215,8 @@ void VBForm::mousedown_event(GMouseEvent& event) if (m_resize_direction == Direction::None) { bool hit_grabber = false; for_each_selected_widget([&](auto& widget) { + if (widget.is_in_layout()) + return; auto grabber = widget.grabber_at(event.position()); if (grabber != Direction::None) { hit_grabber = true; @@ -245,6 +251,8 @@ void VBForm::mousemove_event(GMouseEvent& event) update(); auto delta = event.position() - m_transform_event_origin; for_each_selected_widget([&](auto& widget) { + if (widget.is_in_layout()) + return; auto new_rect = widget.transform_origin_rect().translated(delta); new_rect.set_x(new_rect.x() - (new_rect.x() % m_grid_size)); new_rect.set_y(new_rect.y() - (new_rect.y() % m_grid_size)); @@ -301,6 +309,8 @@ void VBForm::mousemove_event(GMouseEvent& event) update(); for_each_selected_widget([&](auto& widget) { + if (widget.is_in_layout()) + return; auto new_rect = widget.transform_origin_rect(); Size minimum_size { 5, 5 }; new_rect.set_x(new_rect.x() + change_x); @@ -317,6 +327,8 @@ void VBForm::mousemove_event(GMouseEvent& event) set_cursor_type_from_grabber(m_resize_direction); } else { for (auto& widget : m_selected_widgets) { + if (widget->is_in_layout()) + continue; auto grabber_at = widget->grabber_at(event.position()); set_cursor_type_from_grabber(grabber_at); if (grabber_at != Direction::None) diff --git a/DevTools/VisualBuilder/VBWidget.cpp b/DevTools/VisualBuilder/VBWidget.cpp index 2450d7e5a7..f1b3a1879e 100644 --- a/DevTools/VisualBuilder/VBWidget.cpp +++ b/DevTools/VisualBuilder/VBWidget.cpp @@ -105,7 +105,8 @@ void VBWidget::add_property(const String& name, Function<GVariant(const GWidget& } #define VB_ADD_PROPERTY(gclass, name, getter, setter, variant_type) \ - add_property(name, \ + add_property( \ + name, \ [](auto& widget) -> GVariant { return ((const gclass&)widget).getter(); }, \ [](auto& widget, auto& value) { ((gclass&)widget).setter(value.to_##variant_type()); }) @@ -206,3 +207,12 @@ void VBWidget::capture_transform_origin_rect() { m_transform_origin_rect = rect(); } + +bool VBWidget::is_in_layout() const +{ + if (auto* parent_widget = m_gwidget->parent_widget()) { + if (parent_widget->layout()) + return true; + } + return false; +} diff --git a/DevTools/VisualBuilder/VBWidget.h b/DevTools/VisualBuilder/VBWidget.h index 67f9b67a84..793d15a44f 100644 --- a/DevTools/VisualBuilder/VBWidget.h +++ b/DevTools/VisualBuilder/VBWidget.h @@ -72,6 +72,8 @@ public: Rect transform_origin_rect() const { return m_transform_origin_rect; } void capture_transform_origin_rect(); + bool is_in_layout() const; + private: VBWidget(VBWidgetType, VBForm&, VBWidget* parent); |