Pencil2D Animation
Download Community News Docs Contribute
  • Overview
  • Articles
  • Code
  •  
  • Class List
  • Class Index
  • Class Hierarchy
  • Class Members
  • File List
Loading...
Searching...
No Matches
  • app
  • src
tooloptionwidget.cpp
1/*
2
3Pencil2D - Traditional Animation Software
4Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5Copyright (C) 2012-2020 Matthew Chiawen Chang
6
7This program is free software; you can redistribute it and/or
8modify it under the terms of the GNU General Public License
9as published by the Free Software Foundation; version 2 of the License.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16*/
17#include "tooloptionwidget.h"
18#include "ui_tooloptions.h"
19
20#include <QSettings>
21#include <QDebug>
22
23#include "cameraoptionswidget.h"
24#include "bucketoptionswidget.h"
25#include "spinslider.h"
26#include "editor.h"
27#include "util.h"
28#include "layer.h"
29#include "layermanager.h"
30#include "stroketool.h"
31#include "toolmanager.h"
32
33ToolOptionWidget::ToolOptionWidget(QWidget* parent) : BaseDockWidget(parent)
34{
35 setWindowTitle(tr("Options", "Window title of tool option panel like pen width, feather etc.."));
36
37 QWidget* innerWidget = new QWidget;
38 setWidget(innerWidget);
39 ui = new Ui::ToolOptions;
40 ui->setupUi(innerWidget);
41}
42
43ToolOptionWidget::~ToolOptionWidget()
44{
45 delete ui;
46}
47
48void ToolOptionWidget::initUI()
49{
50 mBucketOptionsWidget = new BucketOptionsWidget(editor(), this);
51 mCameraOptionsWidget = new CameraOptionsWidget(editor(), this);
52 ui->horizontalLayout_2->addWidget(mBucketOptionsWidget);
53 ui->horizontalLayout_2->addWidget(mCameraOptionsWidget);
54
55 mBucketOptionsWidget->setHidden(true);
56 mCameraOptionsWidget->setHidden(true);
57
58 QSettings settings(PENCIL2D, PENCIL2D);
59
60 ui->sizeSlider->init(tr("Width"), SpinSlider::EXPONENT, SpinSlider::INTEGER, StrokeTool::WIDTH_MIN, StrokeTool::WIDTH_MAX);
61 ui->sizeSlider->setValue(settings.value("brushWidth", "3").toDouble());
62 ui->brushSpinBox->setValue(settings.value("brushWidth", "3").toDouble());
63
64 ui->featherSlider->init(tr("Feather"), SpinSlider::LOG, SpinSlider::INTEGER, StrokeTool::FEATHER_MIN, StrokeTool::FEATHER_MAX);
65 ui->featherSlider->setValue(settings.value("brushFeather", "5").toDouble());
66 ui->featherSpinBox->setValue(settings.value("brushFeather", "5").toDouble());
67}
68
69void ToolOptionWidget::updateUI()
70{
71 BaseTool* currentTool = editor()->tools()->currentTool();
72 Q_ASSERT(currentTool);
73
74 setVisibility(currentTool);
75
76 const Properties& p = currentTool->properties;
77
78 if (currentTool->isPropertyEnabled(WIDTH))
79 {
80 setPenWidth(p.width);
81 }
82 if (currentTool->isPropertyEnabled(FEATHER))
83 {
84 setPenFeather(p.feather);
85 }
86 setUseFeather(p.useFeather);
87 setPressure(p.pressure);
88 setPenInvisibility(p.invisibility);
89 setPreserveAlpha(p.preserveAlpha);
90 setVectorMergeEnabled(p.vectorMergeEnabled);
91 setAA(p.useAA);
92 setStabilizerLevel(p.stabilizerLevel);
93 setFillContour(p.useFillContour);
94 setShowSelectionInfo(p.showSelectionInfo);
95 setClosedPath(p.closedPolylinePath);
96}
97
98void ToolOptionWidget::createUI()
99{}
100
101void ToolOptionWidget::makeConnectionToEditor(Editor* editor)
102{
103 auto toolManager = editor->tools();
104
105 connect(ui->useBezierBox, &QCheckBox::clicked, toolManager, &ToolManager::setBezier);
106 connect(ui->useClosedPathBox, &QCheckBox::clicked, toolManager, &ToolManager::setClosedPath);
107 connect(ui->usePressureBox, &QCheckBox::clicked, toolManager, &ToolManager::setPressure);
108 connect(ui->makeInvisibleBox, &QCheckBox::clicked, toolManager, &ToolManager::setInvisibility);
109 connect(ui->preserveAlphaBox, &QCheckBox::clicked, toolManager, &ToolManager::setPreserveAlpha);
110
111 connect(ui->sizeSlider, &SpinSlider::valueChanged, toolManager, &ToolManager::setWidth);
112 connect(ui->featherSlider, &SpinSlider::valueChanged, toolManager, &ToolManager::setFeather);
113
114 auto spinboxValueChanged = static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged);
115 connect(ui->brushSpinBox, spinboxValueChanged, toolManager, &ToolManager::setWidth);
116 clearFocusOnFinished(ui->brushSpinBox);
117 connect(ui->featherSpinBox, spinboxValueChanged, toolManager, &ToolManager::setFeather);
118 clearFocusOnFinished(ui->featherSpinBox);
119
120 connect(ui->useFeatherBox, &QCheckBox::clicked, toolManager, &ToolManager::setUseFeather);
121
122 connect(ui->vectorMergeBox, &QCheckBox::clicked, toolManager, &ToolManager::setVectorMergeEnabled);
123 connect(ui->useAABox, &QCheckBox::clicked, toolManager, &ToolManager::setAA);
124
125 connect(ui->inpolLevelsCombo, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), toolManager, &ToolManager::setStabilizerLevel);
126
127 connect(ui->fillContourBox, &QCheckBox::clicked, toolManager, &ToolManager::setUseFillContour);
128
129 connect(ui->showInfoBox, &QCheckBox::clicked, toolManager, &ToolManager::setShowSelectionInfo);
130
131 connect(toolManager, &ToolManager::toolChanged, this, &ToolOptionWidget::onToolChanged);
132 connect(toolManager, &ToolManager::toolPropertyChanged, this, &ToolOptionWidget::onToolPropertyChanged);
133}
134
135void ToolOptionWidget::onToolPropertyChanged(ToolType, ToolPropertyType ePropertyType)
136{
137 const Properties& p = editor()->tools()->currentTool()->properties;
138
139 switch (ePropertyType)
140 {
141 case WIDTH: setPenWidth(p.width); break;
142 case FEATHER: setPenFeather(p.feather); break;
143 case USEFEATHER: setUseFeather(p.useFeather); break;
144 case PRESSURE: setPressure(p.pressure); break;
145 case INVISIBILITY: setPenInvisibility(p.invisibility); break;
146 case PRESERVEALPHA: setPreserveAlpha(p.preserveAlpha); break;
147 case VECTORMERGE: setVectorMergeEnabled(p.vectorMergeEnabled); break;
148 case ANTI_ALIASING: setAA(p.useAA); break;
149 case STABILIZATION: setStabilizerLevel(p.stabilizerLevel); break;
150 case FILLCONTOUR: setFillContour(p.useFillContour); break;
151 case SHOWSELECTIONINFO: setShowSelectionInfo(p.showSelectionInfo); break;
152 case BEZIER: setBezier(p.bezier_state); break;
153 case CLOSEDPATH: setClosedPath(p.closedPolylinePath); break;
154 case CAMERAPATH: { break; }
155 case TOLERANCE: break;
156 case USETOLERANCE: break;
157 case BUCKETFILLEXPAND: break;
158 case USEBUCKETFILLEXPAND: break;
159 case BUCKETFILLLAYERREFERENCEMODE: break;
160 case FILL_MODE: break;
161 default:
162 Q_ASSERT(false);
163 break;
164 }
165}
166
167void ToolOptionWidget::setVisibility(BaseTool* tool)
168{
169 Q_ASSERT(mBucketOptionsWidget);
170 Q_ASSERT(mCameraOptionsWidget);
171
172 disableAllOptions();
173
174 if (tool->type() == BUCKET)
175 {
176 mBucketOptionsWidget->setHidden(false);
177 return;
178 }
179 else if (tool->type() == CAMERA)
180 {
181 mCameraOptionsWidget->setHidden(false);
182 }
183 else
184 {
185 mCameraOptionsWidget->setHidden(true);
186 mBucketOptionsWidget->setHidden(true);
187 }
188
189 ui->sizeSlider->setVisible(tool->isPropertyEnabled(WIDTH));
190 ui->brushSpinBox->setVisible(tool->isPropertyEnabled(WIDTH));
191 ui->featherSlider->setVisible(tool->isPropertyEnabled(FEATHER));
192 ui->featherSpinBox->setVisible(tool->isPropertyEnabled(FEATHER));
193 ui->useFeatherBox->setVisible(tool->isPropertyEnabled(USEFEATHER));
194 ui->useBezierBox->setVisible(tool->isPropertyEnabled(BEZIER));
195 ui->useClosedPathBox->setVisible(tool->isPropertyEnabled(CLOSEDPATH));
196 ui->usePressureBox->setVisible(tool->isPropertyEnabled(PRESSURE));
197 ui->makeInvisibleBox->setVisible(tool->isPropertyEnabled(INVISIBILITY));
198 ui->preserveAlphaBox->setVisible(tool->isPropertyEnabled(PRESERVEALPHA));
199 ui->useAABox->setVisible(tool->isPropertyEnabled(ANTI_ALIASING));
200 ui->stabilizerLabel->setVisible(tool->isPropertyEnabled(STABILIZATION));
201 ui->inpolLevelsCombo->setVisible(tool->isPropertyEnabled(STABILIZATION));
202 ui->fillContourBox->setVisible(tool->isPropertyEnabled(FILLCONTOUR));
203 ui->showInfoBox->setVisible(tool->isPropertyEnabled(SHOWSELECTIONINFO));
204
205 auto currentLayerType = editor()->layers()->currentLayer()->type();
206 auto propertyType = editor()->tools()->currentTool()->type();
207
208 if (currentLayerType == Layer::VECTOR)
209 {
210 switch (propertyType)
211 {
212 case SMUDGE:
213 ui->sizeSlider->setVisible(false);
214 ui->brushSpinBox->setVisible(false);
215 ui->usePressureBox->setVisible(false);
216 ui->featherSlider->setVisible(false);
217 ui->featherSpinBox->setVisible(false);
218 ui->useFeatherBox->setVisible(false);
219 break;
220 case PENCIL:
221 ui->sizeSlider->setVisible(false);
222 ui->brushSpinBox->setVisible(false);
223 ui->usePressureBox->setVisible(false);
224 break;
225 default:
226 ui->sizeSlider->setLabel(tr("Width"));
227 ui->useAABox->setVisible(false);
228 break;
229 }
230 }
231 else
232 {
233 switch (propertyType)
234 {
235 case PENCIL:
236 ui->fillContourBox->setVisible(false);
237 break;
238 case BUCKET:
239 ui->brushSpinBox->setVisible(false);
240 ui->sizeSlider->setVisible(false);
241 break;
242 case SELECT:
243 case MOVE:
244 ui->sizeSlider->setVisible(false);
245 ui->brushSpinBox->setVisible(false);
246 ui->usePressureBox->setVisible(false);
247 ui->featherSlider->setVisible(false);
248 ui->featherSpinBox->setVisible(false);
249 ui->useFeatherBox->setVisible(false);
250 break;
251 default:
252 ui->makeInvisibleBox->setVisible(false);
253 break;
254 }
255 }
256}
257
258void ToolOptionWidget::onToolChanged(ToolType)
259{
260 updateUI();
261}
262
263void ToolOptionWidget::setPenWidth(qreal width)
264{
265 QSignalBlocker b(ui->sizeSlider);
266 ui->sizeSlider->setEnabled(true);
267 ui->sizeSlider->setValue(width);
268
269 QSignalBlocker b2(ui->brushSpinBox);
270 ui->brushSpinBox->setEnabled(true);
271 ui->brushSpinBox->setValue(width);
272}
273
274void ToolOptionWidget::setPenFeather(qreal featherValue)
275{
276 QSignalBlocker b(ui->featherSlider);
277 ui->featherSlider->setEnabled(true);
278 ui->featherSlider->setValue(featherValue);
279
280 QSignalBlocker b2(ui->featherSpinBox);
281 ui->featherSpinBox->setEnabled(true);
282 ui->featherSpinBox->setValue(featherValue);
283}
284
285void ToolOptionWidget::setUseFeather(bool useFeather)
286{
287 QSignalBlocker b(ui->useFeatherBox);
288 ui->useFeatherBox->setEnabled(true);
289 ui->useFeatherBox->setChecked(useFeather);
290}
291
292void ToolOptionWidget::setPenInvisibility(int x)
293{
294 QSignalBlocker b(ui->makeInvisibleBox);
295 ui->makeInvisibleBox->setEnabled(true);
296 ui->makeInvisibleBox->setChecked(x > 0);
297}
298
299void ToolOptionWidget::setPressure(int x)
300{
301 QSignalBlocker b(ui->usePressureBox);
302 ui->usePressureBox->setEnabled(true);
303 ui->usePressureBox->setChecked(x > 0);
304}
305
306void ToolOptionWidget::setPreserveAlpha(int x)
307{
308 QSignalBlocker b(ui->preserveAlphaBox);
309 ui->preserveAlphaBox->setEnabled(true);
310 ui->preserveAlphaBox->setChecked(x > 0);
311}
312
313void ToolOptionWidget::setVectorMergeEnabled(int x)
314{
315 QSignalBlocker b(ui->vectorMergeBox);
316 ui->vectorMergeBox->setEnabled(true);
317 ui->vectorMergeBox->setChecked(x > 0);
318}
319
320void ToolOptionWidget::setAA(int x)
321{
322 QSignalBlocker b(ui->useAABox);
323 ui->useAABox->setEnabled(true);
324 ui->useAABox->setVisible(false);
325
326 auto layerType = editor()->layers()->currentLayer()->type();
327
328 if (layerType == Layer::BITMAP)
329 {
330 if (x == -1)
331 {
332 ui->useAABox->setEnabled(false);
333 ui->useAABox->setVisible(false);
334 }
335 else
336 {
337 ui->useAABox->setVisible(true);
338 }
339 ui->useAABox->setChecked(x > 0);
340 }
341}
342
343void ToolOptionWidget::setStabilizerLevel(int x)
344{
345 ui->inpolLevelsCombo->setCurrentIndex(qBound(0, x, ui->inpolLevelsCombo->count() - 1));
346}
347
348void ToolOptionWidget::setFillContour(int useFill)
349{
350 QSignalBlocker b(ui->fillContourBox);
351 ui->fillContourBox->setEnabled(true);
352 ui->fillContourBox->setChecked(useFill > 0);
353}
354
355void ToolOptionWidget::setBezier(bool useBezier)
356{
357 QSignalBlocker b(ui->useBezierBox);
358 ui->useBezierBox->setChecked(useBezier);
359}
360
361void ToolOptionWidget::setClosedPath(bool useClosedPath)
362{
363 QSignalBlocker b(ui->useClosedPathBox);
364 ui->useClosedPathBox->setChecked(useClosedPath);
365}
366
367void ToolOptionWidget::setShowSelectionInfo(bool showSelectionInfo)
368{
369 QSignalBlocker b(ui->showInfoBox);
370 ui->showInfoBox->setChecked(showSelectionInfo);
371}
372
373void ToolOptionWidget::disableAllOptions()
374{
375 ui->sizeSlider->hide();
376 ui->brushSpinBox->hide();
377 ui->featherSlider->hide();
378 ui->featherSpinBox->hide();
379 ui->useFeatherBox->hide();
380 ui->useBezierBox->hide();
381 ui->useClosedPathBox->hide();
382 ui->usePressureBox->hide();
383 ui->makeInvisibleBox->hide();
384 ui->preserveAlphaBox->hide();
385 ui->vectorMergeBox->hide();
386 ui->useAABox->hide();
387 ui->inpolLevelsCombo->hide();
388 ui->fillContourBox->hide();
389 ui->showInfoBox->hide();
390 ui->stabilizerLabel->hide();
391}
BaseDockWidget
Definition: basedockwidget.h:27
BaseTool
Definition: basetool.h:70
BucketOptionsWidget
Definition: bucketoptionswidget.h:31
CameraOptionsWidget
Definition: cameraoptionswidget.h:33
Editor
Definition: editor.h:71
Properties
Definition: basetool.h:39
QAbstractButton::clicked
void clicked(bool checked)
QComboBox
QComboBox::activated
void activated(int index)
QDoubleSpinBox
QDoubleSpinBox::valueChanged
void valueChanged(double d)
QObject::connect
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject::tr
QString tr(const char *sourceText, const char *disambiguation, int n)
QSettings
QSignalBlocker
QWidget
QWidget::setHidden
void setHidden(bool hidden)
QWidget::width
width
QWidget::x
x
Generated on Thu Jun 5 2025 14:06:43 for Pencil2D by doxygen 1.9.6 based on revision 4c63407997b2c03e5048716586dec6fbbb755173