harbour-seaprint/qml/components/IntegerSetting.qml

70 lines
1.8 KiB
QML
Raw Normal View History

2021-07-11 15:27:03 +03:00
import QtQuick 2.6
2019-12-01 22:27:00 +03:00
import Sailfish.Silica 1.0
Setting {
2022-07-31 20:48:14 +03:00
property int minimum_high: 0
property int low: _valid ? parent.printer.attrs[name+"-supported"].value.low : (minimum_high != 0) ? 1 : 0
property int high: _valid ? ensure_minimum(parent.printer.attrs[name+"-supported"].value.high) : minimum_high
function ensure_minimum(orig)
{
if(orig < minimum_high)
{
return minimum_high;
}
else
{
return orig;
}
}
2019-12-01 22:27:00 +03:00
property bool suppressChange: false
2021-07-31 13:36:04 +03:00
displayValue: choice != undefined ? choice : default_choice
2019-12-01 22:27:00 +03:00
onChoiceChanged: {
if(choice == undefined)
{
suppressChange = true;
slider.value = slider.minimumValue;
suppressChange = false;
}
}
2020-11-23 22:29:59 +03:00
menu: ContextMenu {
2019-12-01 22:27:00 +03:00
MenuItem {
Slider
{
id: slider
2019-12-01 22:27:00 +03:00
minimumValue: low
2021-12-05 15:23:14 +03:00
maximumValue: high < 50 ? high : 50
2019-12-01 22:27:00 +03:00
width: parent.width
stepSize: 1
onValueChanged:
{
if(!suppressChange)
{
choice = value;
}
2019-12-01 22:27:00 +03:00
}
}
IconButton
{
anchors.right: parent.right
icon.source: "image://theme/icon-s-edit"
onClicked: {var dialog = pageStack.push(Qt.resolvedUrl("IntegerInputDialog.qml"),
{value: choice, title: prettyName,
min: low, max: high});
dialog.accepted.connect(function() {
choice = dialog.value;
})
}
}
}
}
}