From e32d1761c348f854972f0a2fdb9b3279852ee0d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Thu, 9 Aug 2012 13:26:43 +0200 Subject: [PATCH] Properly elide text in large icons TabBox theme Using the same elide adjustments as in Thumbnails theme. BUG: 304847 FIXED-IN: 4.9.1 REVIEW: 105959 --- .../clients/big_icons/contents/ui/main.qml | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tabbox/qml/clients/big_icons/contents/ui/main.qml b/tabbox/qml/clients/big_icons/contents/ui/main.qml index a95264ed70..7115b7f4d9 100644 --- a/tabbox/qml/clients/big_icons/contents/ui/main.qml +++ b/tabbox/qml/clients/big_icons/contents/ui/main.qml @@ -63,6 +63,7 @@ Item { } } Item { + id: captionFrame anchors { top: icons.bottom left: parent.left @@ -73,11 +74,23 @@ Item { bottomMargin: background.margins.bottom } Text { + function constrainWidth() { + if (textItem.width > textItem.maxWidth && textItem.width > 0 && textItem.maxWidth > 0) { + textItem.width = textItem.maxWidth; + } else { + textItem.width = undefined; + } + } + function calculateMaxWidth() { + textItem.maxWidth = bigIconsTabBox.width - captionFrame.anchors.leftMargin - captionFrame.anchors.rightMargin - captionFrame.anchors.rightMargin; + } id: textItem + property int maxWidth: 0 text: icons.currentItem ? icons.currentItem.data.caption : "" horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter color: theme.textColor + elide: Text.ElideMiddle font { bold: true } @@ -85,6 +98,15 @@ Item { verticalCenter: parent.verticalCenter horizontalCenter: parent.horizontalCenter } + onTextChanged: textItem.constrainWidth() + Component.onCompleted: textItem.calculateMaxWidth() + Connections { + target: bigIconsTabBox + onWidthChanged: { + textItem.calculateMaxWidth(); + textItem.constrainWidth(); + } + } } } }