Skip to content
Snippets Groups Projects
Commit 928c2f3c authored by tatiana.novikova's avatar tatiana.novikova Committed by andrey.daragan
Browse files

Features 3048

parent 1ec6bce1
No related branches found
No related tags found
No related merge requests found
......@@ -3,7 +3,6 @@ import QtQuick.Controls 2.0
DapComboBoxForm
{
delegate:
ItemDelegate
{
......@@ -32,112 +31,82 @@ 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
color: "transparent"
width: (index !== currentIndex) ?
widthPopupComboBoxNormal - 2*sidePaddingActive - endRowPadding :
widthPopupComboBoxNormal - indicatorWidth - indicatorLeftInterval - 2 * sidePaddingActive
property int comboBoxIndex: index
property int comboBoxCurrentIndex: currentIndex
FontMetrics
{
id: comboBoxFontMetric
font: fontComboBox
}
property int comboBoxIndex: index
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.length > index) ?
fontComboBox[index] :
fontComboBox[0];
textColor: hovered ? colorTextComboBox[index][1] : colorTextComboBox[index][0]
fullText: getModelData(rectangleTextComboBox.comboBoxIndex, comboBoxTextRole[index])
textElide: (elideTextComboBox.length > index) ?
elideTextComboBox[index] :
elideTextComboBox[0];
horizontalAlignment: (alignTextComboBox.length > index) ?
alignTextComboBox[index] :
alignTextComboBox[0];
Component.onCompleted:
{
if(index === 0)
return Text.AlignLeft;
if(index === comboBoxTextRole.length - 1)
return Text.AlignRight;
return Text.AlignHCenter;
}
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
}
/*Component.onCompleted:
{
setModelDataWidth(rectTextComboBox.comboBoxIndex, comboBoxFontMetric, rectTextComboBox.width);
textDelegateComboBox.width = comboBoxTextRoleWidth[index];
}*/
text:
{
if(rectTextComboBox.comboBoxIndex != rectTextComboBox.comboBoxCurrentIndex)
{
if(comboBoxTextMetric.elideWidth < comboBoxFontMetric.tightBoundingRect(comboBoxTextMetric.text).width)
return checkElidedText(comboBoxFontMetric, comboBoxTextMetric);
else if(comboBoxTextMetric.elideWidth === comboBoxFontMetric.tightBoundingRect(comboBoxTextMetric.text).width)
return comboBoxTextMetric.text;
else
return comboBoxTextMetric.elidedText.replace('', '..');
}
else
{
if(popup.visible)
{
if(comboBoxTextMetric.elideWidth < comboBoxFontMetric.tightBoundingRect(comboBoxTextMetric.text).width)
mainLineText[index] = checkElidedText(comboBoxFontMetric, comboBoxTextMetric);
else
{
if(comboBoxTextMetric.elideWidth === comboBoxFontMetric.tightBoundingRect(comboBoxTextMetric.text).width)
mainLineText[index] = comboBoxTextMetric.text;
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('', '..');
}
console.log("mainLineText[index]", "index", mainLineText[index], index)
return "";
}
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);
}
}
}
}
}
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)
}
}
......@@ -165,89 +134,11 @@ DapComboBoxForm
highlighted: parent.highlightedIndex === index
}
function checkElidedText(fontMetric, textMetric)
{
return 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) + '..')
: '..');
}
function getModelData(rowIndex, modelRole)
{
return model.get(rowIndex)[modelRole];
}
function setModelDataWidth(rowIndex, fontMetric, rowWidth)
{
comboBoxTextRoleWidth = [0];
mainLineText = [""];
var neededWidth = 0;
for(var i = 0; i < comboBoxTextRole.length; i++)
{
mainLineText[i] = "";
comboBoxTextRoleWidth[i] = fontMetric.tightBoundingRect(getModelData(rowIndex, comboBoxTextRole[i])).width;
neededWidth += comboBoxTextRoleWidth[i];
}
neededWidth += roleInterval * (comboBoxTextRole.length - 1);
console.log("neededWidth", neededWidth, "rowWidth", rowWidth);
var oneIndex = 0;
if (neededWidth > rowWidth)
{
oneIndex = comboBoxTextRole.indexOf(mainLineRole);
if(oneIndex === -1)
{
oneIndex = comboBoxTextRole.indexOf("text");
if(oneIndex === -1)
{
oneIndex = comboBoxTextRole.indexOf("name");
if(oneIndex === -1)
oneIndex = 0;
}
}
if(comboBoxTextRoleWidth[oneIndex] < neededWidth - rowWidth)
{
comboBoxTextRoleWidth[oneIndex] = rowWidth / (comboBoxTextRole.length);
var maxWidth = 0;
var maxIndex = 0;
while(neededWidth > rowWidth)
{
maxWidth = comboBoxTextRoleWidth[0];
maxIndex = 0;
for(i = 0; i < comboBoxTextRoleWidth.length; i++)
{
if(maxWidth < comboBoxTextRoleWidth[i])
{
maxWidth = comboBoxTextRoleWidth[i];
maxIndex = i;
}
}
comboBoxTextRoleWidth[maxIndex] -= 10 * pt;
neededWidth = 0;
for(i = 0; i < comboBoxTextRoleWidth.length; i++)
neededWidth += comboBoxTextRoleWidth[i];
}
}
return true;
}
if(neededWidth < rowWidth)
{
oneIndex = comboBoxTextRole.indexOf(mainLineRole);
if(oneIndex === -1)
{
oneIndex = comboBoxTextRole.indexOf("text");
if(oneIndex === -1)
{
oneIndex = comboBoxTextRole.indexOf("name");
if(oneIndex === -1)
oneIndex = 0;
}
}
comboBoxTextRoleWidth[oneIndex] += rowWidth - neededWidth;
return true;
}
return false;
}
}
......@@ -59,23 +59,31 @@ ComboBox
property string colorTopNormalDropShadow
///@detalis colorDropShadow Unboxed shadow color in expanded state.
property string colorDropShadow
///@detalis fontComboBox Font setting combobox.
property alias fontComboBox: dapComboBox.font
//@detalis mainLineText Text without unneccesary part.
property var mainLineText: [""]
property var fontComboBox: []
///@detalis colorTextComboBox Color text setting combobox: array [normalColorText, hilightColorText] for every role
property var colorTextComboBox: []
///@detalis colorMainTextComboBox Color mainline text setting combobox: array [normalTopColorText, hilightTopColorText] for every role
property var colorMainTextComboBox: []
///@detalis elideTextComboBox Elide setting combobox.
property var elideTextComboBox: [Text.ElideRight]
///@detalis alignTextComboBox Align setting combobox.
property var alignTextComboBox: [Text.AlignLeft]
///@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: 5
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
......@@ -107,30 +115,40 @@ 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
{
id: topComboBoxRow
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: index >= mainLineText.length ? "" : mainLineText[index]
horizontalAlignment: (index === 0) ?
Text.AlignLeft :
((index === comboBoxTextRole.length - 1) ? Text.AlignRight : Text.AlignHCenter)
font: fontComboBox
color: popup.visible ? hilightColorTopText : normalColorTopText
verticalAlignment: Text.AlignVCenter
anchors.verticalCenter: parent.verticalCenter
text: (popup.visible) ?
mainRow[index] :
mainLineText
font: (fontComboBox.length > index) ?
fontComboBox[index] :
fontComboBox[0];
width: popup.visible ?
(topComboBoxRow.width - roleInterval * (comboBoxTextRole.length - 1)) / comboBoxTextRole.length :
contentWidth
color: popup.visible ?
colorMainTextComboBox[index][1] :
colorMainTextComboBox[index][0]
horizontalAlignment: popup.visible ?
alignTextComboBox[index] :
Text.AlignLeft
}
}
}
......@@ -183,5 +201,6 @@ ComboBox
verticalOffset: topEffect ? 9 * pt : 0
samples: topEffect ? 13 * pt : 0
color: topEffect ? (dapComboBox.popup.visible ? colorDropShadow : colorTopNormalDropShadow) : "#000000"
z: -1
}
}
......@@ -10,7 +10,7 @@ TextInput
///@detalis elText Elided text string
property string elText
////@detalis fontDapText Font setting combobox.
property alias fontDapText: dapText.font
property font fontDapText
///@details elide Elide style.
property int textElide: Text.ElideRight
///@detalis textMetric Text Metric to elide text
......@@ -26,7 +26,7 @@ TextInput
TextMetrics
{
id: dapTextInputTextMetric
font: parent.font
font: fontDapText
elide: textElide
text: fullText
}
......@@ -35,7 +35,7 @@ TextInput
FontMetrics
{
id: dapTextInputFontMetric
font: parent.font
font: fontDapText
}
text: elText
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment