diff --git a/libdap-qt-ui-qml.qrc b/libdap-qt-ui-qml.qrc index 96a76e108ff4d1374b8f3f8d72748751567ed9ac..ee0c2a1e768eee5bad5d3e11fe1fef786814a388 100644 --- a/libdap-qt-ui-qml.qrc +++ b/libdap-qt-ui-qml.qrc @@ -22,6 +22,8 @@ <file>widgets/DapRadioButtonForm.ui.qml</file> <file>widgets/DapScrollView.qml</file> <file>widgets/DapScrollViewForm.ui.qml</file> + <file>widgets/DapText.qml</file> + <file>widgets/DapTextForm.ui.qml</file> <file>widgets/DapScrollViewHandling.qml</file> </qresource> </RCC> diff --git a/widgets/DapComboBox.qml b/widgets/DapComboBox.qml index c19d5dd7aafe448faa9c497b0ba666266cc07d80..2df31f55dd5bb071bb33af71949c78df99602c03 100644 --- a/widgets/DapComboBox.qml +++ b/widgets/DapComboBox.qml @@ -31,20 +31,14 @@ DapComboBoxForm contentItem: Rectangle { - id: rectTextComboBox - + id: rectangleTextComboBox anchors.fill: parent anchors.topMargin: paddingTopItemDelegate anchors.leftMargin: popup.visible ? sidePaddingActive : sidePaddingNormal anchors.rightMargin: popup.visible ? sidePaddingActive : sidePaddingNormal + border.width: 1 color: "transparent" - width: - { - (index !== currentIndex) ? - widthPopupComboBoxNormal - 2*sidePaddingActive - endRowPadding : - widthPopupComboBoxNormal - indicatorWidth - indicatorLeftInterval - 2 * sidePaddingActive - console.log(widthPopupComboBoxNormal - 2*sidePaddingActive - endRowPadding , widthPopupComboBoxNormal - indicatorWidth - indicatorLeftInterval - 2 * sidePaddingActive) - } + FontMetrics { id: comboBoxFontMetric @@ -54,80 +48,48 @@ DapComboBoxForm property int comboBoxCurrentIndex: currentIndex Row { + id: textRow + width: rectangleTextComboBox.width - ((index != currentIndex) ? + endRowPadding : + (indicatorWidth + indicatorLeftInterval) + ) + height: rectangleTextComboBox.height spacing: roleInterval Repeater { + id: textRepeater model: comboBoxTextRole.length - Text + DapText { - id: textDelegateComboBox - font: fontComboBox - color: hovered ? hilightColorText : normalColorText - horizontalAlignment: + id: textComboBoxDelegate + width: (textRow.width - roleInterval * (comboBoxTextRole.length - 1)) / comboBoxTextRole.length + enabled: false + fontDapText: fontComboBox + textColor: hovered ? hilightColorText : normalColorText + fullText: getModelData(rectangleTextComboBox.comboBoxIndex, comboBoxTextRole[index]) + + Component.onCompleted: { - if(index === 0) - return Text.AlignLeft; - if(index === comboBoxTextRole.length - 1) - return Text.AlignRight; - return Text.AlignHCenter + if(rectangleTextComboBox.comboBoxIndex == rectangleTextComboBox.comboBoxCurrentIndex) + { + var tmp = mainRow; + tmp[index] = elText; + mainRow = tmp; + + if(index == 0) + mainLineText = comboBoxFontMetric.elidedText(fullText, Text.ElideRight, rectangleTextComboBox.width, Qt.TextShowMnemonic); + } } - width: (rectTextComboBox.width - roleInterval * (comboBoxTextRole.length - 1)) / comboBoxTextRole.length - /* { - if(index === 0) - setModelDataWidth(rectTextComboBox.comboBoxIndex, comboBoxFontMetric, rectTextComboBox.width); - console.log("comboBoxIndex", rectTextComboBox.comboBoxIndex, "index", index, "comboBoxTextRole", comboBoxTextRole[index]) - return comboBoxTextRoleWidth[index]; - }*/ - TextMetrics - { - id: comboBoxTextMetric - font: fontComboBox - elide: Text.ElideRight - text: getModelData(rectTextComboBox.comboBoxIndex, comboBoxTextRole[index]) - elideWidth: textDelegateComboBox.width - } - text: - { - console.log(textDelegateComboBox.width) - if(rectTextComboBox.comboBoxIndex != rectTextComboBox.comboBoxCurrentIndex) - { - if(comboBoxTextMetric.elidedText.length < comboBoxTextMetric.text.length) - return checkElidedText(comboBoxFontMetric, comboBoxTextMetric); - return comboBoxTextMetric.elidedText.replace('…', '..'); - } - else - { - if(popup.visible) - { - if(comboBoxTextMetric.elidedText.length < comboBoxTextMetric.text.length) - mainLineText[index] = checkElidedText(comboBoxFontMetric, comboBoxTextMetric); - else - mainLineText[index] = comboBoxTextMetric.elidedText.replace('…', '..'); - } - else - { - if(index === 0) - mainLineText[index] = comboBoxFontMetric.elidedText(getModelData(rectTextComboBox.comboBoxIndex, comboBoxTextRole[index]), - Text.ElideRight, - (widthPopupComboBoxNormal - indicatorWidth - indicatorLeftInterval), - Qt.TextShowMnemonic).replace('…', '..'); - //else mainLineText[index] = ""; - } - //console.log("mainLineText", mainLineText, popup.visible) - return ""; - } - } } } - Rectangle - { - id: endRowRectangle - height: parent.height - width: endRowPadding - color: "transparent" - } + + } + onComboBoxCurrentIndexChanged: + { + mainLineText = comboBoxFontMetric.elidedText(getModelData(currentIndex, comboBoxTextRole[0]), Text.ElideRight, rectangleTextComboBox.width, Qt.TextShowMnemonic); + console.log("mainLineText", mainLineText) } } @@ -219,7 +181,6 @@ DapComboBoxForm for(i = 0; i < comboBoxTextRoleWidth.length; i++) neededWidth += comboBoxTextRoleWidth[i]; } - } return true; } @@ -240,7 +201,6 @@ DapComboBoxForm return true; } return false; - } } diff --git a/widgets/DapComboBoxForm.ui.qml b/widgets/DapComboBoxForm.ui.qml index eb6f502cb751c8d4f6b078033da5dc0ffe46b33a..15bfb4962b062b7a0c37ceea6cd8c34c124e58c4 100644 --- a/widgets/DapComboBoxForm.ui.qml +++ b/widgets/DapComboBoxForm.ui.qml @@ -61,19 +61,21 @@ ComboBox property string colorDropShadow ///@detalis fontComboBox Font setting combobox. property alias fontComboBox: dapComboBox.font - ///@detalis mainLineText Text without unneccesary part. - property var mainLineText: [] ///@detalis comboBoxTextRole The model roles used for the ComboBox. - property var comboBoxTextRole: ["name"] + property var comboBoxTextRole: ["text"] ///@detalis comboBoxTextRoleWidth The model roles width used for the ComboBox. property var comboBoxTextRoleWidth: [100] ///@detalis roleInterval The width between text of model roles used for the ComboBox. - property int roleInterval: 1 + property int roleInterval: 10 ///@detalis endRowPadding The width of padding at the end of one row at ComboBox where it is need. - property int endRowPadding: 0 - ///@detalis mainLineRole The model role for the main line of cloded ComboBox. - property string mainLineRole: "name" + property int endRowPadding: 10 + + ///@detalis mainRow The model role for the main line of cloded ComboBox. + property var mainRow: [""] + //@detalis mainLineText Text without unneccesary part. + property string mainLineText + width: popup.visible ? widthPopupComboBoxActive : widthPopupComboBoxNormal height: popup.visible ? heightComboBoxActive : heightComboBoxNormal @@ -104,39 +106,33 @@ ComboBox contentItem: Rectangle { + id: mainRectangle anchors.fill: parent anchors.verticalCenter: parent.verticalCenter anchors.leftMargin: popup.visible ? sidePaddingActive : sidePaddingNormal - width: widthPopupComboBoxNormal - indicatorWidth - indicatorLeftInterval - color: "transparent" - Row + color: "transparent" + + Row { + width: widthPopupComboBoxNormal - indicatorWidth - indicatorLeftInterval + height: mainRectangle.height spacing: roleInterval Repeater { - id: mainLineRepeater - model: popup.visible ? comboBoxTextRole.length : 1 + id: textCurrentRepeater + model: (popup.visible) ? comboBoxTextRole.length : 1 Text { - id: mainLineComboBoxText - height: dapComboBox.height - text: mainLineText[index] - horizontalAlignment: - { - if(index === 0) - return Text.AlignLeft; - if(index === comboBoxTextRole.length - 1) - return Text.AlignRight; - return Text.AlignHCenter - } - font: fontComboBox - color: popup.visible ? hilightColorTopText : normalColorTopText - verticalAlignment: Text.AlignVCenter + anchors.verticalCenter: parent.verticalCenter + text: (popup.visible) ? mainRow[index] : mainLineText + width: contentWidth + color: "green" } } } } + //Customize drop-down list with shadow effect popup: Popup diff --git a/widgets/DapScrollViewHandling.qml b/widgets/DapScrollViewHandling.qml index 5da84b5dcc54ab61aa103ad3025e192868ad1ba7..8e4ffc53d0fe2b743b4cd0110424eca3973dfc1b 100644 --- a/widgets/DapScrollViewHandling.qml +++ b/widgets/DapScrollViewHandling.qml @@ -21,14 +21,17 @@ MouseArea //If mouse pointer go to parent area onEntered: { - //ScrollButton is needed to be visible only if list lenght more than its height - scrollVisible = viewData.contentHeight > viewData.height; - //If user see the first element - if(viewData.atYBeginning) - scrollDirectionUp = false; - //If user see the last element - if(viewData.atYEnd) - scrollDirectionUp = true; + if(containsMouse) + { + //ScrollButton is needed to be visible only if list lenght more than its height + scrollVisible = viewData.contentHeight > viewData.height; + //If user see the first element + if(viewData.atYBeginning) + scrollDirectionUp = false; + //If user see the last element + if(viewData.atYEnd) + scrollDirectionUp = true; + } } //If mouse pointer go out the parent area diff --git a/widgets/DapTabForm.ui.qml b/widgets/DapTabForm.ui.qml index 778f4fe592095d077f020acdf96075691a7dde20..a5d6ee609a43b4d2569c57d5bcc8ca2292267196 100644 --- a/widgets/DapTabForm.ui.qml +++ b/widgets/DapTabForm.ui.qml @@ -1,4 +1,4 @@ -//**************************************************************************** +//**************************************************************************** // Implements a general view of the tab. //**************************************************************************** @@ -20,6 +20,8 @@ Rectangle ///@detalis Tab frame. property alias dapFrame: frameTab + property alias rightPanel: rightPanel + anchors.fill: parent // Install the top panel widget diff --git a/widgets/DapText.qml b/widgets/DapText.qml new file mode 100644 index 0000000000000000000000000000000000000000..3718df584dd48088c6a29b4ed8cb95ccf40c89a5 --- /dev/null +++ b/widgets/DapText.qml @@ -0,0 +1,70 @@ +import QtQuick 2.4 + +DapTextForm +{ + textMetric.elideWidth: width + + //Text eliding is available only after full item boot + //with all metrics - to delete binding loop + Component.onCompleted: + { + checkTextElide(); + } + //If it needed the dynamic width change + onWidthChanged: checkTextElide() + + //Function to elide text and check result + function checkTextElide() + { + if(textMetric.elideWidth < fontMetric.tightBoundingRect(textMetric.text).width) + { + switch(textElide) + { + case Text.ElideRight: + elText = textMetric.elidedText.substring(0, textMetric.elidedText.length - 1) + + ((fontMetric.tightBoundingRect(textMetric.elidedText.substring(0, textMetric.elidedText.length - 1)).width + + fontMetric.tightBoundingRect(textMetric.text.charAt(textMetric.elidedText.length - 1) + '..').width) < textMetric.elideWidth ? + (textMetric.text.charAt(textMetric.elidedText.length - 1) + '..'): + '..'); + break; + + case Text.ElideLeft: + elText = '..' + ((fontMetric.tightBoundingRect(textMetric.elidedText.substring(1, textMetric.elidedText.length - 1)).width + + fontMetric.tightBoundingRect('..' + textMetric.text.charAt(textMetric.text.length - textMetric.elidedText.length)).width) < textMetric.elideWidth ? + (textMetric.text.charAt(textMetric.text.length - textMetric.elidedText.length)): + '') + textMetric.elidedText.substring(1, textMetric.elidedText.length - 1); + + break; + + case Text.ElideMiddle: + elText = textMetric.elidedText.substring(0, textMetric.elidedText.indexOf('…')) + + ((fontMetric.tightBoundingRect(textMetric.elidedText.substring(0, textMetric.elidedText.indexOf('…'))).width + + fontMetric.tightBoundingRect(textMetric.text.charAt(textMetric.elidedText.indexOf('…')) + '..').width + + fontMetric.tightBoundingRect(textMetric.elidedText.substring(textMetric.elidedText.indexOf('…') + 1, textMetric.elidedText.length)).width) < textMetric.elideWidth ? + (textMetric.text.charAt(textMetric.elidedText.indexOf('…')) + '..'): + '..') + + textMetric.elidedText.substring(textMetric.elidedText.indexOf('…') + 1, textMetric.elidedText.length); + break; + + case Text.ElideNone: + elText = fullText; + } + + } + else + elText = textMetric.elidedText.replace('…', '..'); + } + + //Function to copy full text to the clipboard + function copyFullText() + { + //Replace elide text by full text and select it + text = fullText; + selectAll(); + //Because this method can copy only selected text + copy(); + // User should not see it! + deselect(); + text = elText; + } +} diff --git a/widgets/DapTextForm.ui.qml b/widgets/DapTextForm.ui.qml new file mode 100644 index 0000000000000000000000000000000000000000..7aeebc2868ec2938b80e0ce131eafffca02d0afb --- /dev/null +++ b/widgets/DapTextForm.ui.qml @@ -0,0 +1,41 @@ +import QtQuick 2.4 +import QtQuick.Controls 2.2 + +TextInput +{ + id: dapText + + ///@detalis fullText Full text string + property string fullText + ///@detalis elText Elided text string + property string elText + ////@detalis fontDapText Font setting combobox. + property font fontDapText + ///@details elide Elide style. + property int textElide: Text.ElideRight + ///@detalis textMetric Text Metric to elide text + property alias textMetric: dapTextInputTextMetric + ///@detalis fontMetric Font Metric to check elided text + property alias fontMetric: dapTextInputFontMetric + ///@detalis textColor Color of text + property color textColor + + font: fontDapText + color: textColor + //To do elide + TextMetrics + { + id: dapTextInputTextMetric + font: fontDapText + elide: textElide + text: fullText + } + + // To check elide + FontMetrics + { + id: dapTextInputFontMetric + font: fontDapText + } + text: elText +}