[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdeplasma-addons/applets/frame
From:       Beat Wolf <asraniel () fryx ! ch>
Date:       2010-12-18 23:16:05
Message-ID: 20101218231605.ED63DAC8AA () svn ! kde ! org
[Download RAW message or body]

SVN commit 1207626 by beatwolf:

Correctly set the text size so that it fits for all languages.
BUG:246419


 M  +31 -1     frame.cpp  
 M  +2 -0      frame.h  


--- trunk/KDE/kdeplasma-addons/applets/frame/frame.cpp #1207625:1207626
@@ -398,12 +398,15 @@
         // Set the font and draw text
         p->setRenderHint(QPainter::Antialiasing);
         QFont textFont = \
                Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont);
-        textFont.setPixelSize(qMax(KGlobalSettings::smallestReadableFont().pixelSize(), \
bgRect.height() / 6)); +        \
textFont.setPointSize(qMax(KGlobalSettings::smallestReadableFont().pointSize(), \
bgRect.height() / 6));  p->setFont(textFont);
 
         QTextOption option;
         option.setAlignment(Qt::AlignCenter);
         option.setWrapMode(QTextOption::WordWrap);
+
+        preparePainter(p, bgRect, textFont, message);
+
         p->setPen(QPen(Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor), \
1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));  p->drawText(bgRect, message, \
option);  }
@@ -418,6 +421,33 @@
     }
 }
 
+QRect Frame::preparePainter(QPainter *p, const QRect &rect, const QFont &font, const \
QString &text) +{
+    QRect tmpRect;
+    QFont tmpFont = font;
+    bool first = true;
+
+    // Starting with the given font, decrease its size until it'll fit in the
+    // given rect allowing wrapping where possible
+    do {
+        if (first) {
+            first = false;
+        } else  {
+            tmpFont.setPointSize(qMax(KGlobalSettings::smallestReadableFont().pointSize(), \
tmpFont.pointSize() - 1)); +        }
+
+        const QFontMetrics fm(tmpFont);
+        int flags = Qt::TextWordWrap;
+
+        tmpRect = fm.boundingRect(rect, flags, text);
+    } while (tmpFont.pointSize() > \
KGlobalSettings::smallestReadableFont().pointSize() && +             (tmpRect.width() \
> rect.width() || tmpRect.height() > rect.height())); +    
+    p->setFont(tmpFont);
+    return tmpRect;
+}
+
+
 void Frame::nextPicture()
 {
     m_mySlideShow->setUpdateInterval(0);
--- trunk/KDE/kdeplasma-addons/applets/frame/frame.h #1207625:1207626
@@ -89,6 +89,8 @@
     void initSlideShow();
     void checkSlideFrame();
 
+    QRect preparePainter(QPainter *p, const QRect &rect, const QFont &font, const \
QString &text); +
     /// The current color of the frame
     QColor m_frameColor;
     /// Configuration dialog


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic