From 22d30480179ffe2cea65f006acf77347c9eadab4 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Wed, 14 Sep 2011 08:19:26 +0200 Subject: [PATCH] * Tried to fix OS X layout of ToggleButton. --- src/libtomahawk/widgets/HeaderLabel.cpp | 2 +- src/libtomahawk/widgets/ToggleButton.cpp | 68 ++++++++++++++++--- src/libtomahawk/widgets/ToggleButton.h | 7 +- .../widgets/infowidgets/ArtistInfoWidget.cpp | 2 - 4 files changed, 66 insertions(+), 13 deletions(-) diff --git a/src/libtomahawk/widgets/HeaderLabel.cpp b/src/libtomahawk/widgets/HeaderLabel.cpp index 39b659fd3..bdd033b05 100644 --- a/src/libtomahawk/widgets/HeaderLabel.cpp +++ b/src/libtomahawk/widgets/HeaderLabel.cpp @@ -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 ); diff --git a/src/libtomahawk/widgets/ToggleButton.cpp b/src/libtomahawk/widgets/ToggleButton.cpp index 328412797..dbc94a959 100644 --- a/src/libtomahawk/widgets/ToggleButton.cpp +++ b/src/libtomahawk/widgets/ToggleButton.cpp @@ -18,21 +18,27 @@ #include "ToggleButton.h" +#include "widgets/HeaderLabel.h" #include "utils/stylehelper.h" #include +#include 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(); } diff --git a/src/libtomahawk/widgets/ToggleButton.h b/src/libtomahawk/widgets/ToggleButton.h index 7b395fe9e..d031f874c 100644 --- a/src/libtomahawk/widgets/ToggleButton.h +++ b/src/libtomahawk/widgets/ToggleButton.h @@ -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* ); }; diff --git a/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.cpp b/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.cpp index 361e35143..1fdf09901 100644 --- a/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.cpp +++ b/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.cpp @@ -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 );