]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Deal with the case where the icon might be taller than the text. Approved by fredrik.
authorSimon Paul St James <kdedevel@etotheipiplusone.com>
Mon, 18 Aug 2008 20:25:52 +0000 (20:25 +0000)
committerSimon Paul St James <kdedevel@etotheipiplusone.com>
Mon, 18 Aug 2008 20:25:52 +0000 (20:25 +0000)
svn path=/trunk/KDE/kdebase/apps/; revision=848980

src/kformattedballoontipdelegate.cpp

index 833f612f1b813355d6741f7d190318fb529d251d..5df695ba68b2348395e74e5dd92360e44547830c 100644 (file)
 #include "kformattedballoontipdelegate.h"
 #include <QBitmap>
 #include <QTextDocument>
+#include <kdebug.h>
 
 QSize KFormattedBalloonTipDelegate::sizeHint(const KStyleOptionToolTip *option, const KToolTipItem *item) const
 {
     QTextDocument doc;
     doc.setHtml(item->text());
     QIcon icon = item->icon();
-    QSize is = (icon.isNull()) ? QSize(0,0) : QSize(icon.actualSize(option->decorationSize).width(),0);
-    return doc.size().toSize()+is+QSize(20+5,20+1);
+        
+    QSize iconSize = (icon.isNull()) ? QSize(0,0) : icon.actualSize(option->decorationSize);
+    QSize docSize = doc.size().toSize();
+    QSize contentSize = iconSize + docSize;
+    
+    // Re-adjust contentSize's height so that it is the maximum of the icon
+    // and doc sizes.
+    contentSize.setHeight( iconSize.height() > doc.size().height() ? iconSize.height() : doc.size().height());
+    return contentSize + QSize(20+5,20+1);
 }
 
 void KFormattedBalloonTipDelegate::paint(QPainter *painter, const KStyleOptionToolTip *option, const KToolTipItem *item) const
@@ -62,6 +70,9 @@ void KFormattedBalloonTipDelegate::paint(QPainter *painter, const KStyleOptionTo
     bitmap.fill(Qt::transparent);
     QPainter p(&bitmap);
     doc.drawContents(&p);
+    
+    // Ensure doc text is not stretched when icon is larger.
+    contents.setSize(doc.size().toSize());
 
     painter->drawPixmap(contents, bitmap);
 }