Qt: Support binding settings to QSliders
This commit is contained in:
parent
5bf85a5f3f
commit
5272ecd572
|
@ -8,6 +8,7 @@
|
||||||
#include <QtWidgets/QCheckBox>
|
#include <QtWidgets/QCheckBox>
|
||||||
#include <QtWidgets/QComboBox>
|
#include <QtWidgets/QComboBox>
|
||||||
#include <QtWidgets/QLineEdit>
|
#include <QtWidgets/QLineEdit>
|
||||||
|
#include <QtWidgets/QSlider>
|
||||||
|
|
||||||
namespace SettingWidgetBinder {
|
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.
|
/// Binds a widget's value to a setting, updating it when the value changes.
|
||||||
|
|
||||||
template<typename WidgetType>
|
template<typename WidgetType>
|
||||||
|
|
Loading…
Reference in New Issue