screensaver/snsrplugins/snsrbigclockscreensaverplugin/src/snsranalogclockcontainer.cpp
changeset 97 66b5fe3c07fd
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 analog clock.
       
    15 *
       
    16 */
       
    17 
       
    18 #include "snsranalogclockcontainer.h"
       
    19 
       
    20 #include <QDebug>
       
    21 #include <QTime>
       
    22 #include <QGraphicsLinearLayout>
       
    23 
       
    24 #include <HbExtendedLocale>
       
    25 #include <HbMainWindow>
       
    26 
       
    27 #include "snsranalogclockwidget.h"
       
    28 #include "snsrindicatorwidget.h"
       
    29 #include "snsrswipewidget.h"
       
    30 #include "snsrlabel.h"
       
    31 
       
    32 /*!
       
    33     \class SnsrAnalogClockContainer
       
    34     \ingroup group_snsrbigclockscreensaverplugin
       
    35     \brief Container used for preparing layout for analog clock.
       
    36  */
       
    37 
       
    38 const char *gAnalogLayoutDocml = ":/xml/snsrbigclockscreensaveranalog.docml";
       
    39 const char *gSwipeAnalogLayoutDocml = ":/xml/snsrbigclockscreensaveranalogswipe.docml";
       
    40 
       
    41 
       
    42 const char *gPortraitSectionName = "portrait";
       
    43 const char *gLandscapeSectionName = "landscape";
       
    44 
       
    45 const char *gMainViewName = "view";
       
    46 const char *gMainContainerName = "mainContainer";
       
    47 const char *gClockContainerName = "clockContainer";
       
    48 
       
    49 const char *gDateLabelName = "dateLabel";
       
    50 const char *gAnalogClockWidgetName = "analogClockWidget";
       
    51 const char *gIndicatorWidgetName = "indicatorWidget";
       
    52 
       
    53 const char *gSwipeWidgetName = "swipeWidget";
       
    54 
       
    55 const char *gDateFormatStr = r_qtn_date_usual_with_zero; //"%E%,% %*D%*N%/0%4%/1%5";
       
    56 
       
    57 
       
    58 /*!
       
    59     Constructs a new SnsrAnalogClockContainer.
       
    60  */
       
    61 SnsrAnalogClockContainer::SnsrAnalogClockContainer() :
       
    62     SnsrBigClockContainer(),
       
    63     mDateLabel(0),
       
    64     mAnalogClockWidget(0),
       
    65     mSwipeWidget(0)
       
    66 {
       
    67     SCREENSAVER_TEST_FUNC_ENTRY("SnsrAnalogClockContainer::SnsrAnalogClockContainer")
       
    68     SCREENSAVER_TEST_FUNC_EXIT("SnsrAnalogClockContainer::SnsrAnalogClockContainer")
       
    69 }
       
    70 
       
    71 /*!
       
    72     Destructs the class.
       
    73  */
       
    74 SnsrAnalogClockContainer::~SnsrAnalogClockContainer()
       
    75 {
       
    76     resetIndicatorConnections();
       
    77     //mDateLabel, mAnalogClockWidget - deleted by the parent
       
    78 }
       
    79 
       
    80 /*!
       
    81     Updates displayed time and date.
       
    82  */
       
    83 void SnsrAnalogClockContainer::update()
       
    84 {
       
    85     SCREENSAVER_TEST_FUNC_ENTRY("SnsrAnalogClockContainer::update")
       
    86 
       
    87     // time
       
    88     mAnalogClockWidget->tick();
       
    89 
       
    90     // date
       
    91     mDateLabel->setPlainText(
       
    92         HbExtendedLocale().format(QDate::currentDate(), gDateFormatStr)
       
    93         );
       
    94 
       
    95     if (mSwipeWidget) {
       
    96         mSwipeWidget->setCurrentOrientation(mCurrentOrientation);
       
    97     }
       
    98     
       
    99     SCREENSAVER_TEST_FUNC_EXIT("SnsrAnalogClockContainer::update")
       
   100 }
       
   101 
       
   102 /*!
       
   103     @copydoc SnsrBigClockContainer::updateIntervalInMilliseconds()
       
   104  */
       
   105 int SnsrAnalogClockContainer::updateIntervalInMilliseconds()
       
   106 {
       
   107     return 1000;
       
   108 }
       
   109 
       
   110 /*!
       
   111     @copydoc SnsrBigClockContainer::loadWidgets()
       
   112  */
       
   113 void SnsrAnalogClockContainer::loadWidgets()
       
   114 {
       
   115     //if swipe is used we load the docml file containing it
       
   116     if ( swipeToUnlockSupported() ) {
       
   117         loadWidgets(gSwipeAnalogLayoutDocml);
       
   118         Q_ASSERT_X( mSwipeWidget, gSwipeAnalogLayoutDocml, "Swipe widget not found in DocML file.");
       
   119         connect( mSwipeWidget, SIGNAL(swipeDownDetected()), SIGNAL(unlockRequested()) );
       
   120     }
       
   121     else {
       
   122         loadWidgets(gAnalogLayoutDocml);
       
   123     }
       
   124 }
       
   125 
       
   126 /*!
       
   127     Instantiate widgets from the given docml file
       
   128  */
       
   129 void SnsrAnalogClockContainer::loadWidgets(const char* docmlName)
       
   130 {
       
   131     bool ok(true);
       
   132 
       
   133     // reset widget pointers, any previous widgets are already deleted by now
       
   134     mMainView = 0;
       
   135     mDateLabel = 0;
       
   136     mAnalogClockWidget = 0;
       
   137     mIndicatorWidget = 0;
       
   138     mSwipeWidget = 0;
       
   139     // load widgets from docml
       
   140     qDebug() << docmlName;
       
   141     mDocumentObjects = mDocumentLoader.load(docmlName, &ok);
       
   142     Q_ASSERT_X(ok, docmlName, "Invalid DocML file.");
       
   143     if (ok) {
       
   144         mMainView = mDocumentLoader.findWidget(gMainViewName);
       
   145         mDateLabel = qobject_cast<SnsrLabel *>(
       
   146             mDocumentLoader.findWidget(gDateLabelName));
       
   147         mAnalogClockWidget = qobject_cast<SnsrAnalogClockWidget *>(
       
   148             mDocumentLoader.findWidget(gAnalogClockWidgetName));
       
   149         mIndicatorWidget = qobject_cast<SnsrIndicatorWidget *>(
       
   150             mDocumentLoader.findWidget(gIndicatorWidgetName));
       
   151         mSwipeWidget = qobject_cast<SnsrSwipeWidget *>(
       
   152             mDocumentLoader.findWidget(gSwipeWidgetName));
       
   153         
       
   154         Q_ASSERT_X(
       
   155             mMainView && mDateLabel && mAnalogClockWidget &&
       
   156             mIndicatorWidget,
       
   157             docmlName, "Objects not found in DocML file."
       
   158             );
       
   159         
       
   160         // In case of landscape layout, read also the landscape delta section
       
   161         if ( mCurrentOrientation == Qt::Horizontal ) {
       
   162             qDebug() << "loading: " << docmlName << ", section: " << gLandscapeSectionName;
       
   163             mDocumentLoader.load(docmlName, gLandscapeSectionName, &ok);
       
   164             Q_ASSERT_X(ok, docmlName, "Invalid section in DocML file.");
       
   165         }
       
   166    
       
   167     mIndicatorWidget->setIconColorType(SnsrIndicatorWidget::ThemedColorForActiveMode);
       
   168     connectIndicatorWidgetToModel();
       
   169         
       
   170     mDateLabel->setTextColorType(SnsrLabel::ThemedColorForActiveMode);
       
   171     
       
   172     mBackgroundContainerLayout->addItem(mMainView);
       
   173     }
       
   174 }
       
   175