|
1 /* |
|
2 * Copyright (c) 2009 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: Menu All Applications state. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QPainter> |
|
19 #include <QSize> |
|
20 #include <QTimer> |
|
21 #include "hsmenuitemmodel.h" |
|
22 #include "hsiconsidleloader.h" |
|
23 |
|
24 /*! |
|
25 Constructor |
|
26 \param model with defined icons |
|
27 \param pointer to parent object |
|
28 */ |
|
29 HsIconsIdleLoader::HsIconsIdleLoader(HsMenuItemModel *model, QObject *parent): |
|
30 QObject(parent), |
|
31 mModel(model), |
|
32 mTimer(NULL), |
|
33 mIconSize(mModel->getIconSize()) |
|
34 { |
|
35 mTimer = new QTimer(this); |
|
36 mOutStandingIconToLoad = mModel->rowCount(); |
|
37 connect(mTimer, SIGNAL(timeout()), this, SLOT(processWhenIdle())); |
|
38 mTimer->start(0); // NOTE: zero for idle |
|
39 } |
|
40 |
|
41 /*! |
|
42 Destructor |
|
43 */ |
|
44 HsIconsIdleLoader::~HsIconsIdleLoader() |
|
45 { |
|
46 mTimer->stop(); |
|
47 } |
|
48 |
|
49 /*! |
|
50 Preloading icons if idle |
|
51 \retval void |
|
52 */ |
|
53 void HsIconsIdleLoader::processWhenIdle() |
|
54 { |
|
55 if (mOutStandingIconToLoad >= 1 |
|
56 && mModel->rowCount() >= mOutStandingIconToLoad ) { |
|
57 QPixmap pixmap(mIconSize.toSize()); |
|
58 pixmap.fill(Qt::transparent); |
|
59 |
|
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 } |
|
76 } |
|
77 |