Changeset 561 for trunk/src/gui/widgets/qwidgetanimator.cpp
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/gui/widgets/qwidgetanimator.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** 40 40 ****************************************************************************/ 41 41 42 #include <QtCore/qtimer.h> 43 #include <QtCore/qdatetime.h> 42 #include <QtCore/qpropertyanimation.h> 44 43 #include <QtGui/qwidget.h> 45 #include <QtGui/qtextedit.h> 46 #include <QtGui/private/qwidget_p.h> 47 #include <qdebug.h> 44 #include <QtGui/private/qmainwindowlayout_p.h> 48 45 49 46 #include "qwidgetanimator_p.h" … … 51 48 QT_BEGIN_NAMESPACE 52 49 53 static const int g_animation_steps = 12; 54 static const int g_animation_interval = 16; 55 56 // 1000 * (x/(1 + x*x) + 0.5) on interval [-1, 1] 57 static const int g_animate_function[] = 50 QWidgetAnimator::QWidgetAnimator(QMainWindowLayout *layout) : m_mainWindowLayout(layout) 58 51 { 59 0, 1, 5, 12, 23, 38, 58, 84, 116, 155, 199, 251, 307, 368,60 433, 500, 566, 631, 692, 748, 799, 844, 883, 915, 941, 961,61 976, 987, 994, 998, 100062 };63 static const int g_animate_function_points = sizeof(g_animate_function)/sizeof(int);64 65 static inline int animateHelper(int start, int stop, int step, int steps)66 {67 if (start == stop)68 return start;69 if (step == 0)70 return start;71 if (step == steps)72 return stop;73 74 int x = g_animate_function_points*step/(steps + 1);75 return start + g_animate_function[x]*(stop - start)/1000;76 }77 78 QWidgetAnimator::QWidgetAnimator(QObject *parent)79 : QObject(parent)80 {81 m_time = new QTime();82 m_timer = new QTimer(this);83 m_timer->setInterval(g_animation_interval);84 connect(m_timer, SIGNAL(timeout()), this, SLOT(animationStep()));85 }86 87 QWidgetAnimator::~QWidgetAnimator()88 {89 delete m_time;90 52 } 91 53 92 54 void QWidgetAnimator::abort(QWidget *w) 93 55 { 94 if (m_animation_map.remove(w) == 0) 56 #ifndef QT_NO_ANIMATION 57 AnimationMap::iterator it = m_animation_map.find(w); 58 if (it == m_animation_map.end()) 95 59 return; 96 if (m_animation_map.isEmpty()) { 97 m_timer->stop(); 98 emit finishedAll(); 99 } 60 QPropertyAnimation *anim = *it; 61 m_animation_map.erase(it); 62 anim->stop(); 63 #ifndef QT_NO_MAINWINDOW 64 m_mainWindowLayout->animationFinished(w); 65 #endif 66 #else 67 Q_UNUSED(w); //there is no animation to abort 68 #endif //QT_NO_ANIMATION 100 69 } 70 71 #ifndef QT_NO_ANIMATION 72 void QWidgetAnimator::animationFinished() 73 { 74 QPropertyAnimation *anim = qobject_cast<QPropertyAnimation*>(sender()); 75 abort(static_cast<QWidget*>(anim->targetObject())); 76 } 77 #endif //QT_NO_ANIMATION 101 78 102 79 void QWidgetAnimator::animate(QWidget *widget, const QRect &_final_geometry, bool animate) 103 80 { 104 QRect final_geometry = _final_geometry;105 106 81 QRect r = widget->geometry(); 107 82 if (r.right() < 0 || r.bottom() < 0) 108 83 r = QRect(); 109 84 110 if (r.isNull() || final_geometry.isNull()) 111 animate = false; 85 animate = animate && !r.isNull() && !_final_geometry.isNull(); 112 86 87 // might make the wigdet go away by sending it to negative space 88 const QRect final_geometry = _final_geometry.isValid() || widget->isWindow() ? _final_geometry : 89 QRect(QPoint(-500 - widget->width(), -500 - widget->height()), widget->size()); 90 91 #ifndef QT_NO_ANIMATION 113 92 AnimationMap::const_iterator it = m_animation_map.constFind(widget); 114 if (it == m_animation_map.constEnd()) { 115 if (r == final_geometry) { 116 emit finished(widget); 117 return; 118 } 119 } else { 120 if ((*it).r2 == final_geometry) 121 return; 122 } 93 if (it != m_animation_map.constEnd() && (*it)->endValue().toRect() == final_geometry) 94 return; 123 95 124 if (animate) { 125 AnimationItem item(widget, r, final_geometry); 126 m_animation_map[widget] = item; 127 if (!m_timer->isActive()) { 128 m_timer->start(); 129 m_time->start(); 130 } 131 } else { 132 m_animation_map.remove(widget); 133 if (m_animation_map.isEmpty()) 134 m_timer->stop(); 135 136 if (!final_geometry.isValid() && !widget->isWindow()) { 137 // Make the wigdet go away by sending it to negative space 138 QSize s = widget->size(); 139 final_geometry = QRect(-500 - s.width(), -500 - s.height(), s.width(), s.height()); 140 } 141 widget->setGeometry(final_geometry); 142 143 emit finished(widget); 144 145 if (m_animation_map.isEmpty()) 146 emit finishedAll(); 147 148 return; 149 } 150 } 151 152 void QWidgetAnimator::animationStep() 153 { 154 int steps = (1 + m_time->restart())/g_animation_interval; 155 AnimationMap::iterator it = m_animation_map.begin(); 156 while (it != m_animation_map.end()) { 157 AnimationItem &item = *it; 158 159 item.step = qMin(item.step + steps, g_animation_steps); 160 161 int x = animateHelper(item.r1.left(), item.r2.left(), 162 item.step, g_animation_steps); 163 int y = animateHelper(item.r1.top(), item.r2.top(), 164 item.step, g_animation_steps); 165 int w = animateHelper(item.r1.width(), item.r2.width(), 166 item.step, g_animation_steps); 167 int h = animateHelper(item.r1.height(), item.r2.height(), 168 item.step, g_animation_steps); 169 170 item.widget->setGeometry(x, y, w, h); 171 172 if (item.step == g_animation_steps) { 173 emit finished(item.widget); 174 AnimationMap::iterator tmp = it; 175 ++it; 176 m_animation_map.erase(tmp); 177 } else { 178 ++it; 179 } 180 } 181 182 if (m_animation_map.isEmpty()) { 183 m_timer->stop(); 184 emit finishedAll(); 185 } 96 QPropertyAnimation *anim = new QPropertyAnimation(widget, "geometry", widget); 97 anim->setDuration(animate ? 200 : 0); 98 anim->setEasingCurve(QEasingCurve::InOutQuad); 99 anim->setEndValue(final_geometry); 100 m_animation_map[widget] = anim; 101 connect(anim, SIGNAL(finished()), SLOT(animationFinished())); 102 anim->start(QPropertyAnimation::DeleteWhenStopped); 103 #else 104 //we do it in one shot 105 widget->setGeometry(final_geometry); 106 #ifndef QT_NO_MAINWINDOW 107 m_mainWindowLayout->animationFinished(widget); 108 #endif //QT_NO_MAINWINDOW 109 #endif //QT_NO_ANIMATION 186 110 } 187 111 188 112 bool QWidgetAnimator::animating() const 189 113 { 190 return m_timer->isActive(); 191 } 192 193 bool QWidgetAnimator::animating(QWidget *widget) 194 { 195 return m_animation_map.contains(widget); 114 return !m_animation_map.isEmpty(); 196 115 } 197 116
Note:
See TracChangeset
for help on using the changeset viewer.