screensaver/screensaverplugins/snsrbigclockscreensaverplugin/src/snsranalogclockcontainer.cpp
changeset 62 341166945d65
child 69 87476091b3f5
equal deleted inserted replaced
57:2e2dc3d30ca8 62:341166945d65
       
     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 analog clock.
       
    15 *
       
    16 */
       
    17 
       
    18 #include "snsranalogclockcontainer.h"
       
    19 
       
    20 #include <QDebug>
       
    21 #include <QTime>
       
    22 #include <QGraphicsLinearLayout>
       
    23 
       
    24 #include <hblabel.h>
       
    25 #include <hbextendedlocale.h>
       
    26 
       
    27 #include "snsranalogclockwidget.h"
       
    28 #include "snsrindicatorwidget.h"
       
    29 #include "snsrswipewidget.h"
       
    30 
       
    31 /*!
       
    32     \class SnsrAnalogClockContainer
       
    33     \ingroup group_snsrbigclockscreensaverplugin
       
    34     \brief Container used for preparing layout for analog clock.
       
    35  */
       
    36 
       
    37 const char *gAnalogLayoutDocml = ":/xml/snsrbigclockscreensaveranalog.docml";
       
    38 
       
    39 const char *gPortraitSectionName = "portrait";
       
    40 const char *gLandscapeSectionName = "landscape";
       
    41 
       
    42 const char *gMainViewName = "view";
       
    43 const char *gMainContainerName = "mainContainer";
       
    44 const char *gClockContainerName = "clockContainer";
       
    45 
       
    46 const char *gDateLabelName = "dateLabel";
       
    47 const char *gAnalogClockWidgetName = "analogClockWidget";
       
    48 const char *gIndicatorWidgetName = "indicatorWidget";
       
    49 
       
    50 const char *gSwipeWidgetName = "swipeWidget";
       
    51 
       
    52 const char *gDateFormatVerticalStr = r_qtn_date_usual_with_zero; //"%E%,% %*D%*N%/0%4%/1%5";
       
    53 const char *gDateFormatHorizontalStr = r_qtn_date_usual_with_zero; //"%E%,% %*D%N%/0%4%/1%5";
       
    54 
       
    55 
       
    56 /*!
       
    57     Constructs a new SnsrAnalogClockContainer.
       
    58  */
       
    59 SnsrAnalogClockContainer::SnsrAnalogClockContainer() :
       
    60     SnsrBigClockContainer(),
       
    61     mDateLabel(0),
       
    62     mAnalogClockWidget(0)/*,
       
    63     mSwipeWidget(0)*/
       
    64     {
       
    65     SCREENSAVER_TEST_FUNC_ENTRY("SnsrAnalogClockContainer::SnsrAnalogClockContainer")
       
    66 
       
    67     bool ok(true);
       
    68 
       
    69     // load analog clock
       
    70     qDebug() << gAnalogLayoutDocml;
       
    71     mDocumentObjects = mDocumentLoader.load(gAnalogLayoutDocml, &ok);
       
    72     Q_ASSERT_X(ok, gAnalogLayoutDocml, "Invalid DocML file.");
       
    73     if (ok) {
       
    74         mMainView = mDocumentLoader.findWidget(gMainViewName);
       
    75         mDateLabel = qobject_cast<HbLabel *>(
       
    76             mDocumentLoader.findWidget(gDateLabelName));
       
    77         mAnalogClockWidget = qobject_cast<SnsrAnalogClockWidget *>(
       
    78             mDocumentLoader.findWidget(gAnalogClockWidgetName));
       
    79         mIndicatorWidget = qobject_cast<SnsrIndicatorWidget *>(
       
    80             mDocumentLoader.findWidget(gIndicatorWidgetName));
       
    81         //We don't implement swipe widget at this poin
       
    82         /*mSwipeWidget = qobject_cast<SnsrSwipeWidget *>(
       
    83             mDocumentLoader.findWidget(gSwipeWidgetName));*/
       
    84         
       
    85         Q_ASSERT_X(
       
    86                 mMainView && mDateLabel && mAnalogClockWidget &&
       
    87                 mIndicatorWidget /*&& mSwipeWidget*/,
       
    88                 gAnalogLayoutDocml, "Objects not found in DocML file."
       
    89                 );
       
    90         
       
    91         //connect( mSwipeWidget, SIGNAL(swipeDownDetected()), SIGNAL(unlockRequested()) );
       
    92 
       
    93         mIndicatorWidget->setLayoutType(SnsrIndicatorWidget::IndicatorsCentered);
       
    94         
       
    95         mBackgroundContainerLayout->addItem(mMainView);
       
    96  //       mSwipeWidget->start();
       
    97     }
       
    98 
       
    99     SCREENSAVER_TEST_FUNC_EXIT("SnsrAnalogClockContainer::SnsrAnalogClockContainer")
       
   100 }
       
   101 
       
   102 /*!
       
   103     Destructs the class.
       
   104  */
       
   105 SnsrAnalogClockContainer::~SnsrAnalogClockContainer()
       
   106 {
       
   107     //mDateLabel, mAnalogClockWidget - deleted by the parent
       
   108 }
       
   109 
       
   110 /*!
       
   111     Updates displayed time and date.
       
   112  */
       
   113 void SnsrAnalogClockContainer::update()
       
   114 {
       
   115     SCREENSAVER_TEST_FUNC_ENTRY("SnsrAnalogClockContainer::update")
       
   116 
       
   117     // time
       
   118     mAnalogClockWidget->tick();
       
   119 
       
   120     // date
       
   121     if (mCurrentOrientation == Qt::Vertical) {
       
   122         mDateLabel->setPlainText(
       
   123             HbExtendedLocale().format(QDate::currentDate(), gDateFormatVerticalStr)
       
   124         );
       
   125     } else {
       
   126         mDateLabel->setPlainText(
       
   127             HbExtendedLocale().format(QDate::currentDate(), gDateFormatHorizontalStr)
       
   128         );
       
   129     }
       
   130     
       
   131     SCREENSAVER_TEST_FUNC_EXIT("SnsrAnalogClockContainer::update")
       
   132 }
       
   133 
       
   134 /*!
       
   135     Changes screensaver layout basing on orientation changes.
       
   136     \param orientation Current orientation.
       
   137  */
       
   138 void SnsrAnalogClockContainer::changeLayout(Qt::Orientation orientation)
       
   139 {
       
   140     SCREENSAVER_TEST_FUNC_ENTRY("SnsrAnalogClockContainer::changeLayout")
       
   141 
       
   142     bool ok(false);
       
   143     if (mCurrentOrientation != orientation) {
       
   144         mCurrentOrientation = orientation;
       
   145 
       
   146         // hide controls to avoid screen flickering
       
   147         mMainView->hide();
       
   148 
       
   149         QString sectionToLoad("");
       
   150         if (mCurrentOrientation == Qt::Horizontal) {
       
   151             sectionToLoad = gLandscapeSectionName;
       
   152         }
       
   153         qDebug() << "loading: " << gAnalogLayoutDocml << ", section: " << sectionToLoad;
       
   154         mDocumentLoader.load(gAnalogLayoutDocml, sectionToLoad, &ok);
       
   155         // view is rebuilt and ready to show
       
   156         update();
       
   157         mMainView->show();
       
   158         Q_ASSERT_X(ok, gAnalogLayoutDocml, "Invalid section in DocML file.");
       
   159     }
       
   160     // update anyway - this is needed in situations when screensaver goes to
       
   161     // foreground but layout change did not occur
       
   162     if (!ok) {
       
   163         update();
       
   164     }
       
   165 
       
   166     SCREENSAVER_TEST_FUNC_EXIT("SnsrAnalogClockContainer::changeLayout")
       
   167 }
       
   168 
       
   169 int SnsrAnalogClockContainer::updateIntervalInMilliseconds()
       
   170 {
       
   171     return 1000;
       
   172 }
       
   173