1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
#include <QLabel>
#include <QPixmap>
#include <QSettings>
#include "playerbutton.h"
PlayerButton::PlayerButton (QWidget *parent, const QString &pic) : QLabel (parent)
{
setMargin (3);
setPx (pic);
setFrameStyle (QFrame::StyledPanel | QFrame::Plain);
setAutoFillBackground (true);
}
void
PlayerButton::enterEvent (QEvent *ev)
{
QSettings s;
QPalette p (palette ());
p.setColor (QPalette::Window, p.color (QPalette::Highlight));
p.setColor (QPalette::WindowText, p.color (QPalette::HighlightedText));
setPalette (p);
if (!m_pixmap_hoover.isNull ())
setPixmap (m_pixmap_hoover);
update ();
}
void
PlayerButton::leaveEvent (QEvent *ev)
{
QPalette p (parentWidget ()->palette ());
setPalette (p);
if (!m_pixmap_hoover.isNull ())
setPixmap (m_pixmap);
update ();
}
void
PlayerButton::setPx (const QString &pic)
{
QPalette p (parentWidget ()->palette ());
QImage i (pic);
if (i.isNull ()) {
setText (pic);
} else {
i.setColor (0, p.color (QPalette::Text).rgb ());
m_pixmap = QPixmap::fromImage (i);
i.setColor (0, p.color (QPalette::HighlightedText).rgb ());
m_pixmap_hoover = QPixmap::fromImage (i);
setPixmap (m_pixmap);
}
}
void
PlayerButton::mousePressEvent (QMouseEvent *ev)
{
emit clicked (ev);
}
|