1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-09 07:36:48 +02:00

* Added ToggleButton, a header-style PushButton with a toggle state.

This commit is contained in:
Christian Muehlhaeuser
2011-09-09 10:24:29 +02:00
parent a1314347f9
commit 20eeaf73ac
2 changed files with 122 additions and 0 deletions

View File

@@ -0,0 +1,70 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tomahawk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ToggleButton.h"
#include "utils/stylehelper.h"
#include <QStylePainter>
ToggleButton::ToggleButton( QWidget* parent )
: QPushButton( parent )
, m_toggled( false )
{
setStyleSheet( QString( "QPushButton { color: white; background-color: %1; border-style: outset; border-width: 1px; border-radius: 4px; border-color: white; font: bold; } "
"QPushButton:pressed { background-color: %2; border-style: inset; }" )
.arg( StyleHelper::headerUpperColor().name() )
.arg( StyleHelper::headerLowerColor().darker().name() ) );
connect( this, SIGNAL( released() ), SLOT( onToggled() ) );
}
ToggleButton::~ToggleButton()
{
}
void
ToggleButton::setDown( bool b )
{
m_toggled = b;
QPushButton::setDown( b );
}
void
ToggleButton::onToggled()
{
m_toggled ^= true;
setDown( m_toggled );
emit toggled( m_toggled );
}
void
ToggleButton::paintEvent( QPaintEvent* event )
{
QStylePainter p( this );
QRect r = event->rect();
StyleHelper::horizontalHeader( &p, r );
QPushButton::paintEvent( event );
}

View File

@@ -0,0 +1,52 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2011, Casey Link <unnamedrambler@gmail.com>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tomahawk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TOGGLEBUTTON_H
#define TOGGLEBUTTON_H
#include <QPushButton>
#include <QPaintEvent>
#include "dllmacro.h"
/**
* \class PushButton
* \brief A styled push-button that has a header background.
*/
class DLLEXPORT ToggleButton : public QPushButton
{
Q_OBJECT
public:
ToggleButton( QWidget* parent = 0 );
virtual ~ToggleButton();
public slots:
void setDown( bool b );
protected:
virtual void paintEvent( QPaintEvent* );
private slots:
void onToggled();
private:
bool m_toggled;
};
#endif