• File: C_combo_set_01.qml
  • Full Path: /home/insbudnet/domains/insbud.net/public_html/download/software/qml/podlipie_stencel/qml/pl/commons/C_combo_set_01.qml
  • File size: 7.3 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

    /*
     * Kontrolka umożliwiająca zmianę parametru (wartości) w/g listy kluczy i ich wartości
     */

    /*
     * Property do ustawienia przy tworzeniu
     */

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

    /*
     * Property prywatne definiowane z prop_p_0
     */

    property string     prv_param_list_value: ""                // lista wartości oddzielonych znakiem "|"
    property string     prv_param_list_key: ""                  // lista kluczy oddzielonych znakiem "|"

    /*
     * Property prywatne
     */

    property int        prv_value: -1                           // 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
    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;
        }

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

    function getCurrentValueIndex() {
        var tmp_value = prv_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 = prv_param_list_value.split("|");

        prv_setting_value = tmp_value[prv_value_index];
        prv_value = prv_setting_value;

        valueChanged(prop_index, prv_setting_value);
    }

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

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

            prv_param_list_key = tmp_value[0];
            prv_param_list_value = tmp_value[1];

            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
                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, prv_param_list_value, prv_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

                }
            }

        }
    }

}