1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-22 16:08:39 -05:00
sdrangel/sdrgui/gui/buttonswitch.cpp

56 lines
1003 B
C++
Raw Normal View History

#include <QPainter>
#include "gui/buttonswitch.h"
ButtonSwitch::ButtonSwitch(QWidget* parent) :
QToolButton(parent)
{
setCheckable(true);
m_originalPalette = palette();
connect(this, SIGNAL(toggled(bool)), this, SLOT(onToggled(bool)));
}
void ButtonSwitch::onToggled(bool checked)
{
blockSignals(true);
setChecked(checked);
blockSignals(false);
if (checked)
{
QPalette p = m_originalPalette;
p.setColor(QPalette::Button, QColor(0x80, 0x46, 0x00));
setPalette(p);
}
else
{
setPalette(m_originalPalette);
}
}
void ButtonSwitch::doToggle(bool checked)
{
onToggled(checked);
}
void ButtonSwitch::setColor(QColor color)
{
QPalette p = m_originalPalette;
p.setColor(QPalette::Button, color);
setPalette(p);
}
void ButtonSwitch::resetColor()
{
if (isChecked())
{
QPalette p = m_originalPalette;
p.setColor(QPalette::Button, QColor(0x80, 0x46, 0x00));
setPalette(p);
}
else
{
setPalette(m_originalPalette);
}
}