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