1 // Copyright (C) 2012-2019 The VPaint Developers.
2 // See the COPYRIGHT file at the top-level directory of this distribution
3 // and at https://github.com/dalboris/vpaint/blob/master/COPYRIGHT
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #include "DevSettings.h"
18 
19 #include <QLabel>
20 #include <QtDebug>
21 
22 DevSettings * DevSettings::s = 0;
DevSettings()23 DevSettings::DevSettings()
24 {
25     s = this;
26     layout_ = new QGridLayout();
27     numWidgets_ = 0;
28 
29     addSection("Cutting");
30 
31     createCheckBox("reverse cut", false);
32     createCheckBox("mobius cut", false);
33 
34     addSection("Inbetweening");
35 
36     createCheckBox("inverse direction", false);
37 
38     addSection("Rendering");
39 
40     createCheckBox("draw edge orientation", false);
41 
42     setLayout(layout_);
43 }
44 
getBool(const QString & name)45 bool DevSettings::getBool(const QString & name)
46 {
47     if(!s || !s->checkBoxes_.contains(name))
48     {
49         qDebug() << "Settings: " << name << "not found";
50         return false;
51     }
52     else
53         return s->checkBoxes_[name]->isChecked();
54 }
55 
getInt(const QString & name)56 int DevSettings::getInt(const QString & name)
57 {
58     if(!s || !s->spinBoxes_.contains(name))
59     {
60         qDebug() << "Settings: " << name << "not found";
61         return 0;
62     }
63     else
64         return s->spinBoxes_[name]->value();
65 }
66 
getDouble(const QString & name)67 double DevSettings::getDouble(const QString & name)
68 {
69     if(!s || !s->doubleSpinBoxes_.contains(name))
70     {
71         qDebug() << "Settings: " << name << "not found";
72         return 0;
73     }
74     else
75         return s->doubleSpinBoxes_[name]->value();
76 }
77 
createSpinBox(const QString & string,int min,int max,int value)78 QSpinBox * DevSettings::createSpinBox(const QString & string, int min, int max, int value)
79 {
80     QSpinBox * spinBox = new QSpinBox();
81     spinBox->setMinimum(min);
82     spinBox->setMaximum(max);
83     spinBox->setValue(value);
84     connect(spinBox, SIGNAL(valueChanged(int)),
85           this, SIGNAL(changed()));
86 
87     addWidget(spinBox, string);
88     spinBoxes_[string] = spinBox;
89 
90     return spinBox;
91 }
92 
createDoubleSpinBox(const QString & string,double min,double max,double value)93 QDoubleSpinBox * DevSettings::createDoubleSpinBox(const QString & string, double min, double max, double value)
94 {
95     QDoubleSpinBox * spinBox = new QDoubleSpinBox();
96     spinBox->setMinimum(min);
97     spinBox->setMaximum(max);
98     spinBox->setValue(value);
99     spinBox->setSingleStep(0.1);
100     connect(spinBox, SIGNAL(valueChanged(double)),
101           this, SIGNAL(changed()));
102 
103     addWidget(spinBox, string);
104     doubleSpinBoxes_[string] = spinBox;
105 
106     return spinBox;
107 }
108 
109 
createCheckBox(const QString & string,bool checked)110 QCheckBox * DevSettings::createCheckBox(const QString & string, bool checked)
111 {
112     QCheckBox * checkBox = new QCheckBox();
113     checkBox->setChecked(checked);
114     connect(checkBox, SIGNAL(toggled(bool)),
115           this, SIGNAL(changed()));
116 
117     addWidget(checkBox, string);
118     checkBoxes_[string] = checkBox;
119 
120     return checkBox;
121 }
122 
addWidget(QWidget * widget,const QString & string)123 void DevSettings::addWidget(QWidget *widget, const QString & string)
124 {
125     QLabel *label = new QLabel(string);
126     layout_->addWidget(widget, numWidgets_, 0);
127     layout_->addWidget(label, numWidgets_, 1);
128     numWidgets_++;
129 }
130 
addSection(const QString & string)131 void DevSettings::addSection(const QString & string)
132 {
133     QString str;
134     str.append("<b>");
135     str.append(string);
136     str.append("</b>");
137     QLabel *label = new QLabel(str);
138     label->setAlignment(Qt::AlignHCenter/*Left*/ | Qt::AlignBottom);
139     if(numWidgets_!=0)
140         label->setMinimumHeight(40);
141     layout_->addWidget(label, numWidgets_, 0, 1, 2);
142     numWidgets_++;
143 }
144