-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathskinbutton.cpp
68 lines (58 loc) · 1.43 KB
/
skinbutton.cpp
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
#include <QPainter>
#include "skinbutton.h"
#include "resoure.h"
#include <QDebug>
SkinButton::SkinButton(qint32 type, QWidget *parent)
: QPushButton(parent)
, m_type(type)
, m_index(0)
, m_state(ButtonNormal)
{
//connect(this, SIGNAL(clicked(bool)), this, SLOT(setIndex(bool)));
}
void SkinButton::setIndex(bool checked)
{
qDebug() << "OOOOOOOOOOOOOOOOOOOOO " << checked;
m_index = checked ? 1 : 0;
}
#if 0
void SkinButton::setIndex(qint8 index)
{
m_index = index;
}
#endif
QSize SkinButton::sizeHint() const
{
return getStatePixmap().size();
}
void SkinButton::enterEvent(QEvent *event)
{
m_state = ButtonHovered;
QPushButton::enterEvent(event);
}
void SkinButton::leaveEvent(QEvent *event)
{
m_state = ButtonNormal;
QPushButton::leaveEvent(event);
}
void SkinButton::mousePressEvent(QMouseEvent *event)
{
m_state = ButtonPressed;
QPushButton::mousePressEvent(event);
}
void SkinButton::mouseReleaseEvent(QMouseEvent *event)
{
m_state = ButtonHovered;
QPushButton::mouseReleaseEvent(event);
}
void SkinButton::paintEvent(QPaintEvent *)
{
QPainter ptr(this);
ptr.drawPixmap(0, 0, width(), height(), getStatePixmap());
}
QPixmap SkinButton::getStatePixmap() const
{
qDebug() << "HHHHHHHHHHHHHHHH m_index , m_state " << m_index << m_state;
return Resource::PixmapManager::inst().getPixmap(
(Resource::IndexPixmapType)m_type, /*m_index * 4 + */m_state);
}