ui/widgets/glxzoomwidget/inc/glxzoomwidget.h
author hgs
Fri, 23 Jul 2010 20:41:04 +0530
changeset 52 a3a4c0de738e
parent 50 a0f57508af73
child 54 0f0f3f26f787
permissions -rw-r--r--
201029
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
hgs
parents:
diff changeset
    34
const int MAXZVALUE = 100;
hgs
parents:
diff changeset
    35
const int MINZVALUE = 0;
hgs
parents:
diff changeset
    36
hgs
parents:
diff changeset
    37
class GLXZOOMWIDGETSHARED_EXPORT GlxZoomWidget : public HbScrollArea
hgs
parents:
diff changeset
    38
{
hgs
parents:
diff changeset
    39
    Q_OBJECT
hgs
parents:
diff changeset
    40
hgs
parents:
diff changeset
    41
    public:
hgs
parents:
diff changeset
    42
    GlxZoomWidget (QGraphicsItem *parent = NULL);
hgs
parents:
diff changeset
    43
    ~GlxZoomWidget ();
hgs
parents:
diff changeset
    44
    void setModel (QAbstractItemModel *model) ;
hgs
parents:
diff changeset
    45
    void indexChanged(int index);
hgs
parents:
diff changeset
    46
    void setWindowSize(QSize windowSize);
hgs
parents:
diff changeset
    47
    void cleanUp();
hgs
parents:
diff changeset
    48
    void activate();
hgs
parents:
diff changeset
    49
    void setMinMaxZValue(int minZvalue, int maxZvalue);
hgs
parents:
diff changeset
    50
    void connectDecodeRequestToPinchEvent();
45
hgs
parents: 44
diff changeset
    51
    
hgs
parents: 44
diff changeset
    52
    /*
hgs
parents: 44
diff changeset
    53
     * This is an overloaded function when an index is changes due to deletion 
hgs
parents: 44
diff changeset
    54
     */
hgs
parents: 44
diff changeset
    55
    void indexChanged();
50
hgs
parents: 45
diff changeset
    56
    void forceZoomToBackground();
45
hgs
parents: 44
diff changeset
    57
    
43
hgs
parents:
diff changeset
    58
    signals:
hgs
parents:
diff changeset
    59
    void pinchGestureReceived(int index);
hgs
parents:
diff changeset
    60
    void zoomWidgetMovedBackground(int index);
hgs
parents:
diff changeset
    61
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 animationFrameChanged(int frameNumber);
hgs
parents:
diff changeset
    71
	void animationTimeLineFinished();
hgs
parents:
diff changeset
    72
hgs
parents:
diff changeset
    73
    protected:
hgs
parents:
diff changeset
    74
    bool sceneEvent(QEvent *event);
hgs
parents:
diff changeset
    75
    bool sceneEventFilter(QGraphicsItem *watched,QEvent *event);
44
hgs
parents: 43
diff changeset
    76
    void timerEvent(QTimerEvent *event);
43
hgs
parents:
diff changeset
    77
    protected slots:
hgs
parents:
diff changeset
    78
    void dataChanged(QModelIndex startIndex, QModelIndex endIndex);
45
hgs
parents: 44
diff changeset
    79
    void modelDestroyed();
43
hgs
parents:
diff changeset
    80
hgs
parents:
diff changeset
    81
    private:
hgs
parents:
diff changeset
    82
    bool executeGestureEvent(QGraphicsItem *source,QGestureEvent *event);
hgs
parents:
diff changeset
    83
    //Responsible for changing the transforms of the widget wrt the ZF and center
hgs
parents:
diff changeset
    84
	//Also adjusts the ZF, center and final size so as to respect the boundaries
hgs
parents:
diff changeset
    85
    void zoomImage(qreal zoomFactor, QPointF center);
hgs
parents:
diff changeset
    86
    //This API will adjust the gesture center to maintain boundaries
hgs
parents:
diff changeset
    87
	//called from GlxZoomWidget::zoomImage
hgs
parents:
diff changeset
    88
    void adjustGestureCenter(QPointF & gestureCenter, qreal& zoomFactor);
hgs
parents:
diff changeset
    89
    //this API will limit the max/min Zoom Size possible
hgs
parents:
diff changeset
    90
	//called from GlxZoomWidget::zoomImage
hgs
parents:
diff changeset
    91
    void limitRequiredSize(QSizeF &requiredSize);
hgs
parents:
diff changeset
    92
	//gets the latest focussed image from the model
hgs
parents:
diff changeset
    93
    void retreiveFocusedImage();
hgs
parents:
diff changeset
    94
    //finalize the transform and update the sizehint of mZoomWidget
hgs
parents:
diff changeset
    95
    void finalizeWidgetTransform();
hgs
parents:
diff changeset
    96
    //get the focused image from the model
hgs
parents:
diff changeset
    97
    QPixmap getFocusedImage();
50
hgs
parents: 45
diff changeset
    98
    //set all the zoom parameters as per the circumstances
hgs
parents: 45
diff changeset
    99
    void setZoomParams();
43
hgs
parents:
diff changeset
   100
52
hgs
parents: 50
diff changeset
   101
    bool isFocussedItemCorrupt();
43
hgs
parents:
diff changeset
   102
    //data members
52
hgs
parents: 50
diff changeset
   103
private:
hgs
parents: 50
diff changeset
   104
    //to be in sync with the model
hgs
parents: 50
diff changeset
   105
    QAbstractItemModel *mModel;
hgs
parents: 50
diff changeset
   106
hgs
parents: 50
diff changeset
   107
    //view Z values 
hgs
parents: 50
diff changeset
   108
    //might push to layouts later
hgs
parents: 50
diff changeset
   109
    int mMinZValue ;
hgs
parents: 50
diff changeset
   110
    int mMaxZValue ;
hgs
parents: 50
diff changeset
   111
    int mTimerId;
hgs
parents: 50
diff changeset
   112
hgs
parents: 50
diff changeset
   113
    //status flags
hgs
parents: 50
diff changeset
   114
    //To check if the decode request has already been send or not
hgs
parents: 50
diff changeset
   115
    bool mImageDecodeRequestSend; 
hgs
parents: 50
diff changeset
   116
    //To check if the pinch gesture is in progress to block any events to HbScrollArea
hgs
parents: 50
diff changeset
   117
    bool mPinchGestureOngoing; 
hgs
parents: 50
diff changeset
   118
    //to check if decoded image is available
hgs
parents: 50
diff changeset
   119
    bool mDecodedImageAvailable;
hgs
parents: 50
diff changeset
   120
    //to check if the widget is actually in Foreground
hgs
parents: 50
diff changeset
   121
    bool mZoomOngoing;
hgs
parents: 50
diff changeset
   122
43
hgs
parents:
diff changeset
   123
    //view widgets
hgs
parents:
diff changeset
   124
    QGraphicsPixmapItem *mZoomItem;   //Item containing the pixmap
hgs
parents:
diff changeset
   125
    QGraphicsWidget *mZoomWidget;     //container :all scaling and transforms would be done on this widget
hgs
parents:
diff changeset
   126
    HbIconItem* mBlackBackgroundItem; //for setting black background
hgs
parents:
diff changeset
   127
hgs
parents:
diff changeset
   128
    int mFocusIndex;
hgs
parents:
diff changeset
   129
hgs
parents:
diff changeset
   130
    //size parameter
hgs
parents:
diff changeset
   131
    QSizeF mItemSize;        // the actual pixmap size. Keep it updated with latest pixmap size
hgs
parents:
diff changeset
   132
    QSizeF mStepCurrentSize; //to save the size before gesture started
hgs
parents:
diff changeset
   133
    QSizeF mCurrentSize;     //save sizes scaled by gesture
hgs
parents:
diff changeset
   134
    QSize mWindowSize;      //the window size
hgs
parents:
diff changeset
   135
    QSizeF mMinScaleSize;   //minimum posible size
hgs
parents:
diff changeset
   136
    QSizeF mMinDecScaleSize;   //the Minimum scale limit after which the image scaling down should be decelerated
hgs
parents:
diff changeset
   137
    QSizeF mMaxScaleSize;   // the maximum scale limit
hgs
parents:
diff changeset
   138
    QSizeF mMaxScaleDecSize;   // the Maximum scale limit after which the image scaling should be decelerated
hgs
parents:
diff changeset
   139
	//for animation effect
hgs
parents:
diff changeset
   140
	qreal m_FinalAnimatedScaleFactor;
hgs
parents:
diff changeset
   141
	QPointF m_AnimRefPoint;
hgs
parents:
diff changeset
   142
	QTimeLine *m_AnimTimeLine;
hgs
parents:
diff changeset
   143
    //for Decoder support
hgs
parents:
diff changeset
   144
    GlxImageDecoderWrapper* mImageDecoder;
hgs
parents:
diff changeset
   145
hgs
parents:
diff changeset
   146
};
hgs
parents:
diff changeset
   147
#endif  //GLXZOOMWIDGET_H