-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmycoin.cpp
86 lines (79 loc) · 2.22 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "mycoin.h"
#include <QDebug>
MyCoin::MyCoin(QString btnImg)
{
QPixmap pix;
bool ret=pix.load(btnImg);
if(!ret)
{
QString str=QString("图片 %1 加载失败").arg(btnImg);
qDebug()<<str;
return ;
}
this->setFixedSize(pix.width(),pix.height());
this->setStyleSheet("QPushButton{border:0px;}");/*设置不规则图片样式*/
this->setIcon(pix);
this->setIconSize(QSize(pix.width(),pix.height()));
//初始化定时器对象
time1=new QTimer(this);
time2=new QTimer(this);
//监听正面翻反面的信号, 并且翻硬币
connect(time1,&QTimer::timeout,[=](){
QPixmap pix;
QString str=QString(":/res/Coin000%1").arg(this->min++);
pix.load(str);
this->setFixedSize(pix.width(),pix.height());
this->setStyleSheet("QPushButton{border:0px;}");/*设置不规则图片样式*/
this->setIcon(pix);
this->setIconSize(QSize(pix.width(),pix.height()));
if(this->min > this->max)
{
this->min = 1;
isAnimation=false;//停止做动画
time1->stop();
}
});
//监听反面翻正面的信号, 并且翻硬币
connect(time2,&QTimer::timeout,[=](){
QPixmap pix;
QString str=QString(":/res/Coin000%1").arg(this->max--);
pix.load(str);
this->setFixedSize(pix.width(),pix.height());
this->setStyleSheet("QPushButton{border:0px;}");/*设置不规则图片样式*/
this->setIcon(pix);
this->setIconSize(QSize(pix.width(),pix.height()));
if(this->max < this->min)
{
this->max = 8;
isAnimation=false;//停止做动画
time2->stop();
}
});
}
void MyCoin::changeFlag()
{
//如果是正面 翻成反面
if(this->flag)
{
time1->start(30);
isAnimation=true;//开始做动画
this->flag = false;
}
else //反面翻正面
{
time2->start(30);
isAnimation=true;//开始做动画
this->flag = true;
}
}
void MyCoin::mousePressEvent(QMouseEvent *e)
{
if(this->isAnimation || this->isWin )
{
return;
}
else
{
QPushButton::mousePressEvent(e);
}
}