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 QSettings settings(PENCIL2D, PENCIL2D);
56
57 ui->sizeSlider->init(tr("Width"), SpinSlider::EXPONENT, SpinSlider::INTEGER, StrokeTool::WIDTH_MIN, StrokeTool::WIDTH_MAX);
58 ui->sizeSlider->setValue(settings.value("brushWidth", "3").toDouble());
59 ui->brushSpinBox->setValue(settings.value("brushWidth", "3").toDouble());
60
61 ui->featherSlider->init(tr("Feather"), SpinSlider::LOG, SpinSlider::INTEGER, StrokeTool::FEATHER_MIN, StrokeTool::FEATHER_MAX);
62 ui->featherSlider->setValue(settings.value("brushFeather", "5").toDouble());
63 ui->featherSpinBox->setValue(settings.value("brushFeather", "5").toDouble());
64}
65
66void ToolOptionWidget::updateUI()
67{
68 BaseTool* currentTool = editor()->tools()->currentTool();
69 Q_ASSERT(currentTool);
70
71 setVisibility(currentTool);
72
73 const Properties& p = currentTool->properties;
74
75 if (currentTool->isPropertyEnabled(WIDTH))
76 {
77 setPenWidth(p.width);
78 }
79 if (currentTool->isPropertyEnabled(FEATHER))
80 {
81 setPenFeather(p.feather);
82 }
83 setUseFeather(p.useFeather);
84 setPressure(p.pressure);
85 setPenInvisibility(p.invisibility);
86 setPreserveAlpha(p.preserveAlpha);
87 setVectorMergeEnabled(p.vectorMergeEnabled);
88 setAA(p.useAA);
89 setStabilizerLevel(p.stabilizerLevel);
90 setFillContour(p.useFillContour);
91 setShowSelectionInfo(p.showSelectionInfo);
92 setClosedPath(p.closedPolylinePath);
93}
94
95void ToolOptionWidget::createUI()
96{}
97
98void ToolOptionWidget::makeConnectionToEditor(Editor* editor)
99{
100 auto toolManager = editor->tools();
101
102 connect(ui->useBezierBox, &QCheckBox::clicked, toolManager, &ToolManager::setBezier);
103 connect(ui->useClosedPathBox, &QCheckBox::clicked, toolManager, &ToolManager::setClosedPath);
104 connect(ui->usePressureBox, &QCheckBox::clicked, toolManager, &ToolManager::setPressure);
105 connect(ui->makeInvisibleBox, &QCheckBox::clicked, toolManager, &ToolManager::setInvisibility);
106 connect(ui->preserveAlphaBox, &QCheckBox::clicked, toolManager, &ToolManager::setPreserveAlpha);
107
108 connect(ui->sizeSlider, &SpinSlider::valueChanged, toolManager, &ToolManager::setWidth);
109 connect(ui->featherSlider, &SpinSlider::valueChanged, toolManager, &ToolManager::setFeather);
110
111 auto spinboxValueChanged = static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged);
112 connect(ui->brushSpinBox, spinboxValueChanged, toolManager, &ToolManager::setWidth);
113 clearFocusOnFinished(ui->brushSpinBox);
114 connect(ui->featherSpinBox, spinboxValueChanged, toolManager, &ToolManager::setFeather);
115 clearFocusOnFinished(ui->featherSpinBox);
116
117 connect(ui->useFeatherBox, &QCheckBox::clicked, toolManager, &ToolManager::setUseFeather);
118
119 connect(ui->vectorMergeBox, &QCheckBox::clicked, toolManager, &ToolManager::setVectorMergeEnabled);
120 connect(ui->useAABox, &QCheckBox::clicked, toolManager, &ToolManager::setAA);
121
122 connect(ui->inpolLevelsCombo, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), toolManager, &ToolManager::setStabilizerLevel);
123
124 connect(ui->fillContourBox, &QCheckBox::clicked, toolManager, &ToolManager::setUseFillContour);
125
126 connect(ui->showInfoBox, &QCheckBox::clicked, toolManager, &ToolManager::setShowSelectionInfo);
127
128 connect(toolManager, &ToolManager::toolChanged, this, &ToolOptionWidget::onToolChanged);
129 connect(toolManager, &ToolManager::toolPropertyChanged, this, &ToolOptionWidget::onToolPropertyChanged);
130}
131
132void ToolOptionWidget::onToolPropertyChanged(ToolType, ToolPropertyType ePropertyType)
133{
134 const Properties& p = editor()->tools()->currentTool()->properties;
135
136 switch (ePropertyType)
137 {
138 case WIDTH: setPenWidth(p.width); break;
139 case FEATHER: setPenFeather(p.feather); break;
140 case USEFEATHER: setUseFeather(p.useFeather); break;
141 case PRESSURE: setPressure(p.pressure); break;
142 case INVISIBILITY: setPenInvisibility(p.invisibility); break;
143 case PRESERVEALPHA: setPreserveAlpha(p.preserveAlpha); break;
144 case VECTORMERGE: setVectorMergeEnabled(p.vectorMergeEnabled); break;
145 case ANTI_ALIASING: setAA(p.useAA); break;
146 case STABILIZATION: setStabilizerLevel(p.stabilizerLevel); break;
147 case FILLCONTOUR: setFillContour(p.useFillContour); break;
148 case SHOWSELECTIONINFO: setShowSelectionInfo(p.showSelectionInfo); break;
149 case BEZIER: setBezier(p.bezier_state); break;
150 case CLOSEDPATH: setClosedPath(p.closedPolylinePath); break;
151 case CAMERAPATH: { break; }
152 case TOLERANCE: break;
153 case USETOLERANCE: break;
154 case BUCKETFILLEXPAND: break;
155 case USEBUCKETFILLEXPAND: break;
156 case BUCKETFILLLAYERREFERENCEMODE: break;
157 case FILL_MODE: break;
158 default:
159 Q_ASSERT(false);
160 break;
161 }
162}
163
164void ToolOptionWidget::setVisibility(BaseTool* tool)
165{
166 Q_ASSERT(mBucketOptionsWidget);
167 Q_ASSERT(mCameraOptionsWidget);
168
169 disableAllOptions();
170
171 if (tool->type() == BUCKET)
172 {
173 mBucketOptionsWidget->setHidden(false);
174 return;
175 }
176 else if (tool->type() == CAMERA)
177 {
178 mCameraOptionsWidget->setHidden(false);
179 }
180 else
181 {
182 mCameraOptionsWidget->setHidden(true);
183 mBucketOptionsWidget->setHidden(true);
184 }
185
186 ui->sizeSlider->setVisible(tool->isPropertyEnabled(WIDTH));
187 ui->brushSpinBox->setVisible(tool->isPropertyEnabled(WIDTH));
188 ui->featherSlider->setVisible(tool->isPropertyEnabled(FEATHER));
189 ui->featherSpinBox->setVisible(tool->isPropertyEnabled(FEATHER));
190 ui->useFeatherBox->setVisible(tool->isPropertyEnabled(USEFEATHER));
191 ui->useBezierBox->setVisible(tool->isPropertyEnabled(BEZIER));
192 ui->useClosedPathBox->setVisible(tool->isPropertyEnabled(CLOSEDPATH));
193 ui->usePressureBox->setVisible(tool->isPropertyEnabled(PRESSURE));
194 ui->makeInvisibleBox->setVisible(tool->isPropertyEnabled(INVISIBILITY));
195 ui->preserveAlphaBox->setVisible(tool->isPropertyEnabled(PRESERVEALPHA));
196 ui->useAABox->setVisible(tool->isPropertyEnabled(ANTI_ALIASING));
197 ui->stabilizerLabel->setVisible(tool->isPropertyEnabled(STABILIZATION));
198 ui->inpolLevelsCombo->setVisible(tool->isPropertyEnabled(STABILIZATION));
199 ui->fillContourBox->setVisible(tool->isPropertyEnabled(FILLCONTOUR));
200 ui->showInfoBox->setVisible(tool->isPropertyEnabled(SHOWSELECTIONINFO));
201
202 auto currentLayerType = editor()->layers()->currentLayer()->type();
203 auto propertyType = editor()->tools()->currentTool()->type();
204
205 if (currentLayerType == Layer::VECTOR)
206 {
207 switch (propertyType)
208 {
209 case SMUDGE:
210 ui->sizeSlider->setVisible(false);
211 ui->brushSpinBox->setVisible(false);
212 ui->usePressureBox->setVisible(false);
213 ui->featherSlider->setVisible(false);
214 ui->featherSpinBox->setVisible(false);
215 ui->useFeatherBox->setVisible(false);
216 break;
217 case PENCIL:
218 ui->sizeSlider->setVisible(false);
219 ui->brushSpinBox->setVisible(false);
220 ui->usePressureBox->setVisible(false);
221 break;
222 default:
223 ui->sizeSlider->setLabel(tr("Width"));
224 ui->useAABox->setVisible(false);
225 break;
226 }
227 }
228 else
229 {
230 switch (propertyType)
231 {
232 case PENCIL:
233 ui->fillContourBox->setVisible(false);
234 break;
235 case BUCKET:
236 ui->brushSpinBox->setVisible(false);
237 ui->sizeSlider->setVisible(false);
238 break;
239 case SELECT:
240 case MOVE:
241 ui->sizeSlider->setVisible(false);
242 ui->brushSpinBox->setVisible(false);
243 ui->usePressureBox->setVisible(false);
244 ui->featherSlider->setVisible(false);
245 ui->featherSpinBox->setVisible(false);
246 ui->useFeatherBox->setVisible(false);
247 break;
248 default:
249 ui->makeInvisibleBox->setVisible(false);
250 break;
251 }
252 }
253}
254
255void ToolOptionWidget::onToolChanged(ToolType)
256{
257 updateUI();
258}
259
260void ToolOptionWidget::setPenWidth(qreal width)
261{
262 QSignalBlocker b(ui->sizeSlider);
263 ui->sizeSlider->setEnabled(true);
264 ui->sizeSlider->setValue(width);
265
266 QSignalBlocker b2(ui->brushSpinBox);
267 ui->brushSpinBox->setEnabled(true);
268 ui->brushSpinBox->setValue(width);
269}
270
271void ToolOptionWidget::setPenFeather(qreal featherValue)
272{
273 QSignalBlocker b(ui->featherSlider);
274 ui->featherSlider->setEnabled(true);
275 ui->featherSlider->setValue(featherValue);
276
277 QSignalBlocker b2(ui->featherSpinBox);
278 ui->featherSpinBox->setEnabled(true);
279 ui->featherSpinBox->setValue(featherValue);
280}
281
282void ToolOptionWidget::setUseFeather(bool useFeather)
283{
284 QSignalBlocker b(ui->useFeatherBox);
285 ui->useFeatherBox->setEnabled(true);
286 ui->useFeatherBox->setChecked(useFeather);
287}
288
289void ToolOptionWidget::setPenInvisibility(int x)
290{
291 QSignalBlocker b(ui->makeInvisibleBox);
292 ui->makeInvisibleBox->setEnabled(true);
293 ui->makeInvisibleBox->setChecked(x > 0);
294}
295
296void ToolOptionWidget::setPressure(int x)
297{
298 QSignalBlocker b(ui->usePressureBox);
299 ui->usePressureBox->setEnabled(true);
300 ui->usePressureBox->setChecked(x > 0);
301}
302
303void ToolOptionWidget::setPreserveAlpha(int x)
304{
305 QSignalBlocker b(ui->preserveAlphaBox);
306 ui->preserveAlphaBox->setEnabled(true);
307 ui->preserveAlphaBox->setChecked(x > 0);
308}
309
310void ToolOptionWidget::setVectorMergeEnabled(int x)
311{
312 QSignalBlocker b(ui->vectorMergeBox);
313 ui->vectorMergeBox->setEnabled(true);
314 ui->vectorMergeBox->setChecked(x > 0);
315}
316
317void ToolOptionWidget::setAA(int x)
318{
319 QSignalBlocker b(ui->useAABox);
320 ui->useAABox->setEnabled(true);
321 ui->useAABox->setVisible(false);
322
323 auto layerType = editor()->layers()->currentLayer()->type();
324
325 if (layerType == Layer::BITMAP)
326 {
327 if (x == -1)
328 {
329 ui->useAABox->setEnabled(false);
330 ui->useAABox->setVisible(false);
331 }
332 else
333 {
334 ui->useAABox->setVisible(true);
335 }
336 ui->useAABox->setChecked(x > 0);
337 }
338}
339
340void ToolOptionWidget::setStabilizerLevel(int x)
341{
342 ui->inpolLevelsCombo->setCurrentIndex(qBound(0, x, ui->inpolLevelsCombo->count() - 1));
343}
344
345void ToolOptionWidget::setFillContour(int useFill)
346{
347 QSignalBlocker b(ui->fillContourBox);
348 ui->fillContourBox->setEnabled(true);
349 ui->fillContourBox->setChecked(useFill > 0);
350}
351
352void ToolOptionWidget::setBezier(bool useBezier)
353{
354 QSignalBlocker b(ui->useBezierBox);
355 ui->useBezierBox->setChecked(useBezier);
356}
357
358void ToolOptionWidget::setClosedPath(bool useClosedPath)
359{
360 QSignalBlocker b(ui->useClosedPathBox);
361 ui->useClosedPathBox->setChecked(useClosedPath);
362}
363
364void ToolOptionWidget::setShowSelectionInfo(bool showSelectionInfo)
365{
366 QSignalBlocker b(ui->showInfoBox);
367 ui->showInfoBox->setChecked(showSelectionInfo);
368}
369
370void ToolOptionWidget::disableAllOptions()
371{
372 ui->sizeSlider->hide();
373 ui->brushSpinBox->hide();
374 ui->featherSlider->hide();
375 ui->featherSpinBox->hide();
376 ui->useFeatherBox->hide();
377 ui->useBezierBox->hide();
378 ui->useClosedPathBox->hide();
379 ui->usePressureBox->hide();
380 ui->makeInvisibleBox->hide();
381 ui->preserveAlphaBox->hide();
382 ui->vectorMergeBox->hide();
383 ui->useAABox->hide();
384 ui->inpolLevelsCombo->hide();
385 ui->fillContourBox->hide();
386 ui->showInfoBox->hide();
387 ui->stabilizerLabel->hide();
388}
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 May 8 2025 04:47:53 for Pencil2D by doxygen 1.9.6 based on revision 4513250b1d5b1a3676ec0e67b06b7a885ceaae39