-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoinbutton.cpp
More file actions
89 lines (72 loc) · 1.98 KB
/
coinbutton.cpp
File metadata and controls
89 lines (72 loc) · 1.98 KB
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 "coinbutton.h"
coinButton::coinButton(QWidget *parent)
: QPushButton{parent}
{
this->setCoin_Status(1);//设置coin初始状态
this->setStyleSheet("QPushButton{border:0px;}");//设置Icon的不规则样式
//设置翻转动画
connect(&this->mTimer,&QTimer::timeout,[=](){
if(this->coin_Status==1)//银币翻金币
{
mFrame--;
}
else
{
mFrame++;
}
QString frameName=QString(":/res/Coin000%1.png").arg(this->mFrame);//动画的逐帧实现 一共8帧
this->setIcon(QIcon(frameName));//设置每一帧的icon
//关闭定时器
if(mFrame==1||mFrame==8)
{
mTimer.stop();
}
});
}
int coinButton::getCoin_Status() const
{
return coin_Status;
}
void coinButton::setCoin_Status(int newCoin_Status)
{
coin_Status = newCoin_Status;
//根据coinStatus设置coin's Icon
if(coin_Status==0)//银币
{
this->setIcon(QIcon(":/res/Coin0008.png"));
}
else
{
this->setIcon(QIcon(":/res/Coin0001.png"));//金币
}
this->setIconSize(this->size());
}
void coinButton::paintEvent(QPaintEvent *e)
{
//绘制金币背景
QPainter painter(this);
QPixmap pix;
pix.load(":/res/BoardNode.png");
painter.drawPixmap(0,0,this->width(),this->height(),pix);
//调用父类的pev函数 重新绘制被覆盖的coin_Icon
QPushButton::paintEvent(e);
}
void coinButton::flip()
{
// this->setCoin_Status(!this->getCoin_Status());//coinStatus状态翻转
this->setStatWithAnimation(!this->getCoin_Status());//传进去的stat参数是什么 就像这个方向翻转
}
void coinButton::setStatWithAnimation(int coinStat)
{
this->coin_Status=coinStat;
if(coin_Status==1)//银币翻金币
{
mFrame=8;
this->mTimer.start(30);//一帧=30ms 所以定时器的触发间隔设置为30ms
}
else//金翻银
{
mFrame=1;
this->mTimer.start(30);
}
}