mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 19:08:58 +03:00
Fix setting double values in setting spinboxes
This commit is contained in:
parent
34abae0c42
commit
c59bb67569
3 changed files with 46 additions and 8 deletions
|
@ -118,7 +118,7 @@ Rectangle {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DelegateChoice {
|
DelegateChoice {
|
||||||
roleValue: UserSettingsModel.Number
|
roleValue: UserSettingsModel.Integer
|
||||||
|
|
||||||
SpinBox {
|
SpinBox {
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
|
@ -129,6 +129,42 @@ Rectangle {
|
||||||
stepSize: model.valueStep
|
stepSize: model.valueStep
|
||||||
value: model.value
|
value: model.value
|
||||||
onValueChanged: model.value = value
|
onValueChanged: model.value = value
|
||||||
|
editable: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DelegateChoice {
|
||||||
|
roleValue: UserSettingsModel.Double
|
||||||
|
|
||||||
|
SpinBox {
|
||||||
|
id: spinbox
|
||||||
|
|
||||||
|
readonly property double div: 100
|
||||||
|
readonly property int decimals: 2
|
||||||
|
|
||||||
|
anchors.right: parent.right
|
||||||
|
width: Math.min(parent.width, implicitWidth)
|
||||||
|
enabled: !deadTimer.running && model.enabled
|
||||||
|
from: model.valueLowerBound * div
|
||||||
|
to: model.valueUpperBound * div
|
||||||
|
stepSize: model.valueStep * div
|
||||||
|
value: model.value * div
|
||||||
|
onValueChanged: model.value = value/div
|
||||||
|
editable: true
|
||||||
|
|
||||||
|
property real realValue: value / div
|
||||||
|
|
||||||
|
validator: DoubleValidator {
|
||||||
|
bottom: Math.min(spinbox.from/spinbox.div, spinbox.to/spinbox.div)
|
||||||
|
top: Math.max(spinbox.from/spinbox.div, spinbox.to/spinbox.div)
|
||||||
|
}
|
||||||
|
|
||||||
|
textFromValue: function(value, locale) {
|
||||||
|
return Number(value / spinbox.div).toLocaleString(locale, 'f', spinbox.decimals)
|
||||||
|
}
|
||||||
|
|
||||||
|
valueFromText: function(text, locale) {
|
||||||
|
return Number.fromLocaleString(locale, text) * spinbox.div
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DelegateChoice {
|
DelegateChoice {
|
||||||
|
|
|
@ -1160,9 +1160,10 @@ UserSettingsModel::data(const QModelIndex &index, int role) const
|
||||||
return Options;
|
return Options;
|
||||||
case TimelineMaxWidth:
|
case TimelineMaxWidth:
|
||||||
case PrivacyScreenTimeout:
|
case PrivacyScreenTimeout:
|
||||||
|
return Integer;
|
||||||
case FontSize:
|
case FontSize:
|
||||||
case ScaleFactor:
|
case ScaleFactor:
|
||||||
return Number;
|
return Double;
|
||||||
case MessageHoverHighlight:
|
case MessageHoverHighlight:
|
||||||
case EnlargeEmojiOnlyMessages:
|
case EnlargeEmojiOnlyMessages:
|
||||||
case Tray:
|
case Tray:
|
||||||
|
@ -1345,7 +1346,7 @@ UserSettingsModel::setData(const QModelIndex &index, const QVariant &value, int
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
case ScaleFactor: {
|
case ScaleFactor: {
|
||||||
if (value.canConvert<double>()) {
|
if (value.canConvert(QMetaType::Double)) {
|
||||||
utils::setScaleFactor(static_cast<float>(value.toDouble()));
|
utils::setScaleFactor(static_cast<float>(value.toDouble()));
|
||||||
return true;
|
return true;
|
||||||
} else
|
} else
|
||||||
|
@ -1415,7 +1416,7 @@ UserSettingsModel::setData(const QModelIndex &index, const QVariant &value, int
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
case TimelineMaxWidth: {
|
case TimelineMaxWidth: {
|
||||||
if (value.userType() == QMetaType::Int) {
|
if (value.canConvert(QMetaType::Int)) {
|
||||||
i->setTimelineMaxWidth(value.toInt());
|
i->setTimelineMaxWidth(value.toInt());
|
||||||
return true;
|
return true;
|
||||||
} else
|
} else
|
||||||
|
@ -1472,7 +1473,7 @@ UserSettingsModel::setData(const QModelIndex &index, const QVariant &value, int
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
case PrivacyScreenTimeout: {
|
case PrivacyScreenTimeout: {
|
||||||
if (value.userType() == QMetaType::Int) {
|
if (value.canConvert(QMetaType::Int)) {
|
||||||
i->setPrivacyScreenTimeout(value.toInt());
|
i->setPrivacyScreenTimeout(value.toInt());
|
||||||
return true;
|
return true;
|
||||||
} else
|
} else
|
||||||
|
@ -1486,8 +1487,8 @@ UserSettingsModel::setData(const QModelIndex &index, const QVariant &value, int
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
case FontSize: {
|
case FontSize: {
|
||||||
if (value.userType() == QMetaType::Double) {
|
if (value.canConvert(QMetaType::Double)) {
|
||||||
i->setFontSize(value.toBool());
|
i->setFontSize(value.toDouble());
|
||||||
return true;
|
return true;
|
||||||
} else
|
} else
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -438,7 +438,8 @@ public:
|
||||||
Toggle,
|
Toggle,
|
||||||
ReadOnlyText,
|
ReadOnlyText,
|
||||||
Options,
|
Options,
|
||||||
Number,
|
Integer,
|
||||||
|
Double,
|
||||||
SectionTitle,
|
SectionTitle,
|
||||||
SectionBar,
|
SectionBar,
|
||||||
KeyStatus,
|
KeyStatus,
|
||||||
|
|
Loading…
Reference in a new issue