-
Notifications
You must be signed in to change notification settings - Fork 1
/
widgetutils.cpp
72 lines (59 loc) · 1.9 KB
/
widgetutils.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 "widgetutils.h"
#include <QRadioButton>
#include <QVBoxLayout>
#include <QStyle>
#include <QGuiApplication>
#include <QDesktopWidget>
#include <QApplication>
#include <QGraphicsOpacityEffect>
#include <QPropertyAnimation>
QWidget *WidgetUtils::createHSeparator()
{
QFrame* line = new QFrame();
line->setFrameShape(QFrame::HLine);
line->setFrameShadow(QFrame::Sunken);
return line;
}
QLabel *WidgetUtils::createInfoLabel(const QString &text)
{
QLabel* infoLabel = new QLabel(text);
infoLabel->setStyleSheet("QLabel { color : #555 }");
return infoLabel;
}
void WidgetUtils::centerWindow(QWidget* widget)
{
Q_ASSERT(widget != NULL);
widget->setGeometry(
QStyle::alignedRect(
Qt::LayoutDirectionAuto,
Qt::AlignCenter,
widget->size(),
qApp->desktop()->availableGeometry()
)
);
}
void WidgetUtils::fadeIn(QWidget *widget)
{
Q_ASSERT(widget != NULL);
QGraphicsOpacityEffect *effect = new QGraphicsOpacityEffect(widget);
widget->setGraphicsEffect(effect);
QPropertyAnimation *animation = new QPropertyAnimation(effect, "opacity");
animation->setDuration(600);
animation->setStartValue(0);
animation->setEndValue(1);
animation->setEasingCurve(QEasingCurve::InBack);
animation->start(QPropertyAnimation::DeleteWhenStopped);
}
void WidgetUtils::fadeOut(QWidget *widget)
{
Q_ASSERT(widget != NULL);
QGraphicsOpacityEffect *effect = new QGraphicsOpacityEffect(widget);
widget->setGraphicsEffect(effect);
QPropertyAnimation *animation = new QPropertyAnimation(effect, "opacity");
animation->setDuration(600);
animation->setStartValue(1);
animation->setEndValue(0);
animation->setEasingCurve(QEasingCurve::OutBack);
animation->start(QPropertyAnimation::DeleteWhenStopped);
animation->connect(animation, &QPropertyAnimation::finished, widget, &QWidget::hide);
}