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