Warning, /graphics/krita/libs/libqml/plugins/components/RangeInput.qml is written in an unsupported language. File is not indexed.
0001 /* This file is part of the KDE project 0002 * SPDX-FileCopyrightText: 2012 Dan Leinir Turthra Jensen <admin@leinir.dk> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 import QtQuick 2.3 0008 import org.krita.sketch 1.0 0009 0010 Item { 0011 id: base; 0012 0013 property bool enabled: true; 0014 property alias placeholder: textField.placeholder; 0015 property real value: 0; 0016 property real min: 0; 0017 property real max: 1000; 0018 property int decimals: 2; 0019 property alias useExponentialValue: valueSlider.useExponentialValue; 0020 0021 height: textField.height + valueSlider.height; 0022 0023 property alias border: valueSlider.border; 0024 property alias background: valueSlider.background; 0025 0026 onMinChanged: d.fixHandle(); 0027 onMaxChanged: d.fixHandle(); 0028 onValueChanged: { 0029 if (decimals === 0) { 0030 if (value !== Math.round(value)) 0031 { 0032 value = Math.round(value); 0033 return; 0034 } 0035 } 0036 else if (value * Math.pow(10, decimals) !== Math.round(value * Math.pow(10, decimals))) { 0037 value = Math.round(value * Math.pow(10, decimals)) / Math.pow(10, decimals); 0038 return; 0039 } 0040 if (value < min) { 0041 value = min; 0042 return; 0043 } 0044 if (value > max) { 0045 value = max; 0046 return; 0047 } 0048 if (textField.text != value) { 0049 textField.text = value.toFixed(decimals); 0050 } 0051 if (useExponentialValue) { 0052 if (valueSlider.exponentialValue !== value) { 0053 valueSlider.exponentialValue = ( (value - min) / (max - min) ) * 100; 0054 } 0055 } 0056 else { 0057 if (valueSlider.value !== value) { 0058 valueSlider.value = ( (value - min) / (max - min) ) * 100; 0059 } 0060 } 0061 } 0062 0063 PanelTextField { 0064 id: textField 0065 anchors { 0066 top: parent.top; 0067 left: parent.left; 0068 right: parent.right; 0069 } 0070 onFocusLost: value = text; 0071 onAccepted: value = text; 0072 numeric: true; 0073 0074 border.width: valueSlider.border.width; 0075 border.color: valueSlider.border.color; 0076 background: valueSlider.background; 0077 } 0078 Slider { 0079 id: valueSlider; 0080 anchors { 0081 top: textField.bottom; 0082 left: parent.left; 0083 right: parent.right; 0084 leftMargin: Constants.DefaultMargin; 0085 rightMargin: Constants.DefaultMargin; 0086 } 0087 highPrecision: true; 0088 onExponentialValueChanged: { 0089 if (useExponentialValue) { 0090 base.value = base.min + ((exponentialValue / 100) * (base.max - base.min)) 0091 } 0092 } 0093 onValueChanged: { 0094 if (!useExponentialValue) { 0095 base.value = base.min + ((value / 100) * (base.max - base.min)); 0096 } 0097 } 0098 } 0099 QtObject { 0100 id: d; 0101 function fixHandle() { 0102 var currentVal = base.value; 0103 // Set the value to something it isn't currently 0104 base.value = base.min; 0105 base.value = base.max; 0106 // Set it back to what it was 0107 base.value = currentVal; 0108 } 0109 } 0110 }