import QtQuick 2.3
import QtQuick.Layouts 1.1
Core {
id: container
/*
* Kontrolka przycisku typu trigger z napisem tekstowym
*/
/*
* Property do ustawienia przy tworzeniu
*/
property string prop_title: "" // nagłówek parametru
property int prop_index : -1 // index parametru setting
/*
* 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
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 } }
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
}
}
}