-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmycoin.cpp
72 lines (67 loc) · 1.66 KB
/
mycoin.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
69
70
71
72
#include "mycoin.h"
MyCoin::MyCoin(QString imgPath):isWin(false),mIsAnimation(false),
Min(0), Max(8)
{
this->initObject(imgPath);
timerGold=new QTimer(this);
timerSilver=new QTimer(this);
connect(timerGold,&QTimer::timeout,[=](){
Min++;
QString imgPath=QString(":/res/Coin000%1.png").arg(Min);
this->initObject(imgPath);
if(Min==8) {
Min=0;
timerGold->stop();
{
mIsAnimation=false;
}
}
});
connect(timerSilver,&QTimer::timeout,[=](){
Max--;
QString imgPath=QString(":/res/Coin000%1.png").arg(Max);
this->initObject(imgPath);
if(Max==1) {
Max=8;
timerSilver->stop();
{
mIsAnimation=false;
}
}
});
}
void MyCoin::initObject(QString imagePath)
{
QPixmap pix;
if(!pix.load(imagePath)) {
qDebug()<<"MyCoin图片加载失败"<<imagePath;
return ;
}
//设置默认大小
this->setFixedSize(pix.width(),pix.height());
//设置按钮边框为0
this->setStyleSheet("QPushButton{border : 0px}");
//设置图标
this->setIcon(QIcon(pix));
//设置图片大小
this->setIconSize(pix.size());
}
void MyCoin::mousePressEvent(QMouseEvent *e)
{
if(this->mIsAnimation || this->isWin) {
qDebug() << "无法点击";
return ;
}
return QPushButton::mousePressEvent(e);
}
void MyCoin::changeCoin()
{
if(this->mIsGold) {
timerGold->start(50);
this->mIsGold=false;
} else {
timerSilver->start(50);
this->mIsGold=true;
}
this->mIsAnimation=true;
}