Home · All Namespaces · All Classes
Signals | Public Member Functions | Protected Slots | Protected Member Functions | Protected Attributes

SwitcherViewBase Class Reference

#include <switcherviewbase.h>

Inheritance diagram for SwitcherViewBase:
Inheritance graph
[legend]
Collaboration diagram for SwitcherViewBase:
Collaboration graph
[legend]

List of all members.

Signals

void animationStateChanged (bool animating)

Public Member Functions

 SwitcherViewBase (Switcher *controller)
virtual ~SwitcherViewBase ()
bool event (QEvent *e)

Protected Slots

virtual void updateData (const QList< const char * > &modifications)
 REIMPLEMENTATION
virtual void endTransition ()
 
virtual void endBounce ()
virtual void applyPinchGestureTargetMode ()
void runOverviewBounceAnimation ()
virtual void updateAnimationStatus ()

Protected Member Functions

virtual void setupModel ()
 
virtual void pinchGestureEvent (QGestureEvent *event, QPinchGesture *gesture)
virtual bool sceneEventFilter (QGraphicsItem *watched, QEvent *event)
virtual void applySwitcherMode ()
 
void removeButtonsFromLayout ()
int buttonIndex (const SwitcherButton *button) const
void calculateNearestButtonAt (const QPointF &centerPoint)
 Calculates which switcher button is nearest to point centerPoint.
virtual void startBounceAnimation ()
void setInwardBounceAnimation (bool i)
void setParentViewportsEnabled (bool enable)
virtual void pinchBegin (const QPointF &centerPoint)
virtual void pinchUpdate (float scaleFactor)
virtual void pinchEnd ()

Protected Attributes

Switchercontroller
QGraphicsLinearLayout * mainLayout
MWidget * pannedWidget
MLayout * pannedLayout
int pinchedButtonPosition
TransformLayoutAnimationlayoutAnimation
bool overpinch
QPropertyAnimation * bounceAnimation
SwitcherModel::Mode pinchGestureTargetMode
MPannableViewportviewport
bool animating
QList< MPannableViewport * > disabledViewports

Detailed Description

The switcher view draws a background for the switcher.

Definition at line 36 of file switcherviewbase.h.


Constructor & Destructor Documentation

SwitcherViewBase::SwitcherViewBase ( Switcher controller  ) 

Constructs a SwitcherViewBase.

Parameters:
container the Switcher controller to be used

Definition at line 45 of file switcherviewbase.cpp.

                                                     :
        MWidgetView(switcher), controller(switcher), mainLayout(new QGraphicsLinearLayout(Qt::Vertical)), pannedWidget(new MWidget), pinchedButtonPosition(-1), layoutAnimation(NULL), overpinch(false), animating(false)
{
    mainLayout->setContentsMargins(0, 0, 0, 0);
    switcher->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    switcher->setLayout(mainLayout);

    pannedLayout = new MLayout(pannedWidget);
    pannedLayout->setContentsMargins(0, 0, 0, 0);

    bounceAnimation = new QPropertyAnimation(this);
    bounceAnimation->setTargetObject(pannedWidget);
    bounceAnimation->setPropertyName("scale");
    bounceAnimation->setStartValue(1.0f);
    bounceAnimation->setEndValue(1.0f);
    connect(bounceAnimation, SIGNAL(finished()), this, SLOT(endBounce()));
    connect(bounceAnimation, SIGNAL(stateChanged(QAbstractAnimation::State,QAbstractAnimation::State)), this, SLOT(updateAnimationStatus()));

    connect(this, SIGNAL(animationStateChanged(bool)), switcher, SLOT(updateAnimationStatus(bool)));
}

Here is the call graph for this function:

SwitcherViewBase::~SwitcherViewBase (  )  [virtual]

Destroys the SwitcherViewBase.

Definition at line 66 of file switcherviewbase.cpp.

Here is the call graph for this function:


Member Function Documentation

void SwitcherViewBase::animationStateChanged ( bool  animating  )  [signal]

Sent when switcher starts or stops animating

void SwitcherViewBase::applyPinchGestureTargetMode (  )  [protected, virtual, slot]

Sets the switcher mode according to current pinch gesture target

Reimplemented in SwitcherView.

Definition at line 301 of file switcherviewbase.cpp.

{
    model()->setSwitcherMode(pinchGestureTargetMode);
}

void SwitcherViewBase::applySwitcherMode (  )  [protected, virtual]

Selects the layout policy and sets up switcher mode dependent signals

Reimplemented in SwitcherView.

Definition at line 95 of file switcherviewbase.cpp.

{
    if (model()->switcherMode() == SwitcherModel::Detailview) {
        controller->setStyleName("DetailviewSwitcher");
    } else {
        controller->setStyleName("OverviewSwitcher");
    }
}

int SwitcherViewBase::buttonIndex ( const SwitcherButton button  )  const [protected]

Returns the index of a SwitcherButton in the model or -1, if not found

Definition at line 115 of file switcherviewbase.cpp.

{
    if(button == NULL) {
        return -1;
    }

    QList<QSharedPointer<SwitcherButton> > buttons = model()->buttons();
    for (int i = 0; i < buttons.count(); ++i) {
        if (buttons.at(i) == button) {
            return i;
        }
    }

    return -1;
}

void SwitcherViewBase::calculateNearestButtonAt ( const QPointF &  centerPoint  )  [protected]

Calculates which switcher button is nearest to point centerPoint.

Definition at line 131 of file switcherviewbase.cpp.

{
    float minDistance = FLT_MAX;
    SwitcherButton *closestButton = NULL;

    foreach (const QSharedPointer<SwitcherButton> &button, model()->buttons()) {
        QLineF vec(centerPoint, button->mapToItem(controller, button->rect().center()));

        float distance = vec.length();

        if(distance < minDistance) {
            minDistance   = distance;
            closestButton = button.data();
        }
    }

    pinchedButtonPosition = buttonIndex(closestButton);
}

Here is the call graph for this function:

void SwitcherViewBase::endBounce (  )  [protected, virtual, slot]

Ends the bounce effect

Definition at line 295 of file switcherviewbase.cpp.

{
    setParentViewportsEnabled(true);
    MainWindow::instance()->setOrientationLocked(false);
}

Here is the call graph for this function:

void SwitcherViewBase::endTransition (  )  [protected, virtual, slot]

Ends the transition between switcher modes

Definition at line 283 of file switcherviewbase.cpp.

Here is the call graph for this function:

bool SwitcherViewBase::event ( QEvent *  e  ) 

REIMPLEMENTATION Re-implented event handler. Needed to enable gestures.

Parameters:
e event to be handled
Returns:
true if event was accepted, otherwise false

Definition at line 79 of file switcherviewbase.cpp.

{
    // This stuff is necessary to receive touch events.
    if (e->type() == QEvent::TouchBegin) {
        e->setAccepted(true);
        return true;
    }
    return MWidgetView::event(e);
}

void SwitcherViewBase::pinchBegin ( const QPointF &  centerPoint  )  [protected, virtual]

Called when the pinch gesture starts

Parameters:
centerPoint the center point of the pinch gesture

Definition at line 176 of file switcherviewbase.cpp.

{
    setParentViewportsEnabled(false);
    calculateNearestButtonAt(centerPoint);

    foreach(const QSharedPointer<SwitcherButton> &button, model()->buttons()) {
        button->installSceneEventFilter(controller);
    }

    MainWindow::instance()->setOrientationLocked(true);
}

Here is the call graph for this function:

void SwitcherViewBase::pinchEnd (  )  [protected, virtual]

Called when the pinch gesture ends

Definition at line 223 of file switcherviewbase.cpp.

{
    layoutAnimation->setManualControl(false);

    if(bounceAnimation->state() == QAbstractAnimation::Paused) {
        bounceAnimation->setDirection(QAbstractAnimation::Backward);
        bounceAnimation->resume();
    }

    // Cancel the transition if the pinch value plus twice the current pinching speed is less or equal to the threshold
    if(layoutAnimation->currentCurveValue() + layoutAnimation->speed() * 2.0f <= style()->pinchCancelThreshold()) {
        pinchGestureTargetMode = pinchGestureTargetMode == SwitcherModel::Detailview ? SwitcherModel::Overview : SwitcherModel::Detailview;
        layoutAnimation->cancelAnimation();
    }

    foreach (const QSharedPointer<SwitcherButton> &button, model()->buttons()) {
        button->setDown(false);
    }
}

Here is the call graph for this function:

void SwitcherViewBase::pinchGestureEvent ( QGestureEvent *  event,
QPinchGesture *  gesture 
) [protected, virtual]

Re-implemented to handle the mode switch

Parameters:
event Gesture event class for general event handling.
gesture Pinch gesture class. Contains all pinch specific information

Finish any currently running animation before starting a new one

Definition at line 243 of file switcherviewbase.cpp.

{
    if((layoutAnimation->isAnimating() && !layoutAnimation->manualControl()) || bounceAnimation->state() == QAbstractAnimation::Running) {
        return;
    }

    switch(gesture->state()) {
    case Qt::GestureStarted:
        pinchBegin(controller->mapFromScene(gesture->centerPoint()));
        break;
    case Qt::GestureUpdated:
        pinchUpdate(gesture->scaleFactor());
        break;
    case Qt::GestureFinished:
        pinchEnd();
        break;
    default:
        break;
    }

    event->accept(gesture);
}

Here is the call graph for this function:

void SwitcherViewBase::pinchUpdate ( float  scaleFactor  )  [protected, virtual]

Called to update the scale factor during the pinch gesture

Parameters:
scaleFactor the updated scale factor

Definition at line 188 of file switcherviewbase.cpp.

{
    if(!layoutAnimation->isAnimating()) {
        pinchGestureTargetMode = scaleFactor >= 1 ? SwitcherModel::Detailview : SwitcherModel::Overview;

        overpinch = pinchGestureTargetMode == model()->switcherMode();

        // Switch the mode and start the transition if needed
        if(model()->switcherMode() != pinchGestureTargetMode) {
            layoutAnimation->setManualControl(true);
            layoutAnimation->start();
            applyPinchGestureTargetMode();
        }
    }

    // Calculate the current animation progress based on the current scale factor
    qreal p = pinchGestureTargetMode == SwitcherModel::Detailview ?
              (scaleFactor - 1.0f) : (1.0f - scaleFactor);

    p = qBound(qreal(0.0), p * style()->pinchLength(), qreal(1));

    if(overpinch) {
        if(bounceAnimation->state() == QAbstractAnimation::Stopped) {
            setInwardBounceAnimation(model()->switcherMode() == SwitcherModel::Overview);
            bounceAnimation->setDirection(QAbstractAnimation::Forward);
            startBounceAnimation();
            bounceAnimation->pause();
        }

        bounceAnimation->setCurrentTime(p * bounceAnimation->duration() / 2);
    } else {
        layoutAnimation->setProgress(p);
    }
}

Here is the call graph for this function:

void SwitcherViewBase::removeButtonsFromLayout (  )  [protected]

Remove all buttons from layout and set parents to NULL Parents are set to NULL to avoid double deletion as buttons are QSharedPointer's in model

Definition at line 71 of file switcherviewbase.cpp.

{
    // Remove all buttons from the layout and set parents to null (do not destroy them)
    for (int i = 0, count = pannedLayout->count(); i < count; i++) {
        static_cast<SwitcherButton *>(pannedLayout->takeAt(0))->setParentItem(0);
    }
}

void SwitcherViewBase::runOverviewBounceAnimation (  )  [protected, slot]

Runs the bounce animation if currently in overview mode

Definition at line 322 of file switcherviewbase.cpp.

Here is the call graph for this function:

bool SwitcherViewBase::sceneEventFilter ( QGraphicsItem *  watched,
QEvent *  event 
) [protected, virtual]

Filters QGraphicsSceneMouseMove events from SwitcherButtons.

Definition at line 267 of file switcherviewbase.cpp.

{
    bool filtered = false;

    if(event->type() == QEvent::GraphicsSceneMouseMove) {
        foreach(const QSharedPointer<SwitcherButton> &button, model()->buttons()) {
            if(button == watched) {
                filtered = true;
                break;
            }
        }
    }

    return filtered;
}

void SwitcherViewBase::setInwardBounceAnimation ( bool  i  )  [protected]

Sets the direction of the bounce animation

Definition at line 306 of file switcherviewbase.cpp.

{
    // set the middle key value to either less than 1 when bouncing or zooming in overview mode,
    // or over 1 when zooming in detail mode
    bounceAnimation->setKeyValueAt(0.5f, 1.0f + (i ? -1.0f : 1.0f) * style()->bounceScale());
}

void SwitcherViewBase::setParentViewportsEnabled ( bool  enable  )  [protected]

Disables or restores the enabled state of all parent viewports

Parameters:
enable if false, disables all parent viewports, otherwise restores their enabled status to what it was when they were last disabled

Definition at line 150 of file switcherviewbase.cpp.

{
    QPointF point = controller->mapToScene(controller->rect().center());

    if(enable) {
        foreach(MPannableViewport *viewport, disabledViewports) {
            viewport->setEnabled(viewport->property(VIEWPORT_ENABLED_PROPERTY).toBool());
            viewport->setProperty(VIEWPORT_ENABLED_PROPERTY, QVariant());
        }
        disabledViewports.clear();
    } else {
        disabledViewports.clear();
        MScene *scene = MainWindow::instance()->scene();
        QList<QGraphicsItem*> items = scene->items(point);

        foreach(QGraphicsItem *item, items) {
            MPannableViewport *viewport = dynamic_cast<MPannableViewport*>(item);
            if(viewport) {
                viewport->setProperty(VIEWPORT_ENABLED_PROPERTY, viewport->isEnabled());
                viewport->setEnabled(false);
                disabledViewports.append(viewport);
            }
        }
    }
}

Here is the call graph for this function:

void SwitcherViewBase::setupModel (  )  [protected, virtual]

REIMPLEMENTATION Re-implemented here to get an update when the model is set

Definition at line 89 of file switcherviewbase.cpp.

Here is the call graph for this function:

void SwitcherViewBase::startBounceAnimation (  )  [protected, virtual]

Starts the bounce animation

Definition at line 313 of file switcherviewbase.cpp.

{
    pannedWidget->setTransformOriginPoint(pannedWidget->mapFromParent(pannedWidget->parentWidget()->rect().center()));

    bounceAnimation->setDuration(style()->bounceDuration());
    bounceAnimation->setEasingCurve(style()->bounceCurve());
    bounceAnimation->start();
}

void SwitcherViewBase::updateAnimationStatus (  )  [protected, virtual, slot]

Updates the animation status and sends animationStateChanged signal if status changed

Definition at line 330 of file switcherviewbase.cpp.

{
}

void SwitcherViewBase::updateData ( const QList< const char * > &  modifications  )  [protected, virtual, slot]

REIMPLEMENTATION

Reimplemented in SwitcherView.

Definition at line 104 of file switcherviewbase.cpp.

{
    MWidgetView::updateData(modifications);
    const char *member;
    foreach(member, modifications) {
        if (member == SwitcherModel::SwitcherMode) {
            applySwitcherMode();
        }
    }
}

Here is the call graph for this function:


Member Data Documentation

bool SwitcherViewBase::animating [protected]

True if switcher is currently animating

Definition at line 151 of file switcherviewbase.h.

QPropertyAnimation* SwitcherViewBase::bounceAnimation [protected]

Animation for the bounce when going to overview mode and when overpinching

Definition at line 142 of file switcherviewbase.h.

The switcher controller

Definition at line 121 of file switcherviewbase.h.

List of viewports that have been disabled

Definition at line 154 of file switcherviewbase.h.

Layout animation for animating switcher buttons

Definition at line 136 of file switcherviewbase.h.

QGraphicsLinearLayout* SwitcherViewBase::mainLayout [protected]

Layouts

Definition at line 124 of file switcherviewbase.h.

bool SwitcherViewBase::overpinch [protected]

True if the pinch direction is to the mode we're already in

Definition at line 139 of file switcherviewbase.h.

MLayout* SwitcherViewBase::pannedLayout [protected]

Layout for the panned widget

Definition at line 130 of file switcherviewbase.h.

MWidget* SwitcherViewBase::pannedWidget [protected]

The widget that will contain all of the switcher buttons

Definition at line 127 of file switcherviewbase.h.

The button being currently pinched

Definition at line 133 of file switcherviewbase.h.

The target mode for pinch gesture

Definition at line 145 of file switcherviewbase.h.

The viewport that shows the switcher buttons

Definition at line 148 of file switcherviewbase.h.


The documentation for this class was generated from the following files:

Copyright © 2010 Nokia Corporation Generated on Thu Nov 4 2010 18:20:43
Doxygen 1.7.1
MeeGo Touch