forked from GeeeekExplorer/PVZ
-
Notifications
You must be signed in to change notification settings - Fork 1
/
button.cpp
44 lines (40 loc) · 1012 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"
Button::Button(QSound *s, QTimer *t)
{
sound = s;
timer = t;
}
QRectF Button::boundingRect() const
{
return QRectF(-80, -20, 160, 40);
}
void Button::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option)
Q_UNUSED(widget)
painter->drawPixmap(QRect(-80, -20, 160, 40), QPixmap(":/images/Button.png"));
painter->setPen(Qt::green);
QFont font("Calibri", 18, QFont::Bold, true);
painter->setFont(font);
if (timer->isActive())
painter->drawText(boundingRect(), Qt::AlignCenter, "PAUSE");
else
painter->drawText(boundingRect(), Qt::AlignCenter, "CONTINUE");
}
void Button::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
if (event->button() == Qt::LeftButton)
{
if (timer->isActive())
{
sound->stop();
timer->stop();
}
else
{
sound->play();
timer->start();
}
}
update();
}