32 #include "nmhswidgetdatetimeobserver.h" |
32 #include "nmhswidgetdatetimeobserver.h" |
33 #include "emailtrace.h" |
33 #include "emailtrace.h" |
34 |
34 |
35 NmHsWidget::NmHsWidget(QGraphicsItem *parent, Qt::WindowFlags flags) |
35 NmHsWidget::NmHsWidget(QGraphicsItem *parent, Qt::WindowFlags flags) |
36 : HbWidget(parent, flags), |
36 : HbWidget(parent, flags), |
37 mEngine(0), |
37 mMainContainer(0), |
|
38 mEmptySpaceContainer(0), |
|
39 mWidgetContainer(0), |
38 mTitleRow(0), |
40 mTitleRow(0), |
|
41 mContentContainer(0), |
|
42 mNoMailsLabel(0), |
|
43 mContentLayout(0), |
|
44 mBackgroundFrameDrawer(0), |
|
45 mTranslator(0), |
|
46 mEngine(0), |
39 mAccountId(0), |
47 mAccountId(0), |
40 mAccountIconName(), |
48 mAccountIconName(), |
41 mTranslator(0), |
|
42 mBackgroundFrameDrawer(0), |
|
43 mIsExpanded(false), |
|
44 mDateObserver(0), |
49 mDateObserver(0), |
45 mNoMailsLabel(0), |
50 mIsExpanded(false) |
46 mWidgetContainer(0), |
|
47 mContentContainer(0), |
|
48 mContentLayout(0) |
|
49 { |
51 { |
50 NM_FUNCTION; |
52 NM_FUNCTION; |
51 } |
53 } |
52 |
54 |
53 /*! |
55 /*! |
82 { |
84 { |
83 NM_FUNCTION; |
85 NM_FUNCTION; |
84 |
86 |
85 QPainterPath path; |
87 QPainterPath path; |
86 path.setFillRule(Qt::WindingFill); |
88 path.setFillRule(Qt::WindingFill); |
87 |
89 if (mWidgetContainer){ |
88 path.addRect(this->rect()); |
90 //add mWidgetContainer using geometry to get |
89 if (mTitleRow){ |
91 //correct point for top-left-corner |
90 path.addPath(mTitleRow->shape()); |
92 QRectF widgetRect = mWidgetContainer->geometry(); |
91 } |
93 path.addRect(widgetRect); |
|
94 |
|
95 //then fetch shape from title row |
|
96 QPainterPath titlepath; |
|
97 titlepath.addPath(mTitleRow->shape()); |
|
98 //translate it's location to be inside mWidgetContainer |
|
99 titlepath.translate(widgetRect.topLeft()); |
|
100 //and finally add it to path |
|
101 path.addPath(titlepath); |
|
102 } |
|
103 //simplified path, i.e. only outlines |
92 return path.simplified(); |
104 return path.simplified(); |
93 } |
105 } |
94 |
106 |
95 /*! |
107 /*! |
96 \fn void NmHsWidget::onShow() |
108 \fn void NmHsWidget::onShow() |
130 |
142 |
131 bool ok(false); |
143 bool ok(false); |
132 loader.load(KNmHsWidgetDocML, &ok); |
144 loader.load(KNmHsWidgetDocML, &ok); |
133 |
145 |
134 if(ok) { |
146 if(ok) { |
135 mWidgetContainer = static_cast<HbWidget*> (loader.findWidget(KNmHsWidgetContainer)); |
147 mMainContainer = static_cast<HbWidget*> (loader.findWidget(KNmHsWidgetMainContainer)); |
|
148 mWidgetContainer = static_cast<HbWidget*> (loader.findWidget(KNmHsWidgetContainer)); |
136 mContentContainer = static_cast<HbWidget*> (loader.findWidget(KNmHsWidgetContentContainer)); |
149 mContentContainer = static_cast<HbWidget*> (loader.findWidget(KNmHsWidgetContentContainer)); |
|
150 mEmptySpaceContainer = static_cast<HbWidget*> (loader.findWidget(KNmHsWidgetEmptySpaceContainer)); |
137 mNoMailsLabel = static_cast<HbLabel*> (loader.findWidget(KNmHsWidgetNoMailsLabel)); |
151 mNoMailsLabel = static_cast<HbLabel*> (loader.findWidget(KNmHsWidgetNoMailsLabel)); |
138 if (!mWidgetContainer || !mContentContainer || !mNoMailsLabel) { |
152 if (!mMainContainer || !mWidgetContainer || !mContentContainer |
|
153 || !mEmptySpaceContainer || !mNoMailsLabel ) { |
139 //something failed in documentloader, no point to continue |
154 //something failed in documentloader, no point to continue |
140 NM_ERROR(1,"NmHsWidget::loadDocML fail @ containers or label"); |
155 NM_ERROR(1,"NmHsWidget::loadDocML fail @ containers or label"); |
141 ok = false; |
156 ok = false; |
142 } |
157 } |
143 } |
158 } |
170 //main level layout needed to control docml objects |
185 //main level layout needed to control docml objects |
171 QGraphicsLinearLayout *widgetLayout = new QGraphicsLinearLayout(Qt::Vertical); |
186 QGraphicsLinearLayout *widgetLayout = new QGraphicsLinearLayout(Qt::Vertical); |
172 widgetLayout->setContentsMargins(KNmHsWidgetContentsMargin, KNmHsWidgetContentsMargin, |
187 widgetLayout->setContentsMargins(KNmHsWidgetContentsMargin, KNmHsWidgetContentsMargin, |
173 KNmHsWidgetContentsMargin, KNmHsWidgetContentsMargin); |
188 KNmHsWidgetContentsMargin, KNmHsWidgetContentsMargin); |
174 widgetLayout->setSpacing(KNmHsWidgetContentsMargin); |
189 widgetLayout->setSpacing(KNmHsWidgetContentsMargin); |
175 widgetLayout->addItem(mWidgetContainer); |
190 widgetLayout->addItem(mMainContainer); |
176 this->setLayout(widgetLayout); |
191 this->setLayout(widgetLayout); |
177 |
192 |
178 //fetch pointer to content container layout |
193 //fetch pointer to content container layout |
179 //to be able to add/remove email rows and no mails label |
194 //to be able to add/remove email rows and no mails label |
180 mContentLayout = (QGraphicsLinearLayout*) mContentContainer->layout(); |
195 mContentLayout = (QGraphicsLinearLayout*) mContentContainer->layout(); |
191 mBackgroundFrameDrawer = new HbFrameDrawer(KNmHsWidgetBackgroundImage, |
206 mBackgroundFrameDrawer = new HbFrameDrawer(KNmHsWidgetBackgroundImage, |
192 HbFrameDrawer::NinePieces); |
207 HbFrameDrawer::NinePieces); |
193 HbFrameItem* backgroundLayoutItem = new HbFrameItem(mBackgroundFrameDrawer); |
208 HbFrameItem* backgroundLayoutItem = new HbFrameItem(mBackgroundFrameDrawer); |
194 //set to NULL to indicate that ownership transferred |
209 //set to NULL to indicate that ownership transferred |
195 mBackgroundFrameDrawer = NULL; |
210 mBackgroundFrameDrawer = NULL; |
196 setBackgroundItem(backgroundLayoutItem); |
211 mWidgetContainer->setBackgroundItem(backgroundLayoutItem); |
197 } |
212 } |
198 |
|
199 |
213 |
200 /*! |
214 /*! |
201 Initializes the widget. |
215 Initializes the widget. |
202 |
216 |
203 called by home screen fw when widget is added to home screen |
217 called by home screen fw when widget is added to home screen |
204 */ |
218 */ |
205 void NmHsWidget::onInitialize() |
219 void NmHsWidget::onInitialize() |
206 { |
220 { |
207 NM_FUNCTION; |
221 NM_FUNCTION; |
208 |
222 |
209 QT_TRY { |
223 QT_TRY { |
210 |
|
211 // Use document loader to load the contents |
224 // Use document loader to load the contents |
212 HbDocumentLoader loader; |
225 HbDocumentLoader loader; |
|
226 //setup localization before docml loading |
|
227 setupLocalization(); |
213 |
228 |
214 //load containers and mNoMailsLabel |
229 //load containers and mNoMailsLabel |
215 if (!loadDocML(loader)) { |
230 if (!loadDocML(loader)) { |
216 NM_ERROR(1,"NmHsWidget::onInitialize Fail @ loader"); |
231 NM_ERROR(1,"NmHsWidget::onInitialize Fail @ loader"); |
217 emit error(); //failure, no point to continue |
232 emit error(); //failure, no point to continue |
226 emit error(); //failure, no point to continue |
241 emit error(); //failure, no point to continue |
227 return; |
242 return; |
228 } |
243 } |
229 |
244 |
230 setupUi(); |
245 setupUi(); |
231 setupLocalization(); |
|
232 |
246 |
233 //Engine construction is 2 phased. |
247 //Engine construction is 2 phased. |
234 mEngine = new NmHsWidgetEmailEngine(mAccountId); |
248 mEngine = new NmHsWidgetEmailEngine(mAccountId); |
235 //Client must connect to exception signals before calling the initialize function |
249 //Client must connect to exception signals before calling the initialize function |
236 //because we don't want to miss any signals. |
250 //because we don't want to miss any signals. |
272 connect(mTitleRow, SIGNAL( mailboxLaunchTriggered() ) |
285 connect(mTitleRow, SIGNAL( mailboxLaunchTriggered() ) |
273 ,mEngine, SLOT( launchMailAppInboxView() ) ); |
286 ,mEngine, SLOT( launchMailAppInboxView() ) ); |
274 connect(mTitleRow, SIGNAL( expandCollapseButtonPressed() ) |
287 connect(mTitleRow, SIGNAL( expandCollapseButtonPressed() ) |
275 ,this, SLOT( handleExpandCollapseEvent() ) ); |
288 ,this, SLOT( handleExpandCollapseEvent() ) ); |
276 |
289 |
277 setMinimumSize(mTitleRow->minimumSize()); |
290 setMinimumSize(mTitleRow->minimumWidth(), |
|
291 mEmptySpaceContainer->minimumHeight() + mTitleRow->minimumHeight()); |
278 } |
292 } |
279 QT_CATCH(...) { |
293 QT_CATCH(...) { |
280 NM_ERROR(1,"NmHsWidget::onInitialize fail @ catch"); |
294 NM_ERROR(1,"NmHsWidget::onInitialize fail @ catch"); |
281 emit error(); |
295 emit error(); |
282 } |
296 } |
283 } |
297 } |
284 |
|
285 |
298 |
286 /*! |
299 /*! |
287 updateMailData slot |
300 updateMailData slot |
288 */ |
301 */ |
289 void NmHsWidget::updateMailData() |
302 void NmHsWidget::updateMailData() |
469 mContentContainer->setVisible(false); |
482 mContentContainer->setVisible(false); |
470 mContentContainer->setMaximumHeight(0); |
483 mContentContainer->setMaximumHeight(0); |
471 } |
484 } |
472 |
485 |
473 //resize the widget to new layout size |
486 //resize the widget to new layout size |
474 qreal totalHeight = mTitleRow->preferredHeight() + mContentContainer->maximumHeight(); |
487 qreal totalHeight = mEmptySpaceContainer->preferredHeight() + mTitleRow->containerHeight() + mContentContainer->maximumHeight(); |
475 //set maximum size, otherwise widget will stay huge also when collapsed |
488 //set maximum sizes, otherwise widget will stay huge also when collapsed |
476 this->setMaximumHeight(totalHeight); |
489 setMaximumHeight(totalHeight); |
|
490 mMainContainer->setMaximumHeight(totalHeight); |
|
491 mWidgetContainer->setMaximumHeight(totalHeight - mEmptySpaceContainer->preferredHeight()); |
477 //resize here or widget cannot draw mail rows when expanding |
492 //resize here or widget cannot draw mail rows when expanding |
478 this->resize(mTitleRow->preferredWidth(), totalHeight); |
493 resize(mTitleRow->maximumWidth(), totalHeight); |
|
494 mMainContainer->resize(mTitleRow->maximumWidth(), totalHeight); |
|
495 mWidgetContainer->resize(mTitleRow->maximumWidth(), totalHeight - mEmptySpaceContainer->preferredHeight()); |
479 |
496 |
480 updateMailRowsVisibility(mailCount); |
497 updateMailRowsVisibility(mailCount); |
481 } |
498 } |
482 |
499 |
483 /*! |
500 /*! |