Permalink
Browse files

qmlui: fix icon popup button selected item

More common code between combo box and icon popup button
  • Loading branch information...
mcallegari committed Nov 27, 2018
1 parent 22a87d3 commit 79b5d57051b71c39a43df29425411f92f6812ac0
Showing with 20 additions and 115 deletions.
  1. +16 −11 qmlui/qml/CustomComboBox.qml
  2. +4 −104 qmlui/qml/IconPopupButton.qml
@@ -42,24 +42,29 @@ ComboBox
property string currentIcon
property int currentValue
property int delegateHeight: UISettings.listItemHeight
signal valueChanged(int value)
onCurrentValueChanged:
onCurrentValueChanged: updateCurrentItem()
function updateCurrentItem()
{
if (!model)
return
//console.log("Value changed:" + currentValue + ", model count: " + model.length)
for (var i = 0; i < model.length; i++)
var iCount = model.length === undefined ? model.count : model.length
//console.log("Value changed:" + currentValue + ", model count: " + iCount)
for (var i = 0; i < iCount; i++)
{
var item = model[i]
var item = model.length === undefined ? model.get(i) : model[i]
if (item.mValue === currentValue)
{
displayText = item.mLabel
if (item.mIcon)
currentIcon = item.mIcon
currentIndex = i
console.log("Label: " + displayText)
return
}
}
@@ -78,7 +83,7 @@ ComboBox
ItemDelegate
{
width: parent.width
implicitHeight: UISettings.listItemHeight
implicitHeight: delegateHeight
highlighted: control.highlightedIndex === index
hoverEnabled: control.hoverEnabled
padding: 0
@@ -111,7 +116,7 @@ ComboBox
{
displayText = text
currentIcon = itemIcon
console.log("Index changed:" + index + ", value: " + itemValue)
//console.log("Index changed:" + index + ", value: " + itemValue)
if (itemValue !== undefined)
{
currentValue = itemValue
@@ -129,7 +134,7 @@ ComboBox
Image
{
visible: itemIcon ? true : false
height: UISettings.listItemHeight - 4
height: delegateHeight - 4
width: height
y: 2
source: itemIcon
@@ -139,16 +144,16 @@ ComboBox
RobotoText
{
label: text
height: UISettings.listItemHeight
height: delegateHeight
fontSize: UISettings.textSizeDefault
}
}
background:
Rectangle
{
width: control.width
height: UISettings.listItemHeight
width: contentItem.width
height: delegateHeight
visible: control.down || control.highlighted || control.visualFocus
color: highlighted ? UISettings.highlight : hovered ? UISettings.bgControl : "transparent"
}
@@ -207,7 +212,7 @@ ComboBox
{
visible: !control.flat || control.down
implicitWidth: 150
implicitHeight: UISettings.listItemHeight
implicitHeight: delegateHeight
color: control.hovered ? UISettings.bgLight : UISettings.bgControl
border.width: 1
border.color: UISettings.bgStrong
@@ -41,6 +41,10 @@ CustomComboBox
}
*/
delegateHeight: UISettings.iconSizeDefault
onDisplayTextChanged: buttonBox.tooltip = displayText
indicator: null
contentItem:
@@ -67,110 +71,6 @@ CustomComboBox
}
}
delegate:
ItemDelegate
{
width: UISettings.bigItemHeight * 2
implicitHeight: UISettings.iconSizeDefault
highlighted: control.highlightedIndex === index
hoverEnabled: control.hoverEnabled
padding: 0
leftPadding: 3
Component.onCompleted:
{
// check for corresponding index
if (index === control.currentIndex)
{
if (model.mIcon)
control.currentIcon = mIcon
if (model.mTextIcon)
textIcon.label = mTextIcon
buttonBox.tooltip = mLabel
}
// check for corresponding value
if (currentValue && mValue === currentValue)
{
if (model.mIcon)
control.currentIcon = mIcon
if (model.mTextIcon)
textIcon.label = mTextIcon
control.currentIndex = index
buttonBox.tooltip = mLabel
}
}
contentItem:
Row
{
spacing: 2
Image
{
visible: model.mIcon ? true : false
height: control.height - 4
width: height
x: 3
y: 2
source: model.mIcon ? mIcon : ""
sourceSize: Qt.size(width, height)
}
Rectangle
{
visible: model.mTextIcon ? true : false
y: 2
height: control.height - 4
width: height
color: UISettings.bgLight
radius: 3
border.width: 1
border.color: UISettings.bgStrong
RobotoText
{
id: txtIcon
height: parent.height
anchors.centerIn: parent
label: model.mTextIcon ? mTextIcon : ""
fontSize: parent.height * 0.9
}
}
RobotoText
{
x: 3
label: mLabel
height: parent.height
}
}
background:
Rectangle
{
visible: control.down || control.highlighted || control.visualFocus
color: highlighted ? UISettings.highlight : hovered ? UISettings.bgMedium : "transparent"
}
onClicked:
{
displayText = mLabel
if (model.mIcon)
control.currentIcon = mIcon
if (model.mTextIcon)
textIcon.label = mTextIcon
currentIndex = index
buttonBox.tooltip = mLabel
control.valueChanged(mValue)
}
Rectangle { height: 1; width: parent.width; y: parent.height - 1 }
}
background:
Rectangle
{

0 comments on commit 79b5d57

Please sign in to comment.