Selaa lähdekoodia

VisualBuilder: Move properties window to its own class.

Andreas Kling 6 vuotta sitten
vanhempi
commit
ec841f3a23

+ 1 - 0
Applications/VisualBuilder/Makefile

@@ -4,6 +4,7 @@ OBJS = \
     VBWidgetRegistry.o \
     VBWidgetPropertyModel.o \
     VBProperty.o \
+    VBPropertiesWindow.o \
     main.o
 
 APP = VisualBuilder 

+ 21 - 0
Applications/VisualBuilder/VBPropertiesWindow.cpp

@@ -0,0 +1,21 @@
+#include "VBPropertiesWindow.h"
+#include <LibGUI/GWidget.h>
+#include <LibGUI/GBoxLayout.h>
+#include <LibGUI/GTableView.h>
+
+VBPropertiesWindow::VBPropertiesWindow()
+{
+    set_title("Properties");
+    set_rect(780, 200, 200, 280);
+
+    auto* widget = new GWidget;
+    widget->set_fill_with_background_color(true);
+    widget->set_layout(make<GBoxLayout>(Orientation::Vertical));
+    set_main_widget(widget);
+
+    m_table_view = new GTableView(widget);
+}
+
+VBPropertiesWindow::~VBPropertiesWindow()
+{
+}

+ 17 - 0
Applications/VisualBuilder/VBPropertiesWindow.h

@@ -0,0 +1,17 @@
+#pragma once
+
+#include <LibGUI/GWindow.h>
+
+class GTableView;
+
+class VBPropertiesWindow final : public GWindow {
+public:
+    VBPropertiesWindow();
+    virtual ~VBPropertiesWindow() override;
+
+    GTableView& table_view() { return *m_table_view; }
+    const GTableView& table_view() const { return *m_table_view; }
+
+private:
+    GTableView* m_table_view { nullptr };
+};

+ 4 - 22
Applications/VisualBuilder/main.cpp

@@ -9,25 +9,23 @@
 #include "VBForm.h"
 #include "VBWidget.h"
 #include "VBWidgetPropertyModel.h"
+#include "VBPropertiesWindow.h"
 #include <unistd.h>
 #include <stdio.h>
 #include <signal.h>
 #include <fcntl.h>
 
 static GWindow* make_toolbox_window();
-static GWindow* make_properties_window();
-
-GTableView* g_property_table_view;
 
 int main(int argc, char** argv)
 {
     GApplication app(argc, argv);
 
-    auto* propbox = make_properties_window();
+    auto* propbox = new VBPropertiesWindow;
 
     auto* form1 = new VBForm("Form1");
-    form1->on_widget_selected = [] (VBWidget* widget) {
-        g_property_table_view->set_model(widget ? &widget->property_model() : nullptr);
+    form1->on_widget_selected = [propbox] (VBWidget* widget) {
+        propbox->table_view().set_model(widget ? &widget->property_model() : nullptr);
     };
 
     auto menubar = make<GMenuBar>();
@@ -137,19 +135,3 @@ GWindow* make_toolbox_window()
     };
     return window;
 }
-
-GWindow* make_properties_window()
-{
-    auto* window = new GWindow;
-    window->set_title("Properties");
-    window->set_rect(780, 200, 200, 280);
-
-    auto* widget = new GWidget;
-    widget->set_fill_with_background_color(true);
-    widget->set_layout(make<GBoxLayout>(Orientation::Vertical));
-    window->set_main_widget(widget);
-
-    g_property_table_view = new GTableView(widget);
-
-    return window;
-}