summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThierry Bastian <thierry.bastian@nokia.com>2009-07-08 14:34:55 (GMT)
committerThierry Bastian <thierry.bastian@nokia.com>2009-07-08 14:47:58 (GMT)
commitc2f2b6509fcd91617ae3eb860d6d3f947c5ea443 (patch)
treed0a50618d1f937cc3655ba92f699cf928dbbe96e
parentc02a9925f10fbf1a4883983f35c735666862a3f6 (diff)
downloadQt-c2f2b6509fcd91617ae3eb860d6d3f947c5ea443.zip
Qt-c2f2b6509fcd91617ae3eb860d6d3f947c5ea443.tar.gz
Qt-c2f2b6509fcd91617ae3eb860d6d3f947c5ea443.tar.bz2
QMainWindow: fix the use of animation and improve code quality
-rw-r--r--src/gui/widgets/qmainwindowlayout.cpp33
-rw-r--r--src/gui/widgets/qwidgetanimator.cpp53
-rw-r--r--src/gui/widgets/qwidgetanimator_p.h4
3 files changed, 38 insertions, 52 deletions
diff --git a/src/gui/widgets/qmainwindowlayout.cpp b/src/gui/widgets/qmainwindowlayout.cpp
index 8fb7c4f..aba9120 100644
--- a/src/gui/widgets/qmainwindowlayout.cpp
+++ b/src/gui/widgets/qmainwindowlayout.cpp
@@ -1527,24 +1527,20 @@ bool QMainWindowLayout::plug(QLayoutItem *widgetItem)
layoutState.remove(previousPath);
pluggingWidget = widget;
- if (dockOptions & QMainWindow::AnimatedDocks) {
- QRect globalRect = currentGapRect;
- globalRect.moveTopLeft(parentWidget()->mapToGlobal(globalRect.topLeft()));
+ QRect globalRect = currentGapRect;
+ globalRect.moveTopLeft(parentWidget()->mapToGlobal(globalRect.topLeft()));
#ifndef QT_NO_DOCKWIDGET
- if (qobject_cast<QDockWidget*>(widget) != 0) {
- QDockWidgetLayout *layout = qobject_cast<QDockWidgetLayout*>(widget->layout());
- if (layout->nativeWindowDeco()) {
- globalRect.adjust(0, layout->titleHeight(), 0, 0);
- } else {
- int fw = widget->style()->pixelMetric(QStyle::PM_DockWidgetFrameWidth, 0, widget);
- globalRect.adjust(-fw, -fw, fw, fw);
- }
+ if (qobject_cast<QDockWidget*>(widget) != 0) {
+ QDockWidgetLayout *layout = qobject_cast<QDockWidgetLayout*>(widget->layout());
+ if (layout->nativeWindowDeco()) {
+ globalRect.adjust(0, layout->titleHeight(), 0, 0);
+ } else {
+ int fw = widget->style()->pixelMetric(QStyle::PM_DockWidgetFrameWidth, 0, widget);
+ globalRect.adjust(-fw, -fw, fw, fw);
}
-#endif
- widgetAnimator.animate(widget, globalRect, true);
- } else {
- animationFinished(widget);
}
+#endif
+ widgetAnimator.animate(widget, globalRect, dockOptions & QMainWindow::AnimatedDocks);
return true;
}
@@ -1576,9 +1572,11 @@ void QMainWindowLayout::animationFinished(QWidget *widget)
tb->d_func()->plug(currentGapRect);
#endif
- applyState(layoutState, false);
#ifndef QT_NO_DOCKWIDGET
#ifndef QT_NO_TABBAR
+ //it is important to set the current tab before applying the layout
+ //so that applyState will not try to counter the result of the animation
+ //by putting the item in negative space
if (qobject_cast<QDockWidget*>(widget) != 0) {
// info() might return null if the widget is destroyed while
// animating but before the animationFinished signal is received.
@@ -1587,6 +1585,9 @@ void QMainWindowLayout::animationFinished(QWidget *widget)
}
#endif
#endif
+
+ applyState(layoutState, false);
+
savedState.clear();
currentGapPos.clear();
pluggingWidget = 0;
diff --git a/src/gui/widgets/qwidgetanimator.cpp b/src/gui/widgets/qwidgetanimator.cpp
index 7a3a464..26cf905 100644
--- a/src/gui/widgets/qwidgetanimator.cpp
+++ b/src/gui/widgets/qwidgetanimator.cpp
@@ -76,59 +76,46 @@ void QWidgetAnimator::animationFinished()
void QWidgetAnimator::animate(QWidget *widget, const QRect &_final_geometry, bool animate)
{
- QRect final_geometry = _final_geometry;
-
QRect r = widget->geometry();
if (r.right() < 0 || r.bottom() < 0)
r = QRect();
-#ifdef QT_NO_ANIMATION
- Q_UNUSED(animate);
-#else
- if (r.isNull() || final_geometry.isNull() || r == final_geometry)
- animate = false;
+ animate = animate && !r.isNull() && !_final_geometry.isNull();
+
+ // might make the wigdet go away by sending it to negative space
+ const QRect final_geometry = _final_geometry.isValid() || widget->isWindow() ? _final_geometry :
+ QRect(QPoint(-500 - widget->width(), -500 - widget->height()), widget->size());
+ if (r == final_geometry)
+ return; //the widget is already where it should be
+#ifndef QT_NO_ANIMATION
AnimationMap::const_iterator it = m_animation_map.constFind(widget);
if (it != m_animation_map.constEnd() && (*it)->endValue().toRect() == final_geometry)
return;
- if (animate) {
- QPropertyAnimation *anim = new QPropertyAnimation(widget, "geometry");
- anim->setDuration(200);
- anim->setEasingCurve(QEasingCurve::InOutQuad);
- anim->setEndValue(final_geometry);
- m_animation_map[widget] = anim;
- connect(anim, SIGNAL(finished()), SLOT(animationFinished()));
- anim->start(QPropertyAnimation::DeleteWhenStopped);
- } else
+ QPropertyAnimation *anim = new QPropertyAnimation(widget, "geometry");
+ anim->setDuration(animate ? 200 : 0);
+ anim->setEasingCurve(QEasingCurve::InOutQuad);
+ anim->setEndValue(final_geometry);
+ m_animation_map[widget] = anim;
+ connect(anim, SIGNAL(finished()), SLOT(animationFinished()));
+ anim->start(QPropertyAnimation::DeleteWhenStopped);
+ Q_ASSERT(animate || widget->geometry() == final_geometry);
+#else
+ //we do it in one shot
+ widget->setGeometry(final_geometry);
+ m_mainWindowLayout->animationFinished(widget);
#endif //QT_NO_ANIMATION
- {
- if (!final_geometry.isValid() && !widget->isWindow()) {
- // Make the wigdet go away by sending it to negative space
- QSize s = widget->size();
- final_geometry = QRect(-500 - s.width(), -500 - s.height(), s.width(), s.height());
- }
- widget->setGeometry(final_geometry);
- }
}
bool QWidgetAnimator::animating() const
{
-#ifdef QT_NO_ANIMATION
- return false;
-#else
return !m_animation_map.isEmpty();
-#endif //QT_NO_ANIMATION
}
bool QWidgetAnimator::animating(QWidget *widget) const
{
-#ifdef QT_NO_ANIMATION
- Q_UNUSED(widget);
- return false;
-#else
return m_animation_map.contains(widget);
-#endif //QT_NO_ANIMATION
}
QT_END_NAMESPACE
diff --git a/src/gui/widgets/qwidgetanimator_p.h b/src/gui/widgets/qwidgetanimator_p.h
index 4047395..64697a9 100644
--- a/src/gui/widgets/qwidgetanimator_p.h
+++ b/src/gui/widgets/qwidgetanimator_p.h
@@ -54,7 +54,6 @@
//
#include <qobject.h>
-#include <qrect.h>
#include <qmap.h>
QT_BEGIN_NAMESPACE
@@ -77,12 +76,11 @@ public:
#ifndef QT_NO_ANIMATION
private Q_SLOTS:
void animationFinished();
+#endif
private:
typedef QMap<QWidget*, QPropertyAnimation*> AnimationMap;
AnimationMap m_animation_map;
-#endif
-private:
QMainWindowLayout *m_mainWindowLayout;
};