Commit 6574cc8b authored by Wescoeur's avatar Wescoeur

feat(ui/modules/Common/Form/ComboBox): supports icon on selected entry + create logic file

parent d648e10c
// =============================================================================
// `ComboBox.qml` Logic.
// =============================================================================
function getSelectedEntryIcon () {
var iconRole = comboBox.iconRole
if (iconRole.length === 0) {
return ''
}
var currentIndex = comboBox.currentIndex
if (currentIndex < 0) {
return ''
}
var model = comboBox.model
return (
Utils.isArray(model)
? model[currentIndex][iconRole]
: model.get(currentIndex)[iconRole]
) || ''
}
function getEntryIcon () {
var iconRole = comboBox.iconRole
return (iconRole.length && item.flattenedModel[iconRole]) || ''
}
function getFlattenedModel () {
return comboBox.textRole.length &&
(typeof modelData !== 'undefined' ? modelData : model)
}
...@@ -5,6 +5,10 @@ import QtQuick.Layouts 1.3 ...@@ -5,6 +5,10 @@ import QtQuick.Layouts 1.3
import Common 1.0 import Common 1.0
import Common.Styles 1.0 import Common.Styles 1.0
import Utils 1.0
import 'ComboBox.js' as Logic
// ============================================================================= // =============================================================================
ComboBox { ComboBox {
...@@ -31,16 +35,28 @@ ComboBox { ...@@ -31,16 +35,28 @@ ComboBox {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
contentItem: Text { contentItem: RowLayout {
color: ComboBoxStyle.contentItem.text.color spacing: ComboBoxStyle.contentItem.spacing
elide: Text.ElideRight width: comboBox.width
Icon {
icon: Logic.getSelectedEntryIcon()
iconSize: ComboBoxStyle.contentItem.iconSize
visible: icon.length > 0
}
Text {
Layout.fillWidth: true
font.pointSize: ComboBoxStyle.contentItem.text.fontSize color: ComboBoxStyle.contentItem.text.color
elide: Text.ElideRight
rightPadding: comboBox.indicator.width + comboBox.spacing font.pointSize: ComboBoxStyle.contentItem.text.fontSize
verticalAlignment: Text.AlignVCenter rightPadding: comboBox.indicator.width + comboBox.spacing
text: comboBox.displayText text: comboBox.displayText
}
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
...@@ -58,8 +74,7 @@ ComboBox { ...@@ -58,8 +74,7 @@ ComboBox {
delegate: ItemDelegate { delegate: ItemDelegate {
id: item id: item
readonly property var flattenedModel: textRole.length readonly property var flattenedModel: Logic.getFlattenedModel()
&& (typeof modelData !== 'undefined' ? modelData : model)
hoverEnabled: true hoverEnabled: true
width: comboBox.width width: comboBox.width
...@@ -95,12 +110,7 @@ ComboBox { ...@@ -95,12 +110,7 @@ ComboBox {
width: item.width width: item.width
Icon { Icon {
Layout.alignment: Qt.AlignVCenter icon: Logic.getEntryIcon()
icon: {
var iconRole = comboBox.iconRole
return (iconRole.length && item.flattenedModel[iconRole]) || ''
}
iconSize: ComboBoxStyle.delegate.contentItem.iconSize iconSize: ComboBoxStyle.delegate.contentItem.iconSize
visible: icon.length > 0 visible: icon.length > 0
......
...@@ -20,6 +20,9 @@ QtObject { ...@@ -20,6 +20,9 @@ QtObject {
} }
property QtObject contentItem: QtObject { property QtObject contentItem: QtObject {
property int iconSize: 20
property int spacing: 5
property QtObject text: QtObject { property QtObject text: QtObject {
property color color: Colors.d property color color: Colors.d
property int fontSize: 10 property int fontSize: 10
......
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