screensaver/screensaverplugins/snsrbigclockscreensaverplugin/snsrswipewidget/src/snsrswipewidget.cpp
changeset 97 66b5fe3c07fd
parent 95 32e56106abf2
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 
       
    23 #include "snsrbigclockcontainer.h"
       
    24 #include "snsranalogclockcontainer.h"
       
    25 #include "snsrswipewidget.h"
       
    26 
       
    27 const char *gSwipeCssFilePath =":/style/snsrswipewidget.css";
       
    28 const char *gSwipeWidgetMLFilePath = ":/style/snsrswipewidget.widgetml";
       
    29 const char *gSwipeColorCssFilePath = ":/style/snsrswipewidget_color.css";
       
    30 
       
    31 const qreal gSwipeDownAngle = 270;
       
    32 const qreal gSwipeAngleTolerance = 25;
       
    33 
       
    34 /*!
       
    35     \class SnsrSwipeWidget
       
    36     \ingroup group_snsrbigclockscreensaverplugins
       
    37     \brief Screensaver swipe widget.
       
    38  */
       
    39 
       
    40 /*!
       
    41     Constructs a new SnsrSwipeWidget.
       
    42     \param parent Parent object.
       
    43  */
       
    44 SnsrSwipeWidget::SnsrSwipeWidget(QGraphicsItem* parent):
       
    45     HbWidget(parent),
       
    46     mSlideLabel(0), mSlideIcon(0)
       
    47 {
       
    48     HbStyleLoader::registerFilePath(gSwipeCssFilePath);
       
    49     HbStyleLoader::registerFilePath(gSwipeWidgetMLFilePath);
       
    50     HbStyleLoader::registerFilePath(gSwipeColorCssFilePath);
       
    51     
       
    52     setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred);
       
    53 
       
    54     createPrimitives();
       
    55 
       
    56     HbEffect::add(mSlideIcon,
       
    57         ":/xml/animate_portrait.fxml",
       
    58         "slideDownPortrait");
       
    59 
       
    60     reset();
       
    61     grabGesture(Qt::SwipeGesture);
       
    62 
       
    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     HbEffect::remove(mSlideIcon);
       
    75 }
       
    76 
       
    77 void SnsrSwipeWidget::start()
       
    78 {
       
    79     // Start animation
       
    80     HbEffect::start(mSlideIcon, "slideDownPortrait", this, "animationComplete");
       
    81 }
       
    82 
       
    83 void SnsrSwipeWidget::reset()
       
    84 {
       
    85     // Cancel animation and disable callback
       
    86     HbEffect::cancel(mSlideIcon, "slideDownPortrait", false, false);
       
    87 }
       
    88 
       
    89 void SnsrSwipeWidget::animationComplete(const HbEffect::EffectStatus &status)
       
    90 {
       
    91     Q_UNUSED(status);
       
    92     HbEffect::start(mSlideIcon, "slideDownPortrait", this, "animationComplete");
       
    93 }
       
    94 
       
    95 
       
    96 /*!
       
    97     Creates all widget primitives.
       
    98  */
       
    99 void SnsrSwipeWidget::createPrimitives()
       
   100 {
       
   101     if (!mSlideLabel) {
       
   102         mSlideLabel = new HbLabel(this);
       
   103         mSlideLabel->setPlainText(hbTrId("txt_screensaver_swipe"));
       
   104         mSlideLabel->setAlignment(Qt::AlignCenter);
       
   105         mSlideLabel->setPreferredHeight(50.0);
       
   106         mSlideLabel->setPreferredWidth(224.0);
       
   107         HbStyle::setItemName(mSlideLabel, QLatin1String("slideLabel"));
       
   108     }
       
   109     if (!mSlideIcon) {
       
   110         mSlideIcon = new HbLabel(QLatin1String("slider"), this);
       
   111         mSlideIcon->setIcon(HbIcon(":/slider"));   
       
   112         mSlideIcon->setAspectRatioMode(Qt::KeepAspectRatioByExpanding);
       
   113         mSlideIcon->setAlignment(Qt::AlignCenter);
       
   114         mSlideIcon->setPreferredHeight(50.0);
       
   115         mSlideIcon->setPreferredWidth(100.0);
       
   116         HbStyle::setItemName(mSlideIcon, QLatin1String("slideIcon"));
       
   117     }
       
   118 }
       
   119 
       
   120 /*!
       
   121     \reimp
       
   122  */
       
   123 
       
   124 void SnsrSwipeWidget::gestureEvent(QGestureEvent *event)
       
   125 {
       
   126     SCREENSAVER_TEST_FUNC_ENTRY("SnsrSwipeWidget::gestureEvent")
       
   127 
       
   128     QGesture *gesture = event->gesture(Qt::SwipeGesture);
       
   129     QSwipeGesture *swipe = static_cast<QSwipeGesture *>(gesture);
       
   130 
       
   131     if ( swipe && swipe->state() == Qt::GestureStarted ) {
       
   132         start();
       
   133         event->accept(Qt::SwipeGesture);
       
   134     }
       
   135     else if ( swipe && swipe->state() == Qt::GestureFinished ) {
       
   136         // TODO: Remove following, currently shows some debug data on screen
       
   137         mSlideLabel->setPlainText( QString("angle=%1, horD=%2, verD=%3 ")
       
   138                 .arg(swipe->swipeAngle())
       
   139                 .arg(swipe->horizontalDirection())
       
   140                 .arg(swipe->verticalDirection()) );
       
   141         
       
   142         // unclock with downward swipe
       
   143         qreal swipeAngle = swipe->swipeAngle();
       
   144         if ( abs(swipeAngle - gSwipeDownAngle) < gSwipeAngleTolerance ) {
       
   145             
       
   146             emit swipeDownDetected();
       
   147             event->accept(Qt::SwipeGesture);
       
   148             }
       
   149     }
       
   150     else { event->ignore(Qt::SwipeGesture); }
       
   151 
       
   152     SCREENSAVER_TEST_FUNC_EXIT("SnsrSwipeWidget::gestureEvent")
       
   153 }