• File: C_value_set_01.qml
  • Full Path: /home/insbudnet/domains/insbud.net/public_html/download/software/qml/podlipie_stencel/qml/pl/commons/C_value_set_01.qml
  • File size: 9.86 KB
  • MIME-type: text/plain
  • Charset: utf-8
 
Open Back
/*
 * Obsługuje typy (opis typów w Core):
 *
 * 2
 *
 */

import QtQuick 2.3
import QtQuick.Layouts 1.1

Core {
    id: container

    /*
     * Kontrolka umożliwiająca zmianę parametru (wartości) np. temperatury, stopnia otwarcia rolety itp
     * Obsługuje settinga i contera
     * Jeżeli seting wynosi 65535 to wyświetlany jest counter. W innym przypadku wyświetlany jest setting
     */

    /*
     * Property do ustawienia przy tworzeniu
     */

    property string     prop_title: ""                          // nagłówek parametru
    property int        prop_index : -1                         // index
    property string     prop_p_0 : "0;1;0;100;°C;1"             // parametry rozdzielone średnikiem, oznaczenie w/g kolejności jak niżej

    /*
     * Property prywatne definiowane z prop_p_0
     */

    property int        prv_div: 0                              // 1 - dzielnik (0 - brak dzielnika)
    property int        prv_value_change : 1                    // 2 - co ile ma być zmieniana wartość
    property int        prv_value_min : 0                       // 3 - wartośc minimalna
    property int        prv_value_max : 100                     // 4 - wartość maksymalna
    property string     prv_unit: "°C"                          // 5 - wyświetlana jednostka
    property int        prv_unit_format: 1                      // 6 - sposób wyświetlania jednostek (jeśli dotyczy): 0 - za wartością w tym samym rozmiarze; 1 - za wartością jako index górny; 2 - za wartością jako index dolny


    /*
     * Property prywatne pozostałe
     */

    property int        prv_value: -1                           // aktualna wyświetlana wartość
    property int        prv_setting_value: 0                    // aktualne wartość setting
    property int        prv_counter_value: 0                    // aktualne wartość counter
    property int        prv_type: 2                             // typ parametru, opis w Core.qml przy funkcji funct_getValue
    property int        prv_initialized : 0                     // kontrolka została zainicjalizowana

    Layout.fillWidth: true
    Layout.fillHeight: true
    Layout.preferredWidth: 50
    Layout.preferredHeight: 100

    color: "#00000000"
    signal valueChanged(int a_index, int a_value)

    // sygnał z rodzica (zmieniono wartość)
    function setValue(a_index, a_setting_value, a_counter_value, a_na1, a_na2) {
        if (container != null) {
            if (a_index === prop_index) {
                prv_setting_value = a_setting_value;
                prv_counter_value = a_counter_value;
                myValueUpdated();
            }
        }
    }

    function myValueUpdated() {
        if (prv_setting_value !== 65535) {
            prv_value = prv_setting_value;
        } else {
            prv_value = prv_counter_value;
        }

        if ((prv_setting_value === -65535) || (prv_counter_value === -65535)) {
            ma_minus.enabled = 0;
            ma_plus.enabled = 0;
        } else {
            ma_minus.enabled = 1;
            ma_plus.enabled = 1;
        }

    }

    function addValue(a_value) {
        prv_value += a_value;

        if (prv_value > prv_value_max) {
            prv_value = prv_value_max;
        }

        if (prv_value < prv_value_min) {
            prv_value = prv_value_min;
        }

        valueChanged(prop_index, prv_value);
    }


    function getValue_text() {
        var result = "";

        result = funct_getValue(prv_type, prv_value, prv_div, prv_unit);

        if ((prv_unit_format == 0) && (result != "- - -")) {
            result = result + " " + prv_unit;
        }

        return result;
    }

    Timer {

        id: timer

        property int prv_timer_interval_default : 170
        property int prv_timer_interval : prv_timer_interval_default
        property bool prv_timer_enabled : false
        property int prv_timer_action : 0

        interval: prv_timer_interval
        running: true
        repeat: true

        onTriggered: {

            if (prv_timer_enabled) {
                if (prv_timer_interval > 10)
                    prv_timer_interval = prv_timer_interval * 0.9;

                if (prv_timer_action) {
                    addValue(prv_value_change)
                } else {
                    addValue(-prv_value_change)
                }
            } else {
                prv_timer_interval = prv_timer_interval_default
            }
        }

    }

    Component.onCompleted: {
        if (!prv_initialized) {
            valueChanged.connect(updateValue);
            commitValue.connect(setValue);

            var tmp_value = prop_p_0.split(";");

            prv_div = tmp_value[0];
            prv_value_change = tmp_value[1];
            prv_value_min = tmp_value[2];
            prv_value_max = tmp_value[3];
            prv_unit = tmp_value[4];
            prv_unit_format = tmp_value[5];

            prv_initialized = 1;
        }
    }


    ColumnLayout {
        anchors.fill: parent
        spacing: 5

        Item {
            Layout.fillWidth: true
            Layout.preferredHeight: 25
            Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter

            Text {
                text: prop_title
                font.pixelSize: parent.height * 0.85
                anchors.fill: parent
                horizontalAlignment: Text.AlignHCenter
                verticalAlignment: Text.AlignVCenter
                clip: true
                wrapMode: Text.WordWrap
                elide: Text.ElideRight

            }

        }

        RowLayout{
            spacing: 0

            Item {
                id: itm_minus
                Layout.preferredHeight: 70
                Layout.preferredWidth: 38

                MouseArea {
                    id: ma_minus
                    anchors.fill: parent
                    onPressed: {
                        addValue(-prv_value_change)
                    }

                    onPressAndHold: {
                        timer.prv_timer_enabled = true
                        timer.prv_timer_action = 0
                    }
                    onReleased: {
                        timer.prv_timer_enabled = false
                    }
                }

                Image {
                    source: "../images/C_value_set_01/buttonMinus.svg"
                    sourceSize.height: height
                    sourceSize.width: width

                    fillMode: Image.PreserveAspectFit
                    anchors.right: parent.right
                    anchors.verticalCenter: parent.verticalCenter

                }
            }

            Item {
                id: itm_value
                Layout.fillHeight: true
                Layout.fillWidth: true

                Rectangle{
                    id: rec_value
                    anchors.fill: parent
                    radius: 10
                    border.width: 2
                    border.color: "#b8b8b8"

                    color: "#e9e9e9"
                }

                Text {
                    id: txt_value
                    x: parent.width * 0.1
                    y: 0
                    width: parent.width * 0.8
                    height: parent.height
                    horizontalAlignment: Text.AlignHCenter
                    verticalAlignment: Text.AlignVCenter

                    color: "#6e6e6e"
                    text: getValue_text()

                    font.family: "Mukti Narrow"
                    font.strikeout: false
                    font.bold: false
                    font.italic: false
                    style: Text.Normal

                    font.pixelSize: 0.6 * parent.height
                    minimumPixelSize: 10
                    fontSizeMode: Text.Fit

                }

                Text {
                    id: txt_value_unit
                    opacity: ((prv_unit_format == 0) || (prv_value == -65535)) ? 0 : 1
                    x :  txt_value.x + txt_value.width / 2 + txt_value.contentWidth / 2 + 5
                    y : (prv_unit_format == 1) ? parent.height - (parent.height * 0.5 + txt_value.contentHeight * 0.5) + height * 0.3 - contentHeight * 0.25 : parent.height - (parent.height * 0.5 + txt_value.contentHeight * 0.5) + height * 0.3 + contentHeight * 0.15
                    width: (parent.width * 0.9 - (txt_value.width)) * 0.8
                    height: txt_value.contentHeight * 0.65
                    verticalAlignment: (prv_unit_format == 1) ? Text.AlignTop : Text.AlignBottom

                    color: "#6e6e6e"
                    text: prv_unit

                    font.family: "Mukti Narrow"
                    font.strikeout: false
                    font.bold: false
                    font.italic: false
                    style: Text.Normal

                    font.pixelSize: 0.5 * txt_value.font.pixelSize
                    minimumPixelSize: 5
                    fontSizeMode: Text.Fit

                }

            }

            Item {
                id: itm_plus
                Layout.preferredHeight: 70
                Layout.preferredWidth: 38

                MouseArea {
                    id: ma_plus
                    anchors.fill: parent
                    onPressed: {
                        addValue(prv_value_change)
                    }
                    onPressAndHold: {
                        timer.prv_timer_enabled = true
                        timer.prv_timer_action = 1
                    }
                    onReleased: {
                        timer.prv_timer_enabled = false
                    }
                }

                Image {
                    source: "../images/C_value_set_01/buttonPlus.svg"
                    sourceSize.height: height
                    sourceSize.width: width

                    fillMode: Image.PreserveAspectFit
                    anchors.left: parent.left
                    anchors.verticalCenter: parent.verticalCenter

                }
            }
        }

    }
}