21 ** If you have questions regarding the use of this file, please contact |
21 ** If you have questions regarding the use of this file, please contact |
22 ** Nokia at developer.feedback@nokia.com. |
22 ** Nokia at developer.feedback@nokia.com. |
23 ** |
23 ** |
24 ****************************************************************************/ |
24 ****************************************************************************/ |
25 |
25 |
26 #include <hbstyleoptionindicatormenu.h> |
|
27 #include <hbindicatorinterface.h> |
26 #include <hbindicatorinterface.h> |
28 #include "hbindicatormenucontent_p.h" |
27 #include "hbindicatormenucontent_p.h" |
29 #include "hbindicatormenuclock_p.h" |
|
30 #include "hbindicatormenudate_p.h" |
|
31 |
28 |
32 static const int ListWidgetItemIndicatorTypeRole = Hb::UserRole; |
29 static const int ListWidgetItemIndicatorTypeRole = Hb::UserRole; |
33 static const int DefaultItemsVisible = 6; |
30 static const int DefaultItemsVisible = 6; |
34 |
31 |
35 HbIndicatorListItem::HbIndicatorListItem(QGraphicsItem *parent) : |
32 HbIndicatorListItem::HbIndicatorListItem(QGraphicsItem *parent) : |
44 item->setObjectName("indicatorListItem"); |
41 item->setObjectName("indicatorListItem"); |
45 item->setContentsMargins(0,0,0,0); |
42 item->setContentsMargins(0,0,0,0); |
46 return item; |
43 return item; |
47 } |
44 } |
48 |
45 |
49 void HbIndicatorListItem::updateChildItems() |
|
50 { |
|
51 QModelIndex index(modelIndex()); |
|
52 bool itemContainsLink = false; |
|
53 HbIndicatorInterface *indicator = |
|
54 HbIndicatorMenuContent::indicatorFromIndex(index); |
|
55 if (indicator && indicator->interactionTypes().testFlag( |
|
56 HbIndicatorInterface::InteractionActivated)){ |
|
57 itemContainsLink = true; |
|
58 } |
|
59 setProperty("link", itemContainsLink); |
|
60 HbListViewItem::updateChildItems(); |
|
61 } |
|
62 |
|
63 IndicatorList::IndicatorList(HbIndicatorMenuContent *content) : |
46 IndicatorList::IndicatorList(HbIndicatorMenuContent *content) : |
64 HbListView(content), mContent(content), mUpdateListSize(false) |
47 HbListView(content), mUpdateListSize(false) |
65 { |
48 { |
66 setItemRecycling(true); |
49 setItemRecycling(true); |
67 setUniformItemSizes(true); |
50 setUniformItemSizes(true); |
68 } |
51 } |
69 |
52 |
70 void IndicatorList::rowsInserted( |
53 void IndicatorList::rowsInserted( |
71 const QModelIndex &parent, int start, int end) |
54 const QModelIndex &parent, int start, int end) |
72 { |
55 { |
73 HbListView::rowsInserted(parent, start, end); |
56 HbListView::rowsInserted(parent, start, end); |
74 if (static_cast<QGraphicsItem*>(this)->isVisible()) { |
57 if (mUpdateListSize == false) { |
|
58 mUpdateListSize = true; |
75 updateGeometry(); |
59 updateGeometry(); |
76 mUpdateListSize = true; |
|
77 } |
60 } |
78 } |
61 } |
79 |
62 |
80 void IndicatorList::rowsRemoved( |
63 void IndicatorList::rowsRemoved( |
81 const QModelIndex &parent,int start,int end) |
64 const QModelIndex &parent,int start,int end) |
82 { |
65 { |
83 HbListView::rowsRemoved(parent, start, end); |
66 HbListView::rowsRemoved(parent, start, end); |
84 if (static_cast<QGraphicsItem*>(this)->isVisible()) { |
67 if (mUpdateListSize == false) { |
|
68 mUpdateListSize = true; |
85 updateGeometry(); |
69 updateGeometry(); |
86 mUpdateListSize = true; |
|
87 } |
70 } |
88 } |
71 } |
89 |
72 |
90 void IndicatorList::dataChanged(const QModelIndex &topLeft, |
73 void IndicatorList::dataChanged(const QModelIndex &topLeft, |
91 const QModelIndex &bottomRight) |
74 const QModelIndex &bottomRight) |
92 { |
75 { |
93 HbListView::dataChanged(topLeft, bottomRight); |
76 HbListView::dataChanged(topLeft, bottomRight); |
94 if (static_cast<QGraphicsItem*>(this)->isVisible()) { |
77 if (mUpdateListSize == false) { |
|
78 mUpdateListSize = true; |
95 updateGeometry(); |
79 updateGeometry(); |
96 mUpdateListSize = true; |
|
97 } |
80 } |
98 } |
81 } |
99 |
82 |
100 QSizeF IndicatorList::sizeHint(Qt::SizeHint which, const QSizeF & constraint) const |
83 QSizeF IndicatorList::sizeHint(Qt::SizeHint which, const QSizeF & constraint) const |
101 { |
84 { |
142 HbWidget(parent) |
127 HbWidget(parent) |
143 { |
128 { |
144 for (int i = 0; i < IndicatorTypes; ++i) { |
129 for (int i = 0; i < IndicatorTypes; ++i) { |
145 mGroupTypeIndeces[i] = 0; |
130 mGroupTypeIndeces[i] = 0; |
146 } |
131 } |
147 |
|
148 mHeaderBackground = style()->createPrimitive(HbStyle::P_Popup_heading_frame, this); |
|
149 |
|
150 mClock = new HbIndicatorMenuClock(this); |
|
151 mDate = new HbIndicatorMenuDate(this); |
|
152 connect(mClock, SIGNAL(dateChanged()), mDate, SLOT(updateDate())); |
|
153 |
132 |
154 mIndicatorList = new IndicatorList(this); |
133 mIndicatorList = new IndicatorList(this); |
155 mIndicatorList->setItemPrototype(new HbIndicatorListItem(this)); |
134 mIndicatorList->setItemPrototype(new HbIndicatorListItem(this)); |
156 mIndicatorList->setModel(&indicatorModel); |
135 mIndicatorList->setModel(&indicatorModel); |
157 connect(mIndicatorList, SIGNAL(activated(QModelIndex)), |
136 connect(mIndicatorList, SIGNAL(activated(QModelIndex)), |
159 connect(mIndicatorList, SIGNAL(scrollingStarted()), |
138 connect(mIndicatorList, SIGNAL(scrollingStarted()), |
160 this, SLOT(indicatorlist_scrollingStarted())); |
139 this, SLOT(indicatorlist_scrollingStarted())); |
161 connect(mIndicatorList, SIGNAL(scrollingEnded()), |
140 connect(mIndicatorList, SIGNAL(scrollingEnded()), |
162 this, SLOT(indicatorlist_scrollingEnded())); |
141 this, SLOT(indicatorlist_scrollingEnded())); |
163 |
142 |
164 HbStyle::setItemName(mHeaderBackground, "background"); |
|
165 HbStyle::setItemName(mClock, "clock"); |
|
166 HbStyle::setItemName(mDate, "date"); |
|
167 HbStyle::setItemName(mIndicatorList, "list"); |
143 HbStyle::setItemName(mIndicatorList, "list"); |
168 |
|
169 updatePrimitives(); |
|
170 } |
144 } |
171 |
145 |
172 HbIndicatorMenuContent::~HbIndicatorMenuContent() |
146 HbIndicatorMenuContent::~HbIndicatorMenuContent() |
173 { |
147 { |
174 } |
148 } |
175 |
149 |
176 |
|
177 int HbIndicatorMenuContent::indicatorCount() const |
150 int HbIndicatorMenuContent::indicatorCount() const |
178 { |
151 { |
179 return indicatorModel.rowCount(); |
152 return indicatorModel.rowCount(); |
180 } |
153 } |
181 |
154 |
182 void HbIndicatorMenuContent::updatePrimitives() |
155 void HbIndicatorMenuContent::updatePrimitives() |
183 { |
156 { |
184 HbStyleOptionPopup option; |
157 repolish(); |
185 if (mHeaderBackground->hasFocus()) { |
|
186 option.headingMode = QIcon::Selected; |
|
187 } else if (mHeaderBackground->isSelected()) { |
|
188 option.headingMode = QIcon::Active; |
|
189 } else { |
|
190 option.headingMode = QIcon::Normal; |
|
191 } |
|
192 style()->updatePrimitive(mHeaderBackground, HbStyle::P_Popup_heading_frame, &option); |
|
193 } |
158 } |
194 |
159 |
195 void HbIndicatorMenuContent::itemActivated(const QModelIndex &modelIndex) |
160 void HbIndicatorMenuContent::itemActivated(const QModelIndex &modelIndex) |
196 { |
161 { |
197 HbIndicatorInterface *indicator = indicatorFromIndex(modelIndex); |
162 HbIndicatorInterface *indicator = indicatorFromIndex(modelIndex); |
201 emit aboutToClose(); |
166 emit aboutToClose(); |
202 } |
167 } |
203 } |
168 } |
204 |
169 |
205 void HbIndicatorMenuContent::indicatorsActivated( |
170 void HbIndicatorMenuContent::indicatorsActivated( |
206 QList<HbIndicatorInterface*> activatedIndicators) |
171 QList<HbIndicatorInterface*> activatedIndicators) |
207 { |
172 { |
208 foreach(HbIndicatorInterface *indicator, activatedIndicators) { |
173 foreach(HbIndicatorInterface *indicator, activatedIndicators) { |
209 indicatorActivated(indicator); |
174 indicatorActivated(indicator); |
210 } |
175 } |
211 } |
176 } |
212 |
177 |
213 void HbIndicatorMenuContent::indicatorActivated( |
178 void HbIndicatorMenuContent::indicatorActivated(HbIndicatorInterface *activatedIndicator) |
214 HbIndicatorInterface *activatedIndicator) |
179 { |
215 { |
180 if (!hasMenuData(*activatedIndicator)) { |
|
181 return; |
|
182 } |
|
183 |
216 QStandardItem *item = new QStandardItem(); |
184 QStandardItem *item = new QStandardItem(); |
217 HbIndicatorInterface::Category category = activatedIndicator->category(); |
185 HbIndicatorInterface::Category category = activatedIndicator->category(); |
218 |
186 |
219 int index = (category < IndicatorTypes) ? mGroupTypeIndeces[category] |
187 int index = (category < IndicatorTypes) ? mGroupTypeIndeces[category] |
220 : indicatorModel.rowCount(); |
188 : indicatorModel.rowCount(); |
236 QObject::connect(activatedIndicator, SIGNAL(dataChanged()), |
204 QObject::connect(activatedIndicator, SIGNAL(dataChanged()), |
237 this, SLOT(indicatorUpdated())); |
205 this, SLOT(indicatorUpdated())); |
238 repolish(); |
206 repolish(); |
239 } |
207 } |
240 |
208 |
241 void HbIndicatorMenuContent::setData( |
209 void HbIndicatorMenuContent::setData(HbIndicatorInterface *source, const QModelIndex &modelIndex) |
242 HbIndicatorInterface *source, |
|
243 const QModelIndex &modelIndex) |
|
244 { |
210 { |
245 QString primaryText = source->indicatorData( |
211 QString primaryText = source->indicatorData( |
246 HbIndicatorInterface::PrimaryTextRole).toString(); |
212 HbIndicatorInterface::PrimaryTextRole).toString(); |
247 QString secondaryText = source->indicatorData( |
213 QString secondaryText = source->indicatorData( |
248 HbIndicatorInterface::SecondaryTextRole).toString(); |
214 HbIndicatorInterface::SecondaryTextRole).toString(); |
260 HbIcon icon(iconPath); |
226 HbIcon icon(iconPath); |
261 indicatorModel.setData(modelIndex, icon, Qt::DecorationRole); |
227 indicatorModel.setData(modelIndex, icon, Qt::DecorationRole); |
262 } |
228 } |
263 } |
229 } |
264 |
230 |
265 void HbIndicatorMenuContent::indicatorRemoved( |
231 void HbIndicatorMenuContent::indicatorRemoved(HbIndicatorInterface *indicatorRemoved) |
266 HbIndicatorInterface *indicatorRemoved) |
|
267 { |
232 { |
268 int index = listIndexFromIndicator(indicatorRemoved); |
233 int index = listIndexFromIndicator(indicatorRemoved); |
269 if (index >= 0) { |
234 if (index >= 0) { |
270 indicatorModel.removeRow(index); |
235 indicatorModel.removeRow(index); |
271 } |
236 } |
272 //update indices. |
237 //update indices. |
273 for(int i = indicatorRemoved->category()+1; i < IndicatorTypes;++i){ |
238 for(int i = indicatorRemoved->category()+1; i < IndicatorTypes;++i){ |
274 mGroupTypeIndeces[i]--; |
239 mGroupTypeIndeces[i]--; |
275 } |
240 } |
276 repolish(); |
241 repolish(); |
277 } |
|
278 |
|
279 void HbIndicatorMenuContent::initStyleOption( |
|
280 HbStyleOptionIndicatorMenu *option) const |
|
281 { |
|
282 HbWidget::initStyleOption(option); |
|
283 } |
242 } |
284 |
243 |
285 //data changed inside indicator. |
244 //data changed inside indicator. |
286 void HbIndicatorMenuContent::indicatorUpdated() |
245 void HbIndicatorMenuContent::indicatorUpdated() |
287 { |
246 { |
303 void HbIndicatorMenuContent::indicatorlist_scrollingEnded() |
263 void HbIndicatorMenuContent::indicatorlist_scrollingEnded() |
304 { |
264 { |
305 emit userActivityEnded(); |
265 emit userActivityEnded(); |
306 } |
266 } |
307 |
267 |
308 HbIndicatorInterface *HbIndicatorMenuContent::indicatorFromIndex( |
268 HbIndicatorInterface *HbIndicatorMenuContent::indicatorFromIndex(const QModelIndex &modelIndex) |
309 const QModelIndex &modelIndex) |
|
310 { |
269 { |
311 QObject *ind_ptr = |
270 QObject *ind_ptr = |
312 modelIndex.data(ListWidgetItemIndicatorTypeRole).value<QObject*>(); |
271 modelIndex.data(ListWidgetItemIndicatorTypeRole).value<QObject*>(); |
313 return qobject_cast<HbIndicatorInterface*>(ind_ptr); |
272 return qobject_cast<HbIndicatorInterface*>(ind_ptr); |
314 } |
273 } |
315 |
274 |
316 int HbIndicatorMenuContent::listIndexFromIndicator( |
275 int HbIndicatorMenuContent::listIndexFromIndicator(HbIndicatorInterface *indicator) |
317 HbIndicatorInterface *indicator) { |
276 { |
318 |
|
319 int index = -1; |
277 int index = -1; |
320 int rowCount = mIndicatorList->model()->rowCount(); |
278 int rowCount = mIndicatorList->model()->rowCount(); |
321 for(int i = 0; i < rowCount; ++i) { |
279 for(int i = 0; i < rowCount; ++i) { |
322 HbIndicatorInterface *itemIndicator = |
280 HbIndicatorInterface *itemIndicator = |
323 indicatorFromIndex(indicatorModel.item(i)->index()); |
281 indicatorFromIndex(indicatorModel.item(i)->index()); |