/* * Copyright (c) 2022-2023, Sam Atkins * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include "PreviewWidget.h" #include #include #include #include #include #include #include #include #include #include namespace ThemeEditor { class AlignmentModel final : public GUI::Model { public: static ErrorOr> try_create() { return adopt_nonnull_ref_or_enomem(new (nothrow) AlignmentModel()); } virtual ~AlignmentModel() = default; virtual int row_count(GUI::ModelIndex const& = GUI::ModelIndex()) const override { return 3; } virtual int column_count(GUI::ModelIndex const& = GUI::ModelIndex()) const override { return 2; } virtual GUI::Variant data(GUI::ModelIndex const& index, GUI::ModelRole role) const override { if (role == GUI::ModelRole::Display) return m_alignments[index.row()].title; if (role == GUI::ModelRole::Custom) return m_alignments[index.row()].setting_value; return {}; } size_t index_of(Gfx::TextAlignment alignment) const { auto match = m_alignments.find_if([&](auto& it) { return it.setting_value == alignment; }); return match.index(); } private: AlignmentModel() = default; struct AlignmentValue { ByteString title; Gfx::TextAlignment setting_value; }; Vector m_alignments { { "Center", Gfx::TextAlignment::Center }, { "Left", Gfx::TextAlignment::CenterLeft }, { "Right", Gfx::TextAlignment::CenterRight }, }; }; struct Property { Variant role; }; struct PropertyGroup { ByteString title; Vector properties; }; struct PropertyTab { StringView title; Vector property_groups; }; class MainWidget final : public GUI::Widget { C_OBJECT_ABSTRACT(MainWidget); public: static ErrorOr> try_create(); virtual ~MainWidget() override = default; ErrorOr initialize_menubar(GUI::Window&); GUI::Window::CloseRequestDecision request_close(); void update_title(); ErrorOr load_from_file(ByteString const& filename, NonnullOwnPtr file); private: explicit MainWidget(NonnullRefPtr); virtual void drag_enter_event(GUI::DragEvent&) override; virtual void drop_event(GUI::DropEvent&) override; void save_to_file(ByteString const& filename, NonnullOwnPtr file); ErrorOr encode(); void set_path(ByteString); void build_override_controls(); ErrorOr add_property_tab(PropertyTab const&); void set_alignment(Gfx::AlignmentRole, Gfx::TextAlignment); void set_color(Gfx::ColorRole, Gfx::Color); void set_flag(Gfx::FlagRole, bool); void set_metric(Gfx::MetricRole, int); void set_path(Gfx::PathRole, ByteString); void set_palette(Gfx::Palette); enum class PathPickerTarget { File, Folder, }; void show_path_picker_dialog(StringView property_display_name, GUI::TextBox&, PathPickerTarget); RefPtr m_preview_widget; RefPtr m_property_tabs; RefPtr m_statusbar; RefPtr m_save_action; RefPtr m_theme_override_apply; RefPtr m_theme_override_reset; Optional m_path; Gfx::Palette m_current_palette; MonotonicTime m_last_modified_time { MonotonicTime::now() }; RefPtr m_alignment_model; Array, to_underlying(Gfx::AlignmentRole::__Count)> m_alignment_inputs; Array, to_underlying(Gfx::ColorRole::__Count)> m_color_inputs; Array, to_underlying(Gfx::FlagRole::__Count)> m_flag_inputs; Array, to_underlying(Gfx::MetricRole::__Count)> m_metric_inputs; Array, to_underlying(Gfx::PathRole::__Count)> m_path_inputs; OwnPtr m_preview_type_action_group; }; }