From fb0e158ebf2a8c9a67452340aa1d38676b2a123e Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Wed, 24 Dec 2014 15:19:16 -0800 Subject: [PATCH] New Fact controls --- .../FactControls/FactCheckBox.qml | 26 ++++++++++ qml/QGroundControl/FactControls/FactLabel.qml | 2 +- .../FactControls/FactTextField.qml | 52 +++++++++++++++++-- 3 files changed, 76 insertions(+), 4 deletions(-) create mode 100644 qml/QGroundControl/FactControls/FactCheckBox.qml diff --git a/qml/QGroundControl/FactControls/FactCheckBox.qml b/qml/QGroundControl/FactControls/FactCheckBox.qml new file mode 100644 index 000000000..ea8252161 --- /dev/null +++ b/qml/QGroundControl/FactControls/FactCheckBox.qml @@ -0,0 +1,26 @@ +import QtQuick 2.2 +import QtQuick.Controls 1.2 +import QtQuick.Controls.Styles 1.2 +import QGroundControl.FactSystem 1.0 + +CheckBox { + property Fact fact: Fact { value: 0 } + property variant checkedValue: 1 + property variant uncheckedValue: 0 + + partiallyCheckedEnabled: fact.value != checkedValue && fact.value != uncheckedValue + checkedState: fact.value == checkedValue ? Qt.Checked : (fact.value == uncheckedValue ? Qt.Unchecked : Qt.PartiallyChecked) + + text: "Label" + + onClicked: { + fact.value = checked ? checkedValue : uncheckedValue + } + + style: CheckBoxStyle { + label: Text { + color: palette.windowText + text: control.text + } + } +} diff --git a/qml/QGroundControl/FactControls/FactLabel.qml b/qml/QGroundControl/FactControls/FactLabel.qml index a98f050b6..c883c7174 100644 --- a/qml/QGroundControl/FactControls/FactLabel.qml +++ b/qml/QGroundControl/FactControls/FactLabel.qml @@ -9,5 +9,5 @@ Label { color: palette.windowText - text: fact.value + text: fact.valueString } diff --git a/qml/QGroundControl/FactControls/FactTextField.qml b/qml/QGroundControl/FactControls/FactTextField.qml index b42ac3cc5..8e62a878d 100644 --- a/qml/QGroundControl/FactControls/FactTextField.qml +++ b/qml/QGroundControl/FactControls/FactTextField.qml @@ -5,10 +5,56 @@ import QGroundControl.FactSystem 1.0 TextField { property Fact fact: Fact { value: 0 } + property bool showUnits: false + QGCPalette { id: palette; colorGroup: enabled ? QGCPalette.Active : QGCPalette.Disabled } - QGCPalette { id: palette; colorGroup: QGCPalette.Active } + text: fact.valueString + textColor: palette.text - text: fact.value + Label { + id: unitsLabelWidthGenerator + text: parent.fact.units + width: contentWidth + ((parent.__contentHeight/3)*2) + visible: false + } - onAccepted: fact.value = text + style: TextFieldStyle { + background: Item { + id: backgroundItem + + Rectangle { + anchors.fill: parent + anchors.bottomMargin: -1 + color: "#44ffffff" + } + + Rectangle { + anchors.fill: parent + + border.color: control.activeFocus ? "#47b" : "#999" + color: palette.base + } + + Text { + id: unitsLabel + + anchors.top: parent.top + anchors.bottom: parent.bottom + + verticalAlignment: Text.AlignVCenter + horizontalAlignment: Text.AlignHCenter + + x: parent.width - width + width: unitsLabelWidthGenerator.width + + text: control.fact.units + color: control.textColor + visible: control.showUnits + } + } + + padding.right: control.showUnits ? unitsLabelWidthGenerator.width : control.__contentHeight/3 + } + + onEditingFinished: fact.value = text } -- 2.22.0