1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-04 21:27:58 +02: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 ); QPainter p( this );
QRect r = contentsRect(); QRect r = contentsRect();
StyleHelper::horizontalHeader(&p, r); StyleHelper::horizontalHeader( &p, r );
QTextOption to( alignment() | Qt::AlignVCenter ); QTextOption to( alignment() | Qt::AlignVCenter );
r.adjust( 8, 0, -8, 0 ); r.adjust( 8, 0, -8, 0 );

View File

@@ -18,21 +18,27 @@
#include "ToggleButton.h" #include "ToggleButton.h"
#include "widgets/HeaderLabel.h"
#include "utils/stylehelper.h" #include "utils/stylehelper.h"
#include <QStylePainter> #include <QStylePainter>
#include <QStyleOptionButton>
ToggleButton::ToggleButton( QWidget* parent ) ToggleButton::ToggleButton( QWidget* parent )
: QPushButton( 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; } " QFont f( font() );
"QPushButton:checked { background-color: %2; border-style: inset; }" f.setBold( true );
"QPushButton:pressed { background-color: %2; border-style: inset; }" ) f.setPixelSize( 11 );
.arg( StyleHelper::headerUpperColor().name() ) setFont( f );
.arg( StyleHelper::headerLowerColor().darker().name() ) );
HeaderLabel* hl = new HeaderLabel( (QWidget*)0 );
setFixedHeight( hl->sizeHint().height() + 8 );
delete hl;
setCheckable( true ); 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 void
ToggleButton::paintEvent( QPaintEvent* event ) ToggleButton::paintEvent( QPaintEvent* event )
{ {
QStylePainter p( this ); 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" #include "dllmacro.h"
/** /**
* \class PushButton * \class ToggleButton
* \brief A styled push-button that has a header background. * \brief A styled toggle-button that has a header background.
*/ */
class DLLEXPORT ToggleButton : public QPushButton class DLLEXPORT ToggleButton : public QPushButton
{ {
@@ -36,6 +36,9 @@ public:
ToggleButton( QWidget* parent = 0 ); ToggleButton( QWidget* parent = 0 );
virtual ~ToggleButton(); virtual ~ToggleButton();
public slots:
virtual void setText( const QString& text );
protected: protected:
virtual void paintEvent( QPaintEvent* ); 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->layoutWidget->layout() );
TomahawkUtils::unmarginLayout( ui->layoutWidget1->layout() ); TomahawkUtils::unmarginLayout( ui->layoutWidget1->layout() );
TomahawkUtils::unmarginLayout( ui->layoutWidget2->layout() ); TomahawkUtils::unmarginLayout( ui->layoutWidget2->layout() );
TomahawkUtils::unmarginLayout( ui->verticalLayout_5->layout() );
TomahawkUtils::unmarginLayout( ui->albumHeader->layout() ); TomahawkUtils::unmarginLayout( ui->albumHeader->layout() );
m_albumsModel = new TreeModel( ui->albums ); m_albumsModel = new TreeModel( ui->albums );
@@ -70,7 +69,6 @@ ArtistInfoWidget::ArtistInfoWidget( const Tomahawk::artist_ptr& artist, QWidget*
ui->topHits->setTrackModel( m_topHitsModel ); ui->topHits->setTrackModel( m_topHitsModel );
ui->albumHeader->setContentsMargins( 0, 0, 4, 0 ); ui->albumHeader->setContentsMargins( 0, 0, 4, 0 );
ui->button->setFixedWidth( 200 );
ui->button->setChecked( true ); ui->button->setChecked( true );
m_pixmap = QPixmap( RESPATH "images/no-album-art-placeholder.png" ).scaledToWidth( 48, Qt::SmoothTransformation ); m_pixmap = QPixmap( RESPATH "images/no-album-art-placeholder.png" ).scaledToWidth( 48, Qt::SmoothTransformation );