From dc79dfe403ef810d495801d597c5e55150cc84af Mon Sep 17 00:00:00 2001
From: Christian Muehlhaeuser <muesli@gmail.com>
Date: Fri, 6 Jan 2012 08:03:25 +0100
Subject: [PATCH] * Hardcoded a bunch of font-sizes. Should be properly fixed
 eventually.

---
 .../playlist/albumitemdelegate.cpp            |  6 +--
 .../playlist/playlistitemdelegate.cpp         |  8 ++--
 src/libtomahawk/playlistinterface.cpp         |  1 +
 src/libtomahawk/widgets/OverlayButton.cpp     | 41 +++++++++----------
 src/libtomahawk/widgets/welcomewidget.cpp     |  9 ++--
 src/sourcetree/sourcedelegate.cpp             | 10 ++---
 6 files changed, 36 insertions(+), 39 deletions(-)

diff --git a/src/libtomahawk/playlist/albumitemdelegate.cpp b/src/libtomahawk/playlist/albumitemdelegate.cpp
index 62f90a3ee..7860147af 100644
--- a/src/libtomahawk/playlist/albumitemdelegate.cpp
+++ b/src/libtomahawk/playlist/albumitemdelegate.cpp
@@ -129,7 +129,8 @@ AlbumItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
 
     QString text;
     QFont font = opt.font;
-    QFont boldFont = opt.font;
+    font.setPixelSize( 11 );
+    QFont boldFont = font;
     boldFont.setBold( true );
 
     QRect textRect = option.rect.adjusted( 0, option.rect.height() - 32, 0, -2 );
@@ -140,6 +141,7 @@ AlbumItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
     else if ( !item->artist().isNull() )
         name = item->artist()->name();
 
+    painter->setFont( boldFont );
     bool oneLiner = false;
     if ( item->album().isNull() || item->album()->artist().isNull() )
         oneLiner = true;
@@ -149,14 +151,12 @@ AlbumItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
 
     if ( oneLiner )
     {
-        painter->setFont( boldFont );
         to.setAlignment( Qt::AlignHCenter | Qt::AlignVCenter );
         text = painter->fontMetrics().elidedText( name, Qt::ElideRight, textRect.width() - 3 );
         painter->drawText( textRect, text, to );
     }
     else
     {
-        painter->setFont( boldFont );
         to.setAlignment( Qt::AlignHCenter | Qt::AlignTop );
         text = painter->fontMetrics().elidedText( item->album()->name(), Qt::ElideRight, textRect.width() - 3 );
         painter->drawText( textRect, text, to );
diff --git a/src/libtomahawk/playlist/playlistitemdelegate.cpp b/src/libtomahawk/playlist/playlistitemdelegate.cpp
index f0b38237f..c1ba1b8b9 100644
--- a/src/libtomahawk/playlist/playlistitemdelegate.cpp
+++ b/src/libtomahawk/playlist/playlistitemdelegate.cpp
@@ -79,7 +79,10 @@ PlaylistItemDelegate::sizeHint( const QStyleOptionViewItem& option, const QModel
     {
         int style = index.data( TrackModel::StyleRole ).toInt();
         if ( style == TrackModel::Short || style == TrackModel::ShortWithAvatars )
-            size.setHeight( 44 );
+        {
+            int rowHeight = option.fontMetrics.height() + 8;
+            size.setHeight( rowHeight * 2 );
+        }
     }
 
     return size;
@@ -235,8 +238,7 @@ PlaylistItemDelegate::paintShort( QPainter* painter, const QStyleOptionViewItem&
         QString text = painter->fontMetrics().elidedText( upperText, Qt::ElideRight, r.width() );
         painter->drawText( r.adjusted( 0, 1, 0, 0 ), text, m_topOption );
 
-
-        painter->setFont( opt.font);
+        painter->setFont( opt.font );
         text = painter->fontMetrics().elidedText( lowerText, Qt::ElideRight, r.width() );
         painter->drawText( r.adjusted( 0, 1, 0, 0 ), text, m_bottomOption );
     }
diff --git a/src/libtomahawk/playlistinterface.cpp b/src/libtomahawk/playlistinterface.cpp
index 58c71345d..8c03d9df1 100644
--- a/src/libtomahawk/playlistinterface.cpp
+++ b/src/libtomahawk/playlistinterface.cpp
@@ -23,6 +23,7 @@
 using namespace Tomahawk;
 
 PlaylistInterface::PlaylistInterface ()
+    : QObject()
 {
     qRegisterMetaType<Tomahawk::PlaylistInterface::RepeatMode>( "Tomahawk::PlaylistInterface::RepeatMode" );
 }
diff --git a/src/libtomahawk/widgets/OverlayButton.cpp b/src/libtomahawk/widgets/OverlayButton.cpp
index 3cdb88507..f2d5c09e8 100644
--- a/src/libtomahawk/widgets/OverlayButton.cpp
+++ b/src/libtomahawk/widgets/OverlayButton.cpp
@@ -20,12 +20,14 @@
 
 #include <QPainter>
 #include <QPropertyAnimation>
+#include <QAbstractScrollArea>
+#include <QScrollBar>
 
 #include "utils/logger.h"
 
 #define CORNER_ROUNDNESS 8.0
 #define FADING_DURATION 500
-#define FONT_SIZE 16
+#define FONT_SIZE 12
 #define OPACITY 0.70
 
 
@@ -34,7 +36,7 @@ OverlayButton::OverlayButton( QWidget* parent )
     , m_opacity( 0.0 )
     , m_parent( parent )
 {
-    resize( 0, 26 );
+    resize( 0, 28 );
     setAttribute( Qt::WA_TranslucentBackground, true );
 
     setOpacity( m_opacity );
@@ -78,8 +80,12 @@ OverlayButton::setText( const QString& text )
 {
     m_text = text;
 
-    QFontMetrics fm( font() );
-    resize( fm.width( text ) + 16, height() );
+    QFont f( font() );
+    f.setPixelSize( FONT_SIZE );
+    f.setBold( true );
+
+    QFontMetrics fm( f );
+    resize( fm.width( text ) + 24, height() );
 }
 
 
@@ -120,7 +126,13 @@ void
 OverlayButton::paintEvent( QPaintEvent* event )
 {
     Q_UNUSED( event );
-    QPoint corner( m_parent->contentsRect().width() - width() - 12, m_parent->height() - height() - 12 );
+
+    int scrollBarWidth = 0;
+    QAbstractScrollArea* scrollArea = qobject_cast<QAbstractScrollArea*>( m_parent );
+    if ( scrollArea && scrollArea->verticalScrollBar()->isVisible() )
+        scrollBarWidth = scrollArea->verticalScrollBar()->width();
+
+    QPoint corner( m_parent->contentsRect().width() - width() - scrollBarWidth - 12, m_parent->height() - height() - 12 );
     move( corner );
 
     QPainter p( this );
@@ -141,25 +153,10 @@ OverlayButton::paintEvent( QPaintEvent* event )
 
     // shrink to fit if needed
     QFont f( font() );
-    f.setPointSize( FONT_SIZE );
+    f.setPixelSize( FONT_SIZE );
     f.setBold( true );
 
-    QRectF textRect = r.adjusted( 8, 8, -8, -8 );
-    qreal availHeight = textRect.height();
-
-    QFontMetricsF fm( f );
-    qreal textHeight = fm.boundingRect( textRect, Qt::AlignCenter | Qt::TextWordWrap, text() ).height();
-    while ( textHeight > availHeight )
-    {
-        if ( f.pointSize() <= 4 ) // don't try harder
-            break;
-
-        f.setPointSize( f.pointSize() - 1 );
-        fm = QFontMetricsF( f );
-        textHeight = fm.boundingRect( textRect, Qt::AlignCenter | Qt::TextWordWrap, text() ).height();
-    }
-
     p.setFont( f );
     p.setPen( Qt::white );
-    p.drawText( r.adjusted( 8, 8, -8, -8 ), text(), to );
+    p.drawText( r, text(), to );
 }
diff --git a/src/libtomahawk/widgets/welcomewidget.cpp b/src/libtomahawk/widgets/welcomewidget.cpp
index aa776af6c..43c9cb114 100644
--- a/src/libtomahawk/widgets/welcomewidget.cpp
+++ b/src/libtomahawk/widgets/welcomewidget.cpp
@@ -265,12 +265,11 @@ PlaylistDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
     QTextOption to;
     to.setAlignment( Qt::AlignCenter );
     QFont font = opt.font;
-#ifdef Q_WS_MAC
-    font.setPointSize( font.pointSize() - 2 );
-#endif
+    font.setPixelSize( 10 );
 
     QFont boldFont = font;
     boldFont.setBold( true );
+    boldFont.setPixelSize( 11 );
 
     QPixmap icon;
     RecentlyPlayedPlaylistsModel::PlaylistTypes type = (RecentlyPlayedPlaylistsModel::PlaylistTypes)index.data( RecentlyPlayedPlaylistsModel::PlaylistTypeRole ).toInt();
@@ -314,9 +313,7 @@ PlaylistDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
     QRect r( option.rect.width() - avatar.width() - 10, option.rect.top() + option.rect.height()/2 - avatar.height()/2, avatar.width(), avatar.height() );
     painter->drawPixmap( r, avatar );
 
-    QFont font2 = font;
-    font2.setPointSize( font2.pointSize() - 1 );
-    painter->setFont( font2 );
+    painter->setFont( font );
     QString author = index.data( RecentlyPlayedPlaylistsModel::PlaylistRole ).value< Tomahawk::playlist_ptr >()->author()->friendlyName();
     if ( author.contains( "@" ) )
         author = author.mid( 0, author.indexOf( '@' ) );
diff --git a/src/sourcetree/sourcedelegate.cpp b/src/sourcetree/sourcedelegate.cpp
index ea69300b4..ad0fd4855 100644
--- a/src/sourcetree/sourcedelegate.cpp
+++ b/src/sourcetree/sourcedelegate.cpp
@@ -140,6 +140,8 @@ SourceDelegate::paintCollection( QPainter* painter, const QStyleOptionViewItem&
     QFont normal = painter->font();
     QFont bold = painter->font();
     bold.setBold( true );
+    QFont figFont = bold;
+    figFont.setPixelSize( 10 );
 
     SourceTreeItem* item = index.data( SourcesModel::SourceTreeItemRole ).value< SourceTreeItem* >();
     SourceItem* colItem = qobject_cast< SourceItem* >( item );
@@ -153,7 +155,7 @@ SourceDelegate::paintCollection( QPainter* painter, const QStyleOptionViewItem&
     if ( status && colItem && !colItem->source().isNull() )
     {
         tracks = QString::number( colItem->source()->trackCount() );
-        figWidth = painter->fontMetrics().width( tracks );
+        figWidth = QFontMetrics( figFont ).width( tracks );
         name = colItem->source()->friendlyName();
     }
 
@@ -231,10 +233,8 @@ SourceDelegate::paintCollection( QPainter* painter, const QStyleOptionViewItem&
         QRect figRect = option.rect.adjusted( option.rect.width() - figWidth - 8, 0, -13, -option.rect.height() + 16 );
         int hd = ( option.rect.height() - figRect.height() ) / 2;
         figRect.adjust( 0, hd, 0, hd );
-#ifdef Q_WS_WIN
-        figRect.adjust( -3, 0, 3, 0 );
-#endif
-        painter->setFont( bold );
+
+        painter->setFont( figFont );
 
         QColor figColor( 167, 183, 211 );
         painter->setPen( figColor );