screensaver/screensaverplugins/snsrbigclockscreensaverplugin/src/snsrbigclockcontainer.cpp
changeset 69 87476091b3f5
parent 62 341166945d65
child 86 e4f038c420f7
equal deleted inserted replaced
67:474929a40a0f 69:87476091b3f5
    20 #include <QPainter>
    20 #include <QPainter>
    21 #include <QDebug>
    21 #include <QDebug>
    22 #include <QTime>
    22 #include <QTime>
    23 #include <QGraphicsLinearLayout>
    23 #include <QGraphicsLinearLayout>
    24 
    24 
    25 #include <hblabel.h>
    25 #include <HbEvent>
    26 #include <hbevent.h>
    26 #include <HbColorScheme>
    27 #include <hbcolorscheme.h>
    27 #include <HbMainWindow>
    28 
       
    29 #include <qsysteminfo.h>
       
    30 
    28 
    31 #include "snsrbigclockcontainer.h"
    29 #include "snsrbigclockcontainer.h"
    32 #include "snsrindicatorwidget.h"
    30 #include "snsrindicatorwidget.h"
    33 #include "snsrindicatormodel.h"
    31 #include "snsrindicatormodel.h"
    34 
    32 
    39  */
    37  */
    40 
    38 
    41 const QString snsrBackgroundColorRole("snsrbackground");
    39 const QString snsrBackgroundColorRole("snsrbackground");
    42 const int gStep(5);
    40 const int gStep(5);
    43 
    41 
    44 QTM_USE_NAMESPACE
       
    45 
    42 
    46 /*!
    43 /*!
    47     Constructs a new SnsrBigClockContainer.
    44     Constructs a new SnsrBigClockContainer.
    48  */
    45  */
    49 SnsrBigClockContainer::SnsrBigClockContainer() :
    46 SnsrBigClockContainer::SnsrBigClockContainer() :
    53     mIndicatorModel(0),
    50     mIndicatorModel(0),
    54     mIndicatorWidget(0),
    51     mIndicatorWidget(0),
    55     mCurrentOrientation(-1)
    52     mCurrentOrientation(-1)
    56 {
    53 {
    57     setBackgroundColor();
    54     setBackgroundColor();
    58     mBackgroundContainerLayout = new QGraphicsLinearLayout(Qt::Vertical);
    55     mBackgroundContainerLayout = new QGraphicsLinearLayout(Qt::Vertical, this);
    59     setLayout(mBackgroundContainerLayout);
    56     setLayout(mBackgroundContainerLayout);
    60     qsrand(QTime::currentTime().msec());
    57     qsrand(QTime::currentTime().msec());
    61 }
    58 }
    62 
    59 
    63 /*!
    60 /*!
    64     Destructs the class.
    61     Destructs the class.
    65  */
    62  */
    66 SnsrBigClockContainer::~SnsrBigClockContainer()
    63 SnsrBigClockContainer::~SnsrBigClockContainer()
    67 {
    64 {    
    68     resetIndicatorConnections();
       
    69     
       
    70     // e.g. mIndicatorWidget gets deleted during these calls
    65     // e.g. mIndicatorWidget gets deleted during these calls
    71     mDocumentLoader.reset();
    66     mDocumentLoader.reset();
    72     qDeleteAll(mDocumentObjects);
    67     qDeleteAll(mDocumentObjects);
    73     mDocumentObjects.clear();
    68     mDocumentObjects.clear();
    74 
    69 
    81 
    76 
    82     Slot for members update in container e.g. when time or date changed.
    77     Slot for members update in container e.g. when time or date changed.
    83  */
    78  */
    84 
    79 
    85 /*!
    80 /*!
    86     \fn virtual void changeLayout(Qt::Orientation orientation) = 0;
    81     Changes screensaver layout based on orientation changes.
    87 
    82     \param orientation Current orientation.
    88     Slot for members update in container when orientation changed.
    83  */
    89  */
    84 void SnsrBigClockContainer::changeLayout(Qt::Orientation orientation)
       
    85 {
       
    86     SCREENSAVER_TEST_FUNC_ENTRY("SnsrBigClockContainer::changeLayout")
       
    87 
       
    88     if (mCurrentOrientation != orientation) {
       
    89         mCurrentOrientation = orientation;
       
    90         
       
    91         // delete any old widgets
       
    92         if ( mBackgroundContainerLayout->count() ) {
       
    93             mBackgroundContainerLayout->removeAt(0);
       
    94         }
       
    95         mDocumentLoader.reset();
       
    96         qDeleteAll(mDocumentObjects);
       
    97         mDocumentObjects.clear();
       
    98 
       
    99         // reload widgets from docml
       
   100         loadWidgets();
       
   101     }
       
   102     mBackgroundContainerLayout->setGeometry( mainWindow()->layoutRect() );
       
   103     update();
       
   104 
       
   105     SCREENSAVER_TEST_FUNC_EXIT("SnsrBigClockContainer::changeLayout")
       
   106 }
       
   107 
       
   108 /*!
       
   109     Set used indicator model that is owned by the screensaver class. 
       
   110     Model's life cycle must be the same as screensaver's so that indicators'
       
   111     status data can be kept in memory and one can receive updates. 
       
   112     This method should be called when the current container is set.
       
   113  */
       
   114 void SnsrBigClockContainer::setIndicatorModel(SnsrIndicatorModel &model)
       
   115 {
       
   116     mIndicatorModel = &model;
       
   117 }
       
   118 
       
   119 /*!
       
   120     @copydoc Screensaver::getActiveScreenRows()
       
   121  */
       
   122 void SnsrBigClockContainer::getActiveScreenRows(int *firstActiveRow, int *lastActiveRow)
       
   123 {
       
   124     // This default implementation return the whole area of the
       
   125     // container. Inherited low power mode containers can and should
       
   126     // return smaller area which just barely encloses all the content.
       
   127     if ( mMainContainer ) {
       
   128         QRect mainRect = mMainContainer->rect().toRect();
       
   129         if ( mCurrentOrientation == Qt::Vertical ) {
       
   130             *firstActiveRow = mainRect.top();
       
   131             *lastActiveRow = mainRect.bottom();
       
   132         }
       
   133         else {
       
   134             *firstActiveRow = mainRect.left();
       
   135             *lastActiveRow = mainRect.right();
       
   136         }
       
   137     }
       
   138 }
       
   139 
       
   140 /*!
       
   141     Tell if this container wants to lock the screen orientation.
       
   142     Default implementation in not locked but inherited classes may
       
   143     override this.
       
   144  */
       
   145 bool SnsrBigClockContainer::isOrientationLocked()
       
   146 {
       
   147     return false;
       
   148 }
    90 
   149 
    91 /*!
   150 /*!
    92     \fn virtual int updateIntervalInMilliseconds() = 0;
   151     \fn virtual int updateIntervalInMilliseconds() = 0;
    93 
   152 
    94     Concrete inherited container classes must implement this to return
   153     Concrete inherited container classes must implement this to return
    95     the desired update interval for that clock mode.
   154     the desired update interval for that clock mode.
    96  */
   155  */
    97 
   156 
    98 /*!
   157 /*!
    99     Set used indicator model and do necessary initializations to show currently
   158     \fn virtual int loadWidgets() = 0;
   100     active indicators.
   159 
   101  */
   160     Concrete inherited container classes must implement this to instantiate
   102 void SnsrBigClockContainer::initIndicators(SnsrIndicatorModel &model)
   161     all the widgets shown in the container. The base class calls this
   103 {
   162     method when screen layuot is changed. The old widgets are already 
   104     mIndicatorModel = &model;
   163     deleted by the base class before this is called. Also changing the visible
   105     if (mIndicatorWidget) {
   164     container is treated as a layout change, and results in call to this method.
   106         connect(mIndicatorModel, SIGNAL(indicatorsUpdated(QList<SnsrIndicatorInfo>)),
   165     Thus, inherited containers don't have to load their widgets yet in their
   107                 mIndicatorWidget, SLOT(showIndicators(QList<SnsrIndicatorInfo>)));
   166     constructors.
   108                 
   167  */
   109         connect(mIndicatorModel, SIGNAL(allIndicatorsDeactivated()),
       
   110                 mIndicatorWidget, SLOT(removeAllIndicators()));
       
   111         
       
   112         mIndicatorModel->initializeIndicatorWidget();
       
   113     }
       
   114 }
       
   115 
   168 
   116 /*!
   169 /*!
   117     \reimp
   170     \reimp
   118  */
   171  */
   119 void SnsrBigClockContainer::changeEvent(QEvent *event)
   172 void SnsrBigClockContainer::changeEvent(QEvent *event)
   227     // Return new position between points p1 and p3.
   280     // Return new position between points p1 and p3.
   228     return p2;
   281     return p2;
   229 }
   282 }
   230 
   283 
   231 /*!
   284 /*!
       
   285     Do necessary initializations to show currently active indicators.
       
   286     Should be called after the indicator widget is created.
       
   287  */
       
   288 void SnsrBigClockContainer::initIndicatorWidget()
       
   289 {
       
   290     Q_ASSERT(mIndicatorModel && mIndicatorWidget);
       
   291     
       
   292     connect(mIndicatorModel, SIGNAL(indicatorsUpdated(QList<SnsrIndicatorInfo>)),
       
   293             mIndicatorWidget, SLOT(showIndicators(QList<SnsrIndicatorInfo>)));
       
   294                 
       
   295     connect(mIndicatorModel, SIGNAL(allIndicatorsDeactivated()),
       
   296             mIndicatorWidget, SLOT(removeAllIndicators()));
       
   297         
       
   298     mIndicatorModel->initializeIndicatorWidget();
       
   299 }
       
   300 
       
   301 /*!
   232     Disconnect connections between indicator model and widget.
   302     Disconnect connections between indicator model and widget.
       
   303     Should be called before deleting the indicator widget.
   233  */
   304  */
   234 void SnsrBigClockContainer::resetIndicatorConnections()
   305 void SnsrBigClockContainer::resetIndicatorConnections()
   235 {
   306 {   
   236     disconnect(mIndicatorModel, SIGNAL(indicatorsUpdated(QList<SnsrIndicatorInfo>)),
   307     if (mIndicatorWidget && mIndicatorModel) {
   237                mIndicatorWidget, SLOT(showIndicators(QList<SnsrIndicatorInfo>)));
   308         disconnect(mIndicatorModel, SIGNAL(indicatorsUpdated(QList<SnsrIndicatorInfo>)),
   238     
   309                    mIndicatorWidget, SLOT(showIndicators(QList<SnsrIndicatorInfo>)));
   239     disconnect(mIndicatorModel, SIGNAL(allIndicatorsDeactivated()),
   310         
   240                mIndicatorWidget, SLOT(removeAllIndicators()));
   311         disconnect(mIndicatorModel, SIGNAL(allIndicatorsDeactivated()),
       
   312                    mIndicatorWidget, SLOT(removeAllIndicators()));
       
   313     }
   241 }
   314 }
   242 
   315 
   243 /*!
   316 /*!
   244     Set background color.
   317     Set background color.
   245  */
   318  */