diff --git a/data/pref.xml b/data/pref.xml
index ec102f34d59..69d6d12aea6 100644
--- a/data/pref.xml
+++ b/data/pref.xml
@@ -317,9 +317,22 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/app/ui/context_bar.cpp b/src/app/ui/context_bar.cpp
index ae4697c6c78..e6a30b7f45d 100644
--- a/src/app/ui/context_bar.cpp
+++ b/src/app/ui/context_bar.cpp
@@ -1164,22 +1164,15 @@ class ContextBar::DynamicsField : public ButtonSet
if (!m_popup.get())
m_popup.reset(new DynamicsPopup(this));
- auto activeTool = App::instance()->activeTool();
- m_popup->loadDynamicsPref();
- m_dynamics = m_popup->getDynamics();
m_sameInAllTools = m_popup->sharedSettings();
+ m_popup->loadDynamicsPref(m_sameInAllTools);
+ m_dynamics = m_popup->getDynamics();
m_popup->Close.connect(
[this](CloseEvent&) {
deselectItems();
- auto activeTool = App::instance()->activeTool();
m_dynamics = m_popup->getDynamics();
m_sameInAllTools = m_popup->sharedSettings();
- if (m_sameInAllTools) {
- for (Tool* tool : *App::instance()->toolBox())
- saveDynamicsPref(tool);
- }
- else
- saveDynamicsPref(activeTool);
+ saveDynamicsPref(App::instance()->activeTool());
});
m_popup->refreshVisibility();
@@ -1207,45 +1200,87 @@ class ContextBar::DynamicsField : public ButtonSet
}
void saveDynamicsPref(Tool* tool) {
- auto& dynaPref = Preferences::instance().tool(tool).dynamics;
- dynaPref.stabilizer(m_dynamics.stabilizer);
- dynaPref.stabilizerFactor(m_dynamics.stabilizerFactor);
- dynaPref.size(m_dynamics.size);
- dynaPref.angle(m_dynamics.angle);
- dynaPref.gradient(m_dynamics.gradient);
- dynaPref.minSize.setValue(m_dynamics.minSize);
- dynaPref.minAngle.setValue(m_dynamics.minAngle);
- dynaPref.minPressureThreshold(m_dynamics.minPressureThreshold);
- dynaPref.minVelocityThreshold(m_dynamics.minVelocityThreshold);
- dynaPref.maxPressureThreshold(m_dynamics.maxPressureThreshold);
- dynaPref.maxVelocityThreshold(m_dynamics.maxVelocityThreshold);
- dynaPref.colorFromTo(m_dynamics.colorFromTo);
- dynaPref.matrixIndex(m_popup->ditheringIndex());
+ m_sameInAllTools = m_popup->sharedSettings();
Preferences::instance().shared.shareDynamics(m_sameInAllTools);
+
+ if (m_sameInAllTools) {
+ auto& sharedPref = Preferences::instance().shared;
+ sharedPref.stabilizer(m_dynamics.stabilizer);
+ sharedPref.stabilizerFactor(m_dynamics.stabilizerFactor);
+ sharedPref.size(m_dynamics.size);
+ sharedPref.angle(m_dynamics.angle);
+ sharedPref.gradient(m_dynamics.gradient);
+ sharedPref.minSize.setValue(m_dynamics.minSize);
+ sharedPref.minAngle.setValue(m_dynamics.minAngle);
+ sharedPref.minPressureThreshold(m_dynamics.minPressureThreshold);
+ sharedPref.minVelocityThreshold(m_dynamics.minVelocityThreshold);
+ sharedPref.maxPressureThreshold(m_dynamics.maxPressureThreshold);
+ sharedPref.maxVelocityThreshold(m_dynamics.maxVelocityThreshold);
+ sharedPref.colorFromTo(m_dynamics.colorFromTo);
+ sharedPref.matrixIndex(m_popup->ditheringIndex());
+ }
+ else {
+ auto& dynaPref = Preferences::instance().tool(tool).dynamics;
+ dynaPref.stabilizer(m_dynamics.stabilizer);
+ dynaPref.stabilizerFactor(m_dynamics.stabilizerFactor);
+ dynaPref.size(m_dynamics.size);
+ dynaPref.angle(m_dynamics.angle);
+ dynaPref.gradient(m_dynamics.gradient);
+ dynaPref.minSize.setValue(m_dynamics.minSize);
+ dynaPref.minAngle.setValue(m_dynamics.minAngle);
+ dynaPref.minPressureThreshold(m_dynamics.minPressureThreshold);
+ dynaPref.minVelocityThreshold(m_dynamics.minVelocityThreshold);
+ dynaPref.maxPressureThreshold(m_dynamics.maxPressureThreshold);
+ dynaPref.maxVelocityThreshold(m_dynamics.maxVelocityThreshold);
+ dynaPref.colorFromTo(m_dynamics.colorFromTo);
+ dynaPref.matrixIndex(m_popup->ditheringIndex());
+ }
}
void loadDynamicsPref() {
- auto& dynaPref = Preferences::instance()
- .tool(App::instance()->activeTool()).dynamics;
- m_dynamics.stabilizer = dynaPref.stabilizer();
- m_dynamics.stabilizerFactor = dynaPref.stabilizerFactor();
- m_dynamics.size = dynaPref.size();
- m_dynamics.angle = dynaPref.angle();
- m_dynamics.gradient = dynaPref.gradient();
- m_dynamics.minSize = dynaPref.minSize();
- m_dynamics.minAngle = dynaPref.minAngle();
- m_dynamics.minPressureThreshold = dynaPref.minPressureThreshold();
- m_dynamics.minVelocityThreshold = dynaPref.minVelocityThreshold();
- m_dynamics.maxPressureThreshold = dynaPref.maxPressureThreshold();
- m_dynamics.maxVelocityThreshold = dynaPref.maxVelocityThreshold();
- m_dynamics.colorFromTo = dynaPref.colorFromTo();
-
- DitheringSelector matrixSel(DitheringSelector::SelectMatrix);
- matrixSel.setSelectedItemIndex(dynaPref.matrixIndex());
- render::DitheringMatrix matrix(matrixSel.ditheringMatrix());
- m_dynamics.ditheringMatrix = matrix;
-
m_sameInAllTools = Preferences::instance().shared.shareDynamics();
+
+ if (m_sameInAllTools) {
+ auto& sharedPref = Preferences::instance().shared;
+ m_dynamics.stabilizer = sharedPref.stabilizer();
+ m_dynamics.stabilizerFactor = sharedPref.stabilizerFactor();
+ m_dynamics.size = sharedPref.size();
+ m_dynamics.angle = sharedPref.angle();
+ m_dynamics.gradient = sharedPref.gradient();
+ m_dynamics.minSize = sharedPref.minSize();
+ m_dynamics.minAngle = sharedPref.minAngle();
+ m_dynamics.minPressureThreshold = sharedPref.minPressureThreshold();
+ m_dynamics.minVelocityThreshold = sharedPref.minVelocityThreshold();
+ m_dynamics.maxPressureThreshold = sharedPref.maxPressureThreshold();
+ m_dynamics.maxVelocityThreshold = sharedPref.maxVelocityThreshold();
+ m_dynamics.colorFromTo = sharedPref.colorFromTo();
+
+ DitheringSelector matrixSel(DitheringSelector::SelectMatrix);
+ matrixSel.setSelectedItemIndex(sharedPref.matrixIndex());
+ render::DitheringMatrix matrix(matrixSel.ditheringMatrix());
+ m_dynamics.ditheringMatrix = matrix;
+ }
+ else {
+ auto& dynaPref = Preferences::instance()
+ .tool(App::instance()->activeTool()).dynamics;
+ m_dynamics.stabilizer = dynaPref.stabilizer();
+ m_dynamics.stabilizerFactor = dynaPref.stabilizerFactor();
+ m_dynamics.size = dynaPref.size();
+ m_dynamics.angle = dynaPref.angle();
+ m_dynamics.gradient = dynaPref.gradient();
+ m_dynamics.minSize = dynaPref.minSize();
+ m_dynamics.minAngle = dynaPref.minAngle();
+ m_dynamics.minPressureThreshold = dynaPref.minPressureThreshold();
+ m_dynamics.minVelocityThreshold = dynaPref.minVelocityThreshold();
+ m_dynamics.maxPressureThreshold = dynaPref.maxPressureThreshold();
+ m_dynamics.maxVelocityThreshold = dynaPref.maxVelocityThreshold();
+ m_dynamics.colorFromTo = dynaPref.colorFromTo();
+
+ DitheringSelector matrixSel(DitheringSelector::SelectMatrix);
+ matrixSel.setSelectedItemIndex(dynaPref.matrixIndex());
+ render::DitheringMatrix matrix(matrixSel.ditheringMatrix());
+ m_dynamics.ditheringMatrix = matrix;
+ }
}
private:
diff --git a/src/app/ui/dithering_selector.cpp b/src/app/ui/dithering_selector.cpp
index 60933745b12..ba6874b59ac 100644
--- a/src/app/ui/dithering_selector.cpp
+++ b/src/app/ui/dithering_selector.cpp
@@ -198,7 +198,13 @@ void DitheringSelector::onInitTheme(ui::InitThemeEvent& ev)
setSizeHint(getItem(0)->sizeHint());
}
-void DitheringSelector::regenerate()
+void DitheringSelector::setSelectedIndex(int itemIndex)
+{
+ setSelectedItemIndex(itemIndex);
+ regenerate(itemIndex);
+}
+
+void DitheringSelector::regenerate(int selectedItemIndex)
{
deleteAllItems();
@@ -255,9 +261,9 @@ void DitheringSelector::regenerate()
}
break;
}
-
- setSelectedItemIndex(0);
- setSizeHint(getItem(0)->sizeHint());
+ selectedItemIndex = std::min(std::max(0, selectedItemIndex), getItemCount()-1);
+ setSelectedItemIndex(selectedItemIndex);
+ setSizeHint(getItem(selectedItemIndex)->sizeHint());
}
render::DitheringAlgorithm DitheringSelector::ditheringAlgorithm()
diff --git a/src/app/ui/dithering_selector.h b/src/app/ui/dithering_selector.h
index ffbd6493687..f8290695e54 100644
--- a/src/app/ui/dithering_selector.h
+++ b/src/app/ui/dithering_selector.h
@@ -27,13 +27,13 @@ namespace app {
render::DitheringAlgorithm ditheringAlgorithm();
render::DitheringMatrix ditheringMatrix();
+ void setSelectedIndex(int itemIndex);
protected:
void onInitTheme(ui::InitThemeEvent& ev) override;
private:
- void regenerate();
-
+ void regenerate(int selectedItemIndex = 0);
Type m_type;
obs::scoped_connection m_extChanges;
};
diff --git a/src/app/ui/dynamics_popup.cpp b/src/app/ui/dynamics_popup.cpp
index 3cca3d69442..0aa1475e89b 100644
--- a/src/app/ui/dynamics_popup.cpp
+++ b/src/app/ui/dynamics_popup.cpp
@@ -16,6 +16,7 @@
#include "app/ui/skin/skin_theme.h"
#include "os/font.h"
#include "os/surface.h"
+#include "ui/fit_bounds.h"
#include "ui/message.h"
#include "ui/paint_event.h"
#include "ui/scale.h"
@@ -50,6 +51,8 @@ enum {
} // anonymous namespace
+static bool g_same_toggle = false;
+
// Special slider to set the min/max threshold values of a sensor
class DynamicsPopup::ThresholdSlider : public Widget {
public:
@@ -275,7 +278,20 @@ DynamicsPopup::DynamicsPopup(Delegate* delegate)
setHotRegion(m_hotRegion);
}
});
-
+ m_dynamics->sameInAllTools()->Click.connect(
+ [this]{
+ // if sameInAllTools is true here, this means:
+ // "Transition false to true of 'Same in all tools' and the
+ // current parameters in the DynamicsPopup windows are the
+ // old one, i.e non-shared parameters."
+ bool sameInAllTools = m_dynamics->sameInAllTools()->isSelected();
+ // Save the old dynamics options:
+ saveDynamicsPref(!sameInAllTools);
+ Preferences::instance().shared.shareDynamics(sameInAllTools);
+ // Load the new dynamics options:
+ loadDynamicsPref(sameInAllTools);
+ refreshVisibility();
+ });
m_dynamics->gradientPlaceholder()->addChild(m_ditheringSel);
m_dynamics->pressurePlaceholder()->addChild(m_pressureThreshold = new ThresholdSlider);
m_dynamics->velocityPlaceholder()->addChild(m_velocityThreshold = new ThresholdSlider);
@@ -295,39 +311,117 @@ int DynamicsPopup::ditheringIndex() const {
return 0;
}
-void DynamicsPopup::loadDynamicsPref() {
- auto& dynaPref = Preferences::instance().tool(
- App::instance()->activeTool()).dynamics;
- m_dynamics->stabilizer()->setSelected(dynaPref.stabilizer());
- m_stabilizerFactorBackup = dynaPref.stabilizerFactor();
- m_dynamics->stabilizerFactor()->setValue(
- dynaPref.stabilizer() ? m_stabilizerFactorBackup : 0);
- m_dynamics->minSize()->setValue(dynaPref.minSize());
- m_dynamics->minAngle()->setValue(dynaPref.minAngle());
- m_pressureThreshold->minThreshold(dynaPref.minPressureThreshold());
- m_pressureThreshold->maxThreshold(dynaPref.maxPressureThreshold());
- m_velocityThreshold->minThreshold(dynaPref.minVelocityThreshold());
- m_velocityThreshold->maxThreshold(dynaPref.maxVelocityThreshold());
- m_fromTo = dynaPref.colorFromTo();
-
- setCheck(SIZE_WITH_PRESSURE,
- dynaPref.size() == tools::DynamicSensor::Pressure);
- setCheck(SIZE_WITH_VELOCITY,
- dynaPref.size() == tools::DynamicSensor::Velocity);
- setCheck(ANGLE_WITH_PRESSURE,
- dynaPref.angle() == tools::DynamicSensor::Pressure);
- setCheck(ANGLE_WITH_VELOCITY,
- dynaPref.angle() == tools::DynamicSensor::Velocity);
- setCheck(GRADIENT_WITH_PRESSURE,
- dynaPref.gradient() == tools::DynamicSensor::Pressure);
- setCheck(GRADIENT_WITH_VELOCITY,
- dynaPref.gradient() == tools::DynamicSensor::Velocity);
-
- if (m_ditheringSel)
- m_ditheringSel->setSelectedItemIndex(dynaPref.matrixIndex());
+void DynamicsPopup::loadDynamicsPref(bool sameInAllTools) {
+ m_dynamics->sameInAllTools()->setSelected(sameInAllTools);
+ if (sameInAllTools) {
+ auto sharedPref = &Preferences::instance().shared;
+ m_dynamics->stabilizer()->setSelected(sharedPref->stabilizer());
+ m_stabilizerFactorBackup = sharedPref->stabilizerFactor();
+ m_dynamics->stabilizerFactor()->setValue(
+ sharedPref->stabilizer() ? m_stabilizerFactorBackup : 0);
+ m_dynamics->minSize()->setValue(sharedPref->minSize());
+ m_dynamics->minAngle()->setValue(sharedPref->minAngle());
+ m_pressureThreshold->minThreshold(
+ sharedPref->minPressureThreshold());
+ m_pressureThreshold->maxThreshold(
+ sharedPref->maxPressureThreshold());
+ m_velocityThreshold->minThreshold(
+ sharedPref->minVelocityThreshold());
+ m_velocityThreshold->maxThreshold(
+ sharedPref->maxVelocityThreshold());
+ m_fromTo = sharedPref->colorFromTo();
+
+ setCheck(SIZE_WITH_PRESSURE,
+ sharedPref->size() == tools::DynamicSensor::Pressure);
+ setCheck(SIZE_WITH_VELOCITY,
+ sharedPref->size() == tools::DynamicSensor::Velocity);
+ setCheck(ANGLE_WITH_PRESSURE,
+ sharedPref->angle() == tools::DynamicSensor::Pressure);
+ setCheck(ANGLE_WITH_VELOCITY,
+ sharedPref->angle() == tools::DynamicSensor::Velocity);
+ setCheck(GRADIENT_WITH_PRESSURE,
+ sharedPref->gradient() == tools::DynamicSensor::Pressure);
+ setCheck(GRADIENT_WITH_VELOCITY,
+ sharedPref->gradient() == tools::DynamicSensor::Velocity);
+
+ if (m_ditheringSel)
+ m_ditheringSel->setSelectedIndex(sharedPref->matrixIndex());
+ }
+ else {
+ auto& dynaPref = Preferences::instance().tool(
+ App::instance()->activeTool()).dynamics;
+ m_dynamics->stabilizer()->setSelected(dynaPref.stabilizer());
+ m_stabilizerFactorBackup = dynaPref.stabilizerFactor();
+ m_dynamics->stabilizerFactor()->setValue(
+ dynaPref.stabilizer() ? m_stabilizerFactorBackup : 0);
+ m_dynamics->minSize()->setValue(dynaPref.minSize());
+ m_dynamics->minAngle()->setValue(dynaPref.minAngle());
+ m_pressureThreshold->minThreshold(dynaPref.minPressureThreshold());
+ m_pressureThreshold->maxThreshold(dynaPref.maxPressureThreshold());
+ m_velocityThreshold->minThreshold(dynaPref.minVelocityThreshold());
+ m_velocityThreshold->maxThreshold(dynaPref.maxVelocityThreshold());
+ m_fromTo = dynaPref.colorFromTo();
+
+ setCheck(SIZE_WITH_PRESSURE,
+ dynaPref.size() == tools::DynamicSensor::Pressure);
+ setCheck(SIZE_WITH_VELOCITY,
+ dynaPref.size() == tools::DynamicSensor::Velocity);
+ setCheck(ANGLE_WITH_PRESSURE,
+ dynaPref.angle() == tools::DynamicSensor::Pressure);
+ setCheck(ANGLE_WITH_VELOCITY,
+ dynaPref.angle() == tools::DynamicSensor::Velocity);
+ setCheck(GRADIENT_WITH_PRESSURE,
+ dynaPref.gradient() == tools::DynamicSensor::Pressure);
+ setCheck(GRADIENT_WITH_VELOCITY,
+ dynaPref.gradient() == tools::DynamicSensor::Velocity);
+
+ if (m_ditheringSel)
+ m_ditheringSel->setSelectedIndex(dynaPref.matrixIndex());
+ }
+}
- m_dynamics->sameInAllTools()->setSelected(
- Preferences::instance().shared.shareDynamics());
+void DynamicsPopup::saveDynamicsPref(bool sameInAllTools) {
+ tools::DynamicsOptions dyna = getDynamics();
+
+ if (sameInAllTools) {
+ auto sharedPref = &Preferences::instance().shared;
+ sharedPref->stabilizer(dyna.stabilizer);
+ sharedPref->stabilizerFactor(m_stabilizerFactorBackup);
+ sharedPref->minSize(dyna.minSize);
+ sharedPref->minAngle(dyna.minAngle);
+ sharedPref->minPressureThreshold(dyna.minPressureThreshold);
+ sharedPref->maxPressureThreshold(dyna.maxPressureThreshold);
+ sharedPref->minVelocityThreshold(dyna.minVelocityThreshold);
+ sharedPref->maxVelocityThreshold(dyna.maxVelocityThreshold);
+ sharedPref->colorFromTo(m_fromTo);
+
+ sharedPref->size(dyna.size);
+ sharedPref->angle(dyna.angle);
+ sharedPref->gradient(dyna.gradient);
+
+ if (m_ditheringSel)
+ sharedPref->matrixIndex(m_ditheringSel->getSelectedItemIndex());
+ }
+ else {
+ auto dynaPref = &Preferences::instance().tool(
+ App::instance()->activeTool()).dynamics;
+ dynaPref->stabilizer(dyna.stabilizer);
+ dynaPref->stabilizerFactor(m_stabilizerFactorBackup);
+ dynaPref->minSize(dyna.minSize);
+ dynaPref->minAngle(dyna.minAngle);
+ dynaPref->minPressureThreshold(dyna.minPressureThreshold);
+ dynaPref->maxPressureThreshold(dyna.maxPressureThreshold);
+ dynaPref->minVelocityThreshold(dyna.minVelocityThreshold);
+ dynaPref->maxVelocityThreshold(dyna.maxVelocityThreshold);
+ dynaPref->colorFromTo(m_fromTo);
+
+ dynaPref->size(dyna.size);
+ dynaPref->angle(dyna.angle);
+ dynaPref->gradient(dyna.gradient);
+
+ if (m_ditheringSel)
+ dynaPref->matrixIndex(m_ditheringSel->getSelectedItemIndex());
+ }
}
tools::DynamicsOptions DynamicsPopup::getDynamics() const
diff --git a/src/app/ui/dynamics_popup.h b/src/app/ui/dynamics_popup.h
index 04dd2b51d7c..497a7038905 100644
--- a/src/app/ui/dynamics_popup.h
+++ b/src/app/ui/dynamics_popup.h
@@ -37,7 +37,8 @@ namespace app {
tools::DynamicsOptions getDynamics() const;
void setOptionsGridVisibility(bool state);
- void loadDynamicsPref();
+ void loadDynamicsPref(bool sameInAllTools);
+ void saveDynamicsPref(bool sameInAllTools);
int ditheringIndex() const;
void refreshVisibility();
bool sharedSettings() const;