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 #include "star_tool_widget.hpp" 0008 0009 #include <QLabel> 0010 #include <QDoubleSpinBox> 0011 #include <QSpinBox> 0012 #include <QGridLayout> 0013 0014 #include "shape_tool_widget_p.hpp" 0015 #include "widgets/enum_combo.hpp" 0016 0017 using namespace glaxnimate::gui; 0018 using namespace glaxnimate; 0019 0020 class StarToolWidget::Private : public ShapeToolWidget::Private 0021 { 0022 public: 0023 model::PolyStar::StarType star_type() const 0024 { 0025 return model::PolyStar::StarType(combo->current_value()); 0026 } 0027 0028 double spoke_ratio() const 0029 { 0030 return spin_ratio->value(); 0031 } 0032 0033 int points() const 0034 { 0035 return spin_points->value(); 0036 } 0037 0038 protected: 0039 void on_setup_ui(ShapeToolWidget * parent, QVBoxLayout * layout) override 0040 { 0041 group = new QGroupBox(parent); 0042 layout->insertWidget(0, group); 0043 QGridLayout* grid = new QGridLayout(); 0044 group->setLayout(grid); 0045 int row = 0; 0046 0047 combo = new EnumCombo(model::PolyStar::Star, parent); 0048 grid->addWidget(combo, row++, 0, 1, 2); 0049 connect(combo, QOverload<int>::of(&QComboBox::activated), parent, &StarToolWidget::save_settings); 0050 0051 0052 label_ratio = new QLabel(parent); 0053 grid->addWidget(label_ratio, row, 0); 0054 0055 spin_ratio = new QDoubleSpinBox(parent); 0056 spin_ratio->setMinimum(0); 0057 spin_ratio->setMaximum(1); 0058 spin_ratio->setSingleStep(0.1); 0059 connect(spin_ratio, &QDoubleSpinBox::editingFinished, parent, &StarToolWidget::save_settings); 0060 grid->addWidget(spin_ratio, row, 1); 0061 row++; 0062 0063 label_points = new QLabel(parent); 0064 grid->addWidget(label_points, row, 0); 0065 0066 spin_points = new QSpinBox(parent); 0067 spin_points->setMinimum(3); 0068 spin_points->setMaximum(16); 0069 connect(spin_ratio, &QSpinBox::editingFinished, parent, &StarToolWidget::save_settings); 0070 grid->addWidget(spin_points, row, 1); 0071 row++; 0072 0073 on_retranslate(); 0074 } 0075 0076 void on_load_settings() override 0077 { 0078 combo->set_current_value(app::settings::get<int>("tools", "star_type", 0)); 0079 spin_ratio->setValue(app::settings::get<double>("tools", "star_ratio", 0.5)); 0080 spin_points->setValue(app::settings::get<int>("tools", "star_points", 5)); 0081 } 0082 0083 void on_save_settings() override 0084 { 0085 app::settings::set("tools", "star_type", combo->current_value()); 0086 app::settings::set("tools", "star_ratio", spin_ratio->value()); 0087 app::settings::set("tools", "star_points", spin_points->value()); 0088 } 0089 0090 void on_retranslate() override 0091 { 0092 label_ratio->setText("Spoke Ratio"); 0093 label_points->setText("Corners"); 0094 group->setTitle("Star"); 0095 } 0096 0097 EnumCombo* combo; 0098 QLabel* label_ratio; 0099 QDoubleSpinBox* spin_ratio; 0100 QLabel* label_points; 0101 QSpinBox* spin_points; 0102 QGroupBox* group; 0103 }; 0104 0105 0106 StarToolWidget::StarToolWidget(QWidget* parent) 0107 : ShapeToolWidget(std::make_unique<Private>(), parent) 0108 { 0109 } 0110 0111 model::PolyStar::StarType StarToolWidget::star_type() const 0112 { 0113 return static_cast<Private*>(d.get())->star_type(); 0114 } 0115 0116 double StarToolWidget::spoke_ratio() const 0117 { 0118 return static_cast<Private*>(d.get())->spoke_ratio(); 0119 } 0120 0121 0122 int StarToolWidget::points() 0123 { 0124 return static_cast<Private*>(d.get())->points(); 0125 }