Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.
C++
Fix the smoothing sliders to actually save their values
Dmitry Kazakovfe3711346886
diff --git a/libs/ui/kis_aspect_ratio_locker.h b/libs/ui/kis_aspect_ratio_locker.hindex 0d09727c2b..e6ad90af9a 100644--- a/libs/ui/kis_aspect_ratio_locker.h+++ b/libs/ui/kis_aspect_ratio_locker.h@@ -17,6 +17,32 @@ class KisSliderSpinBox;class KisDoubleSliderSpinBox;class KoAspectButton;++/**+ * KisAspectRatioLocker is a class for locking the ratio between two sliders,+ * i.e. to keep width and height of the image proportional.+ *+ * When the locker takes responsibility of two sliders and a button, you+ * should **not** use the valueChanged() and toggled() signals of+ * the sliders and the button themselves. Instead you need to connect to+ * the corresponding signals of the locker.+ *+ * Usage:+ *+ * \code{.cpp}+ *+ * KisIntParseSpinBox *intRoundCornersX = ...;+ * KisIntParseSpinBox *intRoundCornersY = ...;+ * KoAspectButton *cornersAspectButton = ...;+ *+ * auto *cornersAspectLocker = new KisAspectRatioLocker(this);+ * cornersAspectLocker->connectSpinBoxes(intRoundCornersX, intRoundCornersY, cornersAspectButton);+ *+ * connect(cornersAspectLocker, SIGNAL(sliderValueChanged()), SLOT(slotRoundCornersChanged()));+ * connect(cornersAspectLocker, SIGNAL(aspectButtonChanged()), SLOT(slotRoundCornersAspectLockChanged()));+ *+ * \endcode+ */class KRITAUI_EXPORT KisAspectRatioLocker : public QObject{Q_OBJECT@@ -24,13 +50,48 @@ public:KisAspectRatioLocker(QObject *parent = 0);~KisAspectRatioLocker() override;+ /**+ * Link two spin boxes and an aspect button together+ */template <class SpinBoxType>void connectSpinBoxes(SpinBoxType *spinOne, SpinBoxType *spinTwo, KoAspectButton *aspectButton);+ /**+ * Link two angular spin boxes and an aspect button together+ */template <class AngleBoxType>void connectAngleBoxes(AngleBoxType *spinOne, AngleBoxType *spinTwo, KoAspectButton *aspectButton);+ /**+ * Selects whether sliderValueChanged() signal should be emitted+ * continuously while the user drags one of the slider or only+ * once when the drag operation is completed+ */void setBlockUpdateSignalOnDrag(bool block);++ /**+ * Recalculate and lock the new aspect ratio of the sliders.+ * The function takes the current values of the sliders and+ * calculates the new ratio based on them.+ *+ * This function is expected to be used when a saved value+ * is restored into the sliders. Make sure that you block+ * signals of the controls while loading values.+ *+ * Usage:+ *+ * \code{.cpp}+ *+ * // load values in a locked state+ * KisSignalsBlocker b(intRoundCornersX, intRoundCornersY, cornersAspectButton);+ * intRoundCornersX->setValue(cfg.readEntry("roundCornersX", 0));+ * intRoundCornersY->setValue(cfg.readEntry("roundCornersY", 0));+ * cornersAspectButton->setKeepAspectRatio(cfg.readEntry("roundCornersAspectLocked", true));+ *+ * // update new aspect ratio+ * cornersAspectLocker->updateAspect();+ * \endcode+ */void updateAspect();private Q_SLOTS:@@ -40,8 +101,25 @@ private Q_SLOTS:void slotSpinDraggingFinished();Q_SIGNALS:+ /**+ * Emitted when a value of any of the sliders has changed+ * and all aspect corrections have been completed.+ *+ * You should use this signal instead of the own signals+ * of the sliders, because these signals might be either+ * blocked or come in undefined order.+ */void sliderValueChanged();++ /**+ * Emitted when the aspec locking button state is changed.+ */void aspectButtonChanged();++ /**+ * Emitted when the aspec locking button state is changed,+ * but also passing its new state.+ */void aspectButtonToggled(bool value);private:diff --git a/plugins/tools/basictools/kis_tool_brush.cc b/plugins/tools/basictools/kis_tool_brush.ccindex 6271a337e7..fb13f461c0 100644--- a/plugins/tools/basictools/kis_tool_brush.cc+++ b/plugins/tools/basictools/kis_tool_brush.cc@@ -432,10 +432,7 @@ QWidget * KisToolBrush::createOptionWidget()updateSmoothnessDistanceLabel();// make sure that initialization of the value happens **after** we// have configured the slider's range in updateSmoothnessDistanceLabel()- connect(m_sliderSmoothnessDistanceMin, SIGNAL(valueChanged(qreal)), SLOT(slotSetSmoothnessDistanceMin(qreal)));m_sliderSmoothnessDistanceMin->setValue(smoothingOptions()->smoothnessDistanceMin());-- connect(m_sliderSmoothnessDistanceMax, SIGNAL(valueChanged(qreal)), SLOT(slotSetSmoothnessDistanceMax(qreal)));m_sliderSmoothnessDistanceMax->setValue(smoothingOptions()->smoothnessDistanceMax());// Create KoAspectButton@@ -443,7 +440,6 @@ QWidget * KisToolBrush::createOptionWidget()m_distanceAspectButton->setKeepAspectRatio(smoothingOptions()->smoothnessDistanceKeepAspectRatio());m_distanceAspectButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);m_distanceAspectButton->setMinimumSize(QSize(24, 24));- connect(m_distanceAspectButton, SIGNAL(keepAspectRatioChanged(bool)), SLOT(slotSetSmoothnessDistanceKeepAspectRatio(bool)));// Add distanceLabelsQWidget* distanceLabelWidget = new QWidget(optionsWidget);@@ -468,6 +464,14 @@ QWidget * KisToolBrush::createOptionWidget()KisAspectRatioLocker *distanceAspectLocker = new KisAspectRatioLocker(this);distanceAspectLocker->connectSpinBoxes(m_sliderSmoothnessDistanceMin, m_sliderSmoothnessDistanceMax, m_distanceAspectButton);+ connect(distanceAspectLocker, &KisAspectRatioLocker::aspectButtonToggled,+ this, &KisToolBrush::slotSetSmoothnessDistanceKeepAspectRatio);++ connect(distanceAspectLocker, &KisAspectRatioLocker::sliderValueChanged, this, [this]() {+ slotSetSmoothnessDistanceMin(m_sliderSmoothnessDistanceMin->value());+ slotSetSmoothnessDistanceMax(m_sliderSmoothnessDistanceMax->value());+ });+// Finish stabilizer curvem_chkFinishStabilizedCurve = new QCheckBox(optionsWidget);connect(m_chkFinishStabilizedCurve, SIGNAL(toggled(bool)), this, SLOT(setFinishStabilizedCurve(bool)));