[Kde-games-devel] Rough edges in localized KFourInLine

Eneko Nieto enekonieto at gmail.com
Wed Jul 3 14:47:10 UTC 2013


I'm getting mad with adaptFontSize, I hope you can show me the right direction.

First, I still don't know how to get a QPainter from a
QGraphicsTextItem (it extends QGraphicsObject that extends
QGraphicsItem and QObject), so I am creating a dummy QPixmap and a
QPainter to use adaptFontSize on. Sure there is a more ellegant way to
achieve this.

Second, the result I am getting with adaptFontSize are smaller than
they should be. The code for the title ("Quick start") is as follows:

//mTextQuicklaunch->setPlainText("this is a very long line so we need
a small font size");
  // Create and set current font
  QFont font;
  QPixmap p = QPixmap(1, 1);
  QPainter paint(&p);
  paint.setFont(font);
kDebug() << "max fontHeight=" << fontHeight;
  fontHeight = KFontUtils::adaptFontSize(paint,
mTextQuicklaunch->toPlainText(), textWidth, textHeight, fontHeight,
8.0);
kDebug() << "new fontHeight=" << fontHeight;
  font.setPointSizeF(fontHeight);

  // Set font and color for all text items
  mTextQuicklaunch->setFont(font);
  mTextQuicklaunch->setDefaultTextColor(fontColor);
//  mTextQuicklaunch->setTextWidth(textWidth);

  // Set position of sub sprites
  QRectF bounding = mTextQuicklaunch->boundingRect();
kDebug() << "textWidth=" << textWidth;
kDebug() << "bounding.width()=" << bounding.width();
kDebug() << "textHeight=" << textHeight;
kDebug() << "bounding.height()=" << bounding.height();
  mTextQuicklaunch->setPos(posQuickstart.x() * width + (textWidth -
bounding.width()) / 2,
                           posQuickstart.y() * height + (textHeight -
bounding.height()) / 2);

And the output:

kfourinline(4223) DisplayIntro::changeTheme: max fontHeight= 38.64
kfourinline(4223) DisplayIntro::changeTheme: new fontHeight= 16.7947
kfourinline(4223) DisplayIntro::changeTheme: textWidth= 287.1
kfourinline(4223) DisplayIntro::changeTheme: bounding.width()= 152.719
kfourinline(4223) DisplayIntro::changeTheme: textHeight= 55.2
kfourinline(4223) DisplayIntro::changeTheme: bounding.height()= 36

Why adaptFontSize is not returning a bigger font size? Is there more
documentation apart of the API reference
(http://api.kde.org/4.10-api/kdelibs-apidocs/kdeui/html/namespaceKFontUtils.html)?

Besides, I'm not having luck trying to centre the texts. If I use
setTextWidth() then boundingRect() returns near all the width, so I
cannot centre single line texts.

Thanks in advance!

Eneko

2013/6/20 Eneko Nieto <enekonieto at gmail.com>:
> Yes sure, I'll work on this the weekend. Thanks for helping me with
> previous patches :)
>
> Eneko
>
> 2013/6/17 Albert Astals Cid <aacid at kde.org>:
>> El Dilluns, 17 de juny de 2013, a les 08:24:01, Yuri Chornoivan va escriure:
>>> Hi,
>>>
>>> I have compiled and installed KFourInLine from git/master.
>>>
>>> The game looks beautiful until gets translated.
>>>
>>> English:
>>>
>>> https://dl.dropboxusercontent.com/u/55247264/kfourinline_en.png
>>>
>>> Ukrainian:
>>>
>>> https://dl.dropboxusercontent.com/u/55247264/kfourinline_uk.png
>>>
>>> I have cleaned all config files before starting the game.
>>>
>>> Is there any way to fix this?
>>
>> I guess it'd need to use KFontUtils or something similar to make sure the text
>> fits on the available box space.
>>
>> Eneko do you think you can give it a try?
>>
>> Cheers,
>>   Albert
>>
>>>
>>> Thanks in advance for your answers.
>>>
>>> Best regards,
>>> Yuri
>>> _______________________________________________
>>> kde-games-devel mailing list
>>> kde-games-devel at kde.org
>>> https://mail.kde.org/mailman/listinfo/kde-games-devel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: kfourinline_adaptfontsize.patch
Type: application/octet-stream
Size: 4329 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-games-devel/attachments/20130703/67b20411/attachment.obj>


More information about the kde-games-devel mailing list