screensaver/snsrplugins/snsrbigclockscreensaverplugin/snsrswipewidget/src/snsrswipewidget.cpp
changeset 97 66b5fe3c07fd
child 98 e6f74eb7f69f
equal deleted inserted replaced
95:32e56106abf2 97:66b5fe3c07fd
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Swipe Widget.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <QDebug>
       
    19 #include <HbStyleLoader>
       
    20 #include <hbeffect.h>
       
    21 #include <hblabel.h>
       
    22 #include <HbIconItem>
       
    23 #include <HbIconAnimationManager>
       
    24 
       
    25 #include <hbiconitem.h>
       
    26 #include <hbiconanimator.h>
       
    27 
       
    28 #include "snsrbigclockcontainer.h"
       
    29 #include "snsranalogclockcontainer.h"
       
    30 #include "snsrswipewidget.h"
       
    31 
       
    32 const char *gSwipeCssFilePath =":/style/snsrswipewidget.css";
       
    33 const char *gSwipeWidgetMLFilePath = ":/style/snsrswipewidget.widgetml";
       
    34 const char *gSwipeColorCssFilePath = ":/style/snsrswipewidget_color.css";
       
    35 const char *gSwipeIcon = ":/xml/qtg_anim_swipe.axml";
       
    36 const qreal gSwipeDownAngle = 270;
       
    37 const qreal gLandscapeSwipeDownAngle = 180;
       
    38 const qreal gSwipeAngleTolerance = 25;
       
    39 
       
    40 /*!
       
    41     \class SnsrSwipeWidget
       
    42     \ingroup group_snsrbigclockscreensaverplugins
       
    43     \brief Screensaver swipe widget.
       
    44  */
       
    45 
       
    46 /*!
       
    47     Constructs a new SnsrSwipeWidget.
       
    48     \param parent Parent object.
       
    49  */
       
    50 SnsrSwipeWidget::SnsrSwipeWidget(QGraphicsItem* parent):
       
    51     HbWidget(parent),
       
    52     mSlideLabel(0), mIconItem(0),mCurrentOrientation(-1)
       
    53 {
       
    54     HbStyleLoader::registerFilePath(gSwipeCssFilePath);
       
    55     HbStyleLoader::registerFilePath(gSwipeWidgetMLFilePath);
       
    56     HbStyleLoader::registerFilePath(gSwipeColorCssFilePath);
       
    57     
       
    58     setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred);
       
    59 
       
    60     createPrimitives();
       
    61 
       
    62     grabGesture(Qt::SwipeGesture);
       
    63 }
       
    64 
       
    65 /*!
       
    66     Destructs the class.
       
    67  */
       
    68 SnsrSwipeWidget::~SnsrSwipeWidget()
       
    69 {
       
    70     HbStyleLoader::unregisterFilePath( gSwipeCssFilePath );
       
    71     HbStyleLoader::unregisterFilePath( gSwipeWidgetMLFilePath );
       
    72     HbStyleLoader::unregisterFilePath( gSwipeColorCssFilePath );
       
    73 
       
    74 }
       
    75 
       
    76 /*!
       
    77     Creates all widget primitives.
       
    78  */
       
    79 void SnsrSwipeWidget::createPrimitives()
       
    80 {
       
    81     if (!mSlideLabel) {
       
    82         mSlideLabel = new HbLabel(this);
       
    83         mSlideLabel->setPlainText(hbTrId("txt_screensaver_swipe"));
       
    84         mSlideLabel->setAlignment(Qt::AlignCenter);
       
    85         HbStyle::setItemName(mSlideLabel, QLatin1String("slideLabel"));
       
    86     }
       
    87     if (!mIconItem) {
       
    88         HbIconAnimationManager::global()->addDefinitionFile(gSwipeIcon);
       
    89         mIconItem = new HbIconItem(QString("qtg_anim_swipe"),this);
       
    90         HbStyle::setItemName(mIconItem, QLatin1String("slideIcon"));
       
    91         mIconItem->show();
       
    92         mIconItem->animator().startAnimation();
       
    93         mIconItem->setAlignment(Qt::AlignCenter);
       
    94     }
       
    95 }
       
    96 
       
    97 /*!
       
    98     \reimp
       
    99  */
       
   100 
       
   101 void SnsrSwipeWidget::gestureEvent(QGestureEvent *event)
       
   102 {
       
   103     SCREENSAVER_TEST_FUNC_ENTRY("SnsrSwipeWidget::gestureEvent")
       
   104 
       
   105     QGesture *gesture = event->gesture(Qt::SwipeGesture);
       
   106     QSwipeGesture *swipe = static_cast<QSwipeGesture *>(gesture);
       
   107 
       
   108     if ( swipe && swipe->state() == Qt::GestureStarted ) {
       
   109         event->accept(Qt::SwipeGesture);
       
   110         mIconItem->animator().startAnimation();
       
   111     }
       
   112     else if ( swipe && swipe->state() == Qt::GestureFinished ) {
       
   113         // unclock with downward swipe
       
   114         qreal downAngle = (mCurrentOrientation == Qt::Vertical) ? 
       
   115             gSwipeDownAngle : gLandscapeSwipeDownAngle;
       
   116         qreal swipeAngle = swipe->swipeAngle();
       
   117         if ( abs(swipeAngle - downAngle) < gSwipeAngleTolerance ) {
       
   118             emit swipeDownDetected();
       
   119             event->accept(Qt::SwipeGesture);
       
   120         }
       
   121     }
       
   122     else { 
       
   123         event->ignore(Qt::SwipeGesture);
       
   124     }
       
   125 
       
   126     SCREENSAVER_TEST_FUNC_EXIT("SnsrSwipeWidget::gestureEvent")
       
   127 }
       
   128 
       
   129 void SnsrSwipeWidget::setCurrentOrientation(int orientation)
       
   130 {
       
   131     mCurrentOrientation = orientation;
       
   132 }
       
   133 
       
   134