[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kate] part/view: add simple KateFadeEffect
From: Dominik Haumann <dhaumann () kde ! org>
Date: 2013-03-31 20:20:00
Message-ID: 20130331202000.A0624A6059 () git ! kde ! org
[Download RAW message or body]
Git commit 99aeb72c7d847244d80c22375771be30ca5c062a by Dominik Haumann.
Committed on 31/03/2013 at 11:23.
Pushed by dhaumann into branch 'master'.
add simple KateFadeEffect
Example:
KateFadeEffect* fadeEffect = new KateFadeEffect(someWidget);
fadeEffect->fadeIn();
// ...
fadeEffect->fadeOut();
Maybe of interest for:
CCMAIL: agateau@kde.org
A +85 -0 part/view/katefadeeffect.cpp [License: LGPL (v2+)]
A +79 -0 part/view/katefadeeffect.h [License: LGPL (v2+)]
http://commits.kde.org/kate/99aeb72c7d847244d80c22375771be30ca5c062a
diff --git a/part/view/katefadeeffect.cpp b/part/view/katefadeeffect.cpp
new file mode 100644
index 0000000..36262e8
--- /dev/null
+++ b/part/view/katefadeeffect.cpp
@@ -0,0 +1,85 @@
+/* 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 "katefadeeffect.moc"
+
+#include <QWidget>
+#include <QTimeLine>
+#include <QGraphicsOpacityEffect>
+
+static const int frameRange = 40;
+
+KateFadeEffect::KateFadeEffect(QWidget* widget)
+ : QObject(widget)
+ , m_widget(widget)
+{
+ m_timeLine = new QTimeLine(10000, this);
+ m_timeLine->setFrameRange(0, frameRange);
+ m_effect = new QGraphicsOpacityEffect(this);
+ m_effect->setOpacity(1.0);
+ m_widget->setGraphicsEffect(m_effect);
+
+ connect(m_timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(opacityChanged(qreal)));
+ connect(m_timeLine, SIGNAL(finished()), this, SLOT(animationFinished()));
+}
+
+void KateFadeEffect::fadeIn()
+{
+ if (!m_widget || m_widget->isVisible()) {
+ return;
+ }
+
+ m_timeLine->setDirection(QTimeLine::Forward);
+ m_effect->setOpacity(0.0);
+ m_widget->show();
+ m_timeLine->start();
+}
+
+void KateFadeEffect::fadeOut()
+{
+ if (!m_widget || !m_widget->isVisible()) {
+ return;
+ }
+
+ m_effect->setOpacity(1.0);
+ m_timeLine->setDirection(QTimeLine::Backward);
+ m_timeLine->start();
+}
+
+void KateFadeEffect::opacityChanged(qreal value)
+{
+ if (m_widget) {
+ m_effect->setOpacity(value);
+ }
+}
+
+void KateFadeEffect::animationFinished()
+{
+ if (!m_widget) {
+ return;
+ }
+
+ if (m_timeLine->direction() == QTimeLine::Backward) {
+ m_widget->hide();
+ }
+}
+
+// kate: space-indent on; indent-width 2; replace-tabs on;
diff --git a/part/view/katefadeeffect.h b/part/view/katefadeeffect.h
new file mode 100644
index 0000000..befcbcf
--- /dev/null
+++ b/part/view/katefadeeffect.h
@@ -0,0 +1,79 @@
+/* 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>
+
+class QWidget;
+class QTimeLine;
+class 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();
+
+ 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
+ QGraphicsOpacityEffect* m_effect; ///< graphics opacity effect
+};
+
+#endif
+
+// kate: space-indent on; indent-width 2; replace-tabs on;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic