Qt: Support binding settings to QSliders

This commit is contained in:
Connor McLaughlin 2020-01-29 00:01:35 +10:00
parent 5bf85a5f3f
commit 5272ecd572
1 changed files with 20 additions and 0 deletions

View File

@ -8,6 +8,7 @@
#include <QtWidgets/QCheckBox>
#include <QtWidgets/QComboBox>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QSlider>
namespace SettingWidgetBinder {
@ -90,6 +91,25 @@ struct SettingAccessor<QCheckBox>
}
};
template<>
struct SettingAccessor<QSlider>
{
static bool getBoolValue(const QSlider* widget) { return widget->value() > 0; }
static void setBoolValue(QSlider* widget, bool value) { widget->setValue(value ? 1 : 0); }
static int getIntValue(const QSlider* widget) { return widget->value(); }
static void setIntValue(QSlider* widget, int value) { widget->setValue(value); }
static QString getStringValue(const QSlider* widget) { return QStringLiteral("%1").arg(widget->value()); }
static void setStringValue(QSlider* widget, const QString& value) { widget->setValue(value.toInt()); }
template<typename F>
static void connectValueChanged(QSlider* widget, F func)
{
widget->connect(widget, &QSlider::valueChanged, func);
}
};
/// Binds a widget's value to a setting, updating it when the value changes.
template<typename WidgetType>