1#include "strokeoptionswidget.h"
2#include "ui_strokeoptionswidget.h"
5#include "pencilsettings.h"
8#include "polylinetool.h"
11#include "toolmanager.h"
12#include "layermanager.h"
14StrokeOptionsWidget::StrokeOptionsWidget(
Editor* editor,
QWidget *parent) :
24 setContentsMargins(0,0,0,0);
27StrokeOptionsWidget::~StrokeOptionsWidget()
32void StrokeOptionsWidget::initUI()
34 StrokeTool* strokeTool = mEditor->tools()->currentStrokeTool();
35 if (strokeTool ==
nullptr) {
return; }
39 auto widthInfo = p.getInfo(StrokeToolProperties::WIDTH_VALUE);
40 ui->sizeSlider->init(
tr(
"Width"), SpinSlider::EXPONENT, widthInfo.minReal(), widthInfo.maxReal());
42 auto featherInfo = p.getInfo(StrokeToolProperties::FEATHER_VALUE);
43 ui->featherSlider->init(
tr(
"Feather"), SpinSlider::LOG, featherInfo.minReal(), featherInfo.maxReal());
45 mCurrentTool = strokeTool;
47 makeConnectionFromUIToModel();
50void StrokeOptionsWidget::updateUI()
52 StrokeTool* strokeTool = mEditor->tools()->currentStrokeTool();
53 if (strokeTool ==
nullptr) {
return; }
57 updateToolConnections(strokeTool);
59 setVisibility(strokeTool);
63 if (strokeTool->isPropertyEnabled(StrokeToolProperties::WIDTH_VALUE))
65 PropertyInfo info = p.getInfo(StrokeToolProperties::WIDTH_VALUE);
67 ui->sizeSlider->setRange(info.minReal(), info.maxReal());
69 ui->sizeSpinBox->setRange(info.minReal(), info.maxReal());
71 setWidthValue(info.realValue());
73 if (strokeTool->isPropertyEnabled(StrokeToolProperties::FEATHER_VALUE))
75 auto info = p.getInfo(StrokeToolProperties::FEATHER_VALUE);
77 ui->featherSlider->setRange(info.minReal(), info.maxReal());
79 ui->featherSpinBox->setRange(info.minReal(), info.maxReal());
81 setFeatherValue(info.realValue());
84 if (strokeTool->isPropertyEnabled(StrokeToolProperties::FEATHER_ENABLED)) {
85 setFeatherEnabled(p.featherEnabled());
88 if (strokeTool->isPropertyEnabled(StrokeToolProperties::PRESSURE_ENABLED)) {
89 setPressureEnabled(p.pressureEnabled());
92 if (strokeTool->isPropertyEnabled(StrokeToolProperties::INVISIBILITY_ENABLED)) {
93 setPenInvisibilityEnabled(p.invisibilityEnabled());
96 if (strokeTool->isPropertyEnabled(StrokeToolProperties::ANTI_ALIASING_ENABLED)) {
97 setAntiAliasingEnabled(p.AntiAliasingEnabled());
100 if (strokeTool->isPropertyEnabled(StrokeToolProperties::STABILIZATION_VALUE)) {
101 setStabilizerLevel(p.stabilizerLevel());
104 if (strokeTool->isPropertyEnabled(StrokeToolProperties::FILLCONTOUR_ENABLED)) {
105 setFillContourEnabled(p.fillContourEnabled());
108 if (strokeTool->type() == POLYLINE) {
110 setClosedPathEnabled(polyP.closedPathEnabled());
111 setBezierPathEnabled(polyP.bezierPathEnabled());
115void StrokeOptionsWidget::updateToolConnections(
BaseTool* tool)
118 disconnect(mCurrentTool,
nullptr,
this,
nullptr);
122 mCurrentTool = strokeTool;
124 makeConnectionFromModelToUI(strokeTool);
127void StrokeOptionsWidget::makeConnectionFromModelToUI(
StrokeTool* strokeTool)
129 connect(strokeTool, &StrokeTool::widthChanged,
this, &StrokeOptionsWidget::setWidthValue);
130 connect(strokeTool, &StrokeTool::featherChanged,
this, &StrokeOptionsWidget::setFeatherValue);
131 connect(strokeTool, &StrokeTool::featherEnabledChanged,
this, &StrokeOptionsWidget::setFeatherEnabled);
132 connect(strokeTool, &StrokeTool::pressureEnabledChanged,
this, &StrokeOptionsWidget::setPressureEnabled);
133 connect(strokeTool, &StrokeTool::stabilizationLevelChanged,
this, &StrokeOptionsWidget::setStabilizerLevel);
134 connect(strokeTool, &StrokeTool::antiAliasingEnabledChanged,
this, &StrokeOptionsWidget::setAntiAliasingEnabled);
135 connect(strokeTool, &StrokeTool::fillContourEnabledChanged,
this, &StrokeOptionsWidget::setFillContourEnabled);
136 connect(strokeTool, &StrokeTool::invisibleStrokeEnabledChanged,
this, &StrokeOptionsWidget::setPenInvisibilityEnabled);
138 if (strokeTool->type() == POLYLINE) {
140 connect(polyline, &PolylineTool::bezierPathEnabledChanged,
this, &StrokeOptionsWidget::setBezierPathEnabled);
141 connect(polyline, &PolylineTool::closePathChanged,
this, &StrokeOptionsWidget::setClosedPathEnabled);
145void StrokeOptionsWidget::makeConnectionFromUIToModel()
150 PolylineTool* tool = static_cast<PolylineTool*>(mCurrentTool);
151 tool->setUseBezier(enabled);
155 PolylineTool* tool = static_cast<PolylineTool*>(mCurrentTool);
156 tool->setClosePath(enabled);
159 mCurrentTool->setPressureEnabled(enabled);
163 mCurrentTool->setStrokeInvisibleEnabled(enabled);
167 mCurrentTool->setFeatherEnabled(enabled);
171 mCurrentTool->setAntiAliasingEnabled(enabled);
175 mCurrentTool->setFillContourEnabled(enabled);
178 connect(ui->sizeSlider, &SpinSlider::valueChanged, [=](qreal value) {
179 mCurrentTool->setWidth(value);
182 connect(ui->sizeSpinBox, spinboxValueChanged, [=](qreal value) {
183 mCurrentTool->setWidth(value);
186 connect(ui->featherSlider, &SpinSlider::valueChanged, [=](qreal value) {
187 mCurrentTool->setFeather(value);
190 connect(ui->featherSpinBox, spinboxValueChanged, [=](qreal value) {
191 mCurrentTool->setFeather(value);
194 clearFocusOnFinished(ui->sizeSpinBox);
195 clearFocusOnFinished(ui->featherSpinBox);
198 mCurrentTool->setStablizationLevel(value);
202void StrokeOptionsWidget::setVisibility(
BaseTool* tool)
204 ui->sizeSlider->setVisible(tool->isPropertyEnabled(StrokeToolProperties::WIDTH_VALUE));
205 ui->sizeSpinBox->setVisible(tool->isPropertyEnabled(StrokeToolProperties::WIDTH_VALUE));
206 ui->featherSlider->setVisible(tool->isPropertyEnabled(StrokeToolProperties::FEATHER_VALUE));
207 ui->featherSpinBox->setVisible(tool->isPropertyEnabled(StrokeToolProperties::FEATHER_VALUE));
208 ui->useFeatherBox->setVisible(tool->isPropertyEnabled(StrokeToolProperties::FEATHER_ENABLED));
209 ui->usePressureBox->setVisible(tool->isPropertyEnabled(StrokeToolProperties::PRESSURE_ENABLED));
210 ui->makeInvisibleBox->setVisible(tool->isPropertyEnabled(StrokeToolProperties::INVISIBILITY_ENABLED));
211 ui->useAABox->setVisible(tool->isPropertyEnabled(StrokeToolProperties::ANTI_ALIASING_ENABLED));
212 ui->stabilizerLabel->setVisible(tool->isPropertyEnabled(StrokeToolProperties::STABILIZATION_VALUE));
213 ui->inpolLevelsCombo->setVisible(tool->isPropertyEnabled(StrokeToolProperties::STABILIZATION_VALUE));
214 ui->fillContourBox->setVisible(tool->isPropertyEnabled(StrokeToolProperties::FILLCONTOUR_ENABLED));
215 ui->useBezierBox->setVisible(tool->isPropertyEnabled(PolylineToolProperties::BEZIERPATH_ENABLED));
216 ui->useClosedPathBox->setVisible(tool->isPropertyEnabled(PolylineToolProperties::CLOSEDPATH_ENABLED));
219void StrokeOptionsWidget::setWidthValue(qreal width)
222 ui->sizeSlider->setValue(
width);
225 ui->sizeSpinBox->setValue(
width);
228void StrokeOptionsWidget::setFeatherValue(qreal featherValue)
231 ui->featherSlider->setValue(featherValue);
234 ui->featherSpinBox->setValue(featherValue);
237void StrokeOptionsWidget::setFeatherEnabled(
bool enabled)
240 ui->useFeatherBox->setChecked(
enabled);
243void StrokeOptionsWidget::setPenInvisibilityEnabled(
bool enabled)
246 ui->makeInvisibleBox->setChecked(
enabled);
249void StrokeOptionsWidget::setPressureEnabled(
bool enabled)
252 ui->usePressureBox->setChecked(
enabled);
255void StrokeOptionsWidget::setAntiAliasingEnabled(
bool enabled)
258 ui->useAABox->setChecked(
enabled);
261void StrokeOptionsWidget::setStabilizerLevel(
int level)
264 ui->inpolLevelsCombo->setCurrentIndex(level);
267void StrokeOptionsWidget::setFillContourEnabled(
bool enabled)
270 ui->fillContourBox->setChecked(
enabled);
273void StrokeOptionsWidget::setBezierPathEnabled(
bool enabled)
276 ui->useBezierBox->setChecked(
enabled);
279void StrokeOptionsWidget::setClosedPathEnabled(
bool enabled)
282 ui->useClosedPathBox->setChecked(
enabled);
void activated(int index)
void valueChanged(double d)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
QString tr(const char *sourceText, const char *disambiguation, int n)