ui/widgets/glxzoomwidget/inc/glxzoomwidget.h
author hgs
Mon, 23 Aug 2010 18:06:16 +0530
changeset 58 383b67fbdb11
parent 54 0f0f3f26f787
child 62 36d93b4dc635
permissions -rw-r--r--
201033
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
43
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents:
diff changeset
     3
* All rights reserved.
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     8
*
hgs
parents:
diff changeset
     9
* Initial Contributors:
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    11
*
hgs
parents:
diff changeset
    12
* Contributors:
hgs
parents:
diff changeset
    13
*
hgs
parents:
diff changeset
    14
* Description:   glxzoomwidget.h
hgs
parents:
diff changeset
    15
*               definition of the class glxzoomwidget which controls the Zoom behavior of coverflow.
hgs
parents:
diff changeset
    16
*
hgs
parents:
diff changeset
    17
*/
hgs
parents:
diff changeset
    18
#ifndef GLXZOOMWIDGET_H
hgs
parents:
diff changeset
    19
#define GLXZOOMWIDGET_H
hgs
parents:
diff changeset
    20
hgs
parents:
diff changeset
    21
#include <QObject>
hgs
parents:
diff changeset
    22
#include <QGraphicsWidget>
hgs
parents:
diff changeset
    23
#include <QPixmap>
hgs
parents:
diff changeset
    24
#include <hbscrollarea.h>
hgs
parents:
diff changeset
    25
hgs
parents:
diff changeset
    26
#include <glxzoomwidget_global.h>
hgs
parents:
diff changeset
    27
hgs
parents:
diff changeset
    28
class QGestureEvent;
hgs
parents:
diff changeset
    29
class QPinchGesture;
hgs
parents:
diff changeset
    30
class HbIconItem;
hgs
parents:
diff changeset
    31
class GlxImageDecoderWrapper;
hgs
parents:
diff changeset
    32
class QTimeLine;
hgs
parents:
diff changeset
    33
58
hgs
parents: 54
diff changeset
    34
43
hgs
parents:
diff changeset
    35
hgs
parents:
diff changeset
    36
class GLXZOOMWIDGETSHARED_EXPORT GlxZoomWidget : public HbScrollArea
hgs
parents:
diff changeset
    37
{
hgs
parents:
diff changeset
    38
    Q_OBJECT
hgs
parents:
diff changeset
    39
hgs
parents:
diff changeset
    40
    public:
hgs
parents:
diff changeset
    41
    GlxZoomWidget (QGraphicsItem *parent = NULL);
hgs
parents:
diff changeset
    42
    ~GlxZoomWidget ();
hgs
parents:
diff changeset
    43
    void setModel (QAbstractItemModel *model) ;
hgs
parents:
diff changeset
    44
    void indexChanged(int index);
hgs
parents:
diff changeset
    45
    void setWindowSize(QSize windowSize);
hgs
parents:
diff changeset
    46
    void cleanUp();
hgs
parents:
diff changeset
    47
    void activate();
hgs
parents:
diff changeset
    48
    void setMinMaxZValue(int minZvalue, int maxZvalue);
hgs
parents:
diff changeset
    49
    void connectDecodeRequestToPinchEvent();
45
hgs
parents: 44
diff changeset
    50
    
hgs
parents: 44
diff changeset
    51
    /*
hgs
parents: 44
diff changeset
    52
     * This is an overloaded function when an index is changes due to deletion 
hgs
parents: 44
diff changeset
    53
     */
hgs
parents: 44
diff changeset
    54
    void indexChanged();
50
hgs
parents: 45
diff changeset
    55
    void forceZoomToBackground();
45
hgs
parents: 44
diff changeset
    56
    
43
hgs
parents:
diff changeset
    57
    signals:
hgs
parents:
diff changeset
    58
    void pinchGestureReceived(int index);
hgs
parents:
diff changeset
    59
    void zoomWidgetMovedBackground(int index);
54
hgs
parents: 52
diff changeset
    60
    void stepZoom();
hgs
parents: 52
diff changeset
    61
    
43
hgs
parents:
diff changeset
    62
    public slots:
hgs
parents:
diff changeset
    63
    //for Decoder support
hgs
parents:
diff changeset
    64
    void decodedImageAvailable();
hgs
parents:
diff changeset
    65
    void sendDecodeRequest(int index);
hgs
parents:
diff changeset
    66
hgs
parents:
diff changeset
    67
	//for animation effects
hgs
parents:
diff changeset
    68
	void animateZoomIn(QPointF animRefPoint);
hgs
parents:
diff changeset
    69
	void animateZoomOut(QPointF animRefPoint);
hgs
parents:
diff changeset
    70
	void animationTimeLineFinished();
hgs
parents:
diff changeset
    71
54
hgs
parents: 52
diff changeset
    72
	//animate double tap
hgs
parents: 52
diff changeset
    73
	void animateDoubleTap();
hgs
parents: 52
diff changeset
    74
	
43
hgs
parents:
diff changeset
    75
    protected:
hgs
parents:
diff changeset
    76
    bool sceneEvent(QEvent *event);
hgs
parents:
diff changeset
    77
    bool sceneEventFilter(QGraphicsItem *watched,QEvent *event);
44
hgs
parents: 43
diff changeset
    78
    void timerEvent(QTimerEvent *event);
43
hgs
parents:
diff changeset
    79
    protected slots:
hgs
parents:
diff changeset
    80
    void dataChanged(QModelIndex startIndex, QModelIndex endIndex);
45
hgs
parents: 44
diff changeset
    81
    void modelDestroyed();
43
hgs
parents:
diff changeset
    82
hgs
parents:
diff changeset
    83
    private:
hgs
parents:
diff changeset
    84
    bool executeGestureEvent(QGraphicsItem *source,QGestureEvent *event);
hgs
parents:
diff changeset
    85
    //Responsible for changing the transforms of the widget wrt the ZF and center
hgs
parents:
diff changeset
    86
	//Also adjusts the ZF, center and final size so as to respect the boundaries
hgs
parents:
diff changeset
    87
    void zoomImage(qreal zoomFactor, QPointF center);
hgs
parents:
diff changeset
    88
    //This API will adjust the gesture center to maintain boundaries
hgs
parents:
diff changeset
    89
	//called from GlxZoomWidget::zoomImage
hgs
parents:
diff changeset
    90
    void adjustGestureCenter(QPointF & gestureCenter, qreal& zoomFactor);
hgs
parents:
diff changeset
    91
    //this API will limit the max/min Zoom Size possible
hgs
parents:
diff changeset
    92
	//called from GlxZoomWidget::zoomImage
hgs
parents:
diff changeset
    93
    void limitRequiredSize(QSizeF &requiredSize);
hgs
parents:
diff changeset
    94
	//gets the latest focussed image from the model
hgs
parents:
diff changeset
    95
    void retreiveFocusedImage();
hgs
parents:
diff changeset
    96
    //finalize the transform and update the sizehint of mZoomWidget
hgs
parents:
diff changeset
    97
    void finalizeWidgetTransform();
hgs
parents:
diff changeset
    98
    //get the focused image from the model
hgs
parents:
diff changeset
    99
    QPixmap getFocusedImage();
50
hgs
parents: 45
diff changeset
   100
    //set all the zoom parameters as per the circumstances
hgs
parents: 45
diff changeset
   101
    void setZoomParams();
43
hgs
parents:
diff changeset
   102
52
hgs
parents: 50
diff changeset
   103
    bool isFocussedItemCorrupt();
43
hgs
parents:
diff changeset
   104
    //data members
52
hgs
parents: 50
diff changeset
   105
private:
hgs
parents: 50
diff changeset
   106
    //to be in sync with the model
hgs
parents: 50
diff changeset
   107
    QAbstractItemModel *mModel;
hgs
parents: 50
diff changeset
   108
hgs
parents: 50
diff changeset
   109
    //view Z values 
hgs
parents: 50
diff changeset
   110
    //might push to layouts later
hgs
parents: 50
diff changeset
   111
    int mMinZValue ;
hgs
parents: 50
diff changeset
   112
    int mMaxZValue ;
hgs
parents: 50
diff changeset
   113
    int mTimerId;
hgs
parents: 50
diff changeset
   114
hgs
parents: 50
diff changeset
   115
    //status flags
hgs
parents: 50
diff changeset
   116
    //To check if the decode request has already been send or not
hgs
parents: 50
diff changeset
   117
    bool mImageDecodeRequestSend; 
hgs
parents: 50
diff changeset
   118
    //To check if the pinch gesture is in progress to block any events to HbScrollArea
hgs
parents: 50
diff changeset
   119
    bool mPinchGestureOngoing; 
hgs
parents: 50
diff changeset
   120
    //to check if decoded image is available
hgs
parents: 50
diff changeset
   121
    bool mDecodedImageAvailable;
hgs
parents: 50
diff changeset
   122
    //to check if the widget is actually in Foreground
hgs
parents: 50
diff changeset
   123
    bool mZoomOngoing;
hgs
parents: 50
diff changeset
   124
43
hgs
parents:
diff changeset
   125
    //view widgets
hgs
parents:
diff changeset
   126
    QGraphicsPixmapItem *mZoomItem;   //Item containing the pixmap
hgs
parents:
diff changeset
   127
    QGraphicsWidget *mZoomWidget;     //container :all scaling and transforms would be done on this widget
hgs
parents:
diff changeset
   128
    HbIconItem* mBlackBackgroundItem; //for setting black background
hgs
parents:
diff changeset
   129
hgs
parents:
diff changeset
   130
    int mFocusIndex;
hgs
parents:
diff changeset
   131
hgs
parents:
diff changeset
   132
    //size parameter
hgs
parents:
diff changeset
   133
    QSizeF mItemSize;        // the actual pixmap size. Keep it updated with latest pixmap size
hgs
parents:
diff changeset
   134
    QSizeF mStepCurrentSize; //to save the size before gesture started
hgs
parents:
diff changeset
   135
    QSizeF mCurrentSize;     //save sizes scaled by gesture
hgs
parents:
diff changeset
   136
    QSize mWindowSize;      //the window size
hgs
parents:
diff changeset
   137
    QSizeF mMinScaleSize;   //minimum posible size
hgs
parents:
diff changeset
   138
    QSizeF mMinDecScaleSize;   //the Minimum scale limit after which the image scaling down should be decelerated
hgs
parents:
diff changeset
   139
    QSizeF mMaxScaleSize;   // the maximum scale limit
hgs
parents:
diff changeset
   140
    QSizeF mMaxScaleDecSize;   // the Maximum scale limit after which the image scaling should be decelerated
hgs
parents:
diff changeset
   141
	//for animation effect
hgs
parents:
diff changeset
   142
	qreal m_FinalAnimatedScaleFactor;
hgs
parents:
diff changeset
   143
	QPointF m_AnimRefPoint;
hgs
parents:
diff changeset
   144
	QTimeLine *m_AnimTimeLine;
hgs
parents:
diff changeset
   145
    //for Decoder support
hgs
parents:
diff changeset
   146
    GlxImageDecoderWrapper* mImageDecoder;
hgs
parents:
diff changeset
   147
54
hgs
parents: 52
diff changeset
   148
    //stores the incremental scalingfactor(sf) while performing double tap animation
hgs
parents: 52
diff changeset
   149
    qreal mIncSF;
hgs
parents: 52
diff changeset
   150
    //stores the scalingfactor increment applicable for each step of double tap animation
hgs
parents: 52
diff changeset
   151
    qreal msfInc;
58
hgs
parents: 54
diff changeset
   152
    //stores the item size before performing zoomout or zoomin
hgs
parents: 54
diff changeset
   153
    QSizeF minitSize;
54
hgs
parents: 52
diff changeset
   154
    //counter to track the double tap animation steps
hgs
parents: 52
diff changeset
   155
    int mdoubletapSteps;
43
hgs
parents:
diff changeset
   156
};
hgs
parents:
diff changeset
   157
#endif  //GLXZOOMWIDGET_H