screensaverapp/screensaverproviders/snsrbigclockscreensaverprovider/src/snsrdigitalclockcontainer.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:  Container for digital clock.
       
    15 *
       
    16 */
       
    17 
       
    18 #include "snsrdigitalclockcontainer.h"
       
    19 
       
    20 #include <QDebug>
       
    21 #include <QTime>
       
    22 #include <QGraphicsLinearLayout>
       
    23 
       
    24 #include <hblabel.h>
       
    25 #include <hbextendedlocale.h>
       
    26 
       
    27 /*!
       
    28     \class SnsrDigitalClockContainer
       
    29     \ingroup group_snsrbigclockscreensaverprovider
       
    30     \brief Container used for preparing layout for digital clock.
       
    31  */
       
    32 
       
    33 const char *gDigitalLayoutDocml = ":/xml/snsrbigclockscreensaverdigital.docml";
       
    34 extern const char *gPortraitSectionName;
       
    35 extern const char *gLandscapeSectionName;
       
    36 
       
    37 extern const char *gMainViewName;
       
    38 
       
    39 const char *gTimeLabelName = "timeLabel";
       
    40 const char *gAmPmLabelName = "amPmLabel";
       
    41 extern const char *gDateLabelName;
       
    42 
       
    43 extern const char *gDateFormatVerticalStr;
       
    44 extern const char *gDateFormatHorizontalStr;
       
    45 
       
    46 const char *gTimeFormatStr = "%:0%J%:1%T%:3";
       
    47 const char *gAmPmFormatStr = "%B";
       
    48 
       
    49 /*!
       
    50     Constructs a new SnsrDigitalClockContainer.
       
    51  */
       
    52 SnsrDigitalClockContainer::SnsrDigitalClockContainer() :
       
    53     SnsrBigClockContainer(),
       
    54     mTimeLabel(0),
       
    55     mAmPmLabel(0),
       
    56     mDateLabel(0)
       
    57 {
       
    58     SCREENSAVER_TEST_FUNC_ENTRY("SnsrDigitalClockContainer::SnsrDigitalClockContainer")
       
    59 
       
    60     bool ok(true);
       
    61 
       
    62     // load digital clock
       
    63     qDebug() << gDigitalLayoutDocml;
       
    64     mDocumentObjects = mDocumentLoader.load(gDigitalLayoutDocml, &ok);
       
    65     Q_ASSERT_X(ok, gDigitalLayoutDocml, "Invalid DocML file.");
       
    66 
       
    67     if (ok) {
       
    68         mMainContainer = mDocumentLoader.findWidget(gMainViewName);
       
    69         mDateLabel = qobject_cast<HbLabel *>(
       
    70                 mDocumentLoader.findWidget(gDateLabelName));
       
    71         mTimeLabel = qobject_cast<HbLabel *>(
       
    72                 mDocumentLoader.findWidget(gTimeLabelName));
       
    73         mAmPmLabel = qobject_cast<HbLabel *>(
       
    74                 mDocumentLoader.findWidget(gAmPmLabelName));
       
    75         Q_ASSERT_X(
       
    76                 mMainContainer && mDateLabel && mTimeLabel && mAmPmLabel,
       
    77                 gDigitalLayoutDocml, "Objects not found in DocML file."
       
    78                 );
       
    79 
       
    80         mBackgroundContainerLayout->addItem(mMainContainer);
       
    81     }
       
    82 
       
    83     SCREENSAVER_TEST_FUNC_EXIT("SnsrDigitalClockContainer::SnsrDigitalClockContainer")
       
    84 }
       
    85 
       
    86 /*!
       
    87     Destructs the class.
       
    88  */
       
    89 SnsrDigitalClockContainer::~SnsrDigitalClockContainer()
       
    90 {
       
    91     //mTimeLabel, mAmPmLabel, mDateLabel - deleted by the parent
       
    92 }
       
    93 
       
    94 /*!
       
    95     Updates displayed time and date.
       
    96  */
       
    97 void SnsrDigitalClockContainer::update()
       
    98 {
       
    99     SCREENSAVER_TEST_FUNC_ENTRY("SnsrDigitalClockContainer::update")
       
   100 
       
   101     // time
       
   102     mTimeLabel->setPlainText(
       
   103         HbExtendedLocale().format(QTime::currentTime(), gTimeFormatStr)
       
   104         );
       
   105     mAmPmLabel->setPlainText(
       
   106         HbExtendedLocale().format(QTime::currentTime(), gAmPmFormatStr)
       
   107         );
       
   108 
       
   109     // date
       
   110     if (mCurrentOrientation == Qt::Vertical) {
       
   111         mDateLabel->setPlainText(
       
   112             HbExtendedLocale().format(QDate::currentDate(), gDateFormatVerticalStr)
       
   113             );
       
   114     } else {
       
   115         mDateLabel->setPlainText(
       
   116             HbExtendedLocale().format(QDate::currentDate(), gDateFormatHorizontalStr)
       
   117             );
       
   118     }
       
   119 
       
   120     SCREENSAVER_TEST_FUNC_EXIT("SnsrDigitalClockContainer::update")
       
   121 }
       
   122 
       
   123 /*!
       
   124     Changes screensaver layout basing on orientation changes.
       
   125     \param orientation Current orientation.
       
   126  */
       
   127 void SnsrDigitalClockContainer::changeLayout(Qt::Orientation orientation)
       
   128 {
       
   129     SCREENSAVER_TEST_FUNC_ENTRY("SnsrDigitalClockContainer::changeLayout")
       
   130 
       
   131     if (mCurrentOrientation != orientation) {
       
   132         mCurrentOrientation = orientation;
       
   133         bool ok;
       
   134         // hide controls to avoid screen flickering
       
   135         mMainContainer->hide();
       
   136 
       
   137         QString sectionToLoad("");
       
   138         if (mCurrentOrientation == Qt::Vertical) {
       
   139             sectionToLoad = gPortraitSectionName;
       
   140         } else {
       
   141             sectionToLoad = gLandscapeSectionName;
       
   142         }
       
   143         qDebug() << "loading: " << gDigitalLayoutDocml << ", section: " << sectionToLoad;
       
   144         mDocumentLoader.load(gDigitalLayoutDocml, sectionToLoad, &ok);
       
   145         // view is rebuilt and ready to show
       
   146         mMainContainer->show();
       
   147         Q_ASSERT_X(ok, gDigitalLayoutDocml, "Invalid section in DocML file.");
       
   148     }
       
   149     // update anyway - this is needed in situations when screensaver goes to
       
   150     // foreground but layout change did not occur
       
   151     update();
       
   152 
       
   153     SCREENSAVER_TEST_FUNC_EXIT("SnsrDigitalClockContainer::changeLayout")
       
   154 }