Meshroom/meshroom/ui/qml/Controls/IntSelector.qml
Candice Bentéjac 0e71f2a520 [qt6] Update versions for all the imported modules
Qt3D.Extras cannot be updated to 2.6 yet, otherwise there are errors.
2024-11-07 18:09:01 +01:00

93 lines
No EOL
2.2 KiB
QML

import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import MaterialIcons 2.2
/*
* IntSelector with arrows and a text input to select a number
*/
Row {
id: root
property string tooltipText: ""
property int value: 0
property var range: { "min" : 0, "max" : 0 }
Layout.alignment: Qt.AlignVCenter
spacing: 0
property bool displayButtons: previousIntButton.hovered || intInputMouseArea.containsMouse || nextIntButton.hovered
property real buttonsOpacity: displayButtons ? 1.0 : 0.0
MaterialToolButton {
id: previousIntButton
opacity: buttonsOpacity
width: 10
text: MaterialIcons.navigate_before
ToolTip.text: "Previous"
onClicked: {
if (value > range.min) {
value -= 1
}
}
}
TextInput {
id: intInput
ToolTip.text: tooltipText
ToolTip.visible: tooltipText && intInputMouseArea.containsMouse
width: intMetrics.width
height: previousIntButton.height
color: palette.text
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
selectByMouse: true
text: value
onEditingFinished: {
// We first assign the frame to the entered text even if it is an invalid frame number. We do it for extreme cases, for example without doing it, if we are at 0, and put a negative number, value would be still 0 and nothing happens but we will still see the wrong number
value = parseInt(text)
value = Math.min(range.max, Math.max(range.min, parseInt(text)))
focus = false
}
MouseArea {
id: intInputMouseArea
anchors.fill: parent
hoverEnabled: true
acceptedButtons: Qt.NoButton
propagateComposedEvents: true
}
}
MaterialToolButton {
id: nextIntButton
width: 10
opacity: buttonsOpacity
text: MaterialIcons.navigate_next
ToolTip.text: "Next"
onClicked: {
if (value < range.max) {
value += 1
}
}
}
TextMetrics {
id: intMetrics
font: intInput.font
text: "10000"
}
}