17 #include "tooloptionwidget.h"
18 #include "ui_tooloptions.h"
23 #include "spinslider.h"
27 #include "layermanager.h"
28 #include "toolmanager.h"
32 setWindowTitle(
tr(
"Options",
"Window title of tool option panel like pen width, feather etc.."));
36 ui =
new Ui::ToolOptions;
37 ui->setupUi(innerWidget);
40 ToolOptionWidget::~ToolOptionWidget()
45 void ToolOptionWidget::initUI()
49 ui->sizeSlider->init(
tr(
"Width"), SpinSlider::EXPONENT, SpinSlider::INTEGER, 1, 200);
50 ui->sizeSlider->setValue(settings.value(
"brushWidth",
"3").toDouble());
51 ui->brushSpinBox->setValue(settings.value(
"brushWidth",
"3").toDouble());
53 ui->featherSlider->init(
tr(
"Feather"), SpinSlider::LOG, SpinSlider::INTEGER, 1, 99);
54 ui->featherSlider->setValue(settings.value(
"brushFeather",
"5").toDouble());
55 ui->featherSpinBox->setValue(settings.value(
"brushFeather",
"5").toDouble());
57 ui->toleranceSlider->init(
tr(
"Color Tolerance"), SpinSlider::LINEAR, SpinSlider::INTEGER, 0, 100);
58 ui->toleranceSlider->setValue(settings.value(
"Tolerance",
"50").toInt());
59 ui->toleranceSpinBox->setValue(settings.value(
"Tolerance",
"50").toInt());
62 void ToolOptionWidget::updateUI()
64 BaseTool* currentTool = editor()->tools()->currentTool();
65 Q_ASSERT(currentTool);
69 setVisibility(currentTool);
74 setPenFeather(p.feather);
75 setUseFeather(p.useFeather);
76 setPressure(p.pressure);
77 setPenInvisibility(p.invisibility);
78 setPreserveAlpha(p.preserveAlpha);
79 setVectorMergeEnabled(p.vectorMergeEnabled);
81 setStabilizerLevel(p.stabilizerLevel);
82 setTolerance(static_cast<int>(p.tolerance));
83 setFillContour(p.useFillContour);
86 void ToolOptionWidget::createUI()
89 void ToolOptionWidget::makeConnectionToEditor(
Editor* editor)
91 auto toolManager = editor->tools();
98 connect(ui->sizeSlider, &SpinSlider::valueChanged, toolManager, &ToolManager::setWidth);
99 connect(ui->featherSlider, &SpinSlider::valueChanged, toolManager, &ToolManager::setFeather);
102 connect(ui->brushSpinBox, spinboxValueChanged, toolManager, &ToolManager::setWidth);
103 clearFocusOnFinished(ui->brushSpinBox);
104 connect(ui->featherSpinBox, spinboxValueChanged, toolManager, &ToolManager::setFeather);
105 clearFocusOnFinished(ui->featherSpinBox);
114 connect(ui->toleranceSlider, &SpinSlider::valueChanged, toolManager, &ToolManager::setTolerance);
116 clearFocusOnFinished(ui->toleranceSpinBox);
120 connect(toolManager, &ToolManager::toolChanged,
this, &ToolOptionWidget::onToolChanged);
121 connect(toolManager, &ToolManager::toolPropertyChanged,
this, &ToolOptionWidget::onToolPropertyChanged);
124 void ToolOptionWidget::onToolPropertyChanged(ToolType, ToolPropertyType ePropertyType)
126 const Properties& p = editor()->tools()->currentTool()->properties;
128 switch (ePropertyType)
130 case WIDTH: setPenWidth(p.width);
break;
131 case FEATHER: setPenFeather(p.feather);
break;
132 case USEFEATHER: setUseFeather(p.useFeather);
break;
133 case PRESSURE: setPressure(p.pressure);
break;
134 case INVISIBILITY: setPenInvisibility(p.invisibility);
break;
135 case PRESERVEALPHA: setPreserveAlpha(p.preserveAlpha);
break;
136 case VECTORMERGE: setVectorMergeEnabled(p.vectorMergeEnabled);
break;
137 case ANTI_ALIASING: setAA(p.useAA);
break;
138 case STABILIZATION: setStabilizerLevel(p.stabilizerLevel);
break;
139 case TOLERANCE: setTolerance(static_cast<int>(p.tolerance));
break;
140 case FILLCONTOUR: setFillContour(p.useFillContour);
break;
141 case BEZIER: setBezier(p.bezier_state);
break;
148 void ToolOptionWidget::setVisibility(
BaseTool* tool)
150 ui->sizeSlider->setVisible(tool->isPropertyEnabled(WIDTH));
151 ui->brushSpinBox->setVisible(tool->isPropertyEnabled(WIDTH));
152 ui->featherSlider->setVisible(tool->isPropertyEnabled(FEATHER));
153 ui->featherSpinBox->setVisible(tool->isPropertyEnabled(FEATHER));
154 ui->useFeatherBox->setVisible(tool->isPropertyEnabled(USEFEATHER));
155 ui->useBezierBox->setVisible(tool->isPropertyEnabled(BEZIER));
156 ui->usePressureBox->setVisible(tool->isPropertyEnabled(PRESSURE));
157 ui->makeInvisibleBox->setVisible(tool->isPropertyEnabled(INVISIBILITY));
158 ui->preserveAlphaBox->setVisible(tool->isPropertyEnabled(PRESERVEALPHA));
159 ui->useAABox->setVisible(tool->isPropertyEnabled(ANTI_ALIASING));
160 ui->stabilizerLabel->setVisible(tool->isPropertyEnabled(STABILIZATION));
161 ui->inpolLevelsCombo->setVisible(tool->isPropertyEnabled(STABILIZATION));
162 ui->toleranceSlider->setVisible(tool->isPropertyEnabled(TOLERANCE));
163 ui->toleranceSpinBox->setVisible(tool->isPropertyEnabled(TOLERANCE));
164 ui->fillContourBox->setVisible(tool->isPropertyEnabled(FILLCONTOUR));
166 auto currentLayerType = editor()->layers()->currentLayer()->type();
167 auto propertyType = editor()->tools()->currentTool()->type();
169 if (currentLayerType == Layer::VECTOR)
171 switch (propertyType)
174 ui->sizeSlider->setVisible(
false);
175 ui->brushSpinBox->setVisible(
false);
176 ui->usePressureBox->setVisible(
false);
177 ui->featherSlider->setVisible(
false);
178 ui->featherSpinBox->setVisible(
false);
179 ui->useFeatherBox->setVisible(
false);
182 ui->sizeSlider->setVisible(
false);
183 ui->brushSpinBox->setVisible(
false);
184 ui->usePressureBox->setVisible(
false);
187 ui->sizeSlider->setLabel(
tr(
"Stroke Thickness"));
188 ui->toleranceSlider->setVisible(
false);
189 ui->toleranceSpinBox->setVisible(
false);
192 ui->sizeSlider->setLabel(
tr(
"Width"));
193 ui->toleranceSlider->setVisible(
false);
194 ui->toleranceSpinBox->setVisible(
false);
195 ui->useAABox->setVisible(
false);
201 switch (propertyType)
204 ui->fillContourBox->setVisible(
false);
207 ui->brushSpinBox->setVisible(
false);
208 ui->sizeSlider->setVisible(
false);
211 ui->makeInvisibleBox->setVisible(
false);
217 void ToolOptionWidget::onToolChanged(ToolType)
222 void ToolOptionWidget::setPenWidth(qreal width)
225 ui->sizeSlider->setEnabled(
true);
226 ui->sizeSlider->setValue(width);
229 ui->brushSpinBox->setEnabled(
true);
230 ui->brushSpinBox->setValue(width);
233 void ToolOptionWidget::setPenFeather(qreal featherValue)
236 ui->featherSlider->setEnabled(
true);
237 ui->featherSlider->setValue(featherValue);
240 ui->featherSpinBox->setEnabled(
true);
241 ui->featherSpinBox->setValue(featherValue);
244 void ToolOptionWidget::setUseFeather(
bool useFeather)
247 ui->useFeatherBox->setEnabled(
true);
248 ui->useFeatherBox->setChecked(useFeather);
251 void ToolOptionWidget::setPenInvisibility(
int x)
254 ui->makeInvisibleBox->setEnabled(
true);
255 ui->makeInvisibleBox->setChecked(x > 0);
258 void ToolOptionWidget::setPressure(
int x)
261 ui->usePressureBox->setEnabled(
true);
262 ui->usePressureBox->setChecked(x > 0);
265 void ToolOptionWidget::setPreserveAlpha(
int x)
268 ui->preserveAlphaBox->setEnabled(
true);
269 ui->preserveAlphaBox->setChecked(x > 0);
272 void ToolOptionWidget::setVectorMergeEnabled(
int x)
275 ui->vectorMergeBox->setEnabled(
true);
276 ui->vectorMergeBox->setChecked(x > 0);
279 void ToolOptionWidget::setAA(
int x)
282 ui->useAABox->setEnabled(
true);
283 ui->useAABox->setVisible(
false);
285 auto layerType = editor()->layers()->currentLayer()->type();
287 if (layerType == Layer::BITMAP)
291 ui->useAABox->setEnabled(
false);
292 ui->useAABox->setVisible(
false);
296 ui->useAABox->setVisible(
true);
298 ui->useAABox->setChecked(x > 0);
302 void ToolOptionWidget::setStabilizerLevel(
int x)
304 ui->inpolLevelsCombo->setCurrentIndex(qBound(0, x, ui->inpolLevelsCombo->count() - 1));
307 void ToolOptionWidget::setTolerance(
int tolerance)
310 ui->toleranceSlider->setEnabled(
true);
311 ui->toleranceSlider->setValue(tolerance);
314 ui->toleranceSpinBox->setEnabled(
true);
315 ui->toleranceSpinBox->setValue(tolerance);
318 void ToolOptionWidget::setFillContour(
int useFill)
321 ui->fillContourBox->setEnabled(
true);
322 ui->fillContourBox->setChecked(useFill > 0);
325 void ToolOptionWidget::setBezier(
bool useBezier)
328 ui->useBezierBox->setChecked(useBezier);
331 void ToolOptionWidget::disableAllOptions()
333 ui->sizeSlider->hide();
334 ui->brushSpinBox->hide();
335 ui->featherSlider->hide();
336 ui->featherSpinBox->hide();
337 ui->useFeatherBox->hide();
338 ui->useBezierBox->hide();
339 ui->usePressureBox->hide();
340 ui->makeInvisibleBox->hide();
341 ui->preserveAlphaBox->hide();
342 ui->vectorMergeBox->hide();
343 ui->useAABox->hide();
344 ui->inpolLevelsCombo->hide();
345 ui->toleranceSlider->hide();
346 ui->toleranceSpinBox->hide();
347 ui->fillContourBox->hide();
QString tr(const char *sourceText, const char *disambiguation, int n)
void valueChanged(double d)
void activated(int index)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)