1/*
2 SPDX-FileCopyrightText: 2013 Dominik Haumann <dhaumann@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "kateanimation.h"
8
9#include "katefadeeffect.h"
10#include "kateglobal.h"
11
12#include <KMessageWidget>
13
14#include <QStyle>
15#include <QTimer>
16
17KateAnimation::KateAnimation(KMessageWidget *widget, EffectType effect)
18 : QObject(widget)
19 , m_widget(widget)
20 , m_fadeEffect(nullptr)
21{
22 Q_ASSERT(m_widget != nullptr);
23
24 // create wanted effect
25 if (effect == FadeEffect) {
26 m_fadeEffect = new KateFadeEffect(widget);
27
28 connect(sender: m_fadeEffect, signal: &KateFadeEffect::hideAnimationFinished, context: this, slot: &KateAnimation::widgetHidden);
29 connect(sender: m_fadeEffect, signal: &KateFadeEffect::showAnimationFinished, context: this, slot: &KateAnimation::widgetShown);
30 } else {
31 connect(sender: m_widget.data(), signal: &KMessageWidget::hideAnimationFinished, context: this, slot: &KateAnimation::widgetHidden);
32 connect(sender: m_widget.data(), signal: &KMessageWidget::showAnimationFinished, context: this, slot: &KateAnimation::widgetShown);
33 }
34}
35
36bool KateAnimation::isHideAnimationRunning() const
37{
38 return m_fadeEffect ? m_fadeEffect->isHideAnimationRunning() : m_widget->isHideAnimationRunning();
39}
40
41bool KateAnimation::isShowAnimationRunning() const
42{
43 return m_fadeEffect ? m_fadeEffect->isShowAnimationRunning() : m_widget->isShowAnimationRunning();
44}
45
46void KateAnimation::show()
47{
48 Q_ASSERT(m_widget != nullptr);
49
50 // show according to effects config
51 if (m_widget->style()->styleHint(stylehint: QStyle::SH_Widget_Animate, opt: nullptr, widget: m_widget)) {
52 // launch show effect
53 // NOTE: use a singleShot timer to avoid resizing issues when showing the message widget the first time (bug #316666)
54 if (m_fadeEffect) {
55 QTimer::singleShot(interval: 0, receiver: m_fadeEffect, slot: &KateFadeEffect::fadeIn);
56 } else {
57 QTimer::singleShot(interval: 0, receiver: m_widget.data(), slot: &KMessageWidget::animatedShow);
58 }
59 } else {
60 m_widget->show();
61 Q_EMIT widgetShown();
62 }
63}
64
65void KateAnimation::hide()
66{
67 Q_ASSERT(m_widget != nullptr);
68
69 // hide according to effects config
70 if (m_widget->style()->styleHint(stylehint: QStyle::SH_Widget_Animate, opt: nullptr, widget: m_widget)
71 || KTextEditor::EditorPrivate::unitTestMode() // due to timing issues in the unit test
72 ) {
73 // hide depending on effect
74 if (m_fadeEffect) {
75 m_fadeEffect->fadeOut();
76 } else {
77 m_widget->animatedHide();
78 }
79 } else {
80 m_widget->hide();
81 Q_EMIT widgetHidden();
82 }
83}
84
85#include "moc_kateanimation.cpp"
86

source code of ktexteditor/src/view/kateanimation.cpp