/*
* Obsługuje typy (opis typów w Core):
*
* 2
*
*/
import QtQuick 2.3
import QtQuick.Layouts 1.1
Core {
id: container
/*
* Kontrolka wyświetlająca dwie wartości w rzedzie po lewej i prawej
* Lewa i prawa strona z grafikami
* Osobna obsługa kodu błędów
*/
/*
* Property do ustawienia przy tworzeniu
*/
property string prop_title: "" // nagłówek parametru
property int prop_index : -1 // index
property string prop_p_0 : "10;1;°C;thermometer_02.svg;thermometer_01.svg" // parametry rozdzielone średnikiem, oznaczenie w/g kolejności jak niżej
/*
* Property prywatne definiowane z prop_p_0
*/
property int prv_div: 0 // 1 - dzielnik (0 - brak dzielnika)
property int prv_unit_format: 1 // 2 - sposób wyświetlania jednostek (jeśli dotyczy): 0 - za wartością w tym samym rozmiarze; 1 - za wartością jako index górny; 2 - za wartością jako index dolny
property string prv_unit: "°C" // 3 - wyświetlana jednostka
property string prv_left_picture: "thermometer_02.svg" // 4 - grafika po lewej
property string prv_right_picture: "thermometer_01.svg" // 5 - grafika po lewej
/*
* Property prywatne pozostałe
*/
property int prv_left_value : -1 // wartość po lewej
property int prv_left_err : 0 // kod błedu po lewej
property int prv_right_value : -1 // wartość po prawej
property int prv_right_err : 0 // kod błedu po lewej
property int prv_type: 2 // typ parametru, opis w Core.qml przy funkcji funct_getValue
property int prv_initialized : 0 // kontrolka została zainicjalizowana
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_left_value, a_left_err, a_right_value, a_right_err) {
if (container != null) {
if (a_index === prop_index) {
prv_left_value = a_left_value;
prv_left_err = a_left_err;
prv_right_value = a_right_value;
prv_right_err = a_right_err;
}
}
}
function getLeftValue_text() {
var result = "";
if (prv_left_err) {
result = "ERR " + prv_left_err
txt_left_value_unit.opacity = 0;
} else {
result = funct_getValue(prv_type, prv_left_value, prv_div, 0);
if ((prv_unit_format === 0) && (result != "- - -")) {
result = result + " " + prop_p_1;
txt_left_value_unit.opacity = 0;
} else {
txt_left_value_unit.opacity = 1;
}
}
return result;
}
function getRightValue_text() {
var result = "";
if (prv_right_err) {
result = "ERR " + prv_right_err
txt_right_value_unit.opacity = 0;
} else {
result = funct_getValue(prv_type, prv_right_value, prv_div, 0);
if ((prv_unit_format === 0) && (result != "- - -")) {
result = result + " " + prop_p_1;
txt_right_value_unit.opacity = 0;
} else {
txt_right_value_unit.opacity = 1;
}
}
return result;
}
Component.onCompleted: {
if (!prv_initialized) {
valueChanged.connect(updateValue);
commitValue.connect(setValue);
var tmp_value = prop_p_0.split(";");
prv_div = tmp_value[0];
prv_unit_format = tmp_value[1];
prv_unit = tmp_value[2];
prv_left_picture = tmp_value[3];
prv_right_picture = tmp_value[4];
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_left_picture
Layout.preferredHeight: 70
Layout.preferredWidth: 38
Rectangle{
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
width: parent.width * 0.83
height: parent.height * 0.7
color: "#e9e9e9"
border.color: "#b8b8b8"
radius: 3
}
Image {
anchors.centerIn: parent
source: "../images/" + prv_left_picture
sourceSize.height: height
sourceSize.width: width
width: parent.width * 0.5
height: parent.height * 0.6
anchors.verticalCenterOffset: 0
anchors.horizontalCenterOffset: 5
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
}
}
Item {
id: itm_left_value
Layout.fillHeight: true
Layout.fillWidth: true
Rectangle{
id: rec_left_value
anchors.fill: parent
radius: 10
border.width: 2
border.color: "#b8b8b8"
color: "#e9e9e9"
}
Text {
id: txt_left_value
x: parent.width * 0.2
y: parent.height * 0.5 - height * 0.5
width: parent.width * 0.5
// height: (txt_left_value.contentWidth > txt_right_value.contentWidth) ? parent.height : txt_right_value.contentHeight
height: parent.height
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
color: "#6e6e6e"
text: getLeftValue_text()
font.family: "Mukti Narrow"
font.strikeout: false
font.bold: false
font.italic: false
style: Text.Normal
font.pixelSize: 0.6 * parent.height
minimumPixelSize: 10
fontSizeMode: Text.Fit
}
Text {
id: txt_left_value_unit
x : txt_left_value.x + txt_left_value.width / 2 + txt_left_value.contentWidth / 2 + 5
y : (prv_unit_format == 1) ? parent.height - (parent.height * 0.5 + txt_left_value.contentHeight * 0.5) + height * 0.3 - contentHeight * 0.20 : parent.height - (parent.height * 0.5 + txt_left_value.contentHeight * 0.5) + height * 0.3 + contentHeight * 0.15
width: (parent.width * 0.9 - (txt_left_value.width)) * 0.8
height: txt_left_value.contentHeight * 0.65
verticalAlignment: (prv_unit_format == 1) ? Text.AlignTop : Text.AlignBottom
color: "#6e6e6e"
text: prv_unit
font.family: "Mukti Narrow"
font.strikeout: false
font.bold: false
font.italic: false
style: Text.Normal
font.pixelSize: 0.4 * txt_left_value.font.pixelSize
minimumPixelSize: 5
fontSizeMode: Text.Fit
}
}
Item {
id: itm_sep_01
Layout.fillHeight: true
Layout.preferredWidth: 20
}
Item {
id: itm_right_value
Layout.fillHeight: true
Layout.fillWidth: true
Rectangle{
id: rec_right_value
anchors.fill: parent
radius: 10
border.width: 2
border.color: "#b8b8b8"
color: "#e9e9e9"
}
Text {
id: txt_right_value
x: parent.width * 0.2
y: parent.height * 0.5 - height * 0.5
width: parent.width * 0.5
// height: (txt_left_value.contentWidth < txt_right_value.contentWidth) ? parent.height : txt_left_value.contentHeight
height: parent.height
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
color: "#6e6e6e"
text: getRightValue_text()
font.family: "Mukti Narrow"
font.strikeout: false
font.bold: false
font.italic: false
style: Text.Normal
font.pixelSize: 0.6 * parent.height
minimumPixelSize: 10
fontSizeMode: Text.Fit
}
Text {
id: txt_right_value_unit
opacity: ((prv_unit_format == 0) || (prop_setting_value == -65535)) ? 0 : 1
x : txt_right_value.x + txt_right_value.width / 2 + txt_right_value.contentWidth / 2 + 5
y : (prv_unit_format == 1) ? parent.height - (parent.height * 0.5 + txt_right_value.contentHeight * 0.5) + height * 0.3 - contentHeight * 0.20 : parent.height - (parent.height * 0.5 + txt_right_value.contentHeight * 0.5) + height * 0.3 + contentHeight * 0.15
width: (parent.width * 0.9 - (txt_right_value.width)) * 0.8
height: txt_right_value.contentHeight * 0.65
verticalAlignment: (prv_unit_format == 1) ? Text.AlignTop : Text.AlignBottom
color: "#6e6e6e"
text: prv_unit
font.family: "Mukti Narrow"
font.strikeout: false
font.bold: false
font.italic: false
style: Text.Normal
font.pixelSize: 0.4 * txt_right_value.font.pixelSize
minimumPixelSize: 5
fontSizeMode: Text.Fit
}
}
Item {
id: itm_right_picture
Layout.preferredHeight: 70
Layout.preferredWidth: 38
Rectangle{
anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter
width: parent.width * 0.83
height: parent.height * 0.7
color: "#e9e9e9"
border.color: "#b8b8b8"
radius: 3
}
Image {
anchors.centerIn: parent
sourceSize.height: height
sourceSize.width: width
width: parent.width * 0.5
height: parent.height * 0.6
source: "../images/" + prv_right_picture
anchors.verticalCenterOffset: 0
anchors.horizontalCenterOffset: -5
anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter
}
}
}
}
}