62
|
1 |
/*
|
|
2 |
* Copyright (c) 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: Indicator Widget.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "snsrindicatorwidget.h"
|
|
19 |
#include "snsrindicatorinfo.h"
|
|
20 |
|
|
21 |
#include <HbColorScheme>
|
|
22 |
#include <QDebug>
|
|
23 |
#include <QSizePolicy>
|
|
24 |
#include <HbStyleLoader>
|
|
25 |
#include <HbIconItem>
|
|
26 |
#include <HbIndicatorInterface>
|
|
27 |
|
|
28 |
|
|
29 |
const char *gIndicatorCssFilePath =":/style/snsrindicatorwidget.css";
|
|
30 |
const char *gIndicatorWidgetMLFilePath = ":/style/snsrindicatorwidget.widgetml";
|
|
31 |
const char *gIndicatorColorCssFilePath = ":/style/snsrindicatorwidget_color.css";
|
|
32 |
|
|
33 |
const int gNumberOfIcons(6);
|
|
34 |
|
|
35 |
/*!
|
|
36 |
\class SnsrIndicatorWidget
|
|
37 |
\ingroup group_snsrbigclockscreensaverprovider
|
|
38 |
\brief Screensaver indicator widget.
|
|
39 |
*/
|
|
40 |
|
|
41 |
/*!
|
|
42 |
Constructs a new SnsrIndicatorWidget.
|
|
43 |
\param parent Parent object.
|
|
44 |
*/
|
|
45 |
SnsrIndicatorWidget::SnsrIndicatorWidget(QGraphicsItem* parent):
|
86
|
46 |
HbWidget(parent), mLayoutType(IndicatorsCentered), mPowerSaveModeColor(false)
|
62
|
47 |
{
|
|
48 |
HbStyleLoader::registerFilePath(gIndicatorCssFilePath);
|
|
49 |
HbStyleLoader::registerFilePath(gIndicatorWidgetMLFilePath);
|
|
50 |
|
|
51 |
// TODO: will some color variables be added into hbcolorgroup.css so
|
|
52 |
// that one don't need to use hard-coded values? If not, then
|
|
53 |
// changes needed in this widget.
|
|
54 |
HbStyleLoader::registerFilePath(gIndicatorColorCssFilePath);
|
|
55 |
|
|
56 |
setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
|
|
57 |
|
|
58 |
createPrimitives();
|
|
59 |
}
|
|
60 |
|
|
61 |
/*!
|
|
62 |
Destructs the class.
|
|
63 |
*/
|
|
64 |
SnsrIndicatorWidget::~SnsrIndicatorWidget()
|
|
65 |
{
|
|
66 |
// icons within the list are deleted by parent
|
|
67 |
mIcons.clear();
|
|
68 |
|
|
69 |
HbStyleLoader::unregisterFilePath( gIndicatorCssFilePath );
|
|
70 |
HbStyleLoader::unregisterFilePath( gIndicatorWidgetMLFilePath );
|
|
71 |
HbStyleLoader::unregisterFilePath(gIndicatorColorCssFilePath);
|
|
72 |
}
|
|
73 |
|
|
74 |
|
|
75 |
SnsrIndicatorWidget::IndicatorLayoutType SnsrIndicatorWidget::layoutType() const
|
|
76 |
{
|
|
77 |
return mLayoutType;
|
|
78 |
}
|
|
79 |
|
|
80 |
/*!
|
|
81 |
Sets the name of layout definition \a layoutName for selecting
|
|
82 |
the layout of view items of this view from css/xml files.
|
|
83 |
|
|
84 |
This layout is accessible from css file as layout property
|
|
85 |
of the view item.
|
|
86 |
|
|
87 |
*/
|
|
88 |
void SnsrIndicatorWidget::setLayoutType(IndicatorLayoutType type)
|
|
89 |
{
|
|
90 |
if (mLayoutType != type ) {
|
|
91 |
mLayoutType = type;
|
|
92 |
QSizePolicy::Policy hSizePolicy(QSizePolicy::Expanding);
|
|
93 |
if ( mLayoutType == IndicatorsAlignedLeft ) {
|
|
94 |
hSizePolicy = QSizePolicy::Preferred;
|
|
95 |
}
|
|
96 |
setSizePolicy(hSizePolicy,QSizePolicy::Preferred);
|
|
97 |
}
|
|
98 |
}
|
|
99 |
|
|
100 |
/*!
|
86
|
101 |
Set powersave mode status. If save mode is true then we use
|
|
102 |
by default Qt::white as color. Otherwise we use themed color.
|
|
103 |
*/
|
|
104 |
void SnsrIndicatorWidget::setPowerSaveModeColor(bool savemode)
|
|
105 |
{
|
|
106 |
mPowerSaveModeColor = savemode;
|
|
107 |
}
|
|
108 |
|
|
109 |
|
|
110 |
/*!
|
62
|
111 |
This is called whenever indicators' status changes: parameter list
|
|
112 |
tells which indicators should be shown at the given moment. All
|
|
113 |
previously shown indicators should be hidden and show only these
|
|
114 |
indicators passed as a parameter.
|
|
115 |
*/
|
|
116 |
void SnsrIndicatorWidget::showIndicators(const QList<SnsrIndicatorInfo> &indicators)
|
|
117 |
{
|
|
118 |
// Update icon paths so that shown iconItems have
|
|
119 |
// valid icon path and rest have empty path (->invisible)
|
|
120 |
|
|
121 |
int indicatorAmount = indicators.size();
|
|
122 |
|
|
123 |
removeAllIndicators();
|
|
124 |
|
|
125 |
// TODO: after wk18 color is lost after icon name is set again - bug or what?
|
|
126 |
// workaround: ask color from theme and set it again here
|
|
127 |
// If this must be left here, then change back-up color to white?
|
86
|
128 |
QColor iconColor = HbColorScheme::color("qtc_screensaver");
|
62
|
129 |
if (iconColor.spec() == QColor::Invalid ) {
|
86
|
130 |
iconColor = Qt::white;
|
62
|
131 |
}
|
86
|
132 |
|
|
133 |
if ( mPowerSaveModeColor ) {
|
|
134 |
iconColor = Qt::white;
|
|
135 |
}
|
|
136 |
|
62
|
137 |
// update icon paths for items that are gonna be shown
|
|
138 |
for (int i=0; i < indicatorAmount && i < mIcons.size(); ++i) {
|
|
139 |
mIcons.at(i)->setIconName(indicators.at(i).iconPath);
|
|
140 |
mIcons.at(i)->setFlags(HbIcon::Colorized);
|
|
141 |
mIcons.at(i)->setColor(iconColor);
|
|
142 |
}
|
|
143 |
|
|
144 |
// To recalculate layouts
|
|
145 |
updateGeometry();
|
|
146 |
if ( parentLayoutItem() ) {
|
|
147 |
parentLayoutItem()->updateGeometry(); // clear the cache of the parent
|
|
148 |
}
|
|
149 |
}
|
|
150 |
|
|
151 |
/*!
|
|
152 |
Remove all indicators from UI.
|
|
153 |
*/
|
|
154 |
void SnsrIndicatorWidget::removeAllIndicators()
|
|
155 |
{
|
|
156 |
for (int i=0; i < mIcons.size(); ++i) {
|
|
157 |
mIcons.at(i)->setIconName(QString());
|
|
158 |
}
|
|
159 |
}
|
|
160 |
|
|
161 |
/*!
|
|
162 |
If indicator pane is going to be centered, then calculate width so that it's
|
|
163 |
exactly the same as visible icons are taking space (+spacers between them).
|
|
164 |
If indicator pane is left aligned, then actual width doesn't matter.
|
|
165 |
Assumption is that icons are fixed sized.
|
|
166 |
\reimp
|
|
167 |
*/
|
|
168 |
QSizeF SnsrIndicatorWidget::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
|
|
169 |
{
|
|
170 |
QSizeF hint = HbWidget::sizeHint(which, constraint);
|
|
171 |
|
|
172 |
// TODO: seems to work if icons are fixed-sized (units)
|
|
173 |
// TODO: even though size policy is preferred, should we give also
|
|
174 |
// minimum and maximum sizes?
|
|
175 |
if (which == Qt::PreferredSize && layoutType() == IndicatorsCentered ) {
|
|
176 |
qreal width(0);
|
|
177 |
qreal itemWidth(0);
|
|
178 |
qreal iconSpace(0);
|
|
179 |
int visibleIconCount(0);
|
|
180 |
|
|
181 |
// TODO: use geometry or size?
|
|
182 |
for (int i=0; i < mIcons.size(); ++i) {
|
|
183 |
if (!mIcons.at(i)->iconName().isEmpty() ) {
|
|
184 |
visibleIconCount++;
|
|
185 |
itemWidth = mIcons.at(i)->iconItemSize().width();
|
|
186 |
width = width + itemWidth;
|
|
187 |
}
|
|
188 |
}
|
|
189 |
if (visibleIconCount > 1) {
|
|
190 |
style()->parameter("hb-param-margin-gene-middle-horizontal", iconSpace);
|
|
191 |
width = width + ((visibleIconCount-1)*iconSpace);
|
|
192 |
}
|
|
193 |
|
|
194 |
hint.setWidth(width);
|
|
195 |
}
|
|
196 |
|
|
197 |
return hint;
|
|
198 |
}
|
|
199 |
|
|
200 |
/*!
|
|
201 |
Creates all widget primitives.
|
|
202 |
Coloring is handled via CSS.
|
|
203 |
*/
|
|
204 |
void SnsrIndicatorWidget::createPrimitives()
|
|
205 |
{
|
|
206 |
if (!mIcons.isEmpty()) {
|
|
207 |
return;
|
|
208 |
}
|
|
209 |
|
|
210 |
HbIconItem *icon(0);
|
|
211 |
QLatin1String itemNameBase("icon");
|
|
212 |
int itemNameEnd(1);
|
|
213 |
QString itemName("");
|
|
214 |
|
|
215 |
while (mIcons.count() < gNumberOfIcons) {
|
|
216 |
// When created, icon names are left empty -> nothing shown in UI.
|
|
217 |
icon = new HbIconItem(this);
|
|
218 |
icon->setFlags(HbIcon::Colorized);
|
|
219 |
icon->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
|
|
220 |
|
|
221 |
// Create items that are named icon1..icon6.
|
|
222 |
itemName.clear();
|
|
223 |
itemName.append(itemNameBase);
|
|
224 |
itemName.append(QString::number(itemNameEnd));
|
|
225 |
HbStyle::setItemName(icon, itemName);
|
|
226 |
++itemNameEnd;
|
|
227 |
|
|
228 |
mIcons.append(icon);
|
|
229 |
}
|
|
230 |
}
|