OSDN Git Service

kate: always use the KMessageWidget animation feature
authorIvailo Monev <xakepa10@gmail.com>
Mon, 21 Nov 2022 16:57:45 +0000 (18:57 +0200)
committerIvailo Monev <xakepa10@gmail.com>
Mon, 21 Nov 2022 16:59:38 +0000 (18:59 +0200)
note that the KMessageWidget animation is a fade effect so
KateFadeEffect was doing what KMessageWidget already has the feature
for, grow/shrink effect is not a thing

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
kate/part/CMakeLists.txt
kate/part/view/kateanimation.cpp
kate/part/view/kateanimation.h
kate/part/view/katefadeeffect.cpp [deleted file]
kate/part/view/katefadeeffect.h [deleted file]
kate/part/view/katemessagewidget.cpp

index c8e5c4c..ed7629d 100644 (file)
@@ -110,7 +110,6 @@ set(katepart_PART_SRCS
     view/kateviewinternal.cpp
     view/kateviewhelpers.cpp
     view/katemessagewidget.cpp
-    view/katefadeeffect.cpp
     view/kateanimation.cpp
     view/katetextanimation.cpp
 
index 84abfc0..41a4de6 100644 (file)
 
 #include "kateanimation.h"
 #include "moc_kateanimation.cpp"
-#include <katefadeeffect.h>
 
-#include <KMessageWidget>
 #include <QTimer>
+#include <KMessageWidget>
 #include <kglobalsettings.h>
 
-KateAnimation::KateAnimation(KMessageWidget* widget, EffectType effect)
+KateAnimation::KateAnimation(KMessageWidget* widget, bool applyEffect)
   : QObject(widget)
   , m_widget(widget)
-  , m_fadeEffect(0)
+  , m_applyEffect(applyEffect)
 {
   Q_ASSERT(m_widget != 0);
 
-  // create wanted effect
-  if (effect == FadeEffect) {
-    m_fadeEffect = new KateFadeEffect(widget);
-  }
-
   // create tracking timer for hiding the widget
   m_hideTimer = new QTimer(this);
   m_hideTimer->setInterval(550); // 500 from KMessageWidget + 50 to make sure the hide animation is really finished
@@ -71,17 +65,13 @@ void KateAnimation::show()
   }
 
   // show according to effects config
-  if (!(KGlobalSettings::graphicEffectsLevel() & KGlobalSettings::SimpleAnimationEffects)) {
+  if (!m_applyEffect || !(KGlobalSettings::graphicEffectsLevel() & KGlobalSettings::SimpleAnimationEffects)) {
     m_widget->show();
     emit widgetShown();
   } else {
     // launch show effect
     // NOTE: use a singleShot timer to avoid resizing issues when showing the message widget the first time (bug #316666)
-    if (m_fadeEffect) {
-      QTimer::singleShot(0, m_fadeEffect, SLOT(fadeIn()));
-    } else {
-      QTimer::singleShot(0, m_widget, SLOT(animatedShow()));
-    }
+    QTimer::singleShot(0, m_widget, SLOT(animatedShow()));
 
     // start timer in order to track when showing is done (this effectively works
     // around the fact, that KMessageWidget does not have a hidden signal)
@@ -99,16 +89,12 @@ void KateAnimation::hide()
   }
   
   // hide according to effects config
-  if (!(KGlobalSettings::graphicEffectsLevel() & KGlobalSettings::SimpleAnimationEffects)) {
+  if (!m_applyEffect || !(KGlobalSettings::graphicEffectsLevel() & KGlobalSettings::SimpleAnimationEffects)) {
     m_widget->hide();
     emit widgetHidden();
   } else {
     // hide depending on effect
-    if (m_fadeEffect) {
-      m_fadeEffect->fadeOut();
-    } else {
-      m_widget->animatedHide();
-    }
+    m_widget->animatedHide();
 
     // start timer in order to track when hiding is done (this effectively works
     // around the fact, that KMessageWidget does not have a hidden signal)
index e9636a1..517c5f6 100644 (file)
 
 #include <QObject>
 #include <QPointer>
-
 #include <QTimer>
 
 class KMessageWidget;
-class KateFadeEffect;
+
 /**
  * This class provides a fade in/out effect for KMessageWidget%s.
  * Example:
@@ -44,18 +43,9 @@ class KateAnimation : public QObject
 
   public:
     /**
-     * The type of supported animation effects
-     */
-    enum EffectType{
-      FadeEffect = 0, ///< fade in/out
-      GrowEffect      ///< grow / shrink
-    };
-
-  public:
-    /**
      * Constructor.
      */
-    KateAnimation(KMessageWidget* widget, EffectType effect);
+    KateAnimation(KMessageWidget* widget, bool applyEffect);
 
     /**
      * Returns true, if the hide animation is running, otherwise false.
@@ -93,9 +83,9 @@ class KateAnimation : public QObject
 
   private:
     QPointer<KMessageWidget> m_widget; ///< the widget to animate
-    KateFadeEffect * m_fadeEffect;     ///< the fade effect
     QTimer * m_hideTimer;              ///< timer to track hide animation
     QTimer * m_showTimer;              ///< timer to track show animation
+    bool m_applyEffect;
 };
 
 #endif
diff --git a/kate/part/view/katefadeeffect.cpp b/kate/part/view/katefadeeffect.cpp
deleted file mode 100644 (file)
index c1f7cf9..0000000
+++ /dev/null
@@ -1,94 +0,0 @@
-/* This file is part of the KDE and the Kate project
- *
- *   Copyright (C) 2013 Dominik Haumann <dhaumann@kde.org>
- *
- *  This library is free software; you can redistribute it and/or
- *  modify it under the terms of the GNU Library General Public
- *  License as published by the Free Software Foundation; either
- *  version 2 of the License, or (at your option) any later version.
- *
- *  This library is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- *  Library General Public License for more details.
- *
- *  You should have received a copy of the GNU Library General Public License
- *  along with this library; see the file COPYING.LIB.  If not, write to
- *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- *  Boston, MA 02110-1301, USA.
- */
-
-#include "katefadeeffect.h"
-#include "moc_katefadeeffect.cpp"
-
-#include <QWidget>
-#include <QTimeLine>
-#include <QtGui/qgraphicseffect.h>
-#include <QDebug>
-
-KateFadeEffect::KateFadeEffect(QWidget* widget)
-  : QObject(widget)
-  , m_widget(widget)
-  , m_effect(0) // effect only exists during fading animation
-{
-  m_timeLine = new QTimeLine(500, this);
-  m_timeLine->setUpdateInterval(40);
-
-  connect(m_timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(opacityChanged(qreal)));
-  connect(m_timeLine, SIGNAL(finished()), this, SLOT(animationFinished()));
-}
-
-void KateFadeEffect::fadeIn()
-{
-  // stop time line if still running
-  if (m_timeLine->state() == QTimeLine::Running) {
-    m_timeLine->stop();
-  }
-
-  // assign new graphics effect, old one is deleted in setGraphicsEffect()
-  m_effect = new QGraphicsOpacityEffect(this);
-  m_effect->setOpacity(0.0);
-  m_widget->setGraphicsEffect(m_effect);
-
-  // show widget and start fade in animation
-  m_widget->show();
-  m_timeLine->setDirection(QTimeLine::Forward);
-  m_timeLine->start();
-}
-
-void KateFadeEffect::fadeOut()
-{
-  // stop time line if still running
-  if (m_timeLine->state() == QTimeLine::Running) {
-    m_timeLine->stop();
-  }
-
-  // assign new graphics effect, old one is deleted in setGraphicsEffect()
-  m_effect = new QGraphicsOpacityEffect(this);
-  m_effect->setOpacity(1.0);
-  m_widget->setGraphicsEffect(m_effect);
-
-  // start fade out animation
-  m_timeLine->setDirection(QTimeLine::Backward);
-  m_timeLine->start();
-}
-
-void KateFadeEffect::opacityChanged(qreal value)
-{
-  Q_ASSERT(m_effect);
-  m_effect->setOpacity(value);
-}
-
-void KateFadeEffect::animationFinished()
-{
-  // fading finished: remove graphics effect, deletes the effect as well
-  m_widget->setGraphicsEffect(0);
-  Q_ASSERT(!m_effect);
-
-  if (m_timeLine->direction() == QTimeLine::Backward) {
-    m_widget->hide();
-    emit widgetHidden();
-  }
-}
-
-// kate: space-indent on; indent-width 2; replace-tabs on;
diff --git a/kate/part/view/katefadeeffect.h b/kate/part/view/katefadeeffect.h
deleted file mode 100644 (file)
index d5dcc7d..0000000
+++ /dev/null
@@ -1,86 +0,0 @@
-/* This file is part of the KDE and the Kate project
- *
- *   Copyright (C) 2013 Dominik Haumann <dhaumann@kde.org>
- *
- *  This library is free software; you can redistribute it and/or
- *  modify it under the terms of the GNU Library General Public
- *  License as published by the Free Software Foundation; either
- *  version 2 of the License, or (at your option) any later version.
- *
- *  This library is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- *  Library General Public License for more details.
- *
- *  You should have received a copy of the GNU Library General Public License
- *  along with this library; see the file COPYING.LIB.  If not, write to
- *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- *  Boston, MA 02110-1301, USA.
- */
-
-#ifndef KATE_FADE_EFFECT_H
-#define KATE_FADE_EFFECT_H
-
-#include <QObject>
-#include <QPointer>
-
-#include <QWidget>
-#include <QTimeLine>
-#include <QGraphicsOpacityEffect>
-/**
- * This class provides a fade in/out effect for arbitrary QWidget%s.
- * Example:
- * \code
- * KateFadeEffect* fadeEffect = new KateFadeEffect(someWidget);
- * fadeEffect->fadeIn();
- * //...
- * fadeEffect->fadeOut();
- * \endcode
- */
-class KateFadeEffect : public QObject
-{
-  Q_OBJECT
-
-  public:
-    /**
-     * Constructor.
-     * By default, the widget is fully opaque (opacity = 1.0).
-     */
-    KateFadeEffect(QWidget* widget = 0);
-
-  public Q_SLOTS:
-    /**
-     * Call to fade out and hide the widget.
-     */
-    void fadeOut();
-    /**
-     * Call to show and fade in the widget
-     */
-    void fadeIn();
-
-  Q_SIGNALS:
-    /**
-     * This signal is emitted when the hiding animation is finished.
-     * At this point, the associated widget is hidden.
-     */
-    void widgetHidden();
-
-  protected Q_SLOTS:
-    /**
-     * Helper to update opacity value
-     */
-    void opacityChanged(qreal value);
-    /**
-     * When the animation is finished, hide the widget if fading out.
-     */
-    void animationFinished();
-
-  private:
-    QPointer<QWidget> m_widget;         ///< the fading widget
-    QTimeLine* m_timeLine;              ///< update time line
-    QPointer<QGraphicsOpacityEffect> m_effect; ///< graphics opacity effect
-};
-
-#endif
-
-// kate: space-indent on; indent-width 2; replace-tabs on;
index 80fdfd7..66839a1 100644 (file)
@@ -62,7 +62,7 @@ KateMessageWidget::KateMessageWidget(QWidget* parent, bool applyFadeEffect)
   hide();
 
   // create animation controller, and connect widgetHidden() to showNextMessage()
-  m_animation = new KateAnimation(m_messageWidget, applyFadeEffect ? KateAnimation::FadeEffect : KateAnimation::GrowEffect);
+  m_animation = new KateAnimation(m_messageWidget, applyFadeEffect);
   connect(m_animation, SIGNAL(widgetHidden()), this, SLOT(showNextMessage()));
 
   // setup autoHide timer details