Cura/resources/qml/Preferences/ReadOnlySpinBox.qml
Jaime van Kessel e182459dba Fix the updating of material diameter.
This was a weeeird bug. It worked if you changed the value and selected another field.
Pressing enter however (aka; The behavior that 80%+ of the users have) would change it
but it would switch back in half a second. It seems to have been caused by mutliple onEditingFinished
signals being emitted in sequence.
As I can't be bothered to go through the bowels of QML and figure out why exactly this is doing what it's doing,
I just tied the enter to losing the focus, which ensures that the right behavior happens (Field is no longer selected,
and the onEditingFinished is emitted)

Contributes to CURA-6590
2019-07-02 15:16:41 +02:00

55 lines
1.3 KiB
QML

// Copyright (c) 2016 Ultimaker B.V.
// Cura is released under the terms of the LGPLv3 or higher.
import QtQuick 2.1
import QtQuick.Controls 1.1
import QtQuick.Dialogs 1.2
Item
{
id: base
property alias value: spinBox.value
property alias minimumValue: spinBox.minimumValue
property alias maximumValue: spinBox.maximumValue
property alias stepSize: spinBox.stepSize
property alias prefix: spinBox.prefix
property alias suffix: spinBox.suffix
property alias decimals: spinBox.decimals
signal editingFinished();
property bool readOnly: false
width: spinBox.width
height: spinBox.height
SpinBox
{
id: spinBox
enabled: !base.readOnly
opacity: base.readOnly ? 0.5 : 1.0
anchors.fill: parent
onEditingFinished: base.editingFinished()
Keys.onEnterPressed: spinBox.focus = false
Keys.onReturnPressed: spinBox.focus = false
}
Label
{
visible: base.readOnly
text: base.prefix + base.value.toFixed(spinBox.decimals) + base.suffix
anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left
anchors.leftMargin: spinBox.__style ? spinBox.__style.padding.left : 0
color: palette.buttonText
}
SystemPalette { id: palette }
}