111 { |
114 { |
112 NM_FUNCTION; |
115 NM_FUNCTION; |
113 if (mEngine) { |
116 if (mEngine) { |
114 mEngine->suspend(); |
117 mEngine->suspend(); |
115 } |
118 } |
|
119 } |
|
120 |
|
121 /*! |
|
122 \fn bool NmHsWidget::loadDocML(HbDocumentLoader &loader) |
|
123 |
|
124 loads layout data and child items from docml file. Must be called after constructor. |
|
125 /return true if loading succeeded, otherwise false. False indicates that object is unusable |
|
126 */ |
|
127 bool NmHsWidget::loadDocML(HbDocumentLoader &loader) |
|
128 { |
|
129 NM_FUNCTION; |
|
130 |
|
131 bool ok(false); |
|
132 loader.load(KNmHsWidgetDocML, &ok); |
|
133 |
|
134 if(ok) { |
|
135 mWidgetContainer = static_cast<HbWidget*> (loader.findWidget(KNmHsWidgetContainer)); |
|
136 mContentContainer = static_cast<HbWidget*> (loader.findWidget(KNmHsWidgetContentContainer)); |
|
137 mNoMailsLabel = static_cast<HbLabel*> (loader.findWidget(KNmHsWidgetNoMailsLabel)); |
|
138 if (!mWidgetContainer || !mContentContainer || !mNoMailsLabel) { |
|
139 //something failed in documentloader, no point to continue |
|
140 NM_ERROR(1,"NmHsWidget::loadDocML fail @ containers or label"); |
|
141 ok = false; |
|
142 } |
|
143 } |
|
144 return ok; |
116 } |
145 } |
117 |
146 |
118 /*! |
147 /*! |
119 Initializes Localization. |
148 Initializes Localization. |
120 /post mTranslator constructed & localization file loaded |
149 /post mTranslator constructed & localization file loaded |
136 */ |
165 */ |
137 void NmHsWidget::setupUi() |
166 void NmHsWidget::setupUi() |
138 { |
167 { |
139 NM_FUNCTION; |
168 NM_FUNCTION; |
140 |
169 |
141 setContentsMargins(KNmHsWidgetContentsMargin, KNmHsWidgetContentsMargin, |
170 //main level layout needed to control docml objects |
142 KNmHsWidgetContentsMargin, KNmHsWidgetContentsMargin); |
171 QGraphicsLinearLayout *widgetLayout = new QGraphicsLinearLayout(Qt::Vertical); |
143 |
172 widgetLayout->setContentsMargins(KNmHsWidgetContentsMargin, KNmHsWidgetContentsMargin, |
144 //Setup layout |
173 KNmHsWidgetContentsMargin, KNmHsWidgetContentsMargin); |
145 mRowLayout = new QGraphicsLinearLayout(Qt::Vertical); |
174 widgetLayout->setSpacing(KNmHsWidgetContentsMargin); |
146 |
175 widgetLayout->addItem(mWidgetContainer); |
147 mRowLayout->setContentsMargins(KNmHsWidgetContentsMargin, KNmHsWidgetContentsMargin, |
176 this->setLayout(widgetLayout); |
148 KNmHsWidgetContentsMargin, KNmHsWidgetContentsMargin); |
177 |
149 mRowLayout->setSpacing(KNmHsWidgetContentsMargin); |
178 //fetch pointer to content container layout |
150 setLayout(mRowLayout); |
179 //to be able to add/remove email rows and no mails label |
151 |
180 mContentLayout = (QGraphicsLinearLayout*) mContentContainer->layout(); |
152 //background |
181 |
|
182 //set noMailsLabel properties not supported by doc loader |
|
183 QColor newFontColor; |
|
184 newFontColor = HbColorScheme::color("qtc_hs_list_item_content_normal"); |
|
185 mNoMailsLabel->setTextColor(newFontColor); |
|
186 mNoMailsLabel->setVisible(true); |
|
187 |
|
188 mContentLayout->removeItem(mNoMailsLabel); |
|
189 |
|
190 //widget background |
153 mBackgroundFrameDrawer = new HbFrameDrawer(KNmHsWidgetBackgroundImage, |
191 mBackgroundFrameDrawer = new HbFrameDrawer(KNmHsWidgetBackgroundImage, |
154 HbFrameDrawer::NinePieces); |
192 HbFrameDrawer::NinePieces); |
155 HbFrameItem* backgroundLayoutItem = new HbFrameItem(mBackgroundFrameDrawer); |
193 HbFrameItem* backgroundLayoutItem = new HbFrameItem(mBackgroundFrameDrawer); |
156 //set to NULL to indicate that ownership transferred |
194 //set to NULL to indicate that ownership transferred |
157 mBackgroundFrameDrawer = NULL; |
195 mBackgroundFrameDrawer = NULL; |
158 setBackgroundItem(backgroundLayoutItem); |
196 setBackgroundItem(backgroundLayoutItem); |
159 |
197 } |
160 //Create NoMails Label. |
198 |
161 mNoMailsLabel = new HbLabel(this); |
|
162 mNoMailsLabel->setPlainText(hbTrId("txt_mail_widget_info_no_messages")); |
|
163 HbFontSpec fontSpec(HbFontSpec::Secondary); |
|
164 HbStyle style; |
|
165 qreal size; |
|
166 bool found = style.parameter(QString("hb-param-text-height-tiny"), size); |
|
167 if (found) { |
|
168 fontSpec.setTextHeight(size); |
|
169 } |
|
170 mNoMailsLabel->setFontSpec(fontSpec); |
|
171 QColor newFontColor; |
|
172 newFontColor = HbColorScheme::color("qtc_hs_list_item_content_normal"); |
|
173 mNoMailsLabel->setTextColor(newFontColor); |
|
174 mNoMailsLabel->setAlignment(Qt::AlignCenter); |
|
175 mNoMailsLabel->setVisible(false); |
|
176 |
|
177 } |
|
178 |
199 |
179 /*! |
200 /*! |
180 Initializes the widget. |
201 Initializes the widget. |
181 |
202 |
182 called by home screen fw when widget is added to home screen |
203 called by home screen fw when widget is added to home screen |
184 void NmHsWidget::onInitialize() |
205 void NmHsWidget::onInitialize() |
185 { |
206 { |
186 NM_FUNCTION; |
207 NM_FUNCTION; |
187 |
208 |
188 QT_TRY { |
209 QT_TRY { |
|
210 |
|
211 // Use document loader to load the contents |
|
212 HbDocumentLoader loader; |
|
213 |
|
214 //load containers and mNoMailsLabel |
|
215 if (!loadDocML(loader)) { |
|
216 NM_ERROR(1,"NmHsWidget::onInitialize Fail @ loader"); |
|
217 emit error(); //failure, no point to continue |
|
218 return; |
|
219 } |
|
220 |
|
221 //construct title row |
|
222 mTitleRow = new NmHsWidgetTitleRow(this); |
|
223 if (!mTitleRow->setupUI(loader)) { |
|
224 //title row creation failed |
|
225 NM_ERROR(1,"NmHsWidget::onInitialize fail @ titlerow"); |
|
226 emit error(); //failure, no point to continue |
|
227 return; |
|
228 } |
|
229 |
189 setupUi(); |
230 setupUi(); |
190 setupLocalization(); |
231 setupLocalization(); |
191 |
232 |
192 //Engine construction is 2 phased. |
233 //Engine construction is 2 phased. |
193 mEngine = new NmHsWidgetEmailEngine(mAccountId); |
234 mEngine = new NmHsWidgetEmailEngine(mAccountId); |
195 //because we don't want to miss any signals. |
236 //because we don't want to miss any signals. |
196 connect(mEngine, SIGNAL( exceptionOccured(const int&) ), this, |
237 connect(mEngine, SIGNAL( exceptionOccured(const int&) ), this, |
197 SLOT( onEngineException(const int&) )); |
238 SLOT( onEngineException(const int&) )); |
198 if (!mEngine->initialize()) { |
239 if (!mEngine->initialize()) { |
199 //engine construction failed. Give up. |
240 //engine construction failed. Give up. |
|
241 NM_ERROR(1,"NmHsWidget::onInitialize fail @ engine"); |
200 emit error(); |
242 emit error(); |
201 return; |
243 return; |
202 } |
244 } |
203 |
245 |
204 //construct and load docml for title row |
246 |
205 mTitleRow = new NmHsWidgetTitleRow(this); |
|
206 if (!mTitleRow->setupUI()) { |
|
207 //if docml loading fails no point to proceed |
|
208 emit error(); |
|
209 return; |
|
210 } |
|
211 mRowLayout->addItem(mTitleRow); |
|
212 mTitleRow->updateAccountName(mEngine->accountName()); |
247 mTitleRow->updateAccountName(mEngine->accountName()); |
213 |
248 |
214 //create observer for date/time change events |
249 //create observer for date/time change events |
215 mDateObserver = new NmHsWidgetDateTimeObserver(); |
250 mDateObserver = new NmHsWidgetDateTimeObserver(); |
216 |
251 |
236 //Get signals about user actions |
271 //Get signals about user actions |
237 connect(mTitleRow, SIGNAL( mailboxLaunchTriggered() ) |
272 connect(mTitleRow, SIGNAL( mailboxLaunchTriggered() ) |
238 ,mEngine, SLOT( launchMailAppInboxView() ) ); |
273 ,mEngine, SLOT( launchMailAppInboxView() ) ); |
239 connect(mTitleRow, SIGNAL( expandCollapseButtonPressed() ) |
274 connect(mTitleRow, SIGNAL( expandCollapseButtonPressed() ) |
240 ,this, SLOT( handleExpandCollapseEvent() ) ); |
275 ,this, SLOT( handleExpandCollapseEvent() ) ); |
241 |
276 |
|
277 setMinimumSize(mTitleRow->minimumSize()); |
242 } |
278 } |
243 QT_CATCH(...) { |
279 QT_CATCH(...) { |
|
280 NM_ERROR(1,"NmHsWidget::onInitialize fail @ catch"); |
244 emit error(); |
281 emit error(); |
245 } |
282 } |
246 |
|
247 } |
283 } |
248 |
284 |
249 |
285 |
250 /*! |
286 /*! |
251 updateMailData slot |
287 updateMailData slot |
422 } |
464 } |
423 } |
465 } |
424 else { |
466 else { |
425 removeNoMailsLabelFromLayout(); |
467 removeNoMailsLabelFromLayout(); |
426 removeEmailRowsFromLayout(); |
468 removeEmailRowsFromLayout(); |
|
469 mContentContainer->setVisible(false); |
|
470 mContentContainer->setMaximumHeight(0); |
427 } |
471 } |
428 |
472 |
429 //resize the widget to new layout size |
473 //resize the widget to new layout size |
430 setPreferredSize(mRowLayout->preferredSize()); |
474 qreal totalHeight = mTitleRow->preferredHeight() + mContentContainer->maximumHeight(); |
|
475 //set maximum size, otherwise widget will stay huge also when collapsed |
|
476 this->setMaximumHeight(totalHeight); |
|
477 //resize here or widget cannot draw mail rows when expanding |
|
478 this->resize(mTitleRow->preferredWidth(), totalHeight); |
431 |
479 |
432 updateMailRowsVisibility(mailCount); |
480 updateMailRowsVisibility(mailCount); |
433 } |
481 } |
434 |
482 |
435 /*! |
483 /*! |
436 Updates mNoMailsLabel visibility based on widget state |
484 Updates mNoMailsLabel visibility based on widget state |
437 /param mailCount defines how many mail rows is needed |
485 /param mailCount defines how many mail rows is needed |
438 /post if mail count is 0 and mIsExpanded equals true, then |
486 /post if mail count is 0 and mIsExpanded equals true, then |
439 the mNoMailLabel is added to the mRowLayout. |
487 the mNoMailLabel is added to the mContentLayout. |
440 */ |
488 */ |
441 void NmHsWidget::addNoMailsLabelToLayout() |
489 void NmHsWidget::addNoMailsLabelToLayout() |
442 { |
490 { |
443 NM_FUNCTION; |
491 NM_FUNCTION; |
444 //Use sizes defined for titlerow and mailrow docml to indentify the correct size |
492 |
445 //for the mNoMailslabel |
|
446 if (mNoMailsLabel->isVisible() || mMailRows.isEmpty()) { |
493 if (mNoMailsLabel->isVisible() || mMailRows.isEmpty()) { |
447 return; |
494 return; |
448 } |
495 } |
449 QSizeF mailLabelSize(mTitleRow->maximumWidth(), KMaxNumberOfMailsShown |
|
450 * mMailRows.first()->maximumHeight()); |
|
451 mNoMailsLabel->setPreferredSize(mailLabelSize); |
|
452 mNoMailsLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); |
|
453 //Add mNoMailsLabel to layout if not yet there and show it |
496 //Add mNoMailsLabel to layout if not yet there and show it |
454 mRowLayout->addItem(mNoMailsLabel); |
497 mContentLayout->addItem(mNoMailsLabel); |
455 //resize the widget to new layout size |
498 //resize the widget to new layout size |
456 mNoMailsLabel->show(); |
499 mNoMailsLabel->show(); |
457 } |
500 } |
458 |
501 |
459 /*! |
502 /*! |
460 removeNoMailsLabelFromLayout removes mNoMailsLabel from the layout |
503 removeNoMailsLabelFromLayout removes mNoMailsLabel from the layout |
461 /post mNoMailsLabel is not in mRowLayout |
504 /post mNoMailsLabel is not in mContentLayout |
462 */ |
505 */ |
463 void NmHsWidget::removeNoMailsLabelFromLayout() |
506 void NmHsWidget::removeNoMailsLabelFromLayout() |
464 { |
507 { |
465 NM_FUNCTION; |
508 NM_FUNCTION; |
466 //remove mNoMailsLabel from Layout and hide it |
509 //remove mNoMailsLabel from Layout and hide it |
467 mRowLayout->removeItem(mNoMailsLabel); |
510 mContentLayout->removeItem(mNoMailsLabel); |
468 mNoMailsLabel->hide(); |
511 mNoMailsLabel->hide(); |
469 } |
512 } |
470 |
513 |
471 /*! |
514 /*! |
472 addEmailRowsToLayout adds every emailrow to the layout |
515 addEmailRowsToLayout adds every emailrow to the layout |
473 /post all elements in mMailRows are added to mRowLayout |
516 /post all elements in mMailRows are added to mContentLayout |
474 */ |
517 */ |
475 void NmHsWidget::addEmailRowsToLayout() |
518 void NmHsWidget::addEmailRowsToLayout() |
476 { |
519 { |
477 NM_FUNCTION; |
520 NM_FUNCTION; |
478 foreach(NmHsWidgetEmailRow *row, mMailRows) |
521 foreach(NmHsWidgetEmailRow *row, mMailRows) |
479 { |
522 { |
480 mRowLayout->addItem(row); |
523 mContentLayout->addItem(row); |
481 } |
524 } |
482 } |
525 } |
483 |
526 |
484 /*! |
527 /*! |
485 removeEmailRowsFromLayout removes every emailrow from the layout |
528 removeEmailRowsFromLayout removes every emailrow from the layout |
486 /post none of the elements in mMailRows are in mRowLayout |
529 /post none of the elements in mMailRows are in mContentLayout |
487 */ |
530 */ |
488 void NmHsWidget::removeEmailRowsFromLayout() |
531 void NmHsWidget::removeEmailRowsFromLayout() |
489 { |
532 { |
490 NM_FUNCTION; |
533 NM_FUNCTION; |
491 foreach(NmHsWidgetEmailRow *row, mMailRows) |
534 foreach(NmHsWidgetEmailRow *row, mMailRows) |
492 { |
535 { |
493 mRowLayout->removeItem(row); |
536 mContentLayout->removeItem(row); |
494 } |
537 } |
495 } |
538 } |
496 |
539 |
497 /*! |
540 /*! |
498 Updates mail row visibilities in static widget |
541 Updates mail row visibilities in static widget |