• File: C_graphic_status_view_02.qml
  • Full Path: /home/insbudnet/domains/insbud.net/public_html/download/software/qml/sieniczno_nowak/qml/pl/commons/C_graphic_status_view_02.qml
  • File size: 5.97 KB
  • MIME-type: text/plain
  • Charset: utf-8
 
Open Back
import QtQuick 2.3
import QtQuick.Layouts 1.1

Core {
    id: container

    /*
     * Kontrolka przedstawiająca graficznie status (0 i 1) z opisem tekstowym
     */

    /*
     * Property do ustawienia przy tworzeniu
     */

    property string     prop_title: ""                                                          // nagłówek parametru
    property int        prop_index : -1                                                         // index
    property string     prop_p_0 : "arrow_red.svg;arrow_blue.svg;44;64;Otwarty;Zamkniety"       // parametry rozdzielone średnikiem, oznaczenie w/g kolejności jak niżej

    /*
     * Property prywatne definiowane z prop_p_0
     */

    property string     prv_symbol_on: "arrow_red.svg"                                     // symbol - stan 1
    property string     prv_symbol_off: "arrow_blue.svg"                                   // symbol - stan 0
    property string     prv_symbol_width: "44"                                             // szerokość symbolu
    property string     prv_symbol_height: "64"                                            // wysokość symbolu
    property string     prv_text_on: "Otwarty"                                             // tekst dla stanu 1
    property string     prv_text_off: "Zamknięty"                                          // tekst dla stanu 0

    /*
     * Property prywatne pozostałe
     */

    property int        prv_status : 0                                                     // status po lewej
    property int        prv_initialized : 0                                                     // kontrolka została zainicjalizowana

    property double prop_start_width: 44
    property double prop_start_height: 64

    Layout.fillWidth: true
    Layout.minimumWidth: 150
    Layout.maximumWidth: 600

    Layout.fillHeight: true
    Layout.minimumHeight: 100
    Layout.maximumHeight: 250

    Layout.alignment: Qt.AlignHCenter

    width: 300
    height: 100

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

    // sygnal z rodzica (zmieniono wartosc)
    function setValue(a_index, a_status, a_na0, a_na1, a_na2) {
        if (container != null) {
            if (a_index === prop_index) {
                prv_status = a_status;
            }
        }
    }

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

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

            prv_symbol_on = tmp_value[0];
            prv_symbol_off = tmp_value[1];
            prv_symbol_width = tmp_value[2];
            prv_symbol_height = tmp_value[3];
            prv_text_on = tmp_value[4];
            prv_text_off = tmp_value[5];

            prop_start_width = prv_symbol_width;
            prop_start_height = prv_symbol_height;

            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_sep
                Layout.preferredHeight: 70
                Layout.preferredWidth: 38
            }

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

                Item {
                    id: itm_symbol_text
                    anchors.centerIn: parent
                    height: parent.height
                    width: img_symbol.width + 20 + txt_status.width

                    Image {
                        id: img_symbol
                        anchors.verticalCenter: parent.verticalCenter
                        x: 0
                        sourceSize.height: height
                        sourceSize.width: width
                        width: (height * prop_start_width / prop_start_height < itm_value.width * 0.8) ? height * prop_start_width / prop_start_height : itm_value.width * 0.8
                        height: parent.height * 0.8
                        source: (prv_status) ? ("../images/" + prv_symbol_on) : ("../images/" + prv_symbol_off)
                        verticalAlignment: Text.AlignVCenter
                        horizontalAlignment: Text.AlignHCenter
                    }

                    Text {
                        id: txt_status
                        anchors.left: img_symbol.right
                        anchors.leftMargin: 20
                        height: parent.height - 2 * y

                        color: "#6e6e6e"
                        text: (prv_status) ? prv_text_on : prv_text_off
                        verticalAlignment: Text.AlignVCenter
                        horizontalAlignment: Text.AlignLeft

                        font.family: "Mukti Narrow"
                        font.strikeout: false
                        font.bold: false
                        font.italic: false
                        fontSizeMode : Text.Fit
                        minimumPixelSize: 10
                        font.pixelSize: 0.6 * parent.height

                    }


                }

            }

            Item {
                id: itm_right_sep
                Layout.preferredHeight: 70
                Layout.preferredWidth: 38
            }

        }
    }

}