mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-20 07:49:42 +01:00
* Hopefully fixed ToggleButton for all platforms.
This commit is contained in:
parent
5b48442006
commit
bc266e1f7c
@ -26,18 +26,16 @@
|
||||
|
||||
|
||||
ToggleButton::ToggleButton( QWidget* parent )
|
||||
: QPushButton( parent )
|
||||
: QLabel( parent )
|
||||
, m_checked( false )
|
||||
{
|
||||
QFont f( font() );
|
||||
f.setBold( true );
|
||||
f.setPixelSize( 11 );
|
||||
f.setPixelSize( 10 );
|
||||
|
||||
setFont( f );
|
||||
setFixedHeight( sizeHint().height() + 8 );
|
||||
|
||||
HeaderLabel* hl = new HeaderLabel( (QWidget*)0 );
|
||||
setFixedHeight( hl->sizeHint().height() + 8 );
|
||||
delete hl;
|
||||
|
||||
setCheckable( true );
|
||||
setCursor( Qt::PointingHandCursor );
|
||||
}
|
||||
|
||||
@ -50,20 +48,30 @@ ToggleButton::~ToggleButton()
|
||||
void
|
||||
ToggleButton::setText( const QString& s )
|
||||
{
|
||||
QPushButton::setText( s );
|
||||
QLabel::setText( s );
|
||||
setFixedWidth( fontMetrics().width( text() ) + 32 );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ToggleButton::mouseReleaseEvent( QMouseEvent* event )
|
||||
{
|
||||
QFrame::mouseReleaseEvent( event );
|
||||
|
||||
m_checked ^= true;
|
||||
update();
|
||||
|
||||
emit clicked();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ToggleButton::paintEvent( QPaintEvent* event )
|
||||
{
|
||||
QStylePainter p( this );
|
||||
QPainter p( this );
|
||||
|
||||
p.save();
|
||||
QStyleOptionButton cb;
|
||||
initStyleOption( &cb );
|
||||
QRect r = cb.rect;
|
||||
QRect r = contentsRect();
|
||||
StyleHelper::horizontalHeader( &p, r );
|
||||
p.restore();
|
||||
|
||||
@ -83,7 +91,7 @@ ToggleButton::paintEvent( QPaintEvent* event )
|
||||
{
|
||||
p.setBrush( StyleHelper::headerHighlightColor() );
|
||||
}
|
||||
else if ( cb.state & QStyle::State_MouseOver )
|
||||
else if ( false )
|
||||
{
|
||||
p.setBrush( StyleHelper::headerLowerColor() );
|
||||
}
|
||||
@ -98,7 +106,7 @@ ToggleButton::paintEvent( QPaintEvent* event )
|
||||
QTextOption to( Qt::AlignCenter );
|
||||
r.adjust( 8, 0, -8, 0 );
|
||||
p.setBrush( StyleHelper::headerTextColor() );
|
||||
p.drawText( r, cb.text, to );
|
||||
p.drawText( r, text(), to );
|
||||
|
||||
p.restore();
|
||||
}
|
||||
|
@ -19,7 +19,7 @@
|
||||
#ifndef TOGGLEBUTTON_H
|
||||
#define TOGGLEBUTTON_H
|
||||
|
||||
#include <QPushButton>
|
||||
#include <QLabel>
|
||||
#include <QPaintEvent>
|
||||
|
||||
#include "dllmacro.h"
|
||||
@ -28,7 +28,7 @@
|
||||
* \class ToggleButton
|
||||
* \brief A styled toggle-button that has a header background.
|
||||
*/
|
||||
class DLLEXPORT ToggleButton : public QPushButton
|
||||
class DLLEXPORT ToggleButton : public QLabel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@ -36,11 +36,23 @@ public:
|
||||
ToggleButton( QWidget* parent = 0 );
|
||||
virtual ~ToggleButton();
|
||||
|
||||
QSize minimumSizeHint() const { return sizeHint(); }
|
||||
|
||||
bool isChecked() const { return m_checked; }
|
||||
|
||||
public slots:
|
||||
virtual void setText( const QString& text );
|
||||
virtual void setChecked( bool b ) { m_checked = b; }
|
||||
|
||||
signals:
|
||||
void clicked();
|
||||
|
||||
protected:
|
||||
virtual void paintEvent( QPaintEvent* );
|
||||
void mouseReleaseEvent( QMouseEvent* event );
|
||||
|
||||
private:
|
||||
bool m_checked;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -73,7 +73,7 @@ ArtistInfoWidget::ArtistInfoWidget( const Tomahawk::artist_ptr& artist, QWidget*
|
||||
|
||||
m_pixmap = QPixmap( RESPATH "images/no-album-art-placeholder.png" ).scaledToWidth( 48, Qt::SmoothTransformation );
|
||||
|
||||
connect( ui->button, SIGNAL( toggled( bool ) ), SLOT( onModeToggle( bool ) ) );
|
||||
connect( ui->button, SIGNAL( clicked() ), SLOT( onModeToggle() ) );
|
||||
|
||||
connect( Tomahawk::InfoSystem::InfoSystem::instance(),
|
||||
SIGNAL( info( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ),
|
||||
@ -92,9 +92,9 @@ ArtistInfoWidget::~ArtistInfoWidget()
|
||||
|
||||
|
||||
void
|
||||
ArtistInfoWidget::onModeToggle( bool officialReleases )
|
||||
ArtistInfoWidget::onModeToggle()
|
||||
{
|
||||
m_albumsModel->setMode( officialReleases ? TreeModel::InfoSystem : TreeModel::Database );
|
||||
m_albumsModel->setMode( ui->button->isChecked() ? TreeModel::InfoSystem : TreeModel::Database );
|
||||
m_albumsModel->clear();
|
||||
m_albumsModel->addAlbums( m_artist, QModelIndex() );
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ private slots:
|
||||
void infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output );
|
||||
void infoSystemFinished( QString target );
|
||||
|
||||
void onModeToggle( bool officialReleases );
|
||||
void onModeToggle();
|
||||
|
||||
private:
|
||||
Ui::ArtistInfoWidget *ui;
|
||||
|
Loading…
x
Reference in New Issue
Block a user