screensaver/screensaverplugins/snsrbigclockscreensaverplugin/src/snsroledanalogclockcontainer.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 oled analog clock.
       
    15 *
       
    16 */
       
    17 
       
    18 #include "snsroledanalogclockcontainer.h"
       
    19 
       
    20 #include <QDebug>
       
    21 #include <QGraphicsLinearLayout>
       
    22 #include <QTimer>
       
    23 #include <QTime>
       
    24 #include <HbExtendedLocale>
       
    25 #include <HbMainWindow>
       
    26 
       
    27 #include "snsroledclockwidget.h"
       
    28 #include "snsrindicatorwidget.h"
       
    29 #include "snsrlabel.h"
       
    30 
       
    31 /*!
       
    32     \class SnsrOledAnalogClockContainer
       
    33     \ingroup group_snsrbigclockscreensaverplugin
       
    34     \brief Container used for preparing layout for oled analog clock.
       
    35  */
       
    36 
       
    37 const char *gOledAnalogLayoutDocml = ":/xml/snsrbigclockscreensaveroledanalog.docml";
       
    38 extern const char *gPortraitSectionName;
       
    39 extern const char *gLandscapeSectionName;
       
    40 
       
    41 extern const char *gMainViewName;
       
    42 extern const char *gMainContainerName;
       
    43 extern const char *gClockContainerName;
       
    44 extern const char *gIndicatorWidgetName;
       
    45 
       
    46 extern const char *gDateLabelName;
       
    47 extern const char *gDateFormatVerticalStr;
       
    48 extern const char *gDateFormatHorizontalStr;
       
    49 
       
    50 const char *gOledAnalogClockWidgetName = "oledAnalogClockWidget";
       
    51 
       
    52 
       
    53 /*!
       
    54     Constructs a new SnsrOledAnalogClockContainer.
       
    55  */
       
    56 SnsrOledAnalogClockContainer::SnsrOledAnalogClockContainer() :
       
    57     SnsrBigClockContainer(), mClockContainer(0), mOledClockWidget(0),
       
    58     mDateLabel(0), mDestPosition(QPointF()), mInitialize(false)
       
    59 {
       
    60     SCREENSAVER_TEST_FUNC_ENTRY("SnsrOledAnalogClockContainer::SnsrOledAnalogClockContainer")
       
    61     SCREENSAVER_TEST_FUNC_EXIT("SnsrOledAnalogClockContainer::SnsrOledAnalogClockContainer")
       
    62 }
       
    63 
       
    64 /*!
       
    65     Destructs the class.
       
    66  */
       
    67 SnsrOledAnalogClockContainer::~SnsrOledAnalogClockContainer()
       
    68 {
       
    69     resetIndicatorConnections();
       
    70     //mOledClockWidget etc - deleted by the parent
       
    71 }
       
    72 
       
    73 /*!
       
    74     Updates OLED analog clock widget position.
       
    75  */
       
    76 void SnsrOledAnalogClockContainer::updatePosition()
       
    77 {
       
    78     QSizeF containerSize = mMainContainer->size();
       
    79     
       
    80     // Container must have a valid size to enable calculating the 
       
    81     // destination position for the clock.
       
    82     if ( containerSize.width() > 0 && containerSize.height() > 0 ) {
       
    83         containerSize -= mClockContainer->size();
       
    84         QRectF containerRect( mMainContainer->pos(), containerSize );
       
    85         if ( mInitialize ) {
       
    86             // disconnect container from parent layout,
       
    87             // connected container resets its position to the one defined in docml
       
    88             // after label text updates
       
    89             mClockContainer->setParentLayoutItem(0);
       
    90 
       
    91             QPointF clockPos = nextRandomPosition( mClockContainer->pos(), mDestPosition, containerRect );
       
    92             mClockContainer->setPos( clockPos );
       
    93         }
       
    94         else {
       
    95             mDestPosition = randomPosition( containerRect );
       
    96             mInitialize = true;
       
    97         }
       
    98     }
       
    99 }
       
   100 
       
   101 /*!
       
   102     Updates displayed time.
       
   103  */
       
   104 void SnsrOledAnalogClockContainer::update()
       
   105 {
       
   106     SCREENSAVER_TEST_FUNC_ENTRY("SnsrOledAnalogClockContainer::update")
       
   107 
       
   108     // time
       
   109     mOledClockWidget->tick();
       
   110     
       
   111     // date
       
   112     const char *dateFormat = (mCurrentOrientation == Qt::Vertical) ?
       
   113         gDateFormatVerticalStr : gDateFormatHorizontalStr;
       
   114     QString dateText = HbExtendedLocale().format( QDate::currentDate(), dateFormat );
       
   115     mDateLabel->setPlainText( dateText );
       
   116     
       
   117     // position
       
   118     updatePosition();
       
   119     
       
   120     SCREENSAVER_TEST_FUNC_EXIT("SnsrOledAnalogClockContainer::update")
       
   121 }
       
   122 
       
   123 int SnsrOledAnalogClockContainer::updateIntervalInMilliseconds()
       
   124 {
       
   125     return 60*1000;
       
   126 }
       
   127 
       
   128 /*!
       
   129     @copydoc Screensaver::DisplayPowerMode()
       
   130  */
       
   131 Screensaver::ScreenPowerMode SnsrOledAnalogClockContainer::displayPowerMode()
       
   132 {
       
   133     return Screensaver::ScreenModeLowPower;
       
   134 }
       
   135 
       
   136 /*!
       
   137     @copydoc SnsrBigClockContainer::getActiveScreenRows()
       
   138  */
       
   139 void SnsrOledAnalogClockContainer::getActiveScreenRows(int *firstActiveRow, int *lastActiveRow)
       
   140 {
       
   141     if ( mClockContainer ) {
       
   142         QRect clockRect( mClockContainer->pos().toPoint(), 
       
   143                          mClockContainer->size().toSize() );
       
   144         if ( mCurrentOrientation == Qt::Vertical ) {
       
   145             *firstActiveRow = clockRect.top();
       
   146             *lastActiveRow = clockRect.bottom() + 1;
       
   147         }
       
   148         else {
       
   149             *firstActiveRow = clockRect.left();
       
   150             *lastActiveRow = clockRect.right() + 1;
       
   151         }
       
   152     }
       
   153 }
       
   154 
       
   155 /*!
       
   156     Orientation is locked in power save mode as sensors are off anyway,
       
   157     at least after some timeout.
       
   158  */
       
   159 bool SnsrOledAnalogClockContainer::isOrientationLocked()
       
   160 {
       
   161     return true;
       
   162 }
       
   163 
       
   164 void SnsrOledAnalogClockContainer::loadWidgets()
       
   165 {
       
   166     bool ok(true);
       
   167 
       
   168     // reset widget pointers, any previous widgets are already deleted by now
       
   169     mMainView = 0;
       
   170     mMainContainer = 0;
       
   171     mClockContainer = 0;
       
   172     mOledClockWidget = 0;
       
   173     mDateLabel = 0;
       
   174     mIndicatorWidget = 0;
       
   175     mInitialize = false;
       
   176     
       
   177     // load widgets from docml
       
   178     qDebug() << gOledAnalogLayoutDocml;
       
   179     mDocumentObjects = mDocumentLoader.load(gOledAnalogLayoutDocml, &ok);
       
   180     Q_ASSERT_X(ok, gOledAnalogLayoutDocml, "Invalid DocML file.");
       
   181     if (ok) {
       
   182         mMainView = mDocumentLoader.findWidget(gMainViewName);
       
   183         mMainContainer = mDocumentLoader.findWidget(gMainContainerName);
       
   184         mClockContainer = mDocumentLoader.findWidget(gClockContainerName);
       
   185         mOledClockWidget = qobject_cast<SnsrOledClockWidget *>(
       
   186               mDocumentLoader.findWidget(gOledAnalogClockWidgetName));
       
   187         mDateLabel = qobject_cast<SnsrLabel *>(
       
   188               mDocumentLoader.findWidget(gDateLabelName));
       
   189         mIndicatorWidget = qobject_cast<SnsrIndicatorWidget *>(
       
   190               mDocumentLoader.findWidget(gIndicatorWidgetName));
       
   191         Q_ASSERT_X(
       
   192                 mMainView && mMainContainer && mClockContainer
       
   193                 && mOledClockWidget && mDateLabel && mIndicatorWidget,
       
   194                 gOledAnalogLayoutDocml, "Objects not found in DocML file."
       
   195                 );
       
   196         
       
   197         // In case of landscape layout, read also the landscape delta section
       
   198         if ( mCurrentOrientation == Qt::Horizontal ) {
       
   199             qDebug() << "loading: " << gOledAnalogLayoutDocml << ", section: " << gLandscapeSectionName;
       
   200             mDocumentLoader.load(gOledAnalogLayoutDocml, gLandscapeSectionName, &ok);
       
   201             Q_ASSERT_X(ok, gOledAnalogLayoutDocml, "Invalid section in DocML file.");
       
   202         }
       
   203 
       
   204         mIndicatorWidget->setLayoutType(SnsrIndicatorWidget::IndicatorsCentered);
       
   205         mIndicatorWidget->setPowerSaveModeColor(true);
       
   206         initIndicatorWidget();
       
   207 
       
   208         // powersave mode color
       
   209         mDateLabel->setTextColor(Qt::white);
       
   210 
       
   211         mBackgroundContainerLayout->addItem(mMainView);
       
   212     }
       
   213 }
       
   214 
       
   215 // end of file