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
bucketoptionswidget.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 "bucketoptionswidget.h"
18#include "ui_bucketoptionswidget.h"
19
20#include <QDebug>
21
22#include "spinslider.h"
23#include "pencilsettings.h"
24
25#include "layer.h"
26#include "editor.h"
27#include "layermanager.h"
28#include "toolmanager.h"
29#include "util.h"
30
31BucketOptionsWidget::BucketOptionsWidget(Editor* editor, QWidget* parent) :
32 QWidget(parent),
33 ui(new Ui::BucketOptionsWidget),
34 mEditor(editor)
35{
36 ui->setupUi(this);
37
38 ui->colorToleranceSlider->init(tr("Color tolerance"), SpinSlider::GROWTH_TYPE::LINEAR, SpinSlider::VALUE_TYPE::INTEGER, 0, MAX_COLOR_TOLERANCE);
39 ui->expandSlider->init(tr("Expand fill"), SpinSlider::GROWTH_TYPE::LINEAR, SpinSlider::VALUE_TYPE::INTEGER, 0, MAX_EXPAND);
40 ui->strokeThicknessSlider->init(tr("Stroke thickness"), SpinSlider::GROWTH_TYPE::LOG, SpinSlider::VALUE_TYPE::FLOAT, 1, MAX_STROKE_THICKNESS);
41
42 QSettings settings(PENCIL2D, PENCIL2D);
43
44 ui->colorToleranceCheckbox->setChecked(settings.value(SETTING_BUCKET_TOLERANCE_ON, true).toBool());
45 ui->expandCheckbox->setChecked(settings.value(SETTING_BUCKET_FILL_EXPAND_ON, true).toBool());
46
47 ui->expandSpinBox->setMaximum(MAX_EXPAND);
48 ui->strokeThicknessSpinBox->setMaximum(MAX_STROKE_THICKNESS);
49 ui->colorToleranceSpinbox->setMaximum(MAX_COLOR_TOLERANCE);
50 ui->strokeThicknessSpinBox->setMinimum(1);
51
52 ui->referenceLayerComboBox->addItem(tr("Current layer", "Reference Layer Options"), 0);
53 ui->referenceLayerComboBox->addItem(tr("All layers", "Reference Layer Options"), 1);
54 ui->referenceLayerComboBox->setToolTip(tr("Refers to the layer that used to flood fill from"));
55
56 ui->blendModeComboBox->addItem(tr("Overlay", "Blend Mode dropdown option"), 0);
57 ui->blendModeComboBox->addItem(tr("Replace", "Blend Mode dropdown option"), 1);
58 ui->blendModeComboBox->addItem(tr("Behind", "Blend Mode dropdown option"), 2);
59 ui->blendModeComboBox->setToolTip(tr("Defines how the fill will behave when the new color is not opaque"));
60
61 connect(ui->colorToleranceSlider, &SpinSlider::valueChanged, mEditor->tools(), &ToolManager::setTolerance);
62 connect(ui->colorToleranceSpinbox, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), mEditor->tools(), &ToolManager::setTolerance);
63 connect(ui->colorToleranceCheckbox, &QCheckBox::toggled, mEditor->tools(), &ToolManager::setBucketColorToleranceEnabled);
64
65 connect(ui->expandSlider, &SpinSlider::valueChanged, mEditor->tools(), &ToolManager::setBucketFillExpand);
66 connect(ui->expandSpinBox, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), mEditor->tools(), &ToolManager::setBucketFillExpand);
67 connect(ui->expandCheckbox, &QCheckBox::toggled, mEditor->tools(), &ToolManager::setBucketFillExpandEnabled);
68
69 connect(ui->strokeThicknessSlider, &SpinSlider::valueChanged, mEditor->tools(), &ToolManager::setWidth);
70 connect(ui->strokeThicknessSpinBox, static_cast<void (QDoubleSpinBox::*)(qreal)>(&QDoubleSpinBox::valueChanged), mEditor->tools(), &ToolManager::setWidth);
71
72 connect(mEditor->tools(), &ToolManager::toolPropertyChanged, this, &BucketOptionsWidget::onPropertyChanged);
73 connect(mEditor->layers(), &LayerManager::currentLayerChanged, this, &BucketOptionsWidget::onLayerChanged);
74
75 connect(ui->referenceLayerComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), mEditor->tools(), &ToolManager::setBucketFillReferenceMode);
76 connect(ui->blendModeComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), mEditor->tools(), &ToolManager::setFillMode);
77
78 ui->expandSlider->setValue(settings.value(SETTING_BUCKET_FILL_EXPAND, 2).toInt());
79 ui->expandSpinBox->setValue(settings.value(SETTING_BUCKET_FILL_EXPAND, 2).toInt());
80 ui->colorToleranceSlider->setValue(settings.value(SETTING_BUCKET_TOLERANCE, 50).toInt());
81 ui->colorToleranceSpinbox->setValue(settings.value(SETTING_BUCKET_TOLERANCE, 50).toInt());
82 ui->referenceLayerComboBox->setCurrentIndex(settings.value(SETTING_BUCKET_FILL_REFERENCE_MODE, 0).toInt());
83 ui->blendModeComboBox->setCurrentIndex(settings.value(SETTING_FILL_MODE, 0).toInt());
84
85 clearFocusOnFinished(ui->colorToleranceSpinbox);
86 clearFocusOnFinished(ui->expandSpinBox);
87
88 updatePropertyVisibility();
89}
90
91BucketOptionsWidget::~BucketOptionsWidget()
92{
93 delete ui;
94}
95
96void BucketOptionsWidget::updatePropertyVisibility()
97{
98 Layer* layer = mEditor->layers()->currentLayer();
99
100 Q_ASSERT(layer != nullptr);
101
102 switch (layer->type()) {
103 case Layer::VECTOR:
104 ui->strokeThicknessSlider->show();
105 ui->strokeThicknessSpinBox->show();
106
107 ui->colorToleranceCheckbox->hide();
108 ui->colorToleranceSlider->hide();
109 ui->colorToleranceSpinbox->hide();
110 ui->expandCheckbox->hide();
111 ui->expandSlider->hide();
112 ui->expandSpinBox->hide();
113 ui->referenceLayerComboBox->hide();
114 ui->referenceLayerDescLabel->hide();
115 ui->blendModeComboBox->hide();
116 ui->blendModeLabel->hide();
117 break;
118 case Layer::BITMAP: {
119 ui->strokeThicknessSlider->hide();
120 ui->strokeThicknessSpinBox->hide();
121
122 ui->referenceLayerComboBox->show();
123 ui->referenceLayerDescLabel->show();
124 ui->colorToleranceCheckbox->show();
125 ui->colorToleranceSlider->show();
126 ui->colorToleranceSpinbox->show();
127 ui->expandCheckbox->show();
128 ui->expandSlider->show();
129 ui->expandSpinBox->show();
130 ui->blendModeComboBox->show();
131 ui->blendModeLabel->show();
132 break;
133 }
134 default:
135 ui->strokeThicknessSlider->hide();
136 ui->strokeThicknessSpinBox->hide();
137 ui->colorToleranceCheckbox->hide();
138 ui->colorToleranceSlider->hide();
139 ui->colorToleranceSpinbox->hide();
140 ui->expandCheckbox->hide();
141 ui->expandSlider->hide();
142 ui->expandSpinBox->hide();
143 ui->referenceLayerComboBox->hide();
144 ui->referenceLayerDescLabel->hide();
145 ui->blendModeComboBox->hide();
146 ui->blendModeLabel->hide();
147 }
148}
149
150void BucketOptionsWidget::onPropertyChanged(ToolType, ToolPropertyType propertyType)
151{
152 const Properties& p = mEditor->tools()->currentTool()->properties;
153 switch (propertyType)
154 {
155 case ToolPropertyType::TOLERANCE:
156 setColorTolerance(static_cast<int>(p.tolerance)); break;
157 case ToolPropertyType::USETOLERANCE:
158 setColorToleranceEnabled(p.toleranceEnabled); break;
159 case ToolPropertyType::WIDTH:
160 setStrokeWidth(static_cast<int>(p.width)); break;
161 case ToolPropertyType::BUCKETFILLEXPAND:
162 setFillExpand(static_cast<int>(p.bucketFillExpand)); break;
163 case ToolPropertyType::USEBUCKETFILLEXPAND:
164 setFillExpandEnabled(p.bucketFillExpandEnabled); break;
165 case ToolPropertyType::BUCKETFILLLAYERREFERENCEMODE:
166 setFillReferenceMode(p.bucketFillReferenceMode); break;
167 case ToolPropertyType::FILL_MODE:
168 setFillMode(p.fillMode); break;
169 default:
170 break;
171 }
172}
173
174void BucketOptionsWidget::onLayerChanged(int)
175{
176 updatePropertyVisibility();
177}
178
179void BucketOptionsWidget::setColorTolerance(int tolerance)
180{
181 QSignalBlocker b(ui->colorToleranceSlider);
182 ui->colorToleranceSlider->setValue(tolerance);
183
184 QSignalBlocker b2(ui->colorToleranceSpinbox);
185 ui->colorToleranceSpinbox->setValue(tolerance);
186}
187
188void BucketOptionsWidget::setColorToleranceEnabled(bool enabled)
189{
190 QSignalBlocker b(ui->colorToleranceCheckbox);
191 ui->colorToleranceCheckbox->setChecked(enabled);
192}
193
194void BucketOptionsWidget::setFillMode(int mode)
195{
196 QSignalBlocker b(ui->blendModeComboBox);
197 ui->blendModeComboBox->setCurrentIndex(mode);
198}
199
200void BucketOptionsWidget::setFillExpandEnabled(bool enabled)
201{
202 QSignalBlocker b(ui->expandCheckbox);
203 ui->expandCheckbox->setChecked(enabled);
204}
205
206void BucketOptionsWidget::setFillExpand(int value)
207{
208 QSignalBlocker b(ui->expandSlider);
209 ui->expandSlider->setValue(value);
210
211 QSignalBlocker b2(ui->expandSpinBox);
212 ui->expandSpinBox->setValue(value);
213}
214
215void BucketOptionsWidget::setFillReferenceMode(int referenceMode)
216{
217 QSignalBlocker b(ui->referenceLayerComboBox);
218 ui->referenceLayerComboBox->setCurrentIndex(referenceMode);
219}
220
221void BucketOptionsWidget::setStrokeWidth(qreal value)
222{
223 QSignalBlocker b(ui->strokeThicknessSlider);
224 ui->strokeThicknessSlider->setValue(value);
225
226 QSignalBlocker b2(ui->strokeThicknessSpinBox);
227 ui->strokeThicknessSpinBox->setValue(value);
228}
BucketOptionsWidget
Definition: bucketoptionswidget.h:31
Editor
Definition: editor.h:71
Layer
Definition: layer.h:33
Properties
Definition: basetool.h:39
QAbstractButton::toggled
void toggled(bool checked)
QComboBox
QComboBox::currentIndexChanged
void currentIndexChanged(int index)
QDoubleSpinBox
QDoubleSpinBox::valueChanged
void valueChanged(double d)
QSettings
QSignalBlocker
QSpinBox
QSpinBox::valueChanged
void valueChanged(int i)
QWidget
QWidget::enabled
enabled
QWidget::setupUi
void setupUi(QWidget *widget)
Generated on Thu May 8 2025 04:47:53 for Pencil2D by doxygen 1.9.6 based on revision 4513250b1d5b1a3676ec0e67b06b7a885ceaae39