blob: effd85ded9de6a869ecae1353dad407e521315e4 (
plain)
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
|
// Copyright (C) 2017 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include "fullscreennotification.h"
#include <QGraphicsOpacityEffect>
#include <QPropertyAnimation>
#include <QSequentialAnimationGroup>
FullScreenNotification::FullScreenNotification(QWidget *parent)
: QLabel(parent)
, m_previouslyVisible(false)
{
setText(tr("You are now in full screen mode. Press ESC to quit!"));
setStyleSheet(
"font-size: 24px;"
"color: white;"
"background-color: black;"
"border-color: white;"
"border-width: 2px;"
"border-style: solid;"
"padding: 100px");
setAttribute(Qt::WA_TransparentForMouseEvents);
auto effect = new QGraphicsOpacityEffect;
effect->setOpacity(1);
setGraphicsEffect(effect);
auto animations = new QSequentialAnimationGroup(this);
animations->addPause(3000);
auto opacityAnimation = new QPropertyAnimation(effect, "opacity", animations);
opacityAnimation->setDuration(2000);
opacityAnimation->setStartValue(1.0);
opacityAnimation->setEndValue(0.0);
opacityAnimation->setEasingCurve(QEasingCurve::OutQuad);
animations->addAnimation(opacityAnimation);
connect(this, &FullScreenNotification::shown,
[animations](){ animations->start(); });
connect(animations, &QAbstractAnimation::finished,
[this](){ this->hide(); });
}
void FullScreenNotification::showEvent(QShowEvent *event)
{
QLabel::showEvent(event);
if (!m_previouslyVisible && isVisible())
emit shown();
m_previouslyVisible = isVisible();
}
|