diff --git a/libs/ui/CMakeLists.txt b/libs/ui/CMakeLists.txt --- a/libs/ui/CMakeLists.txt +++ b/libs/ui/CMakeLists.txt @@ -452,6 +452,7 @@ forms/wdgbookmarkedconfigurationseditor.ui forms/wdgapplyprofile.ui forms/wdgcustompattern.ui + forms/wdgfreehandbrushoptions.ui forms/wdglayerproperties.ui forms/wdgcolorsettings.ui forms/wdgtabletsettings.ui diff --git a/libs/ui/forms/wdgfreehandbrushoptions.ui b/libs/ui/forms/wdgfreehandbrushoptions.ui new file mode 100644 --- /dev/null +++ b/libs/ui/forms/wdgfreehandbrushoptions.ui @@ -0,0 +1,238 @@ + + + WdgFreehandBrushOptions + + + + 0 + 0 + 292 + 452 + + + + + + + + + Stabilizer Strength: + + + + + + + + 0 + 20 + + + + 5 + + + + + + + Custom Settings + + + false + + + + + + + + + + + + 0 + 20 + + + + + + + + Distance: + + + + + + + Stroke Ending: + + + + + + + + 0 + 20 + + + + + + + + Finish Line + + + true + + + + + + + Smooth Pressure + + + true + + + + + + + Scalable Distance + + + true + + + + + + + Stabilize Sensors + + + true + + + + + + + + 0 + 0 + + + + Type: + + + + + + + + + + + 0 + 20 + + + + + + + + Delay + + + + + + + + + Qt::Horizontal + + + + + + + Snap to Assistants + + + + + + + + + + 0 + 20 + + + + + + + + + 0 + 0 + + + + Magnetism: + + + + + + + Snap Single + + + + + + + + + Qt::Vertical + + + + 5 + 5 + + + + + + + + + KisDoubleSliderSpinBox + QWidget +
kis_slider_spin_box.h
+ 1 +
+ + KisSliderSpinBox + QWidget +
kis_slider_spin_box.h
+ 1 +
+
+ + +
diff --git a/libs/ui/tool/kis_tool_paint.h b/libs/ui/tool/kis_tool_paint.h --- a/libs/ui/tool/kis_tool_paint.h +++ b/libs/ui/tool/kis_tool_paint.h @@ -39,7 +39,6 @@ #include #include - #include "kis_tool.h" #include @@ -110,9 +109,6 @@ /// Add a widget and a label to the current option widget layout. virtual void addOptionWidgetOption(QWidget *control, QWidget *label = 0); - void showControl(QWidget *control, bool value); - void enableControl(QWidget *control, bool value); - QWidget * createOptionWidget() override; /** diff --git a/libs/ui/tool/kis_tool_paint.cc b/libs/ui/tool/kis_tool_paint.cc --- a/libs/ui/tool/kis_tool_paint.cc +++ b/libs/ui/tool/kis_tool_paint.cc @@ -537,24 +537,6 @@ return result; } -void KisToolPaint::showControl(QWidget *control, bool value) -{ - control->setVisible(value); - QWidget *label = findLabelWidget(m_optionsWidgetLayout, control); - if (label) { - label->setVisible(value); - } -} - -void KisToolPaint::enableControl(QWidget *control, bool value) -{ - control->setEnabled(value); - QWidget *label = findLabelWidget(m_optionsWidgetLayout, control); - if (label) { - label->setEnabled(value); - } -} - void KisToolPaint::addOptionWidgetLayout(QLayout *layout) { Q_ASSERT(m_optionsWidgetLayout != 0); diff --git a/plugins/tools/basictools/CMakeLists.txt b/plugins/tools/basictools/CMakeLists.txt --- a/plugins/tools/basictools/CMakeLists.txt +++ b/plugins/tools/basictools/CMakeLists.txt @@ -6,6 +6,7 @@ default_tools.cc kis_tool_colorpicker.cc kis_tool_brush.cc + kis_tool_brush_tooloptionswidget.cpp kis_tool_line.cc kis_tool_line_helper.cpp kis_tool_fill.cc diff --git a/plugins/tools/basictools/kis_tool_brush.h b/plugins/tools/basictools/kis_tool_brush.h --- a/plugins/tools/basictools/kis_tool_brush.h +++ b/plugins/tools/basictools/kis_tool_brush.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2003-2004 Boudewijn Rempt + * Copyright (c) 2017 Scott Petrovic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -32,6 +33,8 @@ #include #include #include +#include +#include "kis_tool_brush_tooloptionswidget.h" class QCheckBox; class QComboBox; @@ -42,6 +45,23 @@ class KisSliderSpinBox; class KisDoubleSliderSpinBox; +/** + The stabilizer will have certain presets that range from none to strong + This is the data structure that will help creating these presets + */ +typedef struct BrushStabilizerSetting { + // list options a seting type can have + int smoothingType = 1; // 0 = none, 1 = basic, 2 = weighted, 3 = stabilizer + float distance = 0.0; + float strokeEnding = 0.0; + int delayDistance = 0; + bool hasSmoothPressure = false; + bool hasScalableDistance = false; + bool hasDelay = false; + bool hasFinishLine = false; + bool hasStabilizerSensors = false; +} BrushStabilizerSetting; + class KisToolBrush : public KisToolFreehand { Q_OBJECT @@ -76,12 +96,19 @@ bool finishStabilizedCurve() const; bool stabilizeSensors() const; + /// each smoothing/stabilizer type has its own set of settings. This will show/hide UI + /// element based off whatever smoothing type is selected + void updateStabilizerSettingsVisibility(int smoothingTypeIndex); + protected: KConfigGroup m_configGroup; // only used in the multihand tool for now protected Q_SLOTS: void resetCursorStyle() override; + /// toggles whethe we are using stabilizer presets or manually setting values + void slotCustomSettingsChecked(bool checked); + public Q_SLOTS: void activate(ToolActivation toolActivation, const QSet &shapes) override; void deactivate() override; @@ -89,9 +116,16 @@ void slotSetMagnetism(int magnetism); void slotSetSmoothingType(int index); void slotSetTailAgressiveness(qreal argh_rhhrr); + + /// toggled we enable or disable using assistants on the canvas to paint with + void slotUseAssistants(bool isUsing); void setSmoothPressure(bool value); void setUseScalableDistance(bool value); + /// the stabilizer slider that determines the + /// stabilizer preset we are using + void slotStabilizerPresetChanged(int value); + void setUseDelayDistance(bool value); void setDelayDistance(qreal value); @@ -116,26 +150,16 @@ private: void addSmoothingAction(int enumId, const QString &id, const QString &name, const QIcon &icon, KActionCollection *globalCollection); -private: - QComboBox *m_cmbSmoothingType; - - QCheckBox *m_chkAssistant; - KisSliderSpinBox *m_sliderMagnetism; - QCheckBox *m_chkOnlyOneAssistant; - KisDoubleSliderSpinBox *m_sliderSmoothnessDistance; - KisDoubleSliderSpinBox *m_sliderTailAggressiveness; - QCheckBox *m_chkSmoothPressure; - QCheckBox *m_chkUseScalableDistance; + /// internal function for modifying the GUI display. It is paired with using custom settings for the stabilizer + void hideAllStabilizerUIFields(); - QCheckBox *m_chkStabilizeSensors; - QCheckBox *m_chkDelayDistance; - KisDoubleSliderSpinBox *m_sliderDelayDistance; +private: + QList stabilizerSettings; - QCheckBox *m_chkFinishStabilizedCurve; QSignalMapper m_signalMapper; + KisToolBrushToolOptionsWidget *m_toolBrushOptions = 0; }; - class KisToolBrushFactory : public KoToolFactoryBase { diff --git a/plugins/tools/basictools/kis_tool_brush.cc b/plugins/tools/basictools/kis_tool_brush.cc --- a/plugins/tools/basictools/kis_tool_brush.cc +++ b/plugins/tools/basictools/kis_tool_brush.cc @@ -3,6 +3,7 @@ * * Copyright (c) 2003-2004 Boudewijn Rempt * Copyright (c) 2015 Moritz Molch + * Copyright (c) 2017 Scott Petrovic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -38,11 +39,11 @@ #include "kis_config.h" #include "kis_slider_spin_box.h" #include "kundo2magicstring.h" +#include "ui_wdgfreehandbrushoptions.h" #define MAXIMUM_SMOOTHNESS_DISTANCE 1000.0 // 0..1000.0 == weight in gui #define MAXIMUM_MAGNETISM 1000 - void KisToolBrush::addSmoothingAction(int enumId, const QString &id, const QString &name, const QIcon &icon, KActionCollection *globalCollection) { /** @@ -77,6 +78,48 @@ addSmoothingAction(KisSmoothingOptions::WEIGHTED_SMOOTHING, "set_weighted_brush_smoothing", i18nc("@action", "Brush Smoothing: Weighted"), KisIconUtils::loadIcon("smoothing-weighted"), collection); addSmoothingAction(KisSmoothingOptions::STABILIZER, "set_stabilizer_brush_smoothing", i18nc("@action", "Brush Smoothing: Stabilizer"), KisIconUtils::loadIcon("smoothing-stabilizer"), collection); + + // add stabilizer preset options from 0 - 4 + BrushStabilizerSetting setting; + + // setting of 0 -- weakest stabilizer settings + setting.smoothingType = 1; // basic + stabilizerSettings.append(setting); + + // setting of 1 + setting.smoothingType = 2; // weighted smoothing + setting.distance = 20.0; + setting.strokeEnding = 0.3; + setting.hasSmoothPressure = false; + setting.hasScalableDistance = false; + stabilizerSettings.append(setting); + + // setting of 2 + setting.smoothingType = 2; + setting.distance = 60.0; + setting.strokeEnding = 0.4; + setting.hasSmoothPressure = false; + setting.hasScalableDistance = true; + stabilizerSettings.append(setting); + + // setting of 3 + setting.smoothingType = 3; // stabilizer + setting.distance = 26.0; + setting.hasDelay = true; + setting.delayDistance = 4; + setting.hasStabilizerSensors = false; + setting.hasSmoothPressure = true; + stabilizerSettings.append(setting); + + + // setting of 4 - strongest stabilizer settings + setting.smoothingType = 3; + setting.distance = 30.0; + setting.hasDelay = true; + setting.delayDistance = 40; + setting.hasStabilizerSensors = true; + setting.hasSmoothPressure = true; + stabilizerSettings.append(setting); } KisToolBrush::~KisToolBrush() @@ -123,53 +166,28 @@ * The slot can also be called from smoothing-type-switching * action that would mean the combo box will not be synchronized */ - if (m_cmbSmoothingType->currentIndex() != index) { - m_cmbSmoothingType->setCurrentIndex(index); + if (m_toolBrushOptions->smoothingTypeCombobox->currentIndex() != index) { + m_toolBrushOptions->smoothingTypeCombobox->setCurrentIndex(index); } switch (index) { - case 0: - smoothingOptions()->setSmoothingType(KisSmoothingOptions::NO_SMOOTHING); - showControl(m_sliderSmoothnessDistance, false); - showControl(m_sliderTailAggressiveness, false); - showControl(m_chkSmoothPressure, false); - showControl(m_chkUseScalableDistance, false); - showControl(m_sliderDelayDistance, false); - showControl(m_chkFinishStabilizedCurve, false); - showControl(m_chkStabilizeSensors, false); - break; - case 1: - smoothingOptions()->setSmoothingType(KisSmoothingOptions::SIMPLE_SMOOTHING); - showControl(m_sliderSmoothnessDistance, false); - showControl(m_sliderTailAggressiveness, false); - showControl(m_chkSmoothPressure, false); - showControl(m_chkUseScalableDistance, false); - showControl(m_sliderDelayDistance, false); - showControl(m_chkFinishStabilizedCurve, false); - showControl(m_chkStabilizeSensors, false); - break; - case 2: - smoothingOptions()->setSmoothingType(KisSmoothingOptions::WEIGHTED_SMOOTHING); - showControl(m_sliderSmoothnessDistance, true); - showControl(m_sliderTailAggressiveness, true); - showControl(m_chkSmoothPressure, true); - showControl(m_chkUseScalableDistance, true); - showControl(m_sliderDelayDistance, false); - showControl(m_chkFinishStabilizedCurve, false); - showControl(m_chkStabilizeSensors, false); - break; - case 3: - default: - smoothingOptions()->setSmoothingType(KisSmoothingOptions::STABILIZER); - showControl(m_sliderSmoothnessDistance, true); - showControl(m_sliderTailAggressiveness, false); - showControl(m_chkSmoothPressure, false); - showControl(m_chkUseScalableDistance, true); - showControl(m_sliderDelayDistance, true); - showControl(m_chkFinishStabilizedCurve, true); - showControl(m_chkStabilizeSensors, true); + case 0: + smoothingOptions()->setSmoothingType(KisSmoothingOptions::NO_SMOOTHING); + break; + case 1: + smoothingOptions()->setSmoothingType(KisSmoothingOptions::SIMPLE_SMOOTHING); + break; + case 2: + smoothingOptions()->setSmoothingType(KisSmoothingOptions::WEIGHTED_SMOOTHING); + break; + case 3: + default: + smoothingOptions()->setSmoothingType(KisSmoothingOptions::STABILIZER); } + updateStabilizerSettingsVisibility(index); + + emit smoothingTypeChanged(); } @@ -185,6 +203,25 @@ emit smoothnessFactorChanged(); } +void KisToolBrush::slotStabilizerPresetChanged(int value) +{ + blockSignals(true); + m_toolBrushOptions->smoothingTypeCombobox->setCurrentIndex(stabilizerSettings[value].smoothingType); + m_toolBrushOptions->distanceInputbox->setValue(stabilizerSettings[value].distance); + m_toolBrushOptions->strokeEndingInputbox->setValue(stabilizerSettings[value].strokeEnding); + m_toolBrushOptions->enableStabilizerDelay->setChecked(stabilizerSettings[value].hasDelay); + m_toolBrushOptions->stabilizerDelayInput->setValue(stabilizerSettings[value].delayDistance); + m_toolBrushOptions->smoothPressureCheckbox->setChecked(stabilizerSettings[value].hasSmoothPressure); + m_toolBrushOptions->scalableDistanceCheckbox->setChecked(stabilizerSettings[value].hasScalableDistance); + m_toolBrushOptions->finishLineCheckbox->setChecked(stabilizerSettings[value].hasFinishLine); + m_toolBrushOptions->stabilizeSensorsCheckbox->setChecked(stabilizerSettings[value].hasStabilizerSensors); + blockSignals(false); + + // changing the UI fields causes their visibility to change + // force hide them all since we are done changing values + hideAllStabilizerUIFields(); +} + // used with weighted smoothing void KisToolBrush::setSmoothPressure(bool value) { @@ -243,8 +280,8 @@ void KisToolBrush::setUseDelayDistance(bool value) { smoothingOptions()->setUseDelayDistance(value); - m_sliderDelayDistance->setEnabled(value); - enableControl(m_chkFinishStabilizedCurve, !value); + m_toolBrushOptions->stabilizerDelayInput->setEnabled(value); + m_toolBrushOptions->finishLineCheckbox->setEnabled(!value); emit useDelayDistanceChanged(); } @@ -280,16 +317,16 @@ void KisToolBrush::updateSettingsViews() { - m_cmbSmoothingType->setCurrentIndex(smoothingOptions()->smoothingType()); + m_toolBrushOptions->smoothingTypeCombobox->setCurrentIndex(smoothingOptions()->smoothingType()); - m_sliderSmoothnessDistance->setValue(smoothingOptions()->smoothnessDistance()); - m_chkDelayDistance->setChecked(smoothingOptions()->useDelayDistance()); - m_sliderDelayDistance->setValue(smoothingOptions()->delayDistance()); - m_sliderTailAggressiveness->setValue(smoothingOptions()->tailAggressiveness()); - m_chkSmoothPressure->setChecked(smoothingOptions()->smoothPressure()); - m_chkUseScalableDistance->setChecked(smoothingOptions()->useScalableDistance()); - m_cmbSmoothingType->setCurrentIndex((int)smoothingOptions()->smoothingType()); - m_chkStabilizeSensors->setChecked(smoothingOptions()->stabilizeSensors()); + m_toolBrushOptions->distanceInputbox->setValue(smoothingOptions()->smoothnessDistance()); + m_toolBrushOptions->enableStabilizerDelay->setChecked(smoothingOptions()->useDelayDistance()); + m_toolBrushOptions->distanceInputbox->setValue(smoothingOptions()->delayDistance()); + m_toolBrushOptions->strokeEndingInputbox->setValue(smoothingOptions()->tailAggressiveness()); + m_toolBrushOptions->smoothPressureCheckbox->setChecked(smoothingOptions()->smoothPressure()); + m_toolBrushOptions->scalableDistanceCheckbox->setChecked(smoothingOptions()->useScalableDistance()); + m_toolBrushOptions->smoothingTypeCombobox->setCurrentIndex((int)smoothingOptions()->smoothingType()); + m_toolBrushOptions->stabilizeSensorsCheckbox->setChecked(smoothingOptions()->stabilizeSensors()); emit smoothnessQualityChanged(); emit smoothnessFactorChanged(); @@ -307,6 +344,16 @@ QWidget * KisToolBrush::createOptionWidget() { QWidget *optionsWidget = KisToolFreehand::createOptionWidget(); + + m_toolBrushOptions = new KisToolBrushToolOptionsWidget(); + optionsWidget->layout()->addWidget(m_toolBrushOptions); + + connect(m_toolBrushOptions->customStabilizerSettingsCheckbox, SIGNAL(toggled(bool)), this, SLOT(slotCustomSettingsChecked(bool))); + + m_toolBrushOptions->stabilizerStrengthSlider->setRange(0, 4); + connect(m_toolBrushOptions->stabilizerStrengthSlider, SIGNAL(valueChanged(int)), this, SLOT(slotStabilizerPresetChanged(int))); + + optionsWidget->setObjectName(toolId() + "option widget"); // See https://bugs.kde.org/show_bug.cgi?id=316896 @@ -315,155 +362,215 @@ specialSpacer->setFixedSize(0, 0); optionsWidget->layout()->addWidget(specialSpacer); - // Line smoothing configuration - m_cmbSmoothingType = new QComboBox(optionsWidget); - m_cmbSmoothingType->addItems(QStringList() - << i18n("None") - << i18n("Basic") - << i18n("Weighted") - << i18n("Stabilizer")); - connect(m_cmbSmoothingType, SIGNAL(currentIndexChanged(int)), this, SLOT(slotSetSmoothingType(int))); - addOptionWidgetOption(m_cmbSmoothingType, new QLabel(i18n("Brush Smoothing:"))); - - m_sliderSmoothnessDistance = new KisDoubleSliderSpinBox(optionsWidget); - m_sliderSmoothnessDistance->setRange(3.0, MAXIMUM_SMOOTHNESS_DISTANCE, 1); - m_sliderSmoothnessDistance->setEnabled(true); - connect(m_sliderSmoothnessDistance, SIGNAL(valueChanged(qreal)), SLOT(slotSetSmoothnessDistance(qreal))); - m_sliderSmoothnessDistance->setValue(smoothingOptions()->smoothnessDistance()); - addOptionWidgetOption(m_sliderSmoothnessDistance, new QLabel(i18n("Distance:"))); + + m_toolBrushOptions->smoothingTypeCombobox->addItems(QStringList() + << i18n("None") + << i18n("Basic") + << i18n("Weighted") + << i18n("Stabilizer")); + connect(m_toolBrushOptions->smoothingTypeCombobox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotSetSmoothingType(int))); + + + m_toolBrushOptions->distanceInputbox->setRange(3.0, MAXIMUM_SMOOTHNESS_DISTANCE); + m_toolBrushOptions->distanceInputbox->setEnabled(true); + connect(m_toolBrushOptions->distanceInputbox, SIGNAL(valueChanged(qreal)), SLOT(slotSetSmoothnessDistance(qreal))); + m_toolBrushOptions->distanceInputbox->setValue(smoothingOptions()->smoothnessDistance()); + + + m_toolBrushOptions->stabilizerDelayInput->setRange(0, 500); + m_toolBrushOptions->stabilizerDelayInput->setSuffix(i18n(" px")); + m_toolBrushOptions->stabilizerDelayInput->setExponentRatio(3.0); + connect(m_toolBrushOptions->stabilizerDelayInput, SIGNAL(valueChanged(qreal)), SLOT(setDelayDistance(qreal))); // Finish stabilizer curve - m_chkFinishStabilizedCurve = new QCheckBox(optionsWidget); - m_chkFinishStabilizedCurve->setMinimumHeight(qMax(m_sliderSmoothnessDistance->sizeHint().height()-3, - m_chkFinishStabilizedCurve->sizeHint().height())); - connect(m_chkFinishStabilizedCurve, SIGNAL(toggled(bool)), this, SLOT(setFinishStabilizedCurve(bool))); - m_chkFinishStabilizedCurve->setChecked(smoothingOptions()->finishStabilizedCurve()); + connect(m_toolBrushOptions->finishLineCheckbox, SIGNAL(toggled(bool)), this, SLOT(setFinishStabilizedCurve(bool))); + m_toolBrushOptions->finishLineCheckbox->setChecked(smoothingOptions()->finishStabilizedCurve()); // Delay Distance for Stabilizer - QWidget* delayWidget = new QWidget(optionsWidget); - QHBoxLayout* delayLayout = new QHBoxLayout(delayWidget); - delayLayout->setContentsMargins(0,0,0,0); - delayLayout->setSpacing(1); - QLabel* delayLabel = new QLabel(i18n("Delay:"), optionsWidget); - delayLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); - delayLayout->addWidget(delayLabel); - m_chkDelayDistance = new QCheckBox(optionsWidget); - m_chkDelayDistance->setLayoutDirection(Qt::RightToLeft); - delayWidget->setToolTip(i18n("Delay the brush stroke to make the line smoother")); - connect(m_chkDelayDistance, SIGNAL(toggled(bool)), this, SLOT(setUseDelayDistance(bool))); - delayLayout->addWidget(m_chkDelayDistance); - m_sliderDelayDistance = new KisDoubleSliderSpinBox(optionsWidget); - m_sliderDelayDistance->setToolTip(i18n("Radius where the brush is blocked")); - m_sliderDelayDistance->setRange(0, 500); - m_sliderDelayDistance->setSuffix(i18n(" px")); - connect(m_sliderDelayDistance, SIGNAL(valueChanged(qreal)), SLOT(setDelayDistance(qreal))); - - addOptionWidgetOption(m_sliderDelayDistance, delayWidget); - addOptionWidgetOption(m_chkFinishStabilizedCurve, new QLabel(i18n("Finish line:"))); - - m_sliderDelayDistance->setValue(smoothingOptions()->delayDistance()); - m_chkDelayDistance->setChecked(smoothingOptions()->useDelayDistance()); + m_toolBrushOptions->enableStabilizerDelay->setToolTip(i18n("Delay the brush stroke to make the line smoother")); + connect(m_toolBrushOptions->enableStabilizerDelay, SIGNAL(toggled(bool)), this, SLOT(setUseDelayDistance(bool))); + + + m_toolBrushOptions->distanceInputbox->setToolTip(i18n("Radius where the brush is blocked")); + m_toolBrushOptions->distanceInputbox->setRange(3, 1000, 1); + m_toolBrushOptions->distanceInputbox->setExponentRatio(3.0); + + connect(m_toolBrushOptions->distanceInputbox, SIGNAL(valueChanged(qreal)), SLOT(setDelayDistance(qreal))); + + m_toolBrushOptions->distanceInputbox->setValue(smoothingOptions()->delayDistance()); + m_toolBrushOptions->enableStabilizerDelay->setChecked(smoothingOptions()->useDelayDistance()); + // if the state is not flipped, then the previous line doesn't generate any signals - setUseDelayDistance(m_chkDelayDistance->isChecked()); + setUseDelayDistance(m_toolBrushOptions->enableStabilizerDelay->isChecked()); // Stabilize sensors - m_chkStabilizeSensors = new QCheckBox(optionsWidget); - m_chkStabilizeSensors->setMinimumHeight(qMax(m_sliderSmoothnessDistance->sizeHint().height()-3, - m_chkStabilizeSensors->sizeHint().height())); - connect(m_chkStabilizeSensors, SIGNAL(toggled(bool)), this, SLOT(setStabilizeSensors(bool))); - m_chkStabilizeSensors->setChecked(smoothingOptions()->stabilizeSensors()); - addOptionWidgetOption(m_chkStabilizeSensors, new QLabel(i18n("Stabilize Sensors:"))); - - - m_sliderTailAggressiveness = new KisDoubleSliderSpinBox(optionsWidget); - m_sliderTailAggressiveness->setRange(0.0, 1.0, 2); - m_sliderTailAggressiveness->setEnabled(true); - connect(m_sliderTailAggressiveness, SIGNAL(valueChanged(qreal)), SLOT(slotSetTailAgressiveness(qreal))); - m_sliderTailAggressiveness->setValue(smoothingOptions()->tailAggressiveness()); - addOptionWidgetOption(m_sliderTailAggressiveness, new QLabel(i18n("Stroke Ending:"))); - - m_chkSmoothPressure = new QCheckBox(optionsWidget); - m_chkSmoothPressure->setMinimumHeight(qMax(m_sliderSmoothnessDistance->sizeHint().height()-3, - m_chkSmoothPressure->sizeHint().height())); - m_chkSmoothPressure->setChecked(smoothingOptions()->smoothPressure()); - connect(m_chkSmoothPressure, SIGNAL(toggled(bool)), this, SLOT(setSmoothPressure(bool))); - addOptionWidgetOption(m_chkSmoothPressure, new QLabel(QString("%1:").arg(i18n("Smooth Pressure")))); - - m_chkUseScalableDistance = new QCheckBox(optionsWidget); - m_chkUseScalableDistance->setChecked(smoothingOptions()->useScalableDistance()); - m_chkUseScalableDistance->setMinimumHeight(qMax(m_sliderSmoothnessDistance->sizeHint().height()-3, - m_chkUseScalableDistance->sizeHint().height())); - m_chkUseScalableDistance->setToolTip(i18nc("@info:tooltip", + connect(m_toolBrushOptions->stabilizeSensorsCheckbox, SIGNAL(toggled(bool)), this, SLOT(setStabilizeSensors(bool))); + m_toolBrushOptions->stabilizeSensorsCheckbox->setChecked(smoothingOptions()->stabilizeSensors()); + + m_toolBrushOptions->strokeEndingInputbox->setRange(0.0, 1.0, 2); + m_toolBrushOptions->strokeEndingInputbox->setSingleStep(0.01); + m_toolBrushOptions->strokeEndingInputbox->setEnabled(true); + connect(m_toolBrushOptions->strokeEndingInputbox, SIGNAL(valueChanged(qreal)), SLOT(slotSetTailAgressiveness(qreal))); + m_toolBrushOptions->strokeEndingInputbox->setValue(smoothingOptions()->tailAggressiveness()); + + m_toolBrushOptions->smoothPressureCheckbox->setChecked(smoothingOptions()->smoothPressure()); + + connect(m_toolBrushOptions->smoothPressureCheckbox, SIGNAL(toggled(bool)), this, SLOT(setSmoothPressure(bool))); + + m_toolBrushOptions->scalableDistanceCheckbox->setChecked(smoothingOptions()->useScalableDistance()); + + m_toolBrushOptions->scalableDistanceCheckbox->setToolTip(i18nc("@info:tooltip", "Scalable distance takes zoom level " "into account and makes the distance " "be visually constant whatever zoom " "level is chosen")); - connect(m_chkUseScalableDistance, SIGNAL(toggled(bool)), this, SLOT(setUseScalableDistance(bool))); - addOptionWidgetOption(m_chkUseScalableDistance, new QLabel(QString("%1:").arg(i18n("Scalable Distance")))); + connect(m_toolBrushOptions->scalableDistanceCheckbox, SIGNAL(toggled(bool)), this, SLOT(setUseScalableDistance(bool))); - // add a line spacer so we know that the next set of options are for different settings - QFrame* line = new QFrame(optionsWidget); - line->setObjectName(QString::fromUtf8("line")); - line->setFrameShape(QFrame::HLine); - addOptionWidgetOption(line); - // Drawing assistant configuration - QWidget* assistantWidget = new QWidget(optionsWidget); - QGridLayout* assistantLayout = new QGridLayout(assistantWidget); - assistantLayout->setContentsMargins(10,0,0,0); - assistantLayout->setSpacing(5); + // allow snapping to assistants be assigned to a shortcut + QAction *toggleaction = KisActionRegistry::instance()->makeQAction("toggle_assistant", this); + addAction("toggle_assistant", toggleaction); + toggleaction->setShortcut(QKeySequence(Qt::ControlModifier + Qt::ShiftModifier + Qt::Key_L)); + connect(toggleaction, SIGNAL(triggered(bool)), m_toolBrushOptions->useAssistantsCheckbox, SLOT(toggle())); + + m_toolBrushOptions->magnetismInputbox->setToolTip(i18n("Assistant Magnetism")); + m_toolBrushOptions->magnetismInputbox->setRange(0, MAXIMUM_MAGNETISM); - m_chkAssistant = new QCheckBox(optionsWidget); - m_chkAssistant->setText(i18n("Snap to Assistants")); + m_toolBrushOptions->magnetismInputbox->setValue(m_magnetism * MAXIMUM_MAGNETISM); + connect( m_toolBrushOptions->magnetismInputbox, SIGNAL(valueChanged(int)), SLOT(slotSetMagnetism(int))); - assistantWidget->setToolTip(i18n("You need to add Ruler Assistants before this tool will work.")); - connect(m_chkAssistant, SIGNAL(toggled(bool)), this, SLOT(setAssistant(bool))); - addOptionWidgetOption(assistantWidget, m_chkAssistant); + m_toolBrushOptions->snapSingleCheckbox->setToolTip(i18nc("@info:tooltip","Make it only snap to a single assistant, prevents snapping mess while using the infinite assistants.")); + m_toolBrushOptions->snapSingleCheckbox->setCheckState(Qt::Checked);//turn on by default. + connect(m_toolBrushOptions->snapSingleCheckbox, SIGNAL(toggled(bool)), this, SLOT(setOnlyOneAssistantSnap(bool))); - m_sliderMagnetism = new KisSliderSpinBox(optionsWidget); - m_sliderMagnetism->setToolTip(i18n("Assistant Magnetism")); - m_sliderMagnetism->setRange(0, MAXIMUM_MAGNETISM); - m_sliderMagnetism->setValue(m_magnetism * MAXIMUM_MAGNETISM); - connect(m_sliderMagnetism, SIGNAL(valueChanged(int)), SLOT(slotSetMagnetism(int))); + connect(m_toolBrushOptions->useAssistantsCheckbox, SIGNAL(toggled(bool)), this, SLOT(slotUseAssistants(bool))); - QAction *toggleaction = KisActionRegistry::instance()->makeQAction("toggle_assistant", this); - addAction("toggle_assistant", toggleaction); - toggleaction->setShortcut(QKeySequence(Qt::ControlModifier + Qt::ShiftModifier + Qt::Key_L)); - connect(toggleaction, SIGNAL(triggered(bool)), m_chkAssistant, SLOT(toggle())); + KisConfig cfg; + slotSetSmoothingType(cfg.lineSmoothingType()); - QLabel* magnetismLabel = new QLabel(i18n("Magnetism:")); - addOptionWidgetOption(m_sliderMagnetism, magnetismLabel); - QLabel* snapSingleLabel = new QLabel(i18n("Snap Single:")); + // add a line spacer so we know that the next set of options are for different settings + QFrame* line = new QFrame(optionsWidget); + line->setObjectName(QString::fromUtf8("line")); + line->setFrameShape(QFrame::HLine); + addOptionWidgetOption(line); - m_chkOnlyOneAssistant = new QCheckBox(optionsWidget); - m_chkOnlyOneAssistant->setToolTip(i18nc("@info:tooltip","Make it only snap to a single assistant, prevents snapping mess while using the infinite assistants.")); - m_chkOnlyOneAssistant->setCheckState(Qt::Checked);//turn on by default. - connect(m_chkOnlyOneAssistant, SIGNAL(toggled(bool)), this, SLOT(setOnlyOneAssistantSnap(bool))); - addOptionWidgetOption(m_chkOnlyOneAssistant, snapSingleLabel); + // hide all the custom stabilizer settings by default + slotCustomSettingsChecked(false); + slotUseAssistants(false); // initialize to not snap to assistants - // set the assistant snapping options to hidden by default and toggle their visibility based based off snapping checkbox - m_sliderMagnetism->setVisible(false); - m_chkOnlyOneAssistant->setVisible(false); - snapSingleLabel->setVisible(false); - magnetismLabel->setVisible(false); + return optionsWidget; +} - connect(m_chkAssistant, SIGNAL(toggled(bool)), m_sliderMagnetism, SLOT(setVisible(bool))); - connect(m_chkAssistant, SIGNAL(toggled(bool)), m_chkOnlyOneAssistant, SLOT(setVisible(bool))); - connect(m_chkAssistant, SIGNAL(toggled(bool)), snapSingleLabel, SLOT(setVisible(bool))); - connect(m_chkAssistant, SIGNAL(toggled(bool)), magnetismLabel, SLOT(setVisible(bool))); +void KisToolBrush::slotCustomSettingsChecked(bool checked) +{ + // toggle on/off the smoothing type combo box part and disable/enable the slider + m_toolBrushOptions->smoothTypeLabel->setVisible(checked); + m_toolBrushOptions->smoothingTypeCombobox->setVisible(checked); + m_toolBrushOptions->stabilizerStrengthSlider->setEnabled(!checked); + + // hide all settings if we are not using custom settings + if (!checked) { + hideAllStabilizerUIFields(); + } else { + updateStabilizerSettingsVisibility(m_toolBrushOptions->smoothingTypeCombobox->currentIndex()); + } +} - KisConfig cfg; - slotSetSmoothingType(cfg.lineSmoothingType()); +void KisToolBrush::hideAllStabilizerUIFields() +{ + m_toolBrushOptions->distanceLabel->setVisible(false); + m_toolBrushOptions->distanceInputbox->setVisible(false); + m_toolBrushOptions->strokeEndingLabel->setVisible(false); + m_toolBrushOptions->strokeEndingInputbox->setVisible(false); + m_toolBrushOptions->enableStabilizerDelay->setVisible(false); + m_toolBrushOptions->stabilizerDelayInput->setVisible(false); + + m_toolBrushOptions->smoothPressureCheckbox->setVisible(false); + m_toolBrushOptions->scalableDistanceCheckbox->setVisible(false); + m_toolBrushOptions->finishLineCheckbox->setVisible(false); + m_toolBrushOptions->stabilizeSensorsCheckbox->setVisible(false); +} - return optionsWidget; +void KisToolBrush::updateStabilizerSettingsVisibility(int smoothingTypeIndex) { + + if (!m_toolBrushOptions) { + return; + } + + switch (smoothingTypeIndex) { + case 0: + m_toolBrushOptions->distanceLabel->setVisible(false); + m_toolBrushOptions->distanceInputbox->setVisible(false); + m_toolBrushOptions->strokeEndingLabel->setVisible(false); + m_toolBrushOptions->strokeEndingInputbox->setVisible(false); + m_toolBrushOptions->enableStabilizerDelay->setVisible(false); + m_toolBrushOptions->stabilizerDelayInput->setVisible(false); + + m_toolBrushOptions->smoothPressureCheckbox->setVisible(false); + m_toolBrushOptions->scalableDistanceCheckbox->setVisible(false); + m_toolBrushOptions->finishLineCheckbox->setVisible(false); + m_toolBrushOptions->stabilizeSensorsCheckbox->setVisible(false); + + break; + case 1: + m_toolBrushOptions->distanceLabel->setVisible(false); + m_toolBrushOptions->distanceInputbox->setVisible(false); + m_toolBrushOptions->strokeEndingLabel->setVisible(false); + m_toolBrushOptions->strokeEndingInputbox->setVisible(false); + m_toolBrushOptions->enableStabilizerDelay->setVisible(false); + m_toolBrushOptions->stabilizerDelayInput->setVisible(false); + + m_toolBrushOptions->smoothPressureCheckbox->setVisible(false); + m_toolBrushOptions->scalableDistanceCheckbox->setVisible(false); + m_toolBrushOptions->finishLineCheckbox->setVisible(false); + m_toolBrushOptions->stabilizeSensorsCheckbox->setVisible(false); + + break; + case 2: + m_toolBrushOptions->distanceLabel->setVisible(true); + m_toolBrushOptions->distanceInputbox->setVisible(true); + m_toolBrushOptions->strokeEndingLabel->setVisible(true); + m_toolBrushOptions->strokeEndingInputbox->setVisible(true); + m_toolBrushOptions->enableStabilizerDelay->setVisible(false); + m_toolBrushOptions->stabilizerDelayInput->setVisible(false); + + m_toolBrushOptions->smoothPressureCheckbox->setVisible(true); + m_toolBrushOptions->scalableDistanceCheckbox->setVisible(true); + m_toolBrushOptions->finishLineCheckbox->setVisible(false); + m_toolBrushOptions->stabilizeSensorsCheckbox->setVisible(false); + + break; + case 3: + default: + m_toolBrushOptions->distanceLabel->setVisible(true); + m_toolBrushOptions->distanceInputbox->setVisible(true); + m_toolBrushOptions->strokeEndingLabel->setVisible(false); + m_toolBrushOptions->strokeEndingInputbox->setVisible(false); + m_toolBrushOptions->enableStabilizerDelay->setVisible(true); + m_toolBrushOptions->stabilizerDelayInput->setVisible(true); + + m_toolBrushOptions->smoothPressureCheckbox->setVisible(true); + m_toolBrushOptions->scalableDistanceCheckbox->setVisible(false); + m_toolBrushOptions->finishLineCheckbox->setVisible(true); + m_toolBrushOptions->stabilizeSensorsCheckbox->setVisible(true); + } } +void KisToolBrush::slotUseAssistants(bool isUsing) +{ + // hide UI elements if we are not snapping to assistants + m_toolBrushOptions->magnetismLabel->setVisible(isUsing); + m_toolBrushOptions->magnetismInputbox->setVisible(isUsing); + m_toolBrushOptions->snapSingleCheckbox->setVisible(isUsing); + setAssistant(isUsing); + +} diff --git a/plugins/tools/basictools/kis_tool_brush_tooloptionswidget.h b/plugins/tools/basictools/kis_tool_brush_tooloptionswidget.h new file mode 100644 --- /dev/null +++ b/plugins/tools/basictools/kis_tool_brush_tooloptionswidget.h @@ -0,0 +1,36 @@ +/* + Copyright (C) 2017 Scott Petrovic + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + + +#ifndef KISTOOLBRUSHOPTIONSCONFIG_H +#define KISTOOLBRUSHOPTIONSCONFIG_H + +#include "ui_wdgfreehandbrushoptions.h" + + +class KisToolBrushToolOptionsWidget : public QWidget, public Ui::WdgFreehandBrushOptions +{ + Q_OBJECT + +public: + KisToolBrushToolOptionsWidget(QWidget *parent=0); + ~KisToolBrushToolOptionsWidget() override; + +}; + +#endif // KISTOOLBRUSHOPTIONSCONFIG_H diff --git a/plugins/tools/basictools/kis_tool_brush_tooloptionswidget.cpp b/plugins/tools/basictools/kis_tool_brush_tooloptionswidget.cpp new file mode 100644 --- /dev/null +++ b/plugins/tools/basictools/kis_tool_brush_tooloptionswidget.cpp @@ -0,0 +1,32 @@ +/* + Copyright (C) 2017 Scott Petrovic + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + + +#include +#include "kis_tool_brush_tooloptionswidget.h" + +KisToolBrushToolOptionsWidget::KisToolBrushToolOptionsWidget(QWidget* parent) + : QWidget(parent) +{ + setupUi(this); +} + + +KisToolBrushToolOptionsWidget::~KisToolBrushToolOptionsWidget() +{ +} diff --git a/plugins/tools/basictools/kis_tool_multihand_config.h b/plugins/tools/basictools/kis_tool_multihand_config.h --- a/plugins/tools/basictools/kis_tool_multihand_config.h +++ b/plugins/tools/basictools/kis_tool_multihand_config.h @@ -31,14 +31,6 @@ KisToolMultiHandConfigWidget(QWidget *parent=0); ~KisToolMultiHandConfigWidget() override; -//Q_SIGNALS: - - -//public Q_SLOTS: - //void cropTypeSelectableChanged(); - -//private: - //KisToolCrop* m_cropTool; }; #endif // KISTOOLMULTIHANDCONFIG_H