-
Notifications
You must be signed in to change notification settings - Fork 1
/
button.cpp
44 lines (36 loc) · 868 Bytes
/
button.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
#include "button.h"
#include <QDebug>
Button::Button(const char * img1, const char * img2, QGraphicsItem *)
{
imgs[0].load(img1);
imgs[1].load(img2);
setPixmap(imgs[0]);
// allow to detect mouse hover
setAcceptHoverEvents(true);
}
void Button::mousePressEvent(QGraphicsSceneMouseEvent *)
{
emit clicked();
setPixmap(imgs[0]);
}
void Button::hoverEnterEvent(QGraphicsSceneHoverEvent *)
{
setPixmap(imgs[1]);
}
void Button::hoverLeaveEvent(QGraphicsSceneHoverEvent *)
{
setPixmap(imgs[0]);
}
Option::Option(const char * img1, const char * img2, QGraphicsItem *)
{
isOn = false;
imgs[0].load(img1);
imgs[1].load(img2);
setPixmap(imgs[0]);
}
void Option::mousePressEvent(QGraphicsSceneMouseEvent *)
{
emit clicked();
isOn = !isOn;
setPixmap(imgs[isOn]);
}