mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-10-05 18:11:36 +02:00
* Tried to fix OS X layout of ToggleButton.
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
Reference in New Issue
Block a user