-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathLabel.cpp
More file actions
112 lines (98 loc) · 3.03 KB
/
Copy pathLabel.cpp
File metadata and controls
112 lines (98 loc) · 3.03 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include "Label.h"
/* --------------- Custom Text Label (With and Without Icon) ------------------ */
Label::Label(bool isIconic,
Qt::Alignment alignment,
QWidget *parent) : QLabel(parent)
{
setAttribute(Qt::WA_TranslucentBackground);
setAlignment(alignment);
}
Label::Label(const QString &family,
int pointSize,
QFont::Weight weight,
bool italic,
const QString &text,
Qt::Alignment alignment,
QWidget *parent) : QLabel(parent)
{
setAttribute(Qt::WA_TranslucentBackground);
setAlignment(alignment);
setText(text);
QFont fnt;
fnt.setPointSize(pointSize);
fnt.setFamily(family);
fnt.setWeight(weight);
fnt.setItalic(italic);
setFont(fnt);
}
AnimatedLabel::AnimatedLabel(bool isIconic,
const QString &family,
int pointSize,
QFont::Weight weight,
bool italic,
const QString &text,
Qt::Alignment alignment,
QWidget *parent) : QLabel(parent)
{
setAttribute(Qt::WA_TranslucentBackground);
setAlignment(alignment);
init();
}
AnimatedLabel::AnimatedLabel(const QString &family,
int pointSize,
QFont::Weight weight,
bool italic,
const QString &text,
Qt::Alignment alignment,
QWidget *parent) : QLabel(parent)
{
setAttribute(Qt::WA_TranslucentBackground);
setAlignment(alignment);
QFont fnt;
fnt.setPointSize(pointSize);
fnt.setFamily(family);
fnt.setWeight(weight);
fnt.setItalic(italic);
setFont(fnt);
setText(text);
}
void AnimatedLabel::init() {
// Opacity effect
effect = new SmoothOpacity(this);
effect->setOpacity(0.0);
setGraphicsEffect(effect);
// Fade In Animation
fadeIn = new QPropertyAnimation(effect, "opacity", this);
fadeIn->setStartValue(0.0);
fadeIn->setEndValue(1.0);
fadeIn->setDuration(500);
fadeIn->setEasingCurve(QEasingCurve::InOutQuad);
// Fade Out Animation
fadeOut = new QPropertyAnimation(effect, "opacity", this);
fadeOut->setStartValue(1.0);
fadeOut->setEndValue(0.0);
fadeOut->setDuration(500);
fadeOut->setEasingCurve(QEasingCurve::InOutQuad);
connect(fadeOut, &QPropertyAnimation::finished, this, [this]() {
QLabel::hide();
setGraphicsEffect(nullptr);
effect->setOpacity(1.0);
});
}
void AnimatedLabel::show() {
if (!isVisible()) {
effect->setOpacity(0.0);
QLabel::show();
}
fadeIn->start();
}
void AnimatedLabel::hide() {
fadeOut->start();
}
void AnimatedLabel::setAnimatedText(const QString &text) {
hide();
QTimer::singleShot(500, this, [this, text]() {
QLabel::setText(text);
show();
});
}