Warning, /games/kbreakout/src/qml/TextItem.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 SPDX-FileCopyrightText: 2012 Viranch Mehta <viranch.mehta@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 import QtQuick 2.3 0008 import org.kde.games.core 0.1 as KgCore 0009 import "globals.js" as Globals 0010 0011 CanvasItem { 0012 id: item 0013 spriteKey: "Display" 0014 property alias text: textItem.text 0015 property int fontSize 0016 0017 Text { 0018 id: textItem 0019 anchors.centerIn: parent 0020 opacity: 220/256 0021 font { bold: true; family: "Helvetica"; pixelSize: fontSize*m_scale } 0022 color: "white" 0023 } 0024 0025 onTextChanged: updateFontSize(); 0026 Component.onCompleted: updateTimer.start(); 0027 0028 Timer { 0029 id: updateTimer 0030 interval: 1 0031 onTriggered: updateFontSize(); 0032 } 0033 0034 function updateFontSize() { 0035 opacity = 0; 0036 fontSize = 72/m_scale; 0037 0038 var w = item.width*0.8; 0039 var h = item.height; 0040 while (textItem.width > w || textItem.height > h) { 0041 var size = Math.min(w * fontSize / textItem.width, h * fontSize / textItem.height); 0042 size = Math.floor(size); 0043 if (size == fontSize) { 0044 break; 0045 } else { 0046 fontSize = size; 0047 } 0048 } 0049 0050 opacity = 1; 0051 } 0052 }