1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-20 07:49:42 +01:00

* Tried to fix OS X layout of ToggleButton.

This commit is contained in:
Christian Muehlhaeuser 2011-09-14 08:19:26 +02:00
parent 1367d82006
commit 22d3048017
4 changed files with 66 additions and 13 deletions

View File

@ -74,7 +74,7 @@ HeaderLabel::paintEvent( QPaintEvent* /* event */ )
{
QPainter p( this );
QRect r = contentsRect();
StyleHelper::horizontalHeader(&p, r);
StyleHelper::horizontalHeader( &p, r );
QTextOption to( alignment() | Qt::AlignVCenter );
r.adjust( 8, 0, -8, 0 );

View File

@ -18,21 +18,27 @@
#include "ToggleButton.h"
#include "widgets/HeaderLabel.h"
#include "utils/stylehelper.h"
#include <QStylePainter>
#include <QStyleOptionButton>
ToggleButton::ToggleButton( QWidget* parent )
: QPushButton( parent )
{
setStyleSheet( QString( "QPushButton { color: white; background-color: %1; border-style: outset; border-width: 1px; border-radius: 4px; border-color: white; font: bold; } "
"QPushButton:checked { background-color: %2; border-style: inset; }"
"QPushButton:pressed { background-color: %2; border-style: inset; }" )
.arg( StyleHelper::headerUpperColor().name() )
.arg( StyleHelper::headerLowerColor().darker().name() ) );
QFont f( font() );
f.setBold( true );
f.setPixelSize( 11 );
setFont( f );
HeaderLabel* hl = new HeaderLabel( (QWidget*)0 );
setFixedHeight( hl->sizeHint().height() + 8 );
delete hl;
setCheckable( true );
setCursor( Qt::PointingHandCursor );
}
@ -41,12 +47,58 @@ ToggleButton::~ToggleButton()
}
void
ToggleButton::setText( const QString& s )
{
QPushButton::setText( s );
setFixedWidth( fontMetrics().width( text() ) + 32 );
}
void
ToggleButton::paintEvent( QPaintEvent* event )
{
QStylePainter p( this );
QRect r = event->rect();
StyleHelper::horizontalHeader( &p, r );
QPushButton::paintEvent( event );
p.save();
QStyleOptionButton cb;
initStyleOption( &cb );
QRect r = cb.rect;
StyleHelper::horizontalHeader( &p, r );
p.restore();
p.save();
p.setRenderHint( QPainter::Antialiasing );
p.setPen( Qt::white );
{
QRect highlightRect( r );
QSize shrink( 2, 4 );
QSize hS( highlightRect.size() );
hS -= shrink;
highlightRect.setSize( hS );
highlightRect.translate( 0, 2 );
if ( isChecked() )
{
p.setBrush( StyleHelper::headerHighlightColor() );
}
else if ( cb.state & QStyle::State_MouseOver )
{
p.setBrush( StyleHelper::headerLowerColor() );
}
else
{
p.setBrush( StyleHelper::headerUpperColor() );
}
p.drawRoundedRect( highlightRect, 10.0, 10.0 );
}
QTextOption to( Qt::AlignCenter );
r.adjust( 8, 0, -8, 0 );
p.setBrush( StyleHelper::headerTextColor() );
p.drawText( r, cb.text, to );
p.restore();
}

View File

@ -25,8 +25,8 @@
#include "dllmacro.h"
/**
* \class PushButton
* \brief A styled push-button that has a header background.
* \class ToggleButton
* \brief A styled toggle-button that has a header background.
*/
class DLLEXPORT ToggleButton : public QPushButton
{
@ -36,6 +36,9 @@ public:
ToggleButton( QWidget* parent = 0 );
virtual ~ToggleButton();
public slots:
virtual void setText( const QString& text );
protected:
virtual void paintEvent( QPaintEvent* );
};

View File

@ -54,7 +54,6 @@ ArtistInfoWidget::ArtistInfoWidget( const Tomahawk::artist_ptr& artist, QWidget*
TomahawkUtils::unmarginLayout( ui->layoutWidget->layout() );
TomahawkUtils::unmarginLayout( ui->layoutWidget1->layout() );
TomahawkUtils::unmarginLayout( ui->layoutWidget2->layout() );
TomahawkUtils::unmarginLayout( ui->verticalLayout_5->layout() );
TomahawkUtils::unmarginLayout( ui->albumHeader->layout() );
m_albumsModel = new TreeModel( ui->albums );
@ -70,7 +69,6 @@ ArtistInfoWidget::ArtistInfoWidget( const Tomahawk::artist_ptr& artist, QWidget*
ui->topHits->setTrackModel( m_topHitsModel );
ui->albumHeader->setContentsMargins( 0, 0, 4, 0 );
ui->button->setFixedWidth( 200 );
ui->button->setChecked( true );
m_pixmap = QPixmap( RESPATH "images/no-album-art-placeholder.png" ).scaledToWidth( 48, Qt::SmoothTransformation );