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

import QtQuick 2.3
import QtQuick.Layouts 1.1

Core {
    id: container

    /*
     * Property do ustawienia przy tworzeniu
     */

    property string     prop_title: ""                          // nagłówek parametru
    property int        prop_param_setting_index_value: -1      // index parametru setting
    property int        prop_param_counter_index_value: -1      // index parametru counter
    property string     prop_param_list_value: ""               // lista wartości oddzielonych znakiem ";"
    property string     prop_param_list_key: ""                 // lista kluczy oddzielonych znakiem ";"

    /*
     * Property prywatne
     */

    property int        prv_value: 0                            // aktualne 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: 1                             // typ parametru, opis w Core.qml przy funkcji funct_getValue
    property int        prv_value_index: 0                      // intex aktualnej wartości

    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 valueUpdated(a_index, a_value) {
        if (a_index === prop_param_setting_index_value) {
            prv_setting_value = a_value;
            myValueUpdated();
        }

        if (a_index === prop_param_counter_index_value) {
            prv_counter_value = a_value;
            myValueUpdated();
        }
    }

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

        prv_value_index = getCurrentValueIndex();

        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 getMaxValueIndex() {
        var tmp_key = prop_param_list_value.split(";");
        return tmp_key.length - 1;
    }

    function getCurrentValueIndex() {
        var tmp_value = prop_param_list_value.split(";");
        var result = 0;

        for (var i = 0; i < tmp_value.length; i++) {
            if (tmp_value[i] === prv_value.toString()) {
                result = i;
            }
        }

        return result;
    }

    function valueIndexChanged() {
        var tmp_value = prop_param_list_value.split(";");

        prv_setting_value = tmp_value[prv_value_index];
        prv_value = prv_setting_value;

        valueChanged(prop_param_setting_index_value, prv_setting_value);
    }

    Component.onCompleted: {
        valueChanged.connect(updateValue);
        commitValue.connect(valueUpdated);
    }


    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
                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
                    onClicked: {
                        if (prv_value_index) {
                            --prv_value_index;
                        } else {
                            prv_value_index = getMaxValueIndex();
                        }

                        valueIndexChanged();
                    }
                }

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

                    height: parent/2

                    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
                    width: 0.7 * parent.width
                    height: 0.7 * parent.height
                    anchors.centerIn: parent


                    color: "#6e6e6e"
                    text: funct_getValue(prv_type, prv_value, prop_param_list_value, prop_param_list_key)


                    font.family: "Mukti Narrow"
                    textFormat: Text.StyledText

                    font.pixelSize: height
                    minimumPixelSize: 0.1 * height
                    elide: Text.ElideRight
                    horizontalAlignment: Text.AlignHCenter
                    verticalAlignment: Text.AlignVCenter

                    fontSizeMode: Text.Fit

                }

            }

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

                MouseArea {
                    id: ma_plus
                    anchors.fill: parent
                    onClicked: {

                        if (prv_value_index < getMaxValueIndex()) {
                            ++prv_value_index;
                        } else {
                            prv_value_index = 0;
                        }

                        valueIndexChanged();
                    }
                }

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

                    height: parent/2

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

                }
            }

        }
    }

}