homescreenapp/widgetplugins/hsclockwidgetplugin/src/hsanalogclockwidget.cpp
changeset 77 4b195f3bea29
parent 61 2b1b11a301d2
equal deleted inserted replaced
61:2b1b11a301d2 77:4b195f3bea29
    18 #include <QGraphicsSceneMouseEvent>
    18 #include <QGraphicsSceneMouseEvent>
    19 #include <QTime>
    19 #include <QTime>
    20 
    20 
    21 #include <HbStyleLoader>
    21 #include <HbStyleLoader>
    22 #include <HbIconItem>
    22 #include <HbIconItem>
    23 #include <HbTouchArea>
    23 #include <HbTapGesture>
    24 #include <HbInstantFeedback>
    24 #include <HbInstantFeedback>
    25 
    25 
    26 #include "hsconfiguration.h"
    26 #include "hsconfiguration.h"
    27 #include "hsanalogclockwidget.h"
    27 #include "hsanalogclockwidget.h"
    28 
    28 
    36     Constructs widget.
    36     Constructs widget.
    37 */
    37 */
    38 HsAnalogClockWidget::HsAnalogClockWidget(QGraphicsItem *parent)
    38 HsAnalogClockWidget::HsAnalogClockWidget(QGraphicsItem *parent)
    39     : HbWidget(parent),
    39     : HbWidget(parent),
    40       mBackground(0), mHourHand(0), mMinuteHand(0), 
    40       mBackground(0), mHourHand(0), mMinuteHand(0), 
    41       mSecondHand(0), mTouchArea(0)
    41       mSecondHand(0)
    42 {
    42 {
    43     HbStyleLoader::registerFilePath(":/hsanalogclockwidget.widgetml");
    43     HbStyleLoader::registerFilePath(":/hsanalogclockwidget.widgetml");
    44     HbStyleLoader::registerFilePath(":/hsanalogclockwidget.css");
    44     HbStyleLoader::registerFilePath(":/hsanalogclockwidget.css");
    45 
    45 
    46     createPrimitives();
    46     createPrimitives();
       
    47     grabGesture(Qt::TapGesture);
    47 }
    48 }
    48 
    49 
    49 /*!
    50 /*!
    50     Destructor.
    51     Destructor.
    51 */
    52 */
    52 HsAnalogClockWidget::~HsAnalogClockWidget()
    53 HsAnalogClockWidget::~HsAnalogClockWidget()
    53 {
    54 {
    54     HbStyleLoader::unregisterFilePath(":/hsanalogclockwidget.widgetml");
    55     HbStyleLoader::unregisterFilePath(":/hsanalogclockwidget.widgetml");
    55     HbStyleLoader::unregisterFilePath(":/hsanalogclockwidget.css");
    56     HbStyleLoader::unregisterFilePath(":/hsanalogclockwidget.css");
    56     mTouchArea->removeEventFilter(this);
       
    57 }
    57 }
    58 
    58 
    59 /*!
    59 #ifdef COVERAGE_MEASUREMENT
    60     Filters touch area events.
    60 #pragma CTC SKIP
    61 */
    61 #endif //COVERAGE_MEASUREMENT
    62 bool HsAnalogClockWidget::eventFilter(QObject *watched, QEvent *event)
    62 void HsAnalogClockWidget::gestureEvent(QGestureEvent *event)
    63 {
    63 {
    64     Q_UNUSED(watched)
    64     HbTapGesture *gesture = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture));
       
    65     if (gesture) {
       
    66         if (gesture->state() == Qt::GestureFinished) {
       
    67             if (gesture->tapStyleHint() == HbTapGesture::Tap) {
       
    68                     HbInstantFeedback::play(HSCONFIGURATION_GET(clockWidgetTapFeedbackEffect));
       
    69                     emit clockTapped();                
       
    70             }
       
    71         }
       
    72     }
       
    73 }
       
    74 #ifdef COVERAGE_MEASUREMENT
       
    75 #pragma CTC ENDSKIP
       
    76 #endif //COVERAGE_MEASUREMENT
    65 
    77 
    66     switch (event->type()) {
       
    67         case QEvent::GraphicsSceneMousePress:
       
    68             return true;
       
    69         case QEvent::GraphicsSceneMouseRelease:
       
    70             handleMouseReleaseEvent(static_cast<QGraphicsSceneMouseEvent *>(event));
       
    71             return true;
       
    72         default:
       
    73             break;
       
    74     }
       
    75 
       
    76     return false;
       
    77 }
       
    78 
    78 
    79 /*!
    79 /*!
    80     Return bounding rect
    80     Return bounding rect
    81 */
    81 */
    82 QRectF HsAnalogClockWidget::boundingRect() const
    82 QRectF HsAnalogClockWidget::boundingRect() const
   128     mMinuteHand = new HbIconItem(QLatin1String("qtg_graf_clock_day_min"), this);
   128     mMinuteHand = new HbIconItem(QLatin1String("qtg_graf_clock_day_min"), this);
   129     HbStyle::setItemName(mMinuteHand, QLatin1String("minute_hand"));
   129     HbStyle::setItemName(mMinuteHand, QLatin1String("minute_hand"));
   130 
   130 
   131     mSecondHand = new HbIconItem(QLatin1String("qtg_graf_clock_day_sec"), this);
   131     mSecondHand = new HbIconItem(QLatin1String("qtg_graf_clock_day_sec"), this);
   132     HbStyle::setItemName(mSecondHand, QLatin1String("second_hand"));
   132     HbStyle::setItemName(mSecondHand, QLatin1String("second_hand"));
   133 
       
   134     mTouchArea = new HbTouchArea(this);
       
   135     mTouchArea->installEventFilter(this);    
       
   136     HbStyle::setItemName(mTouchArea, QLatin1String("toucharea"));
       
   137 }
   133 }
   138 
   134 
   139 /*!
   135 /*!
   140     @copydoc HbWidget::updatePrimitives()
   136     @copydoc HbWidget::updatePrimitives()
   141  */
   137  */
   158     mMinuteHand->setRotation(m);
   154     mMinuteHand->setRotation(m);
   159 
   155 
   160     mSecondHand->setTransformOriginPoint(originPoint);
   156     mSecondHand->setTransformOriginPoint(originPoint);
   161     mSecondHand->setRotation(s);
   157     mSecondHand->setRotation(s);
   162 }
   158 }
   163 
       
   164 /*!
       
   165     \internal
       
   166 */
       
   167 void HsAnalogClockWidget::handleMouseReleaseEvent(QGraphicsSceneMouseEvent *event)
       
   168 {
       
   169     if (!contains(event->pos())) {
       
   170         return;
       
   171     }
       
   172 
       
   173     HbInstantFeedback::play(HSCONFIGURATION_GET(clockWidgetTapFeedbackEffect));
       
   174 
       
   175     emit clockTapped();
       
   176 }