homescreenapp/serviceproviders/hsmenuserviceprovider/src/hsiconsidleloader.cpp
changeset 85 35368b604b28
parent 77 4b195f3bea29
equal deleted inserted replaced
77:4b195f3bea29 85:35368b604b28
    13  *
    13  *
    14  * Description: Menu All Applications state.
    14  * Description: Menu All Applications state.
    15  *
    15  *
    16  */
    16  */
    17 
    17 
       
    18 #include <QPainter>
    18 #include <QSize>
    19 #include <QSize>
    19 #include <QTimer>
    20 #include <QTimer>
    20 #include "hsmenuitemmodel.h"
    21 #include "hsmenuitemmodel.h"
    21 #include "hsiconsidleloader.h"
    22 #include "hsiconsidleloader.h"
    22 
    23 
    26  \param pointer to parent object
    27  \param pointer to parent object
    27  */
    28  */
    28 HsIconsIdleLoader::HsIconsIdleLoader(HsMenuItemModel *model, QObject *parent):
    29 HsIconsIdleLoader::HsIconsIdleLoader(HsMenuItemModel *model, QObject *parent):
    29     QObject(parent),
    30     QObject(parent),
    30     mModel(model),
    31     mModel(model),
    31     mTimer(NULL)
    32     mTimer(NULL),
       
    33     mIconSize(mModel->getIconSize())
    32 {
    34 {
    33     mTimer = new QTimer(this);
    35     mTimer = new QTimer(this);
       
    36     mOutStandingIconToLoad = mModel->rowCount();
    34     connect(mTimer, SIGNAL(timeout()), this, SLOT(processWhenIdle()));
    37     connect(mTimer, SIGNAL(timeout()), this, SLOT(processWhenIdle()));
    35     mTimer->start(0); // NOTE: zero for idle
    38     mTimer->start(0); // NOTE: zero for idle
    36 }
    39 }
    37 
    40 
    38 /*!
    41 /*!
    47  Preloading icons if idle
    50  Preloading icons if idle
    48  \retval void
    51  \retval void
    49  */
    52  */
    50 void HsIconsIdleLoader::processWhenIdle()
    53 void HsIconsIdleLoader::processWhenIdle()
    51 {
    54 {
    52     const QSize iconSize(mModel->getIconSize());
    55     if (mOutStandingIconToLoad >= 1 
    53     for (int i=0; i<mModel->rowCount(); i++) {
    56         && mModel->rowCount() >= mOutStandingIconToLoad ) {
    54         QModelIndex idx = mModel->index(i);
    57     	QPixmap pixmap(mIconSize.toSize());
    55         mModel->entry(idx)->makeIcon(iconSize);
    58     	pixmap.fill(Qt::transparent);
    56     }
    59 
    57     mTimer->stop(); // No more timing
    60         QModelIndex idx = mModel->index(mOutStandingIconToLoad -1);
       
    61         HbIcon icon = mModel->entry(idx)->makeIcon(mIconSize);
       
    62         icon.setSize(mIconSize);
       
    63         // creating raster data
       
    64         QPainter painter;
       
    65         painter.begin(&pixmap);
       
    66         icon.paint(&painter, QRectF(QPointF(), mIconSize), 
       
    67                      Qt::KeepAspectRatio, 
       
    68                      Qt::AlignCenter, 
       
    69                      QIcon::Normal, 
       
    70                      QIcon::Off);
       
    71         painter.end();
       
    72         --mOutStandingIconToLoad;
       
    73     } else {
       
    74     	mTimer->stop(); // No more timing
       
    75 	}
    58 }
    76 }
    59 
    77