KTextEditor

katefadeeffect.cpp
1/*
2 SPDX-FileCopyrightText: 2013 Dominik Haumann <dhaumann@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "katefadeeffect.h"
8
9#include <QGraphicsOpacityEffect>
10#include <QTimeLine>
11#include <QWidget>
12
14 : QObject(widget)
15 , m_widget(widget)
16 , m_effect(nullptr) // effect only exists during fading animation
17{
18 m_timeLine = new QTimeLine(500, this);
19 m_timeLine->setUpdateInterval(40);
20
23}
24
26{
27 return (m_timeLine->direction() == QTimeLine::Backward) && (m_timeLine->state() == QTimeLine::Running);
28}
29
31{
32 return (m_timeLine->direction() == QTimeLine::Forward) && (m_timeLine->state() == QTimeLine::Running);
33}
34
36{
37 // stop time line if still running
38 if (m_timeLine->state() == QTimeLine::Running) {
39 QTimeLine::Direction direction = m_timeLine->direction();
40 m_timeLine->stop();
41 if (direction == QTimeLine::Backward) {
42 // fadeOut animation interrupted
44 }
45 }
46
47 // assign new graphics effect, old one is deleted in setGraphicsEffect()
48 m_effect = new QGraphicsOpacityEffect(this);
49 m_effect->setOpacity(0.0);
50 m_widget->setGraphicsEffect(m_effect);
51
52 // show widget and start fade in animation
53 m_widget->show();
55 m_timeLine->start();
56}
57
59{
60 // stop time line if still running
61 if (m_timeLine->state() == QTimeLine::Running) {
62 QTimeLine::Direction direction = m_timeLine->direction();
63 m_timeLine->stop();
64 if (direction == QTimeLine::Forward) {
65 // fadeIn animation interrupted
67 }
68 }
69
70 // assign new graphics effect, old one is deleted in setGraphicsEffect()
71 m_effect = new QGraphicsOpacityEffect(this);
72 m_effect->setOpacity(1.0);
73 m_widget->setGraphicsEffect(m_effect);
74
75 // start fade out animation
77 m_timeLine->start();
78}
79
81{
82 Q_ASSERT(m_effect);
83 m_effect->setOpacity(value);
84}
85
87{
88 // fading finished: remove graphics effect, deletes the effect as well
89 m_widget->setGraphicsEffect(nullptr);
90 Q_ASSERT(!m_effect);
91
92 if (m_timeLine->direction() == QTimeLine::Backward) {
93 m_widget->hide();
95 } else {
97 }
98}
99
100#include "moc_katefadeeffect.cpp"
bool isHideAnimationRunning() const
Check whether the hide animation started by calling fadeOut() is still running.
void animationFinished()
When the animation is finished, hide the widget if fading out.
void fadeOut()
Call to fade out and hide the widget.
void showAnimationFinished()
This signal is emitted when the fadeIn animation is finished, started by calling fadeIn().
void fadeIn()
Call to show and fade in the widget.
void opacityChanged(qreal value)
Helper to update opacity value.
void hideAnimationFinished()
This signal is emitted when the fadeOut animation is finished, started by calling fadeOut().
KateFadeEffect(QWidget *widget=nullptr)
Constructor.
bool isShowAnimationRunning() const
Check whether the show animation started by calling fadeIn() is still running.
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void finished()
void start()
State state() const const
void stop()
void setUpdateInterval(int interval)
void valueChanged(qreal value)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 20 2024 11:56:00 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.