forked from tiantian180/MilesEdgeworth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProsecutorBadge.cpp
39 lines (34 loc) · 1.01 KB
/
ProsecutorBadge.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
#include "ProsecutorBadge.h"
ProsecutorBadge::ProsecutorBadge(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
setAttribute(Qt::WA_TranslucentBackground);
setWindowFlags(Qt::SubWindow | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
ui.badgeLabel->setScaledContents(true);
animation = new QPropertyAnimation(this, "pos", this);
animation->setDuration(FLYINGTIME); // 动画持续时间
animation->setEasingCurve(QEasingCurve::OutSine);
}
ProsecutorBadge::~ProsecutorBadge()
{}
void ProsecutorBadge::mousePressEvent(QMouseEvent * event)
{
emit badgeClicked();
}
void ProsecutorBadge::setScale(double new_scale)
{
scale = new_scale;
ui.badgeLabel->resize(12 * scale, 12 * scale);
}
void ProsecutorBadge::moveAnimation(int direction)
{
animation->setStartValue(pos()); // 起始位置
if (direction == 1) {
animation->setEndValue(pos() + QPoint(-600 - 150 * scale, 0)); // 结束位置
}
else {
animation->setEndValue(pos() + QPoint(600 + 150 * scale, 0)); // 结束位置
}
animation->start();
}