123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- import QtQuick 2.2
- import QtQuick.Layouts 1.1
- import UM 1.0 as UM
- import Cura 1.0 as Cura
- Item
- {
- id: sliderRoot
-
- property real handleSize: UM.Theme.getSize("slider_handle").width
- property real handleRadius: handleSize / 2
- property color handleColor: UM.Theme.getColor("slider_handle")
- property color handleActiveColor: UM.Theme.getColor("slider_handle_active")
- property color rangeColor: UM.Theme.getColor("slider_groove_fill")
- property real handleLabelWidth: width
-
- property real trackThickness: UM.Theme.getSize("slider_groove").width
- property real trackRadius: UM.Theme.getSize("slider_groove_radius").width
- property color trackColor: UM.Theme.getColor("slider_groove")
-
- property real maximumValue: 100
- property real minimumValue: 0
- property bool roundValues: true
- property real handleValue: maximumValue
- property bool pathsVisible: true
- property bool manuallyChanged: true
- function getHandleValueFromSliderHandle()
- {
- return handle.getValue()
- }
- function setHandleValue(value)
- {
- handle.setValue(value)
- updateRangeHandle()
- }
- function updateRangeHandle()
- {
- rangeHandle.width = handle.x - sliderRoot.handleSize
- }
- function normalizeValue(value)
- {
- return Math.min(Math.max(value, sliderRoot.minimumValue), sliderRoot.maximumValue)
- }
- onWidthChanged : {
-
- setHandleValue(handleValue)
- }
-
- Rectangle
- {
- id: track
- width: sliderRoot.width - sliderRoot.handleSize
- height: sliderRoot.trackThickness
- radius: sliderRoot.trackRadius
- anchors.centerIn: sliderRoot
- color: sliderRoot.trackColor
- visible: sliderRoot.pathsVisible
- }
-
- Item
- {
- id: rangeHandle
- x: handle.width
- height: sliderRoot.handleSize
- width: handle.x - sliderRoot.handleSize
- anchors.verticalCenter: sliderRoot.verticalCenter
- visible: sliderRoot.pathsVisible
- Rectangle
- {
- height: sliderRoot.trackThickness
- width: parent.width + sliderRoot.handleSize
- anchors.centerIn: parent
- radius: sliderRoot.trackRadius
- color: sliderRoot.rangeColor
- }
- }
-
- Rectangle
- {
- id: handle
- x: sliderRoot.handleSize
- width: sliderRoot.handleSize
- height: sliderRoot.handleSize
- anchors.verticalCenter: sliderRoot.verticalCenter
- radius: sliderRoot.handleRadius
- color: handleLabel.activeFocus ? sliderRoot.handleActiveColor : sliderRoot.handleColor
- visible: sliderRoot.pathsVisible
- function onHandleDragged()
- {
- sliderRoot.manuallyChanged = true
-
- sliderRoot.updateRangeHandle()
-
- UM.SimulationView.setCurrentPath(getValue())
- }
-
- function getValue()
- {
- var result = x / (sliderRoot.width - sliderRoot.handleSize)
- result = result * sliderRoot.maximumValue
- result = sliderRoot.roundValues ? Math.round(result) : result
- return result
- }
- function setValueManually(value)
- {
- sliderRoot.manuallyChanged = true
- handle.setValue(value)
- }
-
- function setValue(value)
- {
-
- value = sliderRoot.normalizeValue(value)
- UM.SimulationView.setCurrentPath(value)
- var diff = value / sliderRoot.maximumValue
- var newXPosition = Math.round(diff * (sliderRoot.width - sliderRoot.handleSize))
- x = newXPosition
-
- sliderRoot.updateRangeHandle()
- }
- Keys.onRightPressed: handleLabel.setValue(handleLabel.value + ((event.modifiers & Qt.ShiftModifier) ? 10 : 1))
- Keys.onLeftPressed: handleLabel.setValue(handleLabel.value - ((event.modifiers & Qt.ShiftModifier) ? 10 : 1))
-
- MouseArea
- {
- anchors.fill: parent
- drag
- {
- target: parent
- axis: Drag.XAxis
- minimumX: 0
- maximumX: sliderRoot.width - sliderRoot.handleSize
- }
- onPressed: handleLabel.forceActiveFocus()
- onPositionChanged: parent.onHandleDragged()
- }
- SimulationSliderLabel
- {
- id: handleLabel
- height: sliderRoot.handleSize + UM.Theme.getSize("default_margin").height
- y: parent.y + sliderRoot.handleSize + UM.Theme.getSize("default_margin").height
- anchors.horizontalCenter: parent.horizontalCenter
- target: Qt.point(x + width / 2, sliderRoot.height)
- visible: false
- startFrom: 0
-
- maximumValue: sliderRoot.maximumValue
- value: sliderRoot.handleValue
- busy: UM.SimulationView.busy
- setValue: handle.setValueManually
- }
- }
- }
|