From 4fd16f357a9d45471da92c43139e7e09932be85b Mon Sep 17 00:00:00 2001 From: "tatiana.novikova" <tatiana.novikova@demlabs.net> Date: Mon, 17 Feb 2020 07:32:19 +0000 Subject: [PATCH] Features 3048 --- widgets/DapComboBox.qml | 64 ++++++++++++++++++++++++---------- widgets/DapComboBoxForm.ui.qml | 10 ++++-- widgets/DapTextForm.ui.qml | 2 +- 3 files changed, 54 insertions(+), 22 deletions(-) diff --git a/widgets/DapComboBox.qml b/widgets/DapComboBox.qml index 3e6a0d8..ee809d5 100644 --- a/widgets/DapComboBox.qml +++ b/widgets/DapComboBox.qml @@ -55,6 +55,7 @@ DapComboBoxForm ) height: rectangleTextComboBox.height spacing: roleInterval + property var elTextArray: [] Repeater { @@ -77,36 +78,43 @@ DapComboBoxForm horizontalAlignment: (alignTextComboBox.length > index) ? alignTextComboBox[index] : alignTextComboBox[0]; - + onElTextChanged: textRow.elTextArray[index] = elText Component.onCompleted: { - comboBoxFontMetric.font = (fontComboBox.length > index) ? - fontComboBox[index] : - fontComboBox[0]; if(rectangleTextComboBox.comboBoxIndex == rectangleTextComboBox.comboBoxCurrentIndex) - { - var tmp = mainRow; - tmp[index] = elText; - mainRow = tmp; - - if(rectangleTextComboBox.comboBoxCurrentIndex != -1) - { - if(index == 0) - mainLineText = comboBoxFontMetric.elidedText(fullText, Text.ElideRight, rectangleTextComboBox.width, Qt.TextShowMnemonic); - } - } + { + + var tmp = mainRow; + tmp[index] = elText; + mainRow = tmp; + + if(index == 0) + { + comboBoxFontMetric.font = (fontComboBox.length > index) ? + fontComboBox[index] : + fontComboBox[0]; + mainLineText = comboBoxFontMetric.elidedText(fullText, Text.ElideRight, rectangleTextComboBox.width, Qt.TextShowMnemonic); + } + } } } } + } + Component.onCompleted: + { + if(rectangleTextComboBox.comboBoxCurrentIndex !== -1) + updateMainRow(comboBoxFontMetric, rectangleTextComboBox.comboBoxIndex, rectangleTextComboBox.comboBoxCurrentIndex, textRow.elTextArray, (widthPopupComboBoxNormal - indicatorWidth - indicatorLeftInterval)); + } onComboBoxCurrentIndexChanged: { - mainLineText = comboBoxFontMetric.elidedText(getModelData(currentIndex, comboBoxTextRole[0]), Text.ElideRight, rectangleTextComboBox.width, Qt.TextShowMnemonic); - console.log("mainLineText", mainLineText) + if(rectangleTextComboBox.comboBoxCurrentIndex !== -1) + updateMainRow(comboBoxFontMetric, rectangleTextComboBox.comboBoxIndex, rectangleTextComboBox.comboBoxCurrentIndex, textRow.elTextArray, rectangleTextComboBox.width); + } } @@ -117,7 +125,8 @@ DapComboBoxForm Rectangle { anchors.fill: parent - anchors.bottomMargin: { + anchors.bottomMargin: + { if(index == count - 2) { if(index+1 == currentIndex) @@ -140,5 +149,24 @@ DapComboBoxForm return model.get(rowIndex)[modelRole]; } + function updateMainRow(fm, cbIndex, cbCurrentIndex, elTextArray, width) + { + if(cbIndex === cbCurrentIndex) + { + for(var i = 0; i < comboBoxTextRole.length; i++) + { + fm.font = (fontComboBox.length > i) ? + fontComboBox[i] : + fontComboBox[0]; + + var tmp = mainRow; + tmp[i] = elTextArray[i]; + mainRow = tmp; + + if(i == 0) + mainLineText = fm.elidedText(getModelData(cbCurrentIndex, comboBoxTextRole[0]), Text.ElideRight, width, Qt.TextShowMnemonic); + } + } + } } diff --git a/widgets/DapComboBoxForm.ui.qml b/widgets/DapComboBoxForm.ui.qml index b063a2b..fab312f 100644 --- a/widgets/DapComboBoxForm.ui.qml +++ b/widgets/DapComboBoxForm.ui.qml @@ -1,5 +1,5 @@ import QtQuick 2.0 -import QtQuick.Controls 2.2 +import QtQuick.Controls 2.0 import QtQuick.Controls.Styles 1.4 import QtGraphicalEffects 1.0 @@ -135,10 +135,13 @@ ComboBox { anchors.verticalCenter: parent.verticalCenter text: (popup.visible) ? - mainRow[index] : + (index < mainRow.length ? mainRow[index] : ""): mainLineText - font: (fontComboBox.length > index) ? + font: popup.visible ? + ((fontComboBox.length > index) ? fontComboBox[index] : + fontComboBox[0] + ) : fontComboBox[0]; width: popup.visible ? (topComboBoxRow.width - roleInterval * (comboBoxTextRole.length - 1)) / comboBoxTextRole.length : @@ -165,6 +168,7 @@ ComboBox contentItem: ListView { + id: popupList clip: true implicitHeight: contentHeight model: dapComboBox.popup.visible ? dapComboBox.delegateModel : null diff --git a/widgets/DapTextForm.ui.qml b/widgets/DapTextForm.ui.qml index 7aeebc2..875b427 100644 --- a/widgets/DapTextForm.ui.qml +++ b/widgets/DapTextForm.ui.qml @@ -1,5 +1,5 @@ import QtQuick 2.4 -import QtQuick.Controls 2.2 +import QtQuick.Controls 2.0 TextInput { -- GitLab