InfoSpinBoxes.qml 4.5 KB
Newer Older
1 2
import QtQuick 2.6
import QtQuick.Controls 2.1
3
import QtQuick.Layouts 1.3
4 5 6 7 8 9 10
import App 1.0

Item {
    id: root
    signal valueChanged( real value );
    signal priceChanged( real value );

11 12
    property bool indicatorText: true;

13
    property alias chargingVisible: chargeSpinBox.visible
14
    property alias chargingText: chargingText.text
15

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
    function setChargeValue( value )
    {
        chargeSpinBox.from  = value;
        chargeSpinBox.to    = value;
        chargeSpinBox.value = value;
    }

    function setTimeValue( value )
    {
        timeSpinBox.from  = value;
        timeSpinBox.to    = value;
        timeSpinBox.value = value;
    }

    function setPriceValue( value )
    {
32 33
        priceSpinBox.from  = value;
        priceSpinBox.to    = value;
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
        priceSpinBox.value = value;
    }

    Component.onCompleted:
    {
        chargeSpinBox.from = Variables.initialCharge * 100
    }

    function updateValues( value )
    {
        setSizeStep( 100 )

        chargeSpinBox.updateValue( value );
        timeSpinBox.updateValue( value );
        priceSpinBox.updateValue( value );
    }

    function setSizeStep( value )
    {
        chargeSpinBox.stepSize = value;
        timeSpinBox.stepSize   = Variables.timeOnePercent * value
        priceSpinBox.stepSize  = Variables.priceOnePercent * value
    }

58
    ColumnLayout
59
    {
60 61
        spacing: 30
        id: spinBoxColumn
62

63
        Rectangle
64
        {
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
            color: "#0b2a4a"
            border.color: "#41CD52"
            border.width: Variables.pixelBorderSpinBox
            Layout.preferredWidth: Variables.pixelSpinBoxWidth
            height: Variables.pixelSpinBoxButton
            visible: !root.chargingVisible

            Text
            {
                id: chargingText
                color: "#42cc53"
                height: Variables.pixelSpinBoxButton
                text: qsTr( "Charging in progress" )
                font.pixelSize: Variables.fontChargingProgress
                horizontalAlignment: Qt.AlignLeft
                verticalAlignment: Qt.AlignVCenter
                x:20
            }
83 84
        }

85
        SpinBoxNumber
86
        {
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
            Layout.preferredWidth: Variables.pixelSpinBoxWidth
            id: chargeSpinBox
            indicatorText: root.indicatorText
            function updateValue( inValue )
            {
                chargeSpinBox.value = inValue * 100
            }

            onValueModified:
            {
                var sendValue = value / 100;
                root.valueChanged( sendValue )
                timeSpinBox.updateValue( sendValue )
                priceSpinBox.updateValue( sendValue )
            }
102 103
        }

104
        SpinBoxTime
105
        {
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
            id: timeSpinBox
            indicatorText: root.indicatorText
            Layout.preferredWidth: Variables.pixelSpinBoxWidth

            function updateValue( inValue )
            {
                var chargeToAdd = inValue - Variables.initialCharge
                timeSpinBox.value = chargeToAdd * Variables.timeOnePercent * 100
            }

            onValueModified:
            {
                var chargeToAdd  = value / ( Variables.timeOnePercent * 100 )
                var sendValue = chargeToAdd + Variables.initialCharge;
                root.valueChanged(  sendValue )
                chargeSpinBox.updateValue( sendValue )
                priceSpinBox.updateValue( sendValue )

            }
125 126
        }

127
        SpinBoxPrice
128
        {
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
            id: priceSpinBox
            indicatorText: root.indicatorText
            stepSize: Variables.timeOnePercent * 100
            Layout.preferredWidth: Variables.pixelSpinBoxWidth

            function updateValue( inValue )
            {
                var chargeToAdd = inValue - Variables.initialCharge
                priceSpinBox.value = chargeToAdd * Variables.priceOnePercent * 100
            }

            onValueChanged:
            {
                priceChanged( value )
            }

            onValueModified:
            {
                var chargeToAdd  = value / ( Variables.priceOnePercent * 100 )
                var sendValue = chargeToAdd + Variables.initialCharge;
                root.valueChanged( sendValue )
                chargeSpinBox.updateValue( sendValue )
                timeSpinBox.updateValue( sendValue )
            }
153 154 155 156 157 158
        }

    }

    Text
    {
159 160
        anchors.top: spinBoxColumn.bottom
        anchors.topMargin: 8
161
        color: "#979eb6"
Ionut Alexandrescu's avatar
Ionut Alexandrescu committed
162
        text: qsTr("Charging Rate")+ " 200 Mi/hr 355V 191A"
163
        font.pixelSize: Variables.fontChargingRate
164 165 166 167
    }

}