Ver código fonte

LibGUI: Convert GFrame to ObjectPtr

Andreas Kling 5 anos atrás
pai
commit
55a6e4ac0b

+ 6 - 6
Applications/PaintBrush/ColorDialog.cpp

@@ -35,9 +35,9 @@ void ColorDialog::build()
         Red, Green, Blue
         Red, Green, Blue
     };
     };
 
 
-    auto* preview_widget = new GFrame(right_vertical_container);
-    preview_widget->set_background_color(m_color);
-    preview_widget->set_fill_with_background_color(true);
+    m_preview_widget = GFrame::construct(right_vertical_container);
+    m_preview_widget->set_background_color(m_color);
+    m_preview_widget->set_fill_with_background_color(true);
     right_vertical_container->layout()->add_spacer();
     right_vertical_container->layout()->add_spacer();
     auto* cancel_button = new GButton("Cancel", right_vertical_container);
     auto* cancel_button = new GButton("Cancel", right_vertical_container);
     cancel_button->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
     cancel_button->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
@@ -60,7 +60,7 @@ void ColorDialog::build()
          spinbox->set_max(255);
          spinbox->set_max(255);
          spinbox->set_value(initial_value);
          spinbox->set_value(initial_value);
 
 
-         spinbox->on_change = [=](auto value) {
+         spinbox->on_change = [this, component](auto value) {
              if (component == Red)
              if (component == Red)
                 m_color.set_red(value);
                 m_color.set_red(value);
              if (component == Green)
              if (component == Green)
@@ -68,8 +68,8 @@ void ColorDialog::build()
              if (component == Blue)
              if (component == Blue)
                 m_color.set_blue(value);
                 m_color.set_blue(value);
 
 
-             preview_widget->set_background_color(m_color);
-             preview_widget->update();
+             m_preview_widget->set_background_color(m_color);
+             m_preview_widget->update();
          };
          };
          return spinbox;
          return spinbox;
     };
     };

+ 5 - 1
Applications/PaintBrush/ColorDialog.h

@@ -2,16 +2,20 @@
 
 
 #include <LibGUI/GDialog.h>
 #include <LibGUI/GDialog.h>
 
 
+class GFrame;
+
 class ColorDialog final : public GDialog {
 class ColorDialog final : public GDialog {
     C_OBJECT(ColorDialog)
     C_OBJECT(ColorDialog)
 public:
 public:
-    explicit ColorDialog(Color, CObject* parent = nullptr);
     virtual ~ColorDialog() override;
     virtual ~ColorDialog() override;
 
 
     Color color() const { return m_color; }
     Color color() const { return m_color; }
 
 
 private:
 private:
+    explicit ColorDialog(Color, CObject* parent = nullptr);
+
     void build();
     void build();
 
 
     Color m_color;
     Color m_color;
+    ObjectPtr<GFrame> m_preview_widget;
 };
 };

+ 5 - 5
Applications/PaintBrush/PaletteWidget.cpp

@@ -22,9 +22,9 @@ public:
     virtual void mousedown_event(GMouseEvent& event) override
     virtual void mousedown_event(GMouseEvent& event) override
     {
     {
         if (event.modifiers() & KeyModifier::Mod_Ctrl && event.button() == GMouseButton::Left) {
         if (event.modifiers() & KeyModifier::Mod_Ctrl && event.button() == GMouseButton::Left) {
-            ColorDialog dialog(m_color, window());
-            if (dialog.exec() == GDialog::ExecOK) {
-                m_color = dialog.color();
+            auto dialog = ColorDialog::construct(m_color, window());
+            if (dialog->exec() == GDialog::ExecOK) {
+                m_color = dialog->color();
                 set_background_color(m_color);
                 set_background_color(m_color);
                 update();
                 update();
             }
             }
@@ -55,7 +55,7 @@ PaletteWidget::PaletteWidget(PaintableWidget& paintable_widget, GWidget* parent)
     set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
     set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
     set_preferred_size(0, 34);
     set_preferred_size(0, 34);
 
 
-    m_secondary_color_widget = new GFrame(this);
+    m_secondary_color_widget = GFrame::construct(this);
     m_secondary_color_widget->set_frame_thickness(2);
     m_secondary_color_widget->set_frame_thickness(2);
     m_secondary_color_widget->set_frame_shape(FrameShape::Container);
     m_secondary_color_widget->set_frame_shape(FrameShape::Container);
     m_secondary_color_widget->set_frame_shadow(FrameShadow::Sunken);
     m_secondary_color_widget->set_frame_shadow(FrameShadow::Sunken);
@@ -63,7 +63,7 @@ PaletteWidget::PaletteWidget(PaintableWidget& paintable_widget, GWidget* parent)
     m_secondary_color_widget->set_fill_with_background_color(true);
     m_secondary_color_widget->set_fill_with_background_color(true);
     set_secondary_color(paintable_widget.secondary_color());
     set_secondary_color(paintable_widget.secondary_color());
 
 
-    m_primary_color_widget = new GFrame(this);
+    m_primary_color_widget = GFrame::construct(this);
     m_primary_color_widget->set_frame_thickness(2);
     m_primary_color_widget->set_frame_thickness(2);
     m_primary_color_widget->set_frame_shape(FrameShape::Container);
     m_primary_color_widget->set_frame_shape(FrameShape::Container);
     m_primary_color_widget->set_frame_shadow(FrameShadow::Sunken);
     m_primary_color_widget->set_frame_shadow(FrameShadow::Sunken);

+ 2 - 2
Applications/PaintBrush/PaletteWidget.h

@@ -15,6 +15,6 @@ public:
 
 
 private:
 private:
     PaintableWidget& m_paintable_widget;
     PaintableWidget& m_paintable_widget;
-    GFrame* m_primary_color_widget { nullptr };
-    GFrame* m_secondary_color_widget { nullptr };
+    ObjectPtr<GFrame> m_primary_color_widget;
+    ObjectPtr<GFrame> m_secondary_color_widget;
 };
 };

+ 1 - 1
Applications/Taskbar/TaskbarWindow.cpp

@@ -21,7 +21,7 @@ TaskbarWindow::TaskbarWindow()
 
 
     GDesktop::the().on_rect_change = [this](const Rect& rect) { on_screen_rect_change(rect); };
     GDesktop::the().on_rect_change = [this](const Rect& rect) { on_screen_rect_change(rect); };
 
 
-    auto* widget = new GFrame;
+    auto widget = GFrame::construct();
     widget->set_fill_with_background_color(true);
     widget->set_fill_with_background_color(true);
     widget->set_layout(make<GBoxLayout>(Orientation::Horizontal));
     widget->set_layout(make<GBoxLayout>(Orientation::Horizontal));
     widget->layout()->set_margins({ 3, 2, 3, 2 });
     widget->layout()->set_margins({ 3, 2, 3, 2 });

+ 1 - 1
Libraries/LibGUI/GFilePicker.cpp

@@ -192,7 +192,7 @@ GFilePicker::GFilePicker(Mode mode, const StringView& file_name, const StringVie
         }
         }
     };
     };
 
 
-    auto* preview_container = new GFrame(horizontal_container);
+    auto preview_container = GFrame::construct(horizontal_container);
     preview_container->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
     preview_container->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
     preview_container->set_preferred_size(180, 0);
     preview_container->set_preferred_size(180, 0);
     preview_container->set_frame_shape(FrameShape::Container);
     preview_container->set_frame_shape(FrameShape::Container);

+ 1 - 1
Libraries/LibGUI/GFrame.h

@@ -6,7 +6,6 @@
 class GFrame : public GWidget {
 class GFrame : public GWidget {
     C_OBJECT(GFrame)
     C_OBJECT(GFrame)
 public:
 public:
-    explicit GFrame(GWidget* parent = nullptr);
     virtual ~GFrame() override;
     virtual ~GFrame() override;
 
 
     int frame_thickness() const { return m_thickness; }
     int frame_thickness() const { return m_thickness; }
@@ -22,6 +21,7 @@ public:
     Rect frame_inner_rect() const { return frame_inner_rect_for_size(size()); }
     Rect frame_inner_rect() const { return frame_inner_rect_for_size(size()); }
 
 
 protected:
 protected:
+    explicit GFrame(GWidget* parent = nullptr);
     void paint_event(GPaintEvent&) override;
     void paint_event(GPaintEvent&) override;
 
 
 private:
 private: