screensaverapp/screensaverproviders/snsrbigclockscreensaverprovider/snsrclockwidgets/src/snsroledclockwidget.cpp
changeset 39 4e8ebe173323
parent 36 cdae8c6c3876
child 42 517f4fb5ec74
child 46 23b5d6a29cce
equal deleted inserted replaced
36:cdae8c6c3876 39:4e8ebe173323
     1 /*
       
     2 * Copyright (c) 2009 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: Oled Clock Widget.
       
    15 *
       
    16 */
       
    17 
       
    18 #include "snsroledclockwidget.h"
       
    19 
       
    20 #include <QGraphicsSvgItem>
       
    21 #include <QTime>
       
    22 
       
    23 #include "snsrstyleoptionoledanalogclock.h"
       
    24 
       
    25 #ifdef Q_OS_SYMBIAN
       
    26 const char *gOledClockPluginPath("../../snsrresources/plugins/snsrstyleplugins/snsroledclockstyleplugin.dll");
       
    27 #else
       
    28 const char *gOledClockPluginPath("snsrresources/plugins/snsrstyleplugins/snsroledclockstyleplugin.dll");
       
    29 #endif
       
    30 
       
    31 /*!
       
    32     \class SnsrOledClockWidget
       
    33     \ingroup group_snsrbigclockscreensaverprovider
       
    34     \brief Screensaver oled clock widget.
       
    35  */
       
    36 
       
    37 /*!
       
    38     Constructs a new SnsrOledClockWidget.
       
    39     \param stylePluginPath Style plugin path.
       
    40     \param parent Parent object.
       
    41  */
       
    42 SnsrOledClockWidget::SnsrOledClockWidget(QGraphicsItem* parent):
       
    43     HbWidget(parent), mStylePluginName(gOledClockPluginPath),
       
    44     mClockBackground(0), mClockHourHand(0), mClockMinuteHand(0),
       
    45     mClockDateFrame(0), mClockDateLabel(0)
       
    46 {
       
    47     setPluginBaseId(style()->registerPlugin(mStylePluginName));
       
    48 
       
    49     createPrimitives();
       
    50     updatePrimitives();
       
    51 }
       
    52 
       
    53 /*!
       
    54     Destructs the class.
       
    55  */
       
    56 SnsrOledClockWidget::~SnsrOledClockWidget()
       
    57 {
       
    58     delete mClockBackground;
       
    59     delete mClockHourHand;
       
    60     delete mClockMinuteHand;
       
    61     delete mClockDateFrame;
       
    62     delete mClockDateLabel;
       
    63 
       
    64     style()->unregisterPlugin(mStylePluginName);
       
    65 }
       
    66 
       
    67 /*!
       
    68     @copydoc HbWidget::resizeEvent()
       
    69  */
       
    70 void SnsrOledClockWidget::resizeEvent(QGraphicsSceneResizeEvent *event)
       
    71 {
       
    72     QGraphicsWidget::resizeEvent(event);
       
    73     updatePrimitives();
       
    74 }
       
    75 
       
    76 /*!
       
    77     Creates all widget primitives.
       
    78  */
       
    79 void SnsrOledClockWidget::createPrimitives()
       
    80 {
       
    81     if (pluginBaseId()==-1) {
       
    82         return;
       
    83     }
       
    84     if (!mClockBackground) {
       
    85         mClockBackground = style()->createPrimitive((HbStyle::Primitive)(pluginBaseId()), this);
       
    86     }
       
    87     if (!mClockHourHand) {
       
    88         mClockHourHand = style()->createPrimitive((HbStyle::Primitive)(pluginBaseId()+SnsrStyleOptionOledAnalogClock::HourHandItemIndex), this);
       
    89     }
       
    90     if (!mClockMinuteHand) {
       
    91         mClockMinuteHand = style()->createPrimitive((HbStyle::Primitive)(pluginBaseId()+SnsrStyleOptionOledAnalogClock::MinuteHandItemIndex), this);
       
    92     }
       
    93     if (!mClockDateFrame) {
       
    94         mClockDateFrame = style()->createPrimitive((HbStyle::Primitive)(pluginBaseId()+SnsrStyleOptionOledAnalogClock::DateFrameItemIndex), this);
       
    95     }
       
    96     if (!mClockDateLabel) {
       
    97         mClockDateLabel = style()->createPrimitive((HbStyle::Primitive)(pluginBaseId()+SnsrStyleOptionOledAnalogClock::DateLabelItemIndex), this);
       
    98     }
       
    99 }
       
   100 
       
   101 /*!
       
   102     @copydoc HbWidget::updatePrimitives()
       
   103  */
       
   104 void SnsrOledClockWidget::updatePrimitives()
       
   105 {
       
   106     if (pluginBaseId()==-1) {
       
   107         return;
       
   108     }
       
   109 
       
   110     // Calculate angles for clock hands.
       
   111     QTime time = QTime::currentTime();
       
   112     qreal s = 6 * time.second();
       
   113     qreal m = 6 * (time.minute() + s/360);
       
   114     qreal h = 30 * ((time.hour() % 12) + m/360);
       
   115 
       
   116     SnsrStyleOptionOledAnalogClock option;
       
   117     initStyleOption(&option);
       
   118     option.mM = m;
       
   119     option.mH = h;
       
   120 
       
   121     QDate currentdate = QDate::currentDate();
       
   122     option.mShortDate = QDate::shortDayName(currentdate.dayOfWeek())+" "+QString::number(currentdate.day());
       
   123 
       
   124     if (mClockBackground) {
       
   125         style()->updatePrimitive(mClockBackground, (HbStyle::Primitive)(pluginBaseId()), &option);
       
   126     }
       
   127     if (mClockHourHand) {
       
   128         style()->updatePrimitive(mClockHourHand, (HbStyle::Primitive)(pluginBaseId()+SnsrStyleOptionOledAnalogClock::HourHandItemIndex), &option);
       
   129     }
       
   130     if (mClockMinuteHand) {
       
   131         style()->updatePrimitive(mClockMinuteHand, (HbStyle::Primitive)(pluginBaseId()+SnsrStyleOptionOledAnalogClock::MinuteHandItemIndex), &option);
       
   132     }
       
   133     if (mClockDateFrame) {
       
   134         style()->updatePrimitive(mClockDateFrame, (HbStyle::Primitive)(pluginBaseId()+SnsrStyleOptionOledAnalogClock::DateFrameItemIndex), &option);
       
   135     }
       
   136     if (mClockDateLabel) {
       
   137         style()->updatePrimitive(mClockDateLabel, (HbStyle::Primitive)(pluginBaseId()+SnsrStyleOptionOledAnalogClock::DateLabelItemIndex), &option);
       
   138     }
       
   139 }
       
   140 
       
   141 /*!
       
   142     Updates primitives when time change.
       
   143  */
       
   144 void SnsrOledClockWidget::tick()
       
   145 {
       
   146     updatePrimitives();
       
   147 }