1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-06 06:07:37 +02:00

* Store and use a default font height & size.

This commit is contained in:
Christian Muehlhaeuser
2012-09-01 16:16:53 +02:00
parent b4b9ff9d9e
commit 4d3cad5ca1
7 changed files with 34 additions and 29 deletions

View File

@@ -198,9 +198,7 @@ TomahawkApp::init()
QFont f = font(); QFont f = font();
tDebug() << "Default font:" << f.pixelSize() << f.pointSize() << f.pointSizeF() << f.family(); tDebug() << "Default font:" << f.pixelSize() << f.pointSize() << f.pointSizeF() << f.family();
tDebug() << "Font heights:" << QFontMetrics( f ).height(); tDebug() << "Font heights:" << QFontMetrics( f ).height();
f.setPixelSize( HeaderLabel::defaultFontSize() ); TomahawkUtils::setDefaultFontSize( f.pointSize() );
QFontMetrics fm( f );
TomahawkUtils::setHeaderHeight( fm.height() + 8 );
#endif #endif
TomahawkUtils::setHeadless( m_headless ); TomahawkUtils::setHeadless( m_headless );

View File

@@ -50,7 +50,8 @@
namespace TomahawkUtils namespace TomahawkUtils
{ {
static int s_headerHeight = 0; static int s_defaultFontSize = 0;
static int s_defaultFontHeight = 0;
QPixmap QPixmap
@@ -320,16 +321,30 @@ createAvatarFrame( const QPixmap &avatar )
int int
headerHeight() defaultFontSize()
{ {
return s_headerHeight; return s_defaultFontSize;
}
int
defaultFontHeight()
{
if ( s_defaultFontHeight <= 0 )
{
QFont f;
f.setPointSize( defaultFontSize() );
s_defaultFontHeight = QFontMetrics( f ).height();
}
return s_defaultFontHeight;
} }
void void
setHeaderHeight( int height ) setDefaultFontSize( int points )
{ {
s_headerHeight = height; s_defaultFontSize = points;
} }

View File

@@ -57,8 +57,9 @@ namespace TomahawkUtils
DLLEXPORT void unmarginLayout( QLayout* layout ); DLLEXPORT void unmarginLayout( QLayout* layout );
DLLEXPORT int headerHeight(); DLLEXPORT int defaultFontSize();
DLLEXPORT void setHeaderHeight( int height ); DLLEXPORT int defaultFontHeight();
DLLEXPORT void setDefaultFontSize( int points );
DLLEXPORT QPixmap defaultPixmap( ImageType type, ImageMode mode = TomahawkUtils::Original, const QSize& size = QSize( 0, 0 ) ); DLLEXPORT QPixmap defaultPixmap( ImageType type, ImageMode mode = TomahawkUtils::Original, const QSize& size = QSize( 0, 0 ) );

View File

@@ -72,9 +72,10 @@ protected:
p.drawLine( l1 ); p.drawLine( l1 );
p.drawLine( l2 ); p.drawLine( l2 );
} }
virtual QSize sizeHint() const {
return QSize( 20, TomahawkUtils::headerHeight() );
virtual QSize sizeHint() const
{
return QSize( 20, TomahawkUtils::defaultFontHeight() + 8 );
} }
}; };
@@ -92,7 +93,7 @@ BreadcrumbButton::BreadcrumbButton( Breadcrumb* parent, QAbstractItemModel* mode
layout()->addWidget( m_combo ); layout()->addWidget( m_combo );
layout()->addWidget( m_arrow ); layout()->addWidget( m_arrow );
setFixedHeight( TomahawkUtils::headerHeight() ); setFixedHeight( TomahawkUtils::defaultFontHeight() + 8 );
m_combo->setSizeAdjustPolicy( QComboBox::AdjustToContents ); m_combo->setSizeAdjustPolicy( QComboBox::AdjustToContents );
setSizePolicy( QSizePolicy::Maximum, QSizePolicy::Expanding ); setSizePolicy( QSizePolicy::Maximum, QSizePolicy::Expanding );

View File

@@ -54,7 +54,7 @@ ComboBox::paintEvent( QPaintEvent* )
QStyleOptionComboBox cb; QStyleOptionComboBox cb;
initStyleOption( &cb ); initStyleOption( &cb );
QRect r = cb.rect; QRect r = cb.rect;
r.setHeight( TomahawkUtils::headerHeight() ); r.setHeight( TomahawkUtils::defaultFontHeight() + 8 );
StyleHelper::horizontalHeader( &p, r ); StyleHelper::horizontalHeader( &p, r );

View File

@@ -26,8 +26,6 @@
#include "utils/StyleHelper.h" #include "utils/StyleHelper.h"
#include "utils/TomahawkUtilsGui.h" #include "utils/TomahawkUtilsGui.h"
static const int s_defaultFontSize = 9;
HeaderLabel::HeaderLabel( QWidget* parent ) HeaderLabel::HeaderLabel( QWidget* parent )
: QLabel( parent ) : QLabel( parent )
@@ -37,11 +35,10 @@ HeaderLabel::HeaderLabel( QWidget* parent )
{ {
QFont f( font() ); QFont f( font() );
f.setBold( true ); f.setBold( true );
f.setPointSize( s_defaultFontSize ); f.setPointSize( TomahawkUtils::defaultFontSize() );
QFontMetrics fm( f );
setFont( f ); setFont( f );
setFixedHeight( fm.height() * 1.4 );
setFixedHeight( TomahawkUtils::defaultFontHeight() * 1.4 );
setMouseTracking( true ); setMouseTracking( true );
} }
@@ -58,13 +55,6 @@ HeaderLabel::sizeHint() const
} }
int
HeaderLabel::defaultFontSize()
{
return s_defaultFontSize;
}
void void
HeaderLabel::mousePressEvent( QMouseEvent* event ) HeaderLabel::mousePressEvent( QMouseEvent* event )
{ {

View File

@@ -69,13 +69,13 @@ SourceTreeView::SourceTreeView( QWidget* parent )
setContentsMargins( 0, 0, 0, 0 ); setContentsMargins( 0, 0, 0, 0 );
QFont fnt; QFont fnt;
fnt.setPointSize( font().pointSize() - 1 ); fnt.setPointSize( TomahawkUtils::defaultFontSize() - 2 );
setFont( fnt ); setFont( fnt );
QFontMetrics fm( fnt ); QFontMetrics fm( fnt );
// This is sort of the longest string in there. With translations // This is sort of the longest string in there. With translations
// we will never get it right so setting it to something reasonable for the average case // we will never get it right so setting it to something reasonable for the average case
setMinimumWidth( fm.width( "Track Album Artist Local Top10") ); setMinimumWidth( fm.width( "Track Album Artist Local Top10" ) );
setHeaderHidden( true ); setHeaderHidden( true );
setRootIsDecorated( true ); setRootIsDecorated( true );