KTextEditor

katefadeeffect.cpp
1 /*
2  SPDX-FileCopyrightText: 2013 Dominik Haumann <[email protected]>
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();
54  m_timeLine->setDirection(QTimeLine::Forward);
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
76  m_timeLine->setDirection(QTimeLine::Backward);
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 }
void opacityChanged(qreal value)
Helper to update opacity value.
void fadeOut()
Call to fade out and hide the widget.
bool isShowAnimationRunning() const
Check whether the show animation started by calling fadeIn() is still running.
Q_EMITQ_EMIT
void animationFinished()
When the animation is finished, hide the widget if fading out.
void hideAnimationFinished()
This signal is emitted when the fadeOut animation is finished, started by calling fadeOut().
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
bool isHideAnimationRunning() const
Check whether the hide animation started by calling fadeOut() is still running.
void valueChanged(qreal value)
KateFadeEffect(QWidget *widget=nullptr)
Constructor.
void stop()
void start()
QTimeLine::State state() const const
void setUpdateInterval(int interval)
void fadeIn()
Call to show and fade in the widget.
void showAnimationFinished()
This signal is emitted when the fadeIn animation is finished, started by calling fadeIn().
virtual QWidget * widget()
void finished()
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Wed Sep 28 2022 03:50:45 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.