From kde-commits Thu Mar 28 21:47:30 2013 From: Viranch Mehta Date: Thu, 28 Mar 2013 21:47:30 +0000 To: kde-commits Subject: [kbreakout] src/qml: Simply the font size calculation for TextItem and get rid of the flickering of Message-Id: <20130328214730.5C0B1A604F () git ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=136450722715615 Git commit 30463d589e3b1dc36b07f1ac7fe7c33aaafb9b38 by Viranch Mehta. Committed on 28/03/2013 at 22:46. Pushed by viranch into branch 'master'. Simply the font size calculation for TextItem and get rid of the flickering= of text M +19 -35 src/qml/TextItem.qml http://commits.kde.org/kbreakout/30463d589e3b1dc36b07f1ac7fe7c33aaafb9b38 diff --git a/src/qml/TextItem.qml b/src/qml/TextItem.qml index d242dbe..a15dea3 100644 --- a/src/qml/TextItem.qml +++ b/src/qml/TextItem.qml @@ -33,47 +33,31 @@ CanvasItem { color: "white" } = - onTextChanged: fontTimerTrigger.restart(); + onTextChanged: updateFontSize(); + Component.onCompleted: updateTimer.start(); = - // assign largest font size and start the timer to update - // font size to fit text - function updateFontSize() { - fontSize =3D 72/m_scale; - fontTimer.start(); - } - = - // do not update font size more frequently than once in 100ms Timer { - id: fontTimerTrigger - interval: 100 - onTriggered: { - if (!fontTimer.running) - updateFontSize(); - } + id: updateTimer + interval: 1 + onTriggered: updateFontSize(); } = - // check font size every 1ms; if text does not fit, decrease the font = size - // stop the timer, if text fits - Timer { - id: fontTimer - interval: 1 - repeat: true - onTriggered: { - var w =3D item.width*0.8; - var h =3D item.height; - if (textItem.width > w || textItem.height > h) { - var size =3D Math.min(w * fontSize / textItem.width, h * f= ontSize / textItem.height); - size =3D Math.floor(size); - if (size =3D=3D fontSize) { - stop(); - opacity =3D 1; - } else { - fontSize =3D size; - } + function updateFontSize() { + opacity =3D 0; + fontSize =3D 72/m_scale; + + var w =3D item.width*0.8; + var h =3D item.height; + while (textItem.width > w || textItem.height > h) { + var size =3D Math.min(w * fontSize / textItem.width, h * fontS= ize / textItem.height); + size =3D Math.floor(size); + if (size =3D=3D fontSize) { + break; } else { - stop(); - opacity =3D 1; + fontSize =3D size; } } + + opacity =3D 1; } }