Warning, /graphics/krita/libs/libqml/plugins/components/RangeCombo.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     property alias model: predefinedList.model;
0026     property bool expanded: false;
0027     onExpandedChanged: {
0028         if(expanded === true) {
0029             base.state = "expanded";
0030         }
0031         else {
0032             base.state = "";
0033         }
0034     }
0035     states: [
0036         State {
0037             name: "expanded";
0038             PropertyChanges { target: predefinedListFlow; height: predefinedListFlow.childrenRect.height; }
0039             PropertyChanges { target: base; height: textField.height + predefinedListFlow.height + valueSlider.height; }
0040         }
0041     ]
0042     transitions: [
0043         Transition {
0044             to: "*"
0045             ParallelAnimation {
0046                 PropertyAnimation { target: predefinedListFlow; property: "height"; duration: Constants.AnimationDuration; }
0047                 PropertyAnimation { target: base; property: "height"; duration: Constants.AnimationDuration; }
0048             }
0049         }
0050     ]
0051 
0052     onMinChanged: d.fixHandle();
0053     onMaxChanged: d.fixHandle();
0054     onValueChanged: {
0055         if (decimals === 0) {
0056             if (value !== Math.round(value))
0057             {
0058                 value = Math.round(value);
0059                 return;
0060             }
0061         }
0062         else if (value * Math.pow(10, decimals) !== Math.round(value * Math.pow(10, decimals))) {
0063             value = Math.round(value * Math.pow(10, decimals)) / Math.pow(10, decimals);
0064             return;
0065         }
0066         if (value < min) {
0067             value = min;
0068             return;
0069         }
0070         if (value > max) {
0071             value = max;
0072             return;
0073         }
0074         if (textField.text != value) {
0075             textField.text = value.toFixed(decimals);
0076         }
0077         if (useExponentialValue) {
0078              if (valueSlider.exponentialValue !== value) {
0079                  valueSlider.exponentialValue = ( (value - min) / (max - min) ) * 100;
0080              }
0081         }
0082         else {
0083             if (valueSlider.value !== value) {
0084                 valueSlider.value = ( (value - min) / (max - min) ) * 100;
0085             }
0086         }
0087     }
0088 
0089     Image {
0090         id: arrowsList
0091         anchors {
0092             right: parent.right;
0093             rightMargin: Constants.DefaultMargin;
0094             top: parent.top;
0095             topMargin: Constants.DefaultMargin;
0096         }
0097         height: textField.height - Constants.DefaultMargin * 2;
0098         width: height;
0099         source: Settings.theme.icon("expansionmarker");
0100         smooth: true
0101         rotation: base.expanded ? 0 : 90;
0102         Behavior on rotation { PropertyAnimation { duration: Constants.AnimationDuration; } }
0103         MouseArea {
0104             anchors.fill: parent;
0105             onClicked: base.expanded = !base.expanded;
0106         }
0107     }
0108     PanelTextField {
0109         id: textField
0110         anchors {
0111             top: parent.top;
0112             left: parent.left;
0113             right: arrowsList.left;
0114         }
0115         onFocusLost: value = text;
0116         onAccepted: value = text;
0117         numeric: true;
0118 
0119         border.width: valueSlider.border.width;
0120         border.color: valueSlider.border.color;
0121         background: valueSlider.background;
0122     }
0123     Flow {
0124         id: predefinedListFlow;
0125         clip: true;
0126         anchors {
0127             top: textField.bottom;
0128             left: parent.left;
0129             right: parent.right;
0130             leftMargin: Constants.DefaultMargin;
0131             rightMargin: Constants.DefaultMargin;
0132         }
0133         height: 0;
0134         Repeater {
0135             id: predefinedList;
0136             delegate: Button {
0137                 width: predefinedListFlow.width / 3;
0138                 height: width;
0139                 text: model.value;
0140                 onClicked: base.value = model.value;
0141             }
0142         }
0143     }
0144     Slider {
0145         id: valueSlider;
0146         anchors {
0147             top: predefinedListFlow.bottom;
0148             left: parent.left;
0149             right: parent.right;
0150             leftMargin: Constants.DefaultMargin;
0151             rightMargin: Constants.DefaultMargin;
0152         }
0153         highPrecision: true;
0154         onExponentialValueChanged: {
0155             if (useExponentialValue) {
0156                 base.value = base.min + ((exponentialValue / 100) * (base.max - base.min))
0157             }
0158         }
0159         onValueChanged: {
0160             if (!useExponentialValue) {
0161                 base.value = base.min + ((value / 100) * (base.max - base.min));
0162             }
0163         }
0164     }
0165     QtObject {
0166         id: d;
0167         function fixHandle() {
0168             var currentVal = base.value;
0169             // Set the value to something it isn't currently
0170             base.value = base.min;
0171             base.value = base.max;
0172             // Set it back to what it was
0173             base.value = currentVal;
0174         }
0175     }
0176 }