screensaver/screensaverplugins/snsrbigclockscreensaverplugin/src/snsrdigitalclockcontainer.cpp
changeset 97 66b5fe3c07fd
parent 95 32e56106abf2
child 98 e6f74eb7f69f
equal deleted inserted replaced
95:32e56106abf2 97:66b5fe3c07fd
     1 /*
       
     2 * Copyright (c) 2009-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:  Container for digital clock.
       
    15 *
       
    16 */
       
    17 
       
    18 #include "snsrdigitalclockcontainer.h"
       
    19 
       
    20 #include <QDebug>
       
    21 #include <QTime>
       
    22 #include <QGraphicsLinearLayout>
       
    23 
       
    24 #include <HbExtendedLocale>
       
    25 #include <HbMainWindow>
       
    26 
       
    27 #include "snsrswipewidget.h"
       
    28 #include "snsrindicatorwidget.h"
       
    29 #include "snsrlabel.h"
       
    30 
       
    31 /*!
       
    32     \class SnsrDigitalClockContainer
       
    33     \ingroup group_snsrbigclockscreensaverplugin
       
    34     \brief Container used for preparing layout for digital clock.
       
    35  */
       
    36 
       
    37 const char *gDigitalLayoutDocml = ":/xml/snsrbigclockscreensaverdigital.docml";
       
    38 extern const char *gPortraitSectionName;
       
    39 extern const char *gLandscapeSectionName;
       
    40 
       
    41 extern const char *gMainViewName;
       
    42 
       
    43 const char *gTimeLabelName = "timeLabel";
       
    44 const char *gAmPmLabelName = "amPmLabel";
       
    45 extern const char *gDateLabelName;
       
    46 
       
    47 extern const char *gDateFormatVerticalStr;
       
    48 extern const char *gDateFormatHorizontalStr;
       
    49 
       
    50 // This is same as r_qtn_time_usual_with_zero defined in
       
    51 // hbi18ndef.h expect am/pm place holders are removed.
       
    52 const char *gTimeFormatStr = "%:0%J%:1%T%:3";
       
    53 const char *gAmPmFormatStr = "%B";
       
    54 
       
    55 extern const char *gIndicatorWidgetName;
       
    56 extern const char *gSwipeWidgetName;
       
    57 
       
    58 
       
    59 /*!
       
    60     Constructs a new SnsrDigitalClockContainer.
       
    61  */
       
    62 SnsrDigitalClockContainer::SnsrDigitalClockContainer() :
       
    63     SnsrBigClockContainer(),
       
    64     mTimeLabel(0),
       
    65     mAmPmLabel(0),
       
    66     mDateLabel(0)/*,
       
    67     mSwipeWidget(0)*/
       
    68 {
       
    69     SCREENSAVER_TEST_FUNC_ENTRY("SnsrDigitalClockContainer::SnsrDigitalClockContainer")
       
    70     SCREENSAVER_TEST_FUNC_EXIT("SnsrDigitalClockContainer::SnsrDigitalClockContainer")
       
    71 }
       
    72 
       
    73 /*!
       
    74     Destructs the class.
       
    75  */
       
    76 SnsrDigitalClockContainer::~SnsrDigitalClockContainer()
       
    77 {
       
    78     resetIndicatorConnections();
       
    79     //mTimeLabel, mAmPmLabel, mDateLabel - deleted by the parent
       
    80 }
       
    81 
       
    82 /*!
       
    83     Updates displayed time and date.
       
    84  */
       
    85 void SnsrDigitalClockContainer::update()
       
    86 {
       
    87     SCREENSAVER_TEST_FUNC_ENTRY("SnsrDigitalClockContainer::update")
       
    88 
       
    89     // time
       
    90     // Even though the format string (hh:mm) contain the leading zero, it's
       
    91     // removed always when clock type is 12h -> h:mm. 
       
    92    
       
    93     // TODO: within this method call, you find a comment in code that
       
    94     // it's intentional to remove leading zero always with 12h type clock.
       
    95     // However it seems to be recommended to use hbExtendedLocale to get
       
    96     // proper time formatting for all locales and settings..
       
    97     mTimeLabel->setPlainText(
       
    98         HbExtendedLocale().format(QTime::currentTime(), gTimeFormatStr)
       
    99         );
       
   100     
       
   101     // if clock type is 24h, this will return an empty string.
       
   102     mAmPmLabel->setPlainText(
       
   103         HbExtendedLocale().format(QTime::currentTime(), gAmPmFormatStr)
       
   104         );
       
   105 
       
   106     // date
       
   107     const char *dateFormat = (mCurrentOrientation == Qt::Vertical) ?
       
   108         gDateFormatVerticalStr : gDateFormatHorizontalStr;
       
   109     QString dateText = HbExtendedLocale().format( QDate::currentDate(), dateFormat );
       
   110     mDateLabel->setPlainText( dateText );
       
   111 
       
   112     SCREENSAVER_TEST_FUNC_EXIT("SnsrDigitalClockContainer::update")
       
   113 }
       
   114 
       
   115 /*!
       
   116     @copydoc SnsrBigClockContainer::updateIntervalInMilliseconds()
       
   117  */
       
   118 int SnsrDigitalClockContainer::updateIntervalInMilliseconds()
       
   119 {
       
   120     return 1000;
       
   121 }
       
   122 
       
   123 /*!
       
   124     @copydoc SnsrBigClockContainer::loadWidgets()
       
   125  */
       
   126 void SnsrDigitalClockContainer::loadWidgets()
       
   127 {
       
   128     // reset widget pointers, any previous widgets are already deleted by now
       
   129     mMainView = 0;
       
   130     mDateLabel = 0;
       
   131     mTimeLabel = 0;
       
   132     mAmPmLabel = 0;
       
   133     mIndicatorWidget = 0;
       
   134     
       
   135     // load widgets from docml
       
   136     bool ok(false);
       
   137     qDebug() << gDigitalLayoutDocml;
       
   138     mDocumentObjects = mDocumentLoader.load(gDigitalLayoutDocml, &ok);
       
   139     Q_ASSERT_X(ok, gDigitalLayoutDocml, "Invalid DocML file.");
       
   140 
       
   141     if (ok) {
       
   142         mMainView = mDocumentLoader.findWidget(gMainViewName);
       
   143         mDateLabel = qobject_cast<SnsrLabel *>(
       
   144                 mDocumentLoader.findWidget(gDateLabelName));
       
   145         mTimeLabel = qobject_cast<SnsrLabel *>(
       
   146                 mDocumentLoader.findWidget(gTimeLabelName));
       
   147         mAmPmLabel = qobject_cast<SnsrLabel *>(
       
   148                 mDocumentLoader.findWidget(gAmPmLabelName));
       
   149         mIndicatorWidget = qobject_cast<SnsrIndicatorWidget *>(
       
   150                 mDocumentLoader.findWidget(gIndicatorWidgetName));
       
   151         // implement swipewidget later on
       
   152         /*mSwipeWidget = qobject_cast<SnsrSwipeWidget *>(
       
   153                 mDocumentLoader.findWidget(gSwipeWidgetName));*/
       
   154 
       
   155         Q_ASSERT_X(
       
   156                 mMainView && mDateLabel && mTimeLabel && mAmPmLabel &&
       
   157                 mIndicatorWidget /*&& mSwipeWidget*/,
       
   158                 gDigitalLayoutDocml, "Objects not found in DocML file."
       
   159                 );
       
   160 
       
   161         // In case of landscape layout, read also the landscape delta section
       
   162         if ( mCurrentOrientation == Qt::Horizontal ) {
       
   163             qDebug() << "loading: " << gDigitalLayoutDocml << ", section: " << gLandscapeSectionName;
       
   164             mDocumentLoader.load(gDigitalLayoutDocml, gLandscapeSectionName, &ok);
       
   165             Q_ASSERT_X(ok, gDigitalLayoutDocml, "Invalid section in DocML file.");
       
   166         }
       
   167 
       
   168         mIndicatorWidget->setLayoutType(SnsrIndicatorWidget::IndicatorsCentered);
       
   169         mIndicatorWidget->setPowerSaveModeColor(false);
       
   170         initIndicatorWidget();
       
   171         
       
   172         mBackgroundContainerLayout->addItem(mMainView);
       
   173 
       
   174         //connect( mSwipeWidget, SIGNAL(swipeDownDetected()), SIGNAL(unlockRequested()) );
       
   175         //mSwipeWidget->start();
       
   176     }
       
   177 }
       
   178