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