summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominik Haumann <dhaumann@kde.org>2014-01-20 17:51:34 (GMT)
committerDominik Haumann <dhaumann@kde.org>2014-01-20 17:51:34 (GMT)
commit0c3b65574284797539197d7b720d2a9a31b21c91 (patch)
tree7c92744ed6b8b816210c5f0ff4e3a0660700188f
parenta71c932bf34a938dc271dd13169e2adce4f3b210 (diff)
adapt to KMessageWidget in KWidgetAddons
- use KMessageWidget::isHideAnimationRunning() - use KMessageWidget::isShowAnimationRunning() - use KMessageWidget::hideAnimationFinished() - use KMessageWidget::showAnimationFinished() - adapt unit test a bit, still makes problems
-rw-r--r--autotests/src/messagetest.cpp8
-rw-r--r--src/view/kateanimation.cpp50
-rw-r--r--src/view/kateanimation.h6
-rw-r--r--src/view/katefadeeffect.cpp16
-rw-r--r--src/view/katefadeeffect.h30
-rw-r--r--src/view/katemessagewidget.cpp6
6 files changed, 68 insertions, 48 deletions
diff --git a/autotests/src/messagetest.cpp b/autotests/src/messagetest.cpp
index 97c2dea..5d266e3 100644
--- a/autotests/src/messagetest.cpp
+++ b/autotests/src/messagetest.cpp
@@ -49,6 +49,7 @@ void MessageTest::testPostMessage()
view->show();
view->resize(400, 300);
QVERIFY(QTest::qWaitForWindowExposed(view));
+ QTest::qWait(1000);
QPointer<Message> message = new Message("Message text", Message::Information);
message->setPosition(Message::TopInView);
@@ -77,6 +78,7 @@ void MessageTest::testAutoHide()
view->show();
view->resize(400, 300);
QVERIFY(QTest::qWaitForWindowExposed(view));
+ QTest::qWait(1000);
//
// show a message with autoHide. Check, if it's deleted correctly
@@ -109,6 +111,7 @@ void MessageTest::testAutoHideAfterUserInteraction()
view->show();
view->resize(400, 300);
QVERIFY(QTest::qWaitForWindowExposed(view));
+ QTest::qWait(1000);
//
// show a message with autoHide. Check, if it's deleted correctly
@@ -152,6 +155,7 @@ void MessageTest::testMessageQueue()
view->show();
view->resize(400, 300);
QVERIFY(QTest::qWaitForWindowExposed(view));
+ QTest::qWait(1000);
//
// add two messages, both with autoHide to 1 second, and check that the queue is processed correctly
@@ -209,6 +213,7 @@ void MessageTest::testPriority()
view->show();
view->resize(400, 300);
QVERIFY(QTest::qWaitForWindowExposed(view));
+ QTest::qWait(1000);
//
// add two messages
@@ -290,6 +295,7 @@ void MessageTest::testCreateView()
v2->resize(400, 300);
QVERIFY(QTest::qWaitForWindowExposed(v1));
QVERIFY(QTest::qWaitForWindowExposed(v2));
+ QTest::qWait(1000);
// make sure both views show the message
QVERIFY(v1->messageWidget()->isVisible());
@@ -313,6 +319,7 @@ void MessageTest::testHideView()
view->show();
view->resize(400, 300);
QVERIFY(QTest::qWaitForWindowExposed(view));
+ QTest::qWait(1000);
// create message that hides after 2s immediately
QPointer<Message> message = new Message("Message text", Message::Information);
@@ -359,6 +366,7 @@ void MessageTest::testHideViewAfterUserInteraction()
view->show();
view->resize(400, 300);
QVERIFY(QTest::qWaitForWindowExposed(view));
+ QTest::qWait(1000);
// create message that hides after 2s immediately
QPointer<Message> message = new Message("Message text", Message::Information);
diff --git a/src/view/kateanimation.cpp b/src/view/kateanimation.cpp
index 7ed9196..c3a1ca0 100644
--- a/src/view/kateanimation.cpp
+++ b/src/view/kateanimation.cpp
@@ -38,44 +38,33 @@ KateAnimation::KateAnimation(KMessageWidget *widget, EffectType effect)
// 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
- m_hideTimer->setSingleShot(true);
- connect(m_hideTimer, SIGNAL(timeout()), this, SIGNAL(widgetHidden()));
- // create tracking timer for showing the widget
- m_showTimer = new QTimer(this);
- m_showTimer->setInterval(550); // 500 from KMessageWidget + 50 to make sure the show animation is really finished
- m_showTimer->setSingleShot(true);
- connect(m_showTimer, SIGNAL(timeout()), this, SIGNAL(widgetShown()));
+ connect(m_fadeEffect, SIGNAL(hideAnimationFinished()), this, SIGNAL(widgetHidden()));
+ connect(m_fadeEffect, SIGNAL(showAnimationFinished()), this, SIGNAL(widgetShown()));
+ } else {
+ connect(m_widget, SIGNAL(hideAnimationFinished()), this, SIGNAL(widgetHidden()));
+ connect(m_widget, SIGNAL(showAnimationFinished()), this, SIGNAL(widgetShown()));
+ }
}
-bool KateAnimation::hideAnimationActive() const
+bool KateAnimation::isHideAnimationRunning() const
{
- return m_hideTimer->isActive();
+ return m_fadeEffect ? m_fadeEffect->isHideAnimationRunning()
+ : m_widget->isHideAnimationRunning();
}
-bool KateAnimation::showAnimationActive() const
+bool KateAnimation::isShowAnimationRunning() const
{
- return m_showTimer->isActive();
+ return m_fadeEffect ? m_fadeEffect->isShowAnimationRunning()
+ : m_widget->isShowAnimationRunning();
}
void KateAnimation::show()
{
Q_ASSERT(m_widget != 0);
- // stop hide timer if needed
- if (m_hideTimer->isActive()) {
- m_hideTimer->stop();
- }
-
// show according to effects config
- if (m_widget->style()->styleHint(QStyle::SH_Widget_Animate, 0, m_widget)
- || KTextEditor::EditorPrivate::unitTestMode() // due to timing issues in the unit test
- ) {
+ if (m_widget->style()->styleHint(QStyle::SH_Widget_Animate, 0, m_widget)) {
// 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) {
@@ -83,10 +72,6 @@ void KateAnimation::show()
} else {
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)
- m_showTimer->start();
} else {
m_widget->show();
emit widgetShown();
@@ -97,11 +82,6 @@ void KateAnimation::hide()
{
Q_ASSERT(m_widget != 0);
- // stop show timer if needed
- if (m_showTimer->isActive()) {
- m_showTimer->stop();
- }
-
// hide according to effects config
if (m_widget->style()->styleHint(QStyle::SH_Widget_Animate, 0, m_widget)
|| KTextEditor::EditorPrivate::unitTestMode() // due to timing issues in the unit test
@@ -112,10 +92,6 @@ void KateAnimation::hide()
} else {
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)
- m_hideTimer->start();
} else {
m_widget->hide();
emit widgetHidden();
diff --git a/src/view/kateanimation.h b/src/view/kateanimation.h
index 8b3f7a2..6de5571 100644
--- a/src/view/kateanimation.h
+++ b/src/view/kateanimation.h
@@ -60,12 +60,12 @@ public:
/**
* Returns true, if the hide animation is running, otherwise false.
*/
- bool hideAnimationActive() const;
+ bool isHideAnimationRunning() const;
/**
* Returns true, if the how animation is running, otherwise false.
*/
- bool showAnimationActive() const;
+ bool isShowAnimationRunning() const;
public Q_SLOTS:
/**
@@ -94,8 +94,6 @@ Q_SIGNALS:
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
};
#endif
diff --git a/src/view/katefadeeffect.cpp b/src/view/katefadeeffect.cpp
index 8a6597d..c20c943 100644
--- a/src/view/katefadeeffect.cpp
+++ b/src/view/katefadeeffect.cpp
@@ -37,6 +37,18 @@ KateFadeEffect::KateFadeEffect(QWidget *widget)
connect(m_timeLine, SIGNAL(finished()), this, SLOT(animationFinished()));
}
+bool KateFadeEffect::isHideAnimationRunning() const
+{
+ return (m_timeLine->direction() == QTimeLine::Backward)
+ && (m_timeLine->state() == QTimeLine::Running);
+}
+
+bool KateFadeEffect::isShowAnimationRunning() const
+{
+ return (m_timeLine->direction() == QTimeLine::Forward)
+ && (m_timeLine->state() == QTimeLine::Running);
+}
+
void KateFadeEffect::fadeIn()
{
// stop time line if still running
@@ -86,7 +98,9 @@ void KateFadeEffect::animationFinished()
if (m_timeLine->direction() == QTimeLine::Backward) {
m_widget->hide();
- emit widgetHidden();
+ emit hideAnimationFinished();
+ } else {
+ emit showAnimationFinished();
}
}
diff --git a/src/view/katefadeeffect.h b/src/view/katefadeeffect.h
index 53c58f7..96f535c 100644
--- a/src/view/katefadeeffect.h
+++ b/src/view/katefadeeffect.h
@@ -48,11 +48,26 @@ public:
*/
KateFadeEffect(QWidget *widget = 0);
+ /**
+ * Check whether the hide animation started by calling fadeOut()
+ * is still running. If animations are disabled, this function always
+ * returns @e false.
+ */
+ bool isHideAnimationRunning() const;
+
+ /**
+ * Check whether the show animation started by calling fadeIn()
+ * is still running. If animations are disabled, this function always
+ * returns @e false.
+ */
+ bool isShowAnimationRunning() const;
+
public Q_SLOTS:
/**
* Call to fade out and hide the widget.
*/
void fadeOut();
+
/**
* Call to show and fade in the widget
*/
@@ -60,16 +75,25 @@ public Q_SLOTS:
Q_SIGNALS:
/**
- * This signal is emitted when the hiding animation is finished.
- * At this point, the associated widget is hidden.
+ * This signal is emitted when the fadeOut animation is finished, started by
+ * calling fadeOut(). If animations are disabled, this signal is
+ * emitted immediately.
*/
- void widgetHidden();
+ void hideAnimationFinished();
+
+ /**
+ * This signal is emitted when the fadeIn animation is finished, started by
+ * calling fadeIn(). If animations are disabled, this signal is
+ * emitted immediately.
+ */
+ void showAnimationFinished();
protected Q_SLOTS:
/**
* Helper to update opacity value
*/
void opacityChanged(qreal value);
+
/**
* When the animation is finished, hide the widget if fading out.
*/
diff --git a/src/view/katemessagewidget.cpp b/src/view/katemessagewidget.cpp
index 4e498c5..077e671 100644
--- a/src/view/katemessagewidget.cpp
+++ b/src/view/katemessagewidget.cpp
@@ -200,7 +200,7 @@ void KateMessageWidget::postMessage(KTextEditor::Message *message,
// catch if the message gets deleted
connect(message, SIGNAL(closed(KTextEditor::Message*)), SLOT(messageDestroyed(KTextEditor::Message*)));
- if (i == 0 && !m_animation->hideAnimationActive()) {
+ if (i == 0 && !m_animation->isHideAnimationRunning()) {
// if message has higher priority than the one currently shown,
// then hide the current one and then show the new one.
if (m_currentMessage) {
@@ -266,8 +266,8 @@ void KateMessageWidget::startAutoHideTimer()
if (!m_currentMessage // no message, nothing to do
|| m_autoHideTime < 0 // message does not want auto-hide
|| m_autoHideTimer->isActive() // auto-hide timer is already active
- || m_animation->hideAnimationActive() // widget is in hide animation phase
- || m_animation->showAnimationActive() // widget is in show animation phase
+ || m_animation->isHideAnimationRunning() // widget is in hide animation phase
+ || m_animation->isShowAnimationRunning() // widget is in show animation phase
) {
return;
}