File: playerbutton.cpp

package info (click to toggle)
esperanza 0.4.0%2Bgit20091017-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,964 kB
  • ctags: 1,206
  • sloc: cpp: 9,629; sh: 48; makefile: 10
file content (86 lines) | stat: -rw-r--r-- 1,870 bytes parent folder | download | duplicates (5)
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/** 
 *  This file is a part of Esperanza, an XMMS2 Client.
 *
 *  Copyright (C) 2005-2007 XMMS2 Team
 *
 *  This program 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 2
 *  of the License, or (at your option) any later version.
 *
 *  This program 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.
 */


#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);
}