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

Core {
    id: container

    /*
     * Kontrolka przycisku typu trigger z symbolem graficznym
     */

    /*
     * Property do ustawienia przy tworzeniu
     */

    property int        prop_index : -1                         // index parametru setting
    property string     prop_grphic: "arrow_red.svg"            // grafika

    /*
     * Property prywatne
     */

    property int        prv_value_off : 0                       // 1 - wartość off
    property int        prv_value_on : 1                        // 2 - wartośc on

    /*
     * Property prywatne pozostałe
     */

    property int        prv_value: 0                            // aktualna wyświetlana wartość (0 lub 1)
    property int        prv_initialized : 0                     // kontrolka została zainicjalizowana
    property int        prv_delay_value : 55                    // czas animacji przyciśnięcia
    property int        prv_on_delay_timer : 0                  // licznik pomocniczy oliczający czas do włączenia przycisku
    property int        prv_off_delay_timer : 0                 // licznik pomocniczy oliczający czas do wyłączenia przycisku
    property int        prv_send_signal_status : 0              // flaga: wyślij sygnał do rodzica
    property double     prv_graphic_scale : 0.7                 // flaga: wyślij sygnał do rodzica

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

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

    Layout.alignment: Qt.AlignHCenter

    width: 300
    height: 100

    color: "#00000000"

    property color buttonColor: "#e9e9e9"
    property color borderColor: "#b8b8b8"
    property color onHoverColor: "#989898"

    signal buttonClick()
    signal valueChanged(int a_index, int a_value)

    Timer {
        id: timer_signal_counter
        interval: 1
        repeat: true
        running: true
        triggeredOnStart: true

        onTriggered: {
            if (prv_on_delay_timer) {
                --prv_on_delay_timer;
                prv_off_delay_timer = prv_delay_value;
                prv_send_signal_status = 1;
            }

            if ((!prv_on_delay_timer) && (prv_value)) {
                prv_value = 0;
            }

            if (prv_off_delay_timer) {
                --prv_off_delay_timer;
            }

            if ((!prv_off_delay_timer) && (prv_send_signal_status)) {
                valueChanged(prop_index, prv_value_on);
                prv_send_signal_status = 0;
            }
        }
    }

    onButtonClick: {
        if (prv_value) {
            prv_value = 0;
        } else {
            prv_value = 1;
            prv_on_delay_timer = prv_delay_value;
        }
    }

    Component.onCompleted: {
        if (!prv_initialized) {
            valueChanged.connect(buttonClicked);

            prv_initialized = 1;
        }
    }

    Item {
        id: itm_button
        x: 10
        y: 10
        width: parent.width - 2 * x
        height: parent.height - 2 * y

        Rectangle{
            id: rec_button
            anchors.fill: parent
            radius: 10
            border.width: 2
            border.color: borderColor

            color: prv_value ? Qt.lighter(buttonColor, 1.5) : buttonColor
            Behavior on color { ColorAnimation{ duration: prv_delay_value } }

            scale: prv_value ? 0.9 : 1.0
            Behavior on scale { NumberAnimation{ duration: prv_delay_value } }

            Image {
                id: img_symbol
                anchors.verticalCenter: parent.verticalCenter
                anchors.horizontalCenter:  parent.horizontalCenter
                sourceSize.height: height
                sourceSize.width: width
                width: parent.height * prv_graphic_scale
                height: parent.height * prv_graphic_scale
                source: "../images/" + prop_grphic
                verticalAlignment: Text.AlignVCenter
                horizontalAlignment: Text.AlignHCenter
            }

        }


        MouseArea {
            id: ma_button
            anchors.fill: parent
            onClicked: buttonClick()
            hoverEnabled: true
            onEntered: rec_button.border.color = onHoverColor
            onExited:  rec_button.border.color = borderColor
        }

    }

}