1 /****************************************************************************
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Copyright (C) 2016 Ivailo Monev
6 ** This file is part of the QtGui module of the Katie Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser
12 ** General Public License version 2.1 as published by the Free Software
13 ** Foundation and appearing in the file LICENSE.LGPL included in the
14 ** packaging of this file. Please review the following information to
15 ** ensure the GNU Lesser General Public License version 2.1 requirements
16 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
20 ****************************************************************************/
22 #include "qapplication.h"
24 #include "qdesktopwidget.h"
25 #include "qeffects_p.h"
32 #include "qelapsedtimer.h"
37 static const int s_duration = 150;
42 The QOpacityEffect object sets the widget opacity
44 class QOpacityEffect: public QObject
48 QOpacityEffect(QWidget* w);
56 QPointer<QWidget> widget;
58 QElapsedTimer checkTime;
61 static QOpacityEffect* q_opacity = nullptr;
63 QOpacityEffect::QOpacityEffect(QWidget* w)
67 connect(widget, SIGNAL(destroyed()), this, SLOT(cancel()));
70 widget->setWindowOpacity(0.0);
72 connect(&anim, SIGNAL(timeout()), this, SLOT(fade()));
76 QOpacityEffect::~QOpacityEffect()
78 // Restore the opacity value
80 widget->setWindowOpacity(1);
85 Sets the widget opacity for the time elapsed
87 void QOpacityEffect::fade()
89 const int tempel = checkTime.elapsed();
90 const double alpha = tempel / double(s_duration);
92 if (alpha >= 1.0 || !widget) {
95 widget->setWindowOpacity(1.0);
100 widget->setWindowOpacity(alpha);
104 void QOpacityEffect::cancel()
114 void qFadeEffect(QWidget* w)
118 q_opacity->deleteLater();
125 q_opacity = new QOpacityEffect(w);
130 #include "moc_qeffects.cpp"
132 #endif //QT_NO_EFFECTS