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

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

10 11
    property bool indicatorText: true;

12 13
    property alias chargingVisible: chargeSpinBox.visible

14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
    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 )
    {
30 31
        priceSpinBox.from  = value;
        priceSpinBox.to    = value;
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
        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
    }

    SpinBoxNumber
    {
        id: chargeSpinBox
59
        indicatorText: root.indicatorText
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
        function updateValue( inValue )
        {
            chargeSpinBox.value = inValue * 100
        }

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

        }
    }

    SpinBoxTime
    {
        id: timeSpinBox
78
        indicatorText: root.indicatorText
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
        y: 60

        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 )

        }
    }

    SpinBoxPrice
    {
        id: priceSpinBox
101
        indicatorText: root.indicatorText
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
        y: 119
        stepSize: Variables.timeOnePercent * 100

        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 )
        }
    }

    Text
    {
        y: 170
        color: "#979eb6"
        text: qsTr("Charging Rate 200 Mi/hr 355V 191A")
131
        font.pixelSize: Variables.fontChargingRate
132 133 134 135
    }

}