1 /*
2  * Copyright (c) 2009,2010 Lukáš Tvrdý (lukast.dev@gmail.com)
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 
19 #ifndef KIS_GRIDOP_OPTION_H
20 #define KIS_GRIDOP_OPTION_H
21 
22 #include <kis_paintop_option.h>
23 
24 const QString GRID_WIDTH = "Grid/gridWidth";
25 const QString GRID_HEIGHT = "Grid/gridHeight";
26 const QString GRID_DIVISION_LEVEL = "Grid/divisionLevel";
27 const QString GRID_PRESSURE_DIVISION = "Grid/pressureDivision";
28 const QString GRID_SCALE = "Grid/scale";
29 const QString GRID_VERTICAL_BORDER = "Grid/verticalBorder";
30 const QString GRID_HORIZONTAL_BORDER = "Grid/horizontalBorder";
31 const QString GRID_RANDOM_BORDER = "Grid/randomBorder";
32 
33 
34 class KisGridOpOptionsWidget;
35 
36 class KisGridOpOption : public KisPaintOpOption
37 {
38 public:
39     KisGridOpOption();
40     ~KisGridOpOption() override;
41 
42     int gridWidth() const;
43     void setWidth(int width) const;
44 
45     int gridHeight() const;
46     void setHeight(int height) const;
47 
48     int divisionLevel() const;
49     bool pressureDivision() const;
50     qreal scale() const;
51 
52 
53     qreal vertBorder() const;
54     qreal horizBorder() const;
55     bool randomBorder() const;
56 
57     void writeOptionSetting(KisPropertiesConfigurationSP setting) const override;
58     void readOptionSetting(const KisPropertiesConfigurationSP setting) override;
59 
60 private:
61     KisGridOpOptionsWidget * m_options;
62 
63 };
64 
65 struct KisGridOpProperties : public KisPaintopPropertiesBase
66 {
67     int grid_width;
68     int grid_height;
69     int grid_division_level;
70     bool grid_pressure_division;
71     qreal grid_scale;
72     qreal grid_vertical_border;
73     qreal grid_horizontal_border;
74     bool grid_random_border;
75 
76 
readOptionSettingImplKisGridOpProperties77     void readOptionSettingImpl(const KisPropertiesConfiguration *setting) override {
78         grid_width = qMax(1, setting->getInt(GRID_WIDTH));
79         grid_height = qMax(1, setting->getInt(GRID_HEIGHT));
80         grid_division_level = setting->getInt(GRID_DIVISION_LEVEL);
81         grid_pressure_division = setting->getBool(GRID_PRESSURE_DIVISION);
82         grid_scale = setting->getDouble(GRID_SCALE);
83         grid_vertical_border = setting->getDouble(GRID_VERTICAL_BORDER);
84         grid_horizontal_border = setting->getDouble(GRID_HORIZONTAL_BORDER);
85         grid_random_border = setting->getBool(GRID_RANDOM_BORDER);
86     }
87 
writeOptionSettingImplKisGridOpProperties88     void writeOptionSettingImpl(KisPropertiesConfiguration *setting) const override {
89         setting->setProperty(GRID_WIDTH, qMax(1, grid_width));
90         setting->setProperty(GRID_HEIGHT, qMax(1, grid_height));
91         setting->setProperty(GRID_DIVISION_LEVEL, grid_division_level);
92         setting->setProperty(GRID_PRESSURE_DIVISION, grid_pressure_division);
93         setting->setProperty(GRID_SCALE, grid_scale);
94         setting->setProperty(GRID_VERTICAL_BORDER, grid_vertical_border);
95         setting->setProperty(GRID_HORIZONTAL_BORDER, grid_horizontal_border);
96         setting->setProperty(GRID_RANDOM_BORDER, grid_random_border);
97     }
98 };
99 
100 #endif
101