screensaver/snsrplugins/snsrbigclockscreensaverplugin/src/snsroleddigitalclockcontainer.cpp
changeset 97 66b5fe3c07fd
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 #include <HbExtendedLocale>
       
    25 #include <HbMainWindow>
       
    26 
       
    27 #include "snsrlabel.h"
       
    28 #include "snsrindicatorwidget.h"
       
    29 #include "snsroledtimelabel.h"
       
    30 
       
    31 
       
    32 /*!
       
    33     \class SnsrOledDigitalClockContainer
       
    34     \ingroup group_snsrbigclockscreensaverplugin
       
    35     \brief Container used for preparing layout for oled digital clock.
       
    36  */
       
    37 
       
    38 const char *gOledDigitalLayoutDocml = ":/xml/snsrbigclockscreensaveroleddigital.docml";
       
    39 extern const char *gPortraitSectionName;
       
    40 extern const char *gLandscapeSectionName;
       
    41 
       
    42 extern const char *gMainViewName;
       
    43 extern const char *gMainContainerName;
       
    44 extern const char *gClockContainerName;
       
    45 
       
    46 extern const char *gOledTimeLabelName = "oledTimeLabel";
       
    47 extern const char *gAmPmLabelName;
       
    48 extern const char *gDateLabelName;
       
    49 
       
    50 extern const char *gDateFormatStr;
       
    51 
       
    52 extern const char *gTimeFormatStr;
       
    53 
       
    54 extern const char *gIndicatorWidgetName;
       
    55 
       
    56 
       
    57 
       
    58 /*!
       
    59     Constructs a new SnsrOledDigitalClockContainer.
       
    60  */
       
    61 SnsrOledDigitalClockContainer::SnsrOledDigitalClockContainer() :
       
    62     SnsrBigClockContainer(), mClockContainer(0), mAmPmLabel(0),
       
    63     mTimeLabel(0), mDateLabel(0), mDestPosition(QPointF()),
       
    64     mInitialize(false)
       
    65 {
       
    66     SCREENSAVER_TEST_FUNC_ENTRY("SnsrOledDigitalClockContainer::SnsrOledDigitalClockContainer")
       
    67     SCREENSAVER_TEST_FUNC_EXIT("SnsrOledDigitalClockContainer::SnsrOledDigitalClockContainer")
       
    68 }
       
    69 
       
    70 /*!
       
    71     Destructs the class.
       
    72  */
       
    73 SnsrOledDigitalClockContainer::~SnsrOledDigitalClockContainer()
       
    74 {
       
    75     resetIndicatorConnections();
       
    76     //mTimeLabel, mAmPmLabel, mDateLabel, mMoveTimer - deleted by the parent
       
    77 }
       
    78 
       
    79 /*!
       
    80     Updates OLED digital clock widget position.
       
    81  */
       
    82 void SnsrOledDigitalClockContainer::updatePosition()
       
    83 {
       
    84     QSizeF containerSize = mMainContainer->size();
       
    85     
       
    86     // Container must have a valid size to enable calculating the 
       
    87     // destination position for the clock.
       
    88     if ( containerSize.width() > 0 && containerSize.height() > 0 ) {
       
    89         containerSize -= mClockContainer->boundingRect().size();
       
    90         QRectF containerRect( mMainContainer->pos(), containerSize );
       
    91         if ( mInitialize ) {
       
    92             // disconnect container from parent layout,
       
    93             // connected container resets its position to the one defined in docml
       
    94             // after label text updates
       
    95             mClockContainer->setParentLayoutItem(0);
       
    96 
       
    97             QPointF clockPos = nextRandomPosition( mClockContainer->pos(), mDestPosition, containerRect );
       
    98             mClockContainer->setPos( clockPos );
       
    99         }
       
   100         else {
       
   101             mDestPosition = randomPosition( containerRect );
       
   102             mInitialize = true;
       
   103         }
       
   104     }
       
   105 }
       
   106 
       
   107 /*!
       
   108     Updates displayed time and date.
       
   109  */
       
   110 void SnsrOledDigitalClockContainer::update()
       
   111 {
       
   112     SCREENSAVER_TEST_FUNC_ENTRY("SnsrOledDigitalClockContainer::update")
       
   113 
       
   114     HbExtendedLocale locale = HbExtendedLocale::system();
       
   115     
       
   116     // time
       
   117     mTimeLabel->setText(
       
   118         locale.format(QTime::currentTime(), gTimeFormatStr)
       
   119         );
       
   120     
       
   121     // don't use %B here as some extra space might be added if it's used as an
       
   122     // isolated format string
       
   123     QString amPmString("");
       
   124     if (locale.timeStyle() == HbExtendedLocale::Time12 ) {
       
   125         amPmString = (QTime::currentTime().hour()<12) ? locale.amText() : locale.pmText();
       
   126     }
       
   127     mAmPmLabel->setPlainText( amPmString );
       
   128     
       
   129     // date
       
   130     mDateLabel->setPlainText(
       
   131         locale.format(QDate::currentDate(), gDateFormatStr)
       
   132         );
       
   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->setIconColorType(SnsrIndicatorWidget::FixedColorForPowerSaveMode);
       
   225         connectIndicatorWidgetToModel();
       
   226 
       
   227         mDateLabel->setTextColorType(SnsrLabel::FixedColorForPowerSaveMode);
       
   228         mAmPmLabel->setTextColorType(SnsrLabel::FixedColorForPowerSaveMode);
       
   229 
       
   230         mBackgroundContainerLayout->addItem(mMainView);
       
   231     }
       
   232 }
       
   233 
       
   234 // end of file