17#include "bucketoptionswidget.h"
18#include "ui_bucketoptionswidget.h"
22#include "spinslider.h"
23#include "pencilsettings.h"
27#include "layermanager.h"
28#include "toolmanager.h"
31BucketOptionsWidget::BucketOptionsWidget(
Editor* editor,
QWidget* parent) :
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);
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());
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);
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"));
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"));
61 connect(ui->colorToleranceSlider, &SpinSlider::valueChanged, mEditor->tools(), &ToolManager::setTolerance);
63 connect(ui->colorToleranceCheckbox, &
QCheckBox::toggled, mEditor->tools(), &ToolManager::setBucketColorToleranceEnabled);
65 connect(ui->expandSlider, &SpinSlider::valueChanged, mEditor->tools(), &ToolManager::setBucketFillExpand);
67 connect(ui->expandCheckbox, &
QCheckBox::toggled, mEditor->tools(), &ToolManager::setBucketFillExpandEnabled);
69 connect(ui->strokeThicknessSlider, &SpinSlider::valueChanged, mEditor->tools(), &ToolManager::setWidth);
72 connect(mEditor->tools(), &ToolManager::toolPropertyChanged,
this, &BucketOptionsWidget::onPropertyChanged);
73 connect(mEditor->layers(), &LayerManager::currentLayerChanged,
this, &BucketOptionsWidget::onLayerChanged);
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());
85 clearFocusOnFinished(ui->colorToleranceSpinbox);
86 clearFocusOnFinished(ui->expandSpinBox);
88 updatePropertyVisibility();
91BucketOptionsWidget::~BucketOptionsWidget()
96void BucketOptionsWidget::updatePropertyVisibility()
98 Layer* layer = mEditor->layers()->currentLayer();
100 Q_ASSERT(layer !=
nullptr);
102 switch (layer->type()) {
104 ui->strokeThicknessSlider->show();
105 ui->strokeThicknessSpinBox->show();
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();
118 case Layer::BITMAP: {
119 ui->strokeThicknessSlider->hide();
120 ui->strokeThicknessSpinBox->hide();
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();
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();
150void BucketOptionsWidget::onPropertyChanged(ToolType, ToolPropertyType propertyType)
152 const Properties& p = mEditor->tools()->currentTool()->properties;
153 switch (propertyType)
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;
174void BucketOptionsWidget::onLayerChanged(
int)
176 updatePropertyVisibility();
179void BucketOptionsWidget::setColorTolerance(
int tolerance)
182 ui->colorToleranceSlider->setValue(tolerance);
185 ui->colorToleranceSpinbox->setValue(tolerance);
188void BucketOptionsWidget::setColorToleranceEnabled(
bool enabled)
191 ui->colorToleranceCheckbox->setChecked(
enabled);
194void BucketOptionsWidget::setFillMode(
int mode)
197 ui->blendModeComboBox->setCurrentIndex(mode);
200void BucketOptionsWidget::setFillExpandEnabled(
bool enabled)
203 ui->expandCheckbox->setChecked(
enabled);
206void BucketOptionsWidget::setFillExpand(
int value)
209 ui->expandSlider->setValue(value);
212 ui->expandSpinBox->setValue(value);
215void BucketOptionsWidget::setFillReferenceMode(
int referenceMode)
218 ui->referenceLayerComboBox->setCurrentIndex(referenceMode);
221void BucketOptionsWidget::setStrokeWidth(qreal value)
224 ui->strokeThicknessSlider->setValue(value);
227 ui->strokeThicknessSpinBox->setValue(value);
void currentIndexChanged(int index)
void valueChanged(double d)