screensaverapp/screensaverproviders/snsrbigclockscreensaverprovider/src/snsroledanalogclockcontainer.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 oled analog clock.
       
    15 *
       
    16 */
       
    17 
       
    18 #include "snsroledanalogclockcontainer.h"
       
    19 
       
    20 #include <QDebug>
       
    21 #include <QGraphicsLinearLayout>
       
    22 
       
    23 #include <hblabel.h>
       
    24 
       
    25 #include "snsroledclockwidget.h"
       
    26 
       
    27 /*!
       
    28     \class SnsrOledAnalogClockContainer
       
    29     \ingroup group_snsrbigclockscreensaverprovider
       
    30     \brief Container used for preparing layout for oled analog clock.
       
    31  */
       
    32 
       
    33 const char *gOledAnalogLayoutDocml = ":/xml/snsrbigclockscreensaveroledanalog.docml";
       
    34 extern const char *gPortraitSectionName;
       
    35 extern const char *gLandscapeSectionName;
       
    36 
       
    37 extern const char *gMainViewName;
       
    38 
       
    39 const char *gOledAnalogClockWidgetName = "oledAnalogClockWidget";
       
    40 
       
    41 /*!
       
    42     Constructs a new SnsrOledAnalogClockContainer.
       
    43  */
       
    44 SnsrOledAnalogClockContainer::SnsrOledAnalogClockContainer() :
       
    45     SnsrBigClockContainer(),
       
    46     mOledClockWidget(0)
       
    47 {
       
    48     SCREENSAVER_TEST_FUNC_ENTRY("SnsrOledAnalogClockContainer::SnsrOledAnalogClockContainer")
       
    49 
       
    50     bool ok(true);
       
    51 
       
    52     // load oled analog clock
       
    53     qDebug() << gOledAnalogLayoutDocml;
       
    54     mDocumentObjects = mDocumentLoader.load(gOledAnalogLayoutDocml, &ok);
       
    55     Q_ASSERT_X(ok, gOledAnalogLayoutDocml, "Invalid DocML file.");
       
    56     if (ok) {
       
    57         mMainContainer = mDocumentLoader.findWidget(gMainViewName);
       
    58         mOledClockWidget = qobject_cast<SnsrOledClockWidget *>(
       
    59                 mDocumentLoader.findWidget(gOledAnalogClockWidgetName));
       
    60         Q_ASSERT_X(
       
    61                 mMainContainer && mOledClockWidget, gOledAnalogLayoutDocml,
       
    62                 "Objects not found in DocML file."
       
    63                 );
       
    64 
       
    65         mBackgroundContainerLayout->addItem(mMainContainer);
       
    66     }
       
    67 
       
    68     SCREENSAVER_TEST_FUNC_EXIT("SnsrOledAnalogClockContainer::SnsrOledAnalogClockContainer")
       
    69 }
       
    70 
       
    71 /*!
       
    72     Destructs the class.
       
    73  */
       
    74 SnsrOledAnalogClockContainer::~SnsrOledAnalogClockContainer()
       
    75 {
       
    76     //mOledClockWidget - deleted by the parent
       
    77 }
       
    78 
       
    79 /*!
       
    80     Updates displayed time.
       
    81  */
       
    82 void SnsrOledAnalogClockContainer::update()
       
    83 {
       
    84     SCREENSAVER_TEST_FUNC_ENTRY("SnsrOledAnalogClockContainer::update")
       
    85 
       
    86     // time
       
    87     mOledClockWidget->tick();
       
    88 
       
    89     SCREENSAVER_TEST_FUNC_EXIT("SnsrOledAnalogClockContainer::update")
       
    90 }
       
    91 
       
    92 /*!
       
    93     Changes screensaver layout basing on orientation changes.
       
    94     \param orientation Current orientation.
       
    95  */
       
    96 void SnsrOledAnalogClockContainer::changeLayout(Qt::Orientation orientation)
       
    97 {
       
    98     SCREENSAVER_TEST_FUNC_ENTRY("SnsrOledAnalogClockContainer::changeLayout")
       
    99 
       
   100     if (mCurrentOrientation != orientation) {
       
   101         mCurrentOrientation = orientation;
       
   102         bool ok;
       
   103         // hide controls to avoid screen flickering
       
   104         mMainContainer->hide();
       
   105 
       
   106         QString sectionToLoad("");
       
   107         if (mCurrentOrientation == Qt::Vertical) {
       
   108             sectionToLoad = gPortraitSectionName;
       
   109         } else {
       
   110             sectionToLoad = gLandscapeSectionName;
       
   111         }
       
   112         qDebug() << "loading: " << gOledAnalogLayoutDocml << ", section: " << sectionToLoad;
       
   113         mDocumentLoader.load(gOledAnalogLayoutDocml, sectionToLoad, &ok);
       
   114         // view is rebuilt and ready to show
       
   115         mMainContainer->show();
       
   116         Q_ASSERT_X(ok, gOledAnalogLayoutDocml, "Invalid section in DocML file.");
       
   117     }
       
   118     // update anyway - this is needed in situations when screensaver goes to
       
   119     // foreground but layout change did not occur
       
   120     update();
       
   121 
       
   122     SCREENSAVER_TEST_FUNC_EXIT("SnsrOledAnalogClockContainer::changeLayout")
       
   123 }