Unverified Commit fb5fc249 authored by Don Gagne's avatar Don Gagne Committed by GitHub

Merge pull request #8652 from mavlink/ValueIconPicker

Instrument Values: Icon picker support
parents d8ba7332 43236ab2
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
****************************************************************************/ ****************************************************************************/
import QtQuick 2.3 import QtQuick 2.12
import QtQuick.Dialogs 1.2 import QtQuick.Dialogs 1.2
import QtQuick.Layouts 1.2 import QtQuick.Layouts 1.2
import QtQuick.Controls 2.5 import QtQuick.Controls 2.5
...@@ -304,6 +304,12 @@ Column { ...@@ -304,6 +304,12 @@ Column {
anchors.right: parent.right anchors.right: parent.right
spacing: _margins spacing: _margins
QGCButton {
Layout.fillWidth: true
text: qsTr("Blank Entry")
onClicked: { _valuePickerInstrumentValue.clearFact(); hideDialog() }
}
RowLayout { RowLayout {
Layout.fillWidth: true Layout.fillWidth: true
spacing: ScreenTools.defaultFontPixelWidth spacing: ScreenTools.defaultFontPixelWidth
...@@ -319,7 +325,7 @@ Column { ...@@ -319,7 +325,7 @@ Column {
RowLayout { RowLayout {
spacing: ScreenTools.defaultFontPixelWidth spacing: ScreenTools.defaultFontPixelWidth
QGCLabel { text: qsTr("Font Size (for whole row)") } QGCLabel { text: qsTr("Font Size") }
QGCComboBox { QGCComboBox {
id: fontSizeCombo id: fontSizeCombo
model: _valuePickerInstrumentValue.fontSizeNames model: _valuePickerInstrumentValue.fontSizeNames
...@@ -327,31 +333,46 @@ Column { ...@@ -327,31 +333,46 @@ Column {
sizeToContents: true sizeToContents: true
onActivated: _valuePickerInstrumentValue.fontSize = index onActivated: _valuePickerInstrumentValue.fontSize = index
} }
QGCCheckBox {
text: qsTr("Show Units")
checked: _valuePickerInstrumentValue.showUnits
onClicked: _valuePickerInstrumentValue.showUnits = checked
}
} }
RowLayout { RowLayout {
spacing: ScreenTools.defaultFontPixelWidth spacing: ScreenTools.defaultFontPixelWidth
QGCLabel { text: qsTr("Icon") } QGCLabel { text: qsTr("Icon") }
QGCComboBox {
model: _valuePickerInstrumentValue.iconNames
sizeToContents: true
onActivated: _valuePickerInstrumentValue.icon = currentText
Component.onCompleted: { Rectangle {
currentIndex = find(_valuePickerInstrumentValue.icon) height: iconPositionCombo.height
if (currentIndex == -1) { width: noIconLabel.width + ScreenTools.defaultFontPixelWidth * 2
currentIndex = 0 color: qgcPal.window
} border.color: qgcPal.text
visible: !_valuePickerInstrumentValue.icon
QGCLabel {
id: noIconLabel
anchors.centerIn: parent
text: qsTr("No Icon")
} }
} }
}
RowLayout { QGCColoredImage {
spacing: ScreenTools.defaultFontPixelWidth height: iconPositionCombo.height
width: height
source: _valuePickerInstrumentValue.icon ? "/InstrumentValueIcons/" + _valuePickerInstrumentValue.icon : ""
sourceSize.height: height
fillMode: Image.PreserveAspectFit
mipmap: true
smooth: true
color: qgcPal.text
visible: _valuePickerInstrumentValue.icon
}
QGCLabel { text: qsTr("Icon Position") }
QGCComboBox { QGCComboBox {
id: iconPositionCombo
model: _valuePickerInstrumentValue.iconPositionNames model: _valuePickerInstrumentValue.iconPositionNames
currentIndex: _valuePickerInstrumentValue.iconPosition currentIndex: _valuePickerInstrumentValue.iconPosition
sizeToContents: true sizeToContents: true
...@@ -359,15 +380,19 @@ Column { ...@@ -359,15 +380,19 @@ Column {
} }
} }
QGCCheckBox { SectionHeader {
text: qsTr("Show Units") id: iconListHeader
checked: _valuePickerInstrumentValue.showUnits Layout.fillWidth: true
onClicked: _valuePickerInstrumentValue.showUnits = checked text: qsTr("Icons")
checked: false
} }
QGCButton { Item { width: 1; height: 1 }
text: qsTr("Blank Entry")
onClicked: { _valuePickerInstrumentValue.clearFact(); hideDialog() } Loader {
Layout.fillWidth: true
sourceComponent: iconListHeader.checked ? iconList : undefined
visible: iconListHeader.checked
} }
Loader { Loader {
...@@ -394,6 +419,62 @@ Column { ...@@ -394,6 +419,62 @@ Column {
} }
} }
Component {
id: iconList
Flow {
Rectangle {
height: ScreenTools.minTouchPixels
width: noIconLabel.width + ScreenTools.defaultFontPixelWidth * 2
color: isNoIcon ? qgcPal.text : qgcPal.window
border.color: isNoIcon ? qgcPal.window : qgcPal.text
property bool isNoIcon: _valuePickerInstrumentValue.icon === ""
QGCLabel {
id: noIconLabel
anchors.centerIn: parent
color: parent.isNoIcon ? qgcPal.window : qgcPal.text
text: qsTr("No Icon")
}
MouseArea {
anchors.fill: parent
onClicked: _valuePickerInstrumentValue.icon = ""
}
}
Repeater {
model: _valuePickerInstrumentValue.iconNames
Rectangle {
height: ScreenTools.minTouchPixels
width: height
color: currentSelection ? qgcPal.text : qgcPal.window
property bool currentSelection: _valuePickerInstrumentValue.icon == modelData
QGCColoredImage {
anchors.centerIn: parent
height: parent.height * 0.75
width: height
source: "/InstrumentValueIcons/" + modelData
sourceSize.height: height
fillMode: Image.PreserveAspectFit
mipmap: true
smooth: true
color: currentSelection ? qgcPal.window : qgcPal.text
MouseArea {
anchors.fill: parent
onClicked: _valuePickerInstrumentValue.icon = modelData
}
}
}
}
}
}
Component { Component {
id: factGroupList id: factGroupList
......
...@@ -32,8 +32,6 @@ const char* InstrumentValue::_iconPositionKey = "iconPosition"; ...@@ -32,8 +32,6 @@ const char* InstrumentValue::_iconPositionKey = "iconPosition";
QStringList InstrumentValue::_iconNames; QStringList InstrumentValue::_iconNames;
const QString InstrumentValue::_noIconName = QT_TRANSLATE_NOOP("InstrumentValue", "No Icon");
// Important: The indices of these strings must match the InstrumentValue::IconPosition enumconst QStringList InstrumentValue::_iconPositionNames = { // Important: The indices of these strings must match the InstrumentValue::IconPosition enumconst QStringList InstrumentValue::_iconPositionNames = {
const QStringList InstrumentValue::_iconPositionNames = { const QStringList InstrumentValue::_iconPositionNames = {
QT_TRANSLATE_NOOP("InstrumentValue", "Above"), QT_TRANSLATE_NOOP("InstrumentValue", "Above"),
...@@ -343,7 +341,6 @@ InstrumentValue::InstrumentValue(Vehicle* activeVehicle, FontSize fontSize, QmlO ...@@ -343,7 +341,6 @@ InstrumentValue::InstrumentValue(Vehicle* activeVehicle, FontSize fontSize, QmlO
if (_iconNames.isEmpty()) { if (_iconNames.isEmpty()) {
QDir iconDir(":/InstrumentValueIcons/"); QDir iconDir(":/InstrumentValueIcons/");
_iconNames = iconDir.entryList(); _iconNames = iconDir.entryList();
_iconNames.prepend(_noIconName);
} }
} }
...@@ -482,22 +479,20 @@ void InstrumentValue::clearFact(void) ...@@ -482,22 +479,20 @@ void InstrumentValue::clearFact(void)
_fact = nullptr; _fact = nullptr;
_factGroupName.clear(); _factGroupName.clear();
_label.clear(); _label.clear();
_icon.clear();
_showUnits = true; _showUnits = true;
emit factChanged (_fact); emit factChanged (_fact);
emit factGroupNameChanged (_factGroupName); emit factGroupNameChanged (_factGroupName);
emit labelChanged (_label); emit labelChanged (_label);
emit iconChanged (_icon);
emit showUnitsChanged (_showUnits); emit showUnitsChanged (_showUnits);
} }
void InstrumentValue::setIcon(const QString& icon) void InstrumentValue::setIcon(const QString& icon)
{ {
if (icon != _icon) { if (icon != _icon) {
if (icon == _noIconName) { _icon = icon;
_icon.clear();
} else {
_icon = icon;
}
emit iconChanged(_icon); emit iconChanged(_icon);
} }
} }
......
...@@ -102,8 +102,6 @@ private: ...@@ -102,8 +102,6 @@ private:
static const char* _showUnitsKey; static const char* _showUnitsKey;
static const char* _iconKey; static const char* _iconKey;
static const char* _iconPositionKey; static const char* _iconPositionKey;
static const QString _noIconName;
}; };
Q_DECLARE_METATYPE(InstrumentValue::FontSize) Q_DECLARE_METATYPE(InstrumentValue::FontSize)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment