File indexing completed on 2025-02-02 04:11:35

0001 /*
0002  * SPDX-FileCopyrightText: 2019-2023 Mattia Basaglia <dev@dragon.best>
0003  *
0004  * SPDX-License-Identifier: GPL-3.0-or-later
0005  */
0006 
0007 #pragma once
0008 #include "shape_tool_widget.hpp"
0009 #include "ui_shape_tool_widget.h"
0010 
0011 #include "app/settings/widget.hpp"
0012 
0013 class glaxnimate::gui::ShapeToolWidget::Private
0014 {
0015 public:
0016 
0017     virtual ~Private() = default;
0018 
0019     void load_settings()
0020     {
0021         settings.define();
0022         check_checks();
0023         on_load_settings();
0024     }
0025 
0026     void save_settings()
0027     {
0028         settings.save();
0029         on_save_settings();
0030     }
0031 
0032     void check_checks()
0033     {
0034         if ( !ui.check_group->isChecked() && !ui.check_layer->isChecked() )
0035         {
0036             if ( ui.check_fill->isEnabled() )
0037             {
0038                 old_check_fill = ui.check_fill->isChecked();
0039                 ui.check_fill->setEnabled(false);
0040                 ui.check_fill->setChecked(false);
0041 
0042                 old_check_stroke = ui.check_stroke->isChecked();
0043                 ui.check_stroke->setEnabled(false);
0044                 ui.check_stroke->setChecked(false);
0045             }
0046         }
0047         else if ( !ui.check_fill->isEnabled() )
0048         {
0049             ui.check_fill->setEnabled(true);
0050             ui.check_fill->setChecked(old_check_fill);
0051 
0052             ui.check_stroke->setEnabled(true);
0053             ui.check_stroke->setChecked(old_check_stroke);
0054         }
0055     }
0056 
0057     void setup_ui(ShapeToolWidget* parent)
0058     {
0059         ui.setupUi(parent);
0060         settings.add(ui.check_group, "tools", "shape_");
0061         settings.add(ui.check_layer, "tools", "shape_");
0062         settings.add(ui.check_raw_shape, "tools", "shape_");
0063         settings.add(ui.check_fill, "tools", "shape_");
0064         settings.add(ui.check_stroke, "tools", "shape_");
0065         on_setup_ui(parent, ui.layout);
0066     }
0067 
0068     void retranslate(ShapeToolWidget* parent)
0069     {
0070         ui.retranslateUi(parent);
0071         on_retranslate();
0072     }
0073 
0074     bool create_fill() const
0075     {
0076         return ui.check_fill->isChecked();
0077     }
0078 
0079     bool create_layer() const
0080     {
0081         return ui.check_layer->isChecked();
0082     }
0083 
0084     bool create_group() const
0085     {
0086         return ui.check_group->isChecked();
0087     }
0088 
0089     bool create_stroke() const
0090     {
0091         return ui.check_stroke->isChecked();
0092     }
0093 
0094 protected:
0095     virtual void on_load_settings() {}
0096     virtual void on_save_settings() {}
0097     virtual void on_setup_ui(ShapeToolWidget*, QVBoxLayout*) {}
0098     virtual void on_retranslate() {}
0099 
0100 private:
0101     Ui::ShapeToolWidget ui;
0102     bool old_check_fill;
0103     bool old_check_stroke;
0104     app::settings::WidgetSettingGroup settings;
0105 };