Dim values of unset settings (that are showing the default)

Add a reset option.
This commit is contained in:
Anton Thomasson 2021-03-20 19:45:30 +01:00
parent 0f890337d3
commit 9246d385b0
10 changed files with 111 additions and 15 deletions

View file

@ -5,20 +5,35 @@ Setting {
property int low property int low
property int high property int high
property bool suppressChange: false
displayValue: choice ? choice : default_choice displayValue: choice ? choice : default_choice
onChoiceChanged: {
if(choice == undefined)
{
console.log("choice unset");
suppressChange = true;
slider.value = slider.minimumValue;
suppressChange = false;
}
}
menu: ContextMenu { menu: ContextMenu {
MenuItem { MenuItem {
Slider Slider
{ {
id: slider
minimumValue: low minimumValue: low
maximumValue: high < 100 ? high : 100 maximumValue: high < 100 ? high : 100
width: parent.width width: parent.width
stepSize: 1 stepSize: 1
value: choice ? choice : default_choice
onValueChanged: onValueChanged:
{ {
choice = value; if(!suppressChange)
{
choice = value;
}
} }
} }
IconButton IconButton

View file

@ -6,29 +6,47 @@ Setting {
property int choice_low: 1 property int choice_low: 1
property int choice_high: 0 property int choice_high: 0
property bool suppressChange: false
function update_choice() { function update_choice() {
choice = new Object({low: choice_low, high: choice_high}); choice = new Object({low: choice_low, high: choice_high});
} }
onChoice_highChanged: { onChoice_highChanged: {
if(choice_high < choice_low) if(!suppressChange)
{ {
low_slider.value = choice_high > 0 ? choice_high : 1; if(choice_high < choice_low)
} {
else low_slider.value = choice_high > 0 ? choice_high : 1;
{ }
update_choice() else
{
update_choice()
}
} }
} }
onChoice_lowChanged: { onChoice_lowChanged: {
if(choice_low > choice_high) if(!suppressChange)
{ {
high_slider.value = choice_low if(choice_low > choice_high)
{
high_slider.value = choice_low
}
else
{
update_choice()
}
} }
else }
onChoiceChanged: {
if(choice == undefined)
{ {
update_choice() console.log("choice unset");
suppressChange = true;
low_slider.value = low_slider.minimumValue;
high_slider.value = high_slider.minimumValue;
suppressChange = false;
} }
} }
@ -43,7 +61,6 @@ Setting {
maximumValue: high > 100 ? 100 : high maximumValue: high > 100 ? 100 : high
width: parent.width width: parent.width
stepSize: 1 stepSize: 1
value: choice_low
onValueChanged: onValueChanged:
{ {
choice_low = value; choice_low = value;
@ -72,7 +89,6 @@ Setting {
maximumValue: high > 100 ? 100 : high maximumValue: high > 100 ? 100 : high
width: parent.width width: parent.width
stepSize: 1 stepSize: 1
value: choice_high
onValueChanged: onValueChanged:
{ {
choice_high = value; choice_high = value;

View file

@ -2,7 +2,7 @@ import QtQuick 2.0
import Sailfish.Silica 1.0 import Sailfish.Silica 1.0
Item { Item {
height: button.height + (menu != undefined ? menu.height : 0) height: button.height + (menu != undefined ? menu.height : 0) + resetMenu.height
width: parent.width width: parent.width
property string name property string name
@ -21,6 +21,11 @@ Item {
} }
} }
signal pressAndHold()
onPressAndHold: {
resetMenu.open(this)
}
property alias displayValue: button.value property alias displayValue: button.value
ValueButton { ValueButton {
@ -28,9 +33,20 @@ Item {
enabled: valid enabled: valid
label: prettyName label: prettyName
onClicked: parent.clicked() onClicked: parent.clicked()
onPressAndHold: parent.pressAndHold()
valueColor: choice != undefined ? Theme.highlightColor : Theme.secondaryHighlightColor
} }
property var menu property var menu
property bool hasMenu: true property bool hasMenu: true
ContextMenu {
id: resetMenu
MenuItem {
text: qsTr("Reset")
onClicked: choice = undefined
}
}
} }

View file

@ -450,6 +450,13 @@
<translation>Alle</translation> <translation>Alle</translation>
</message> </message>
</context> </context>
<context>
<name>Setting</name>
<message>
<source>Reset</source>
<translation type="unfinished"></translation>
</message>
</context>
<context> <context>
<name>SettingsPage</name> <name>SettingsPage</name>
<message> <message>

View file

@ -450,6 +450,13 @@
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
</context> </context>
<context>
<name>Setting</name>
<message>
<source>Reset</source>
<translation type="unfinished"></translation>
</message>
</context>
<context> <context>
<name>SettingsPage</name> <name>SettingsPage</name>
<message> <message>

View file

@ -450,6 +450,13 @@
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
</context> </context>
<context>
<name>Setting</name>
<message>
<source>Reset</source>
<translation type="unfinished"></translation>
</message>
</context>
<context> <context>
<name>SettingsPage</name> <name>SettingsPage</name>
<message> <message>

View file

@ -450,6 +450,13 @@
<translation>alles</translation> <translation>alles</translation>
</message> </message>
</context> </context>
<context>
<name>Setting</name>
<message>
<source>Reset</source>
<translation type="unfinished"></translation>
</message>
</context>
<context> <context>
<name>SettingsPage</name> <name>SettingsPage</name>
<message> <message>

View file

@ -450,6 +450,13 @@
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
</context> </context>
<context>
<name>Setting</name>
<message>
<source>Reset</source>
<translation type="unfinished"></translation>
</message>
</context>
<context> <context>
<name>SettingsPage</name> <name>SettingsPage</name>
<message> <message>

View file

@ -450,6 +450,13 @@
<translation></translation> <translation></translation>
</message> </message>
</context> </context>
<context>
<name>Setting</name>
<message>
<source>Reset</source>
<translation type="unfinished"></translation>
</message>
</context>
<context> <context>
<name>SettingsPage</name> <name>SettingsPage</name>
<message> <message>

View file

@ -450,6 +450,13 @@
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
</context> </context>
<context>
<name>Setting</name>
<message>
<source>Reset</source>
<translation type="unfinished"></translation>
</message>
</context>
<context> <context>
<name>SettingsPage</name> <name>SettingsPage</name>
<message> <message>