summaryrefslogtreecommitdiffstats
path: root/hyperui/pageview.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'hyperui/pageview.cpp')
-rw-r--r--hyperui/pageview.cpp120
1 files changed, 21 insertions, 99 deletions
diff --git a/hyperui/pageview.cpp b/hyperui/pageview.cpp
index e2be77c..1d2c25f 100644
--- a/hyperui/pageview.cpp
+++ b/hyperui/pageview.cpp
@@ -30,10 +30,7 @@
****************************************************************************/
#include <QApplication>
-#include <QGraphicsRotation>
-#include <QPropertyAnimation>
#include <QGraphicsLinearLayout>
-#include <QParallelAnimationGroup>
#include <QGraphicsSceneResizeEvent>
#include "dataresource.h"
@@ -42,85 +39,30 @@
#include "pagemenu.h"
#include "pageview.h"
-// XXX: adjust to false when opengl is available
-#define USE_LINEAR_TRANSITION true
-
class PageSlot : public QGraphicsWidget
{
Q_OBJECT
- Q_PROPERTY(qreal pageSlide READ pageSlide WRITE setPageSlide);
public:
- enum MovementType {
- MoveInLeft,
- MoveInRight,
- MoveOutLeft,
- MoveOutRight
- };
-
PageSlot(QGraphicsItem *parent = 0);
- qreal pageSlide() const;
- void setPageSlide(qreal percent);
-
View *contents() const;
void setContents(View *contents);
- QAbstractAnimation *createAnimation(MovementType type);
-
protected:
void resizeEvent(QGraphicsSceneResizeEvent *event);
private:
- bool m_isOut;
- bool m_isLeft;
- qreal m_pageSlide;
- bool m_isLinearTransition;
View *m_contents;
- QGraphicsRotation *m_rotation;
};
PageSlot::PageSlot(QGraphicsItem *parent)
: QGraphicsWidget(parent),
- m_contents(0),
- m_rotation(new QGraphicsRotation(this))
+ m_contents(0)
{
setFlags(QGraphicsItem::ItemHasNoContents);
-
-#ifdef Q_OS_SYMBIAN
- m_isLinearTransition = true;
-#else
- m_isLinearTransition = USE_LINEAR_TRANSITION;
-#endif
-
- m_rotation->setAxis(Qt::YAxis);
-
- QList<QGraphicsTransform*> transforms;
- transforms.append(m_rotation);
- setTransformations(transforms);
-}
-
-qreal PageSlot::pageSlide() const
-{
- return m_pageSlide;
-}
-
-void PageSlot::setPageSlide(qreal percent)
-{
- m_pageSlide = percent;
-
- if (!m_isLinearTransition) {
- // apply flip values
- const qreal np = m_isOut ? percent : (1 - percent);
- m_rotation->setAngle((m_isLeft ? 180 : -180) * np);
- } else {
- // apply linear pos values
- const int sw = size().width();
- const qreal sx = (m_isLeft ? -sw : sw);
- setX(sx * (m_isOut ? percent : 1 - percent));
- }
}
View *PageSlot::contents() const
@@ -141,25 +83,6 @@ void PageSlot::setContents(View *contents)
}
}
-QAbstractAnimation *PageSlot::createAnimation(MovementType type)
-{
- m_isOut = (type == MoveOutLeft || type == MoveOutRight);
- m_isLeft = (type == MoveInLeft || type == MoveOutLeft);
-
- if (!m_isLinearTransition) {
- QVector3D ov(m_isLeft ? 0 : size().width(), 0, 0);
- m_rotation->setOrigin(ov);
- }
-
- QPropertyAnimation *animation = new QPropertyAnimation(this, "pageSlide");
- animation->setDuration(500);
- animation->setEasingCurve(QEasingCurve::OutQuart);
- animation->setStartValue(0.0);
- animation->setEndValue(1.0);
-
- return animation;
-}
-
void PageSlot::resizeEvent(QGraphicsSceneResizeEvent *event)
{
QGraphicsWidget::resizeEvent(event);
@@ -171,14 +94,15 @@ void PageSlot::resizeEvent(QGraphicsSceneResizeEvent *event)
PageView::PageView(QGraphicsItem *parent)
: QGraphicsWidget(parent),
- m_isBack(false)
+ m_isBack(false),
+ m_isAnimating(false)
{
m_topOffset = Resource::intValue("page-view/margin-top");
setFlag(QGraphicsItem::ItemHasNoContents);
QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical);
- layout->setContentsMargins(20, 40, 20, 0);
+ layout->setContentsMargins(20 * 0.75, 40, 20 * 0.75, 0);
QGraphicsLinearLayout *topLayout = new QGraphicsLinearLayout(Qt::Horizontal);
topLayout->setContentsMargins(0, 0, 0, 0);
@@ -206,9 +130,6 @@ PageView::PageView(QGraphicsItem *parent)
topLayout->addStretch(1);
topLayout->addItem(m_backButton);
- m_animationInOut = new QParallelAnimationGroup(this);
- connect(m_animationInOut, SIGNAL(finished()), this, SLOT(transitionFinished()));
-
m_optionsButton->setEnabled(false);
m_oldSlot = new PageSlot(this);
@@ -248,11 +169,14 @@ bool PageView::back()
bool PageView::isAnimating() const
{
- return (m_animationInOut->state() == QAbstractAnimation::Running);
+ return m_isAnimating;
}
void PageView::backClicked()
{
+ if (isAnimating())
+ return;
+
if (m_views.count() < 2)
QApplication::quit();
else
@@ -269,6 +193,11 @@ void PageView::transitionFinished()
View *newView = m_newSlot->contents();
View *oldView = m_oldSlot->contents();
+ disconnect(newView, SIGNAL(transitionInFinished()),
+ this, SLOT(transitionFinished()));
+ disconnect(oldView, SIGNAL(transitionOutFinished()),
+ newView, SLOT(doTransitionOut()));
+
if (m_isBack) {
m_oldSlot->setContents(0);
delete oldView;
@@ -277,33 +206,26 @@ void PageView::transitionFinished()
m_views.push(newView);
}
+ m_isAnimating = false;
m_menu->setText(newView->title());
}
void PageView::animateTransition(View *oldView, View *newView, bool isBack)
{
+ m_isAnimating = true;
+
m_isBack = isBack;
m_oldSlot->setContents(oldView);
m_newSlot->setContents(newView);
- m_animationInOut->clear();
-
newView->show();
- QAbstractAnimation *inAnim;
- QAbstractAnimation *outAnim;
-
- if (isBack) {
- inAnim = m_newSlot->createAnimation(PageSlot::MoveInLeft);
- outAnim = m_oldSlot->createAnimation(PageSlot::MoveOutRight);
- } else {
- inAnim = m_newSlot->createAnimation(PageSlot::MoveInRight);
- outAnim = m_oldSlot->createAnimation(PageSlot::MoveOutLeft);
- }
+ connect(newView, SIGNAL(transitionInFinished()),
+ this, SLOT(transitionFinished()));
+ connect(oldView, SIGNAL(transitionOutFinished()),
+ newView, SLOT(doTransitionIn()));
- m_animationInOut->addAnimation(inAnim);
- m_animationInOut->addAnimation(outAnim);
- m_animationInOut->start();
+ oldView->doTransitionOut();
}
void PageView::resizeEvent(QGraphicsSceneResizeEvent *event)