InfoSpinBoxes.qml 2.96 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 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
import QtQuick 2.6
import QtQuick.Controls 2.1
import App 1.0

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

    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 )
    {
        priceSpinBox.from = value;
        priceSpinBox.to = value;
        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
        function updateValue( inValue )
        {
            chargeSpinBox.value = inValue * 100
        }

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

        }
    }

    SpinBoxTime
    {
        id: timeSpinBox
        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
        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")
        font.pointSize: 10
    }

}