import QtQuick; import QtQuick.Controls; import ColorPalette Item{ id: control implicitHeight: 25 implicitWidth: 100 property bool isLimited: false property bool isHovered: false property var min:0 property var max:100 property var number: 0 property real step : 1 property int precision: 3 property bool isMousePressed: false signal valueChanged(number:var) function setNumber(value:var){ if(value !== number && !isNaN(value)){ number = value if(min < max){ if(number>max){ number = max } if(number{ if(mouse.button === Qt.LeftButton){ control.isMousePressed = true lastPressX = mouse.x lastPressY = mouse.y cursorShape = Qt.BlankCursor } } onReleased: (mouse)=>{ control.isMousePressed = false lastPressX = -1 lastPressY = -1 cursorShape = Qt.SplitHCursor if(!isHovered){ enterAnimation.stop() exitAnimation.start() } } onPositionChanged: (mouse)=>{ if(!input.enabled && mouse.buttons&Qt.LeftButton){ if(!isLimited){ var offset = mouse.x - lastPressX setNumber(number + offset * step) var global = dragArea.mapToGlobal(lastPressX, lastPressY) var local = dragArea.mapFromGlobal(global.x,global.y) helper.setCursorPos(global.x,global.y) } else{ var xPercent = Math.max(0, Math.min(1, mouse.x / dragArea.width)) var range = max - min var newValue = min + xPercent * range control.setNumber(newValue) const validMouseX = Math.max (0, Math.min (dragArea.width, mouse.x)); const validMouseY = Math.max (0, Math.min (dragArea.height, mouse.y)); if (mouse.x !== validMouseX || mouse.y !== validMouseY) { const validGlobalPos = dragArea.mapToGlobal (validMouseX, validMouseY); helper.setCursorPos (validGlobalPos.x, validGlobalPos.y); } } } } } ColorAnimation on border.color{ id: enterAnimation to: ColorPalette.theme.boxHover duration: 100 running: false } ColorAnimation on border.color{ id: exitAnimation to: ColorPalette.theme.textBoxBackground duration: 100 running: false } } }