diff options
author | Thierry Bastian <thierry.bastian@nokia.com> | 2009-07-01 10:14:29 (GMT) |
---|---|---|
committer | Thierry Bastian <thierry.bastian@nokia.com> | 2009-07-01 15:16:10 (GMT) |
commit | d0299745e511640df3e0a26e8c447d0960ac4546 (patch) | |
tree | 860cd92c3dcfbc0fa91337a1e1410c8c35312953 /src/gui/widgets/qwidgetanimator.cpp | |
parent | fef6f4469d4c856abdaaefe1d914c120396ff365 (diff) | |
download | Qt-d0299745e511640df3e0a26e8c447d0960ac4546.zip Qt-d0299745e511640df3e0a26e8c447d0960ac4546.tar.gz Qt-d0299745e511640df3e0a26e8c447d0960ac4546.tar.bz2 |
QMainWindow: cleanup of code in QWidgetAnimator
Diffstat (limited to 'src/gui/widgets/qwidgetanimator.cpp')
-rw-r--r-- | src/gui/widgets/qwidgetanimator.cpp | 79 |
1 files changed, 29 insertions, 50 deletions
diff --git a/src/gui/widgets/qwidgetanimator.cpp b/src/gui/widgets/qwidgetanimator.cpp index c67be4a..56b3f43 100644 --- a/src/gui/widgets/qwidgetanimator.cpp +++ b/src/gui/widgets/qwidgetanimator.cpp @@ -39,12 +39,8 @@ ** ****************************************************************************/ -#include <QtCore/qtimer.h> -#include <QtCore/qdatetime.h> #include <QtGui/qwidget.h> -#include <QtGui/qtextedit.h> -#include <QtGui/private/qwidget_p.h> -#include <qdebug.h> +#include <QtGui/private/qmainwindowlayout_p.h> #include "qwidgetanimator_p.h" @@ -75,18 +71,12 @@ static inline int animateHelper(int start, int stop, int step, int steps) return start + g_animate_function[x]*(stop - start)/1000; } -QWidgetAnimator::QWidgetAnimator(QObject *parent) - : QObject(parent) +QWidgetAnimator::QWidgetAnimator(QMainWindowLayout *layout) : m_mainWindowLayout(layout) { - m_time = new QTime(); - m_timer = new QTimer(this); - m_timer->setInterval(g_animation_interval); - connect(m_timer, SIGNAL(timeout()), this, SLOT(animationStep())); } QWidgetAnimator::~QWidgetAnimator() { - delete m_time; } void QWidgetAnimator::abort(QWidget *w) @@ -94,8 +84,8 @@ void QWidgetAnimator::abort(QWidget *w) if (m_animation_map.remove(w) == 0) return; if (m_animation_map.isEmpty()) { - m_timer->stop(); - emit finishedAll(); + m_timer.stop(); + m_mainWindowLayout->allAnimationsFinished(); } } @@ -107,32 +97,21 @@ void QWidgetAnimator::animate(QWidget *widget, const QRect &_final_geometry, boo if (r.right() < 0 || r.bottom() < 0) r = QRect(); - if (r.isNull() || final_geometry.isNull()) + if (r.isNull() || final_geometry.isNull() || r == final_geometry) animate = false; AnimationMap::const_iterator it = m_animation_map.constFind(widget); - if (it == m_animation_map.constEnd()) { - if (r == final_geometry) { - emit finished(widget); - return; - } - } else { - if ((*it).r2 == final_geometry) - return; - } + if (it != m_animation_map.constEnd() && (*it).r2 == final_geometry) + return; if (animate) { AnimationItem item(widget, r, final_geometry); m_animation_map[widget] = item; - if (!m_timer->isActive()) { - m_timer->start(); - m_time->start(); + if (!m_timer.isActive()) { + m_timer.start(g_animation_interval, this); + m_time.start(); } } else { - m_animation_map.remove(widget); - if (m_animation_map.isEmpty()) - m_timer->stop(); - if (!final_geometry.isValid() && !widget->isWindow()) { // Make the wigdet go away by sending it to negative space QSize s = widget->size(); @@ -140,18 +119,19 @@ void QWidgetAnimator::animate(QWidget *widget, const QRect &_final_geometry, boo } widget->setGeometry(final_geometry); - emit finished(widget); - - if (m_animation_map.isEmpty()) - emit finishedAll(); - - return; + if (m_animation_map.remove(widget)) { + m_mainWindowLayout->animationFinished(widget); + if (m_animation_map.isEmpty()) { + m_timer.stop(); + m_mainWindowLayout->allAnimationsFinished(); + } + } } } -void QWidgetAnimator::animationStep() +void QWidgetAnimator::timerEvent(QTimerEvent *) { - int steps = (1 + m_time->restart())/g_animation_interval; + int steps = (1 + m_time.restart())/g_animation_interval; AnimationMap::iterator it = m_animation_map.begin(); while (it != m_animation_map.end()) { AnimationItem &item = *it; @@ -159,35 +139,34 @@ void QWidgetAnimator::animationStep() item.step = qMin(item.step + steps, g_animation_steps); int x = animateHelper(item.r1.left(), item.r2.left(), - item.step, g_animation_steps); + item.step, g_animation_steps); int y = animateHelper(item.r1.top(), item.r2.top(), - item.step, g_animation_steps); + item.step, g_animation_steps); int w = animateHelper(item.r1.width(), item.r2.width(), - item.step, g_animation_steps); + item.step, g_animation_steps); int h = animateHelper(item.r1.height(), item.r2.height(), - item.step, g_animation_steps); + item.step, g_animation_steps); item.widget->setGeometry(x, y, w, h); if (item.step == g_animation_steps) { - emit finished(item.widget); - AnimationMap::iterator tmp = it; - ++it; - m_animation_map.erase(tmp); + QWidget *widget = item.widget; + it = m_animation_map.erase(it); + m_mainWindowLayout->animationFinished(widget); } else { ++it; } } if (m_animation_map.isEmpty()) { - m_timer->stop(); - emit finishedAll(); + m_timer.stop(); + m_mainWindowLayout->allAnimationsFinished(); } } bool QWidgetAnimator::animating() const { - return m_timer->isActive(); + return m_timer.isActive(); } bool QWidgetAnimator::animating(QWidget *widget) |