summaryrefslogtreecommitdiff
path: root/Userland/Applications/PixelPaint/MainWidget.h
diff options
context:
space:
mode:
authorMustafa Quraish <mustafaq9@gmail.com>2021-09-06 00:11:46 -0400
committerAndreas Kling <kling@serenityos.org>2021-09-06 10:36:08 +0200
commit5a8c6b95e61da7717388241e0c4733de8c1d267f (patch)
tree17800e74aff7cda7d5c3af12d71d008d2e92aa6c /Userland/Applications/PixelPaint/MainWidget.h
parentbbddfeef4bf5dcebd50828806d55a60224ece6b9 (diff)
downloadserenity-5a8c6b95e61da7717388241e0c4733de8c1d267f.zip
PixelPaint: Refactor `main.cpp` into `MainWidget`
Previously, all the UI setup was done in `main.cpp`, with a whole bunch of lambdas,, and actions etc just being stored in the main function. This is probably an artifact from back when it was first created. Most other applications now have a "MainWidget" class of some sort which handles setting up all the UI/menubars, etc. More importantly,, it also lets us handle application-wide events which we were previously not able to do directly, since the main widget was just a default GUI::Widget. This patch moves all the core functionality of the PixelPaint application into PixelPaint::MainWidget, which is then instantiated by the main function. There is likely some more refactoring that would help, but this commit is big enough as it is doing mostly a direct port.
Diffstat (limited to 'Userland/Applications/PixelPaint/MainWidget.h')
-rw-r--r--Userland/Applications/PixelPaint/MainWidget.h73
1 files changed, 73 insertions, 0 deletions
diff --git a/Userland/Applications/PixelPaint/MainWidget.h b/Userland/Applications/PixelPaint/MainWidget.h
new file mode 100644
index 0000000000..4294608499
--- /dev/null
+++ b/Userland/Applications/PixelPaint/MainWidget.h
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2021, Mustafa Quraish <mustafa@cs.toronto.edu>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include "Guide.h"
+#include "Image.h"
+#include "ImageEditor.h"
+#include "Layer.h"
+#include "LayerListWidget.h"
+#include "LayerPropertiesWidget.h"
+#include "PaletteWidget.h"
+#include "ProjectLoader.h"
+#include "Tool.h"
+#include "ToolPropertiesWidget.h"
+#include "ToolboxWidget.h"
+#include <LibGUI/Action.h>
+#include <LibGUI/Forward.h>
+#include <LibGUI/Statusbar.h>
+#include <LibGUI/TabWidget.h>
+#include <LibGUI/Widget.h>
+
+namespace PixelPaint {
+
+class MainWidget : public GUI::Widget {
+ C_OBJECT(MainWidget);
+
+public:
+ virtual ~MainWidget() {};
+
+ void initialize_menubar(GUI::Window&);
+
+ void open_image_fd(int fd, String const& path);
+ void open_image_file(String const& path);
+ void create_default_image();
+
+private:
+ MainWidget();
+
+ ImageEditor* current_image_editor();
+ ImageEditor& create_new_editor(NonnullRefPtr<Image>);
+
+ ProjectLoader m_loader;
+
+ RefPtr<ToolboxWidget> m_toolbox;
+ RefPtr<PaletteWidget> m_palette_widget;
+ RefPtr<LayerListWidget> m_layer_list_widget;
+ RefPtr<LayerPropertiesWidget> m_layer_properties_widget;
+ RefPtr<ToolPropertiesWidget> m_tool_properties_widget;
+ RefPtr<GUI::TabWidget> m_tab_widget;
+ RefPtr<GUI::Statusbar> m_statusbar;
+
+ RefPtr<GUI::Action> m_new_image_action;
+ RefPtr<GUI::Action> m_open_image_action;
+ RefPtr<GUI::Action> m_save_image_as_action;
+
+ RefPtr<GUI::Action> m_copy_action;
+ RefPtr<GUI::Action> m_copy_merged_action;
+ RefPtr<GUI::Action> m_paste_action;
+ RefPtr<GUI::Action> m_undo_action;
+ RefPtr<GUI::Action> m_redo_action;
+
+ RefPtr<GUI::Action> m_zoom_in_action;
+ RefPtr<GUI::Action> m_zoom_out_action;
+ RefPtr<GUI::Action> m_reset_zoom_action;
+ RefPtr<GUI::Action> m_add_guide_action;
+ RefPtr<GUI::Action> m_show_guides_action;
+};
+
+}