aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominik Haumann <dhaumann@kde.org>2014-01-20 16:22:51 (GMT)
committerDominik Haumann <dhaumann@kde.org>2014-01-20 16:22:51 (GMT)
commitc5fe6c274be46d49cb836426463c8af0407258a6 (patch)
treeffa4e2a1d85c93c939d695d756b54ac001d63478
parentc9a1bc4f73a09a32c6499d168f125058463fe3c7 (diff)
extend KMessageWidget animation info
- bool isHideAnimationRunning() const; - bool isShowAnimationRunning() const; - signal void hideAnimationFinished(); - signal void showAnimationFinished(); - add autotest for these functions REVIEW: 115101
-rw-r--r--autotests/CMakeLists.txt1
-rw-r--r--autotests/kmessagewidgetautotest.cpp79
-rw-r--r--autotests/kmessagewidgetautotest.h42
-rw-r--r--src/kmessagewidget.cpp21
-rw-r--r--src/kmessagewidget.h51
5 files changed, 192 insertions, 2 deletions
diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt
index 6ea9d12..a92c03d 100644
--- a/autotests/CMakeLists.txt
+++ b/autotests/CMakeLists.txt
@@ -19,4 +19,5 @@ kwidgetsaddons_unit_tests(
kdualactiontest
kselectaction_unittest
ktimecomboboxtest
+ kmessagewidgetautotest
)
diff --git a/autotests/kmessagewidgetautotest.cpp b/autotests/kmessagewidgetautotest.cpp
new file mode 100644
index 0000000..f46bab0
--- /dev/null
+++ b/autotests/kmessagewidgetautotest.cpp
@@ -0,0 +1,79 @@
+/*
+ Copyright 2014 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 "kmessagewidgetautotest.h"
+
+#include <QtTest/QtTest>
+#include <kmessagewidget.h>
+
+QTEST_MAIN(KMessageWidgetTest)
+
+void KMessageWidgetTest::initTestCase()
+{
+ m_hideSignals = 0;
+ m_showSignals = 0;
+}
+
+void KMessageWidgetTest::testAnimationSignals()
+{
+ KMessageWidget w(QLatin1String("Hello world"));
+
+ connect(&w, SIGNAL(showAnimationFinished()), this, SLOT(showAnimationFinished()));
+ connect(&w, SIGNAL(hideAnimationFinished()), this, SLOT(hideAnimationFinished()));
+
+ QCOMPARE(m_showSignals, 0);
+
+ //
+ // test: showing the message widget should emit showAnimationFinished()
+ // exactly once after the show animation is finished
+ //
+ w.animatedShow();
+
+ while (w.isShowAnimationRunning()) {
+ QCOMPARE(m_showSignals, 0);
+ QTest::qWait(50);
+ }
+
+ QVERIFY(! w.isShowAnimationRunning());
+ QCOMPARE(m_showSignals, 1);
+
+ //
+ // test: hiding the message widget should emit hideAnimationFinished()
+ // exactly once after the show animation is finished
+ //
+ w.animatedHide();
+
+ while (w.isHideAnimationRunning()) {
+ QCOMPARE(m_hideSignals, 0);
+ QTest::qWait(50);
+ }
+
+ QVERIFY(! w.isHideAnimationRunning());
+ QCOMPARE(m_hideSignals, 1);
+}
+
+void KMessageWidgetTest::hideAnimationFinished()
+{
+ ++m_hideSignals;
+}
+
+void KMessageWidgetTest::showAnimationFinished()
+{
+ ++m_showSignals;
+}
diff --git a/autotests/kmessagewidgetautotest.h b/autotests/kmessagewidgetautotest.h
new file mode 100644
index 0000000..062e2b3
--- /dev/null
+++ b/autotests/kmessagewidgetautotest.h
@@ -0,0 +1,42 @@
+/*
+ Copyright 2014 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 KMESSAGEWIDGETTEST_H
+#define KMESSAGEWIDGETTEST_H
+
+#include <QObject>
+
+class KMessageWidgetTest : public QObject
+{
+ Q_OBJECT
+
+private Q_SLOTS:
+ void initTestCase();
+ void testAnimationSignals();
+
+public Q_SLOTS:
+ void hideAnimationFinished();
+ void showAnimationFinished();
+
+private:
+ int m_hideSignals;
+ int m_showSignals;
+};
+
+#endif
diff --git a/src/kmessagewidget.cpp b/src/kmessagewidget.cpp
index deb82a3..4def663 100644
--- a/src/kmessagewidget.cpp
+++ b/src/kmessagewidget.cpp
@@ -1,6 +1,7 @@
/* This file is part of the KDE libraries
*
* Copyright (c) 2011 Aurélien Gâteau <agateau@kde.org>
+ * Copyright (c) 2014 Dominik Haumann <dhaumann@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -186,9 +187,13 @@ void KMessageWidgetPrivate::slotTimeLineFinished()
// We set the whole geometry here, because it may be wrong if a
// KMessageWidget is shown right when the toplevel window is created.
content->setGeometry(0, 0, q->width(), bestContentHeight());
+
+ // notify about finished animation
+ emit q->showAnimationFinished();
} else {
- // Hide
+ // hide and notify about finished animation
q->hide();
+ emit q->hideAnimationFinished();
}
}
@@ -399,6 +404,7 @@ void KMessageWidget::animatedShow()
{
if (!style()->styleHint(QStyle::SH_Widget_Animate, 0, this)) {
show();
+ emit showAnimationFinished();
return;
}
@@ -423,6 +429,7 @@ void KMessageWidget::animatedHide()
{
if (!style()->styleHint(QStyle::SH_Widget_Animate, 0, this)) {
hide();
+ emit hideAnimationFinished();
return;
}
@@ -439,6 +446,18 @@ void KMessageWidget::animatedHide()
}
}
+bool KMessageWidget::isHideAnimationRunning() const
+{
+ return (d->timeLine->direction() == QTimeLine::Backward)
+ && (d->timeLine->state() == QTimeLine::Running);
+}
+
+bool KMessageWidget::isShowAnimationRunning() const
+{
+ return (d->timeLine->direction() == QTimeLine::Forward)
+ && (d->timeLine->state() == QTimeLine::Running);
+}
+
QIcon KMessageWidget::icon() const
{
return d->icon;
diff --git a/src/kmessagewidget.h b/src/kmessagewidget.h
index a17bccf..87c6fde 100644
--- a/src/kmessagewidget.h
+++ b/src/kmessagewidget.h
@@ -1,6 +1,7 @@
/* This file is part of the KDE libraries
*
* Copyright (c) 2011 Aurélien Gâteau <agateau@kde.org>
+ * Copyright (c) 2014 Dominik Haumann <dhaumann@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -69,7 +70,7 @@ class KMessageWidgetPrivate;
* @li Confirm success of "critical" transactions
* @li Indicate completion of background tasks
*
- * Example of inadapted uses:
+ * Example of unadapted uses:
*
* @li Indicate successful saving of a file
* @li Indicate a file has been successfully removed
@@ -140,6 +141,26 @@ public:
*/
QIcon icon() const;
+ /**
+ * Check whether the hide animation started by calling animatedHide()
+ * is still running. If animations are disabled, this function always
+ * returns @e false.
+ *
+ * @see animatedHide(), hideAnimationFinished()
+ * @since 5.0
+ */
+ bool isHideAnimationRunning() const;
+
+ /**
+ * Check whether the show animation started by calling animatedShow()
+ * is still running. If animations are disabled, this function always
+ * returns @e false.
+ *
+ * @see animatedShow(), showAnimationFinished()
+ * @since 5.0
+ */
+ bool isShowAnimationRunning() const;
+
public Q_SLOTS:
void setText(const QString &text);
@@ -184,6 +205,34 @@ Q_SIGNALS:
*/
void linkHovered(const QString &contents);
+ /**
+ * This signal is emitted when the hide animation is finished, started by
+ * calling animatedHide(). If animations are disabled, this signal is
+ * emitted immediately after the message widget got hidden.
+ *
+ * @note This signal is @e not emitted if the widget was hidden by
+ * calling hide(), so this signal is only useful in conjunction
+ * with animatedHide().
+ *
+ * @see animatedHide()
+ * @since 5.0
+ */
+ void hideAnimationFinished();
+
+ /**
+ * This signal is emitted when the show animation is finished, started by
+ * calling animatedShow(). If animations are disabled, this signal is
+ * emitted immediately after the message widget got shown.
+ *
+ * @note This signal is @e not emitted if the widget was shown by
+ * calling show(), so this signal is only useful in conjunction
+ * with animatedShow().
+ *
+ * @see animatedShow()
+ * @since 5.0
+ */
+ void showAnimationFinished();
+
protected:
void paintEvent(QPaintEvent *event);