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

import QtQuick 2.3
import QtQuick.Layouts 1.1

Core {
    id: container

    property string prop_title: "Zamknij wszystkie"
    property int prop_index : 0
    property int prop_type : 1
    property string prop_p_0 : "65535"
    property string prop_p_1 : "1"

    property int prv_value_current : 0
    property int prv_value_on : 1
    property int prv_value_off : 0

    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"

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

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

    // sygnal od rodzica (zmieniono wartość)
    function setValue(a_index, a_setting_value, a_counter_value, a_empty1, a_empty2) {

        if (a_index == prop_index) {
            if (a_setting_value != 65535) {
                if (a_setting_value == prv_value_on) {
                    prv_value_current = 1;
                } else {
                    prv_value_current = 0;
                }
            } else {
                if (a_counter_value == prv_value_on) {
                    prv_value_current = 1;
                } else {
                    prv_value_current = 0;
                }
            }
        }
    }

    onButtonClick: {
        if (prv_value_current) {
            valueChanged(prop_index, prv_value_off);
            prv_value_current = 0;
        } else {
            valueChanged(prop_index, prv_value_on);
            prv_value_current = 1;
        }
    }

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

        prv_value_on = prop_p_1;
        prv_value_off = prop_p_0;

    }


    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: "#e9e9e9"
            color: prv_value_current ? Qt.lighter(buttonColor, 1.5) : buttonColor
            Behavior on color { ColorAnimation{ duration: 55 } }

            scale: prv_value_current ? 0.9 : 1.0
            Behavior on scale { NumberAnimation{ duration: 55 } }

            Text {

                id: txt_title

                x: 20
                y: 20
                width: parent.width - 2 * x
                height: parent.height - 2 * y

                color: "#6e6e6e"
                text: prop_title
                verticalAlignment: Text.AlignVCenter
                horizontalAlignment: Text.AlignHCenter

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

            }

        }


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

    }

}