clock/clockui/clockwidget/clockwidgetimpl/src/clockwidget.cpp
changeset 45 b6db4fd4947b
child 57 bb2d3e476f29
equal deleted inserted replaced
23:fd30d51f876b 45:b6db4fd4947b
       
     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:  Clockwidget
       
    15 *
       
    16 */
       
    17 
       
    18 // System includes
       
    19 #include <QGraphicsLinearLayout>
       
    20 
       
    21 // User includes
       
    22 #include "clockwidget.h"
       
    23 #include "analogclockwidget.h"
       
    24 #include "digitalclockwidget.h"
       
    25 
       
    26 /*!
       
    27     \class ClockWidget
       
    28 
       
    29     This is the generic wrapper for the clockwidget which manages analog and ditial clockwidgets.
       
    30  */
       
    31 
       
    32 /*!
       
    33     Constructor.
       
    34  */
       
    35 ClockWidget::ClockWidget(QGraphicsItem *parent, Qt::WindowFlags flags)
       
    36     : HbWidget(parent, flags),
       
    37       mClockType(ClockTypeDigital)
       
    38 {    
       
    39     loadClockWidget();
       
    40 }
       
    41 
       
    42 /*!
       
    43     Destructor.
       
    44 */
       
    45 ClockWidget::~ClockWidget()
       
    46 {    
       
    47     
       
    48 }
       
    49 
       
    50 /*!
       
    51     Returns the clock type.
       
    52 */
       
    53 ClockWidget::ClockType ClockWidget::clockType() const
       
    54 {
       
    55     return mClockType;
       
    56 }
       
    57   
       
    58 /*!
       
    59     Sets the clock type;
       
    60 */
       
    61 void ClockWidget::setClockType(const ClockType &type)
       
    62 {
       
    63     if (type == ClockTypeAnalog) {
       
    64         if(type != mClockType){
       
    65 	        mClockType = ClockTypeAnalog;
       
    66 	        updateClockWidget();
       
    67         }
       
    68     } else {
       
    69         if(type != mClockType){
       
    70             mClockType = ClockTypeDigital;
       
    71             updateClockWidget();
       
    72         }      
       
    73     }
       
    74 }
       
    75 
       
    76 /*!
       
    77     Updates the clock time with every second
       
    78 */
       
    79 void ClockWidget::updateTime()
       
    80 {
       
    81     if (mClockType == ClockTypeAnalog) {  
       
    82         mAnalogClock->tick();    
       
    83     } else {
       
    84     	mDigitalClock->updatePrimitives();
       
    85     }
       
    86 }
       
    87 
       
    88 /*!
       
    89     Constructs the clockwidget based upon its type.
       
    90 */
       
    91 void ClockWidget::loadClockWidget()
       
    92 {
       
    93     mLayout = new QGraphicsLinearLayout(Qt::Vertical);
       
    94     mLayout->setContentsMargins(0,0,0,0); 
       
    95 
       
    96     if (mClockType == ClockTypeAnalog) {
       
    97 	    mAnalogClock = new AnalogClockWidget(this);        
       
    98 	    mLayout->addItem(mAnalogClock);
       
    99     } else {
       
   100 	    bool useAmPm = false;
       
   101 	    mDigitalClock = new DigitalClockWidget(useAmPm, this);
       
   102 	    mLayout->addItem(mDigitalClock);
       
   103     }
       
   104     setLayout(mLayout);  
       
   105 }
       
   106 
       
   107 /*!
       
   108     Constructs the clockwidget based upon its type.
       
   109 */
       
   110 void ClockWidget::updateClockWidget()
       
   111 {
       
   112     if (mClockType == ClockTypeAnalog) {        
       
   113         mLayout->removeItem(mDigitalClock);
       
   114         delete mDigitalClock;
       
   115         if (!mAnalogClock) {
       
   116         	mAnalogClock = new AnalogClockWidget(this);
       
   117         }
       
   118         mLayout->addItem(mAnalogClock);
       
   119     } else {
       
   120         mLayout->removeItem(mAnalogClock);
       
   121         delete mAnalogClock;
       
   122         if(!mDigitalClock){
       
   123         bool useAmPm = false; // find out this fronm the settings utility
       
   124         mDigitalClock = new DigitalClockWidget(useAmPm, this);
       
   125     }
       
   126     mLayout->addItem(mDigitalClock);
       
   127     }           
       
   128 }
       
   129 
       
   130 ClockWidget::TimeFormat ClockWidget::timeFormat() const
       
   131 {
       
   132     return mTimeFormat;
       
   133 }
       
   134 
       
   135 void ClockWidget::setTimeFormat(const TimeFormat &timeFormat)
       
   136 {
       
   137     if(mDigitalClock){
       
   138 	    mTimeFormat = timeFormat;
       
   139 		if (timeFormat == ClockWidget::TimeFormat12Hrs) {
       
   140 			mDigitalClock->setAmPm(true);
       
   141 		} else {
       
   142 			mDigitalClock->setAmPm(false);
       
   143 		}
       
   144     }
       
   145 }
       
   146 // End of file  --Don't remove this.