From 9d460d55d1ff3070f578aef9326ecc425da68d7d Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 17 Sep 2019 21:22:15 +0200 Subject: [PATCH] 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. :^) --- DevTools/VisualBuilder/VBForm.cpp | 14 +++++++++++++- DevTools/VisualBuilder/VBWidget.cpp | 12 +++++++++++- 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 bd9838ffc52..8e7ef948e00 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 2450d7e5a79..f1b3a1879e6 100644 --- a/DevTools/VisualBuilder/VBWidget.cpp +++ b/DevTools/VisualBuilder/VBWidget.cpp @@ -105,7 +105,8 @@ void VBWidget::add_property(const String& name, Function 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 67f9b67a844..793d15a44f1 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);