90 Hb::WindowFlagNoBackground flag is set for the HbMainWindow. Normally the |
91 Hb::WindowFlagNoBackground flag is set for the HbMainWindow. Normally the |
91 standard background item fills the entire screen so the background is not |
92 standard background item fills the entire screen so the background is not |
92 really visible. |
93 really visible. |
93 |
94 |
94 HbMainWindow has a signalling mechanism for helping control the |
95 HbMainWindow has a signalling mechanism for helping control the |
95 application's view construction. viewReady()-signal is emitted |
96 application's view construction. The viewReady() signal is emitted when a |
96 when view's internal construction is completed and basic parts of |
97 view's internal construction is completed and basic parts of view are |
97 view are already drawn. Same signal is also emitted when current |
98 already drawn. Same signal is also emitted when current view has |
98 view is switched. This helps applications to split the view |
99 changed. This helps applications to split the view construction to |
99 construction to reasonable tasks. For example the lower priority |
100 reasonable tasks. For example the lower priority tasks like opening network |
100 tasks like opening network connection or preparing other currently |
101 connection or preparing other currently hidden application views can happen |
101 hidden application views can happen on background when first view |
102 on background when first view is already drawn. |
102 is already drawn. |
|
103 |
103 |
104 Example of simple Hb application constructing HbMainWindow: |
104 Example of simple Hb application constructing HbMainWindow: |
105 |
105 |
106 \include mainwindow1/main.cpp |
106 \include mainwindow1/main.cpp |
107 |
107 |
169 /*! |
169 /*! |
170 \fn void HbMainWindow::viewReady() |
170 \fn void HbMainWindow::viewReady() |
171 |
171 |
172 This signal is emitted first time when window content is drawn on screen. |
172 This signal is emitted first time when window content is drawn on screen. |
173 It will only be emitted again when current view is changed and drawn on screen. |
173 It will only be emitted again when current view is changed and drawn on screen. |
|
174 |
|
175 This means that this signal is emitted in the following cases: |
|
176 |
|
177 - When the mainwindow is fully constructed, this happens shortly after |
|
178 painting it for the first time. |
|
179 |
|
180 - When a new view is added using addView() or insertView() after the |
|
181 mainwindow is fully constructed and the newly added view becomes the |
|
182 current view. It will not be emitted when calling addView() or |
|
183 insertView() before showing the mainwindow or entering the event loop |
|
184 because in that case the signal will anyway be emitted later, when the |
|
185 mainwindow becomes ready. It is also not emitted when the newly added view |
|
186 does not become the current view. |
|
187 |
|
188 - When the current view is changed using setCurrentView(). |
174 |
189 |
175 If the view switch is animated, the signal is emitted only after the effect has |
190 If the view switch is animated, the signal is emitted only after the effect has |
176 completed. |
191 completed. |
177 |
192 |
178 Application developers may connect to this signal to do lower priority construction |
193 Application developers may connect to this signal to do lower priority construction |
211 { |
226 { |
212 Q_D(HbMainWindow); |
227 Q_D(HbMainWindow); |
213 d->q_ptr = this; |
228 d->q_ptr = this; |
214 |
229 |
215 // No need for any default (e.g. blank white) background for this window. |
230 // No need for any default (e.g. blank white) background for this window. |
216 // Setting this attribute is mandatory in order to have a flicker-less |
|
217 // startup (both with and without splash screen). |
|
218 setAttribute(Qt::WA_NoSystemBackground); |
231 setAttribute(Qt::WA_NoSystemBackground); |
219 |
232 |
220 // Continue with basic initialization. Note: Prefer doing everything that is |
233 // Continue with basic initialization. Note: Prefer doing everything that is |
221 // not absolutely compulsory in _q_delayedConstruction instead. |
234 // not absolutely compulsory in _q_delayedConstruction instead. |
222 |
235 |
406 d->mViewStackWidget->removeAt(index); |
419 d->mViewStackWidget->removeAt(index); |
407 } |
420 } |
408 |
421 |
409 d->mViewStackWidget->insertWidget(-1, view); |
422 d->mViewStackWidget->insertWidget(-1, view); |
410 |
423 |
|
424 // If the newly added view becomes the current one then emit the viewReady |
|
425 // signal (unless the delayed construction is still pending). |
|
426 if (d->mDelayedConstructionHandled && currentView() == view) { |
|
427 QMetaObject::invokeMethod(this, "_q_viewReady", Qt::QueuedConnection); |
|
428 } |
|
429 |
411 return view; |
430 return view; |
412 } |
431 } |
413 |
432 |
414 /*! |
433 /*! |
415 Inserts a \a widget to a given \a index to the HbMainWindow object. |
434 Inserts a \a widget to a given \a index to the HbMainWindow object. |
434 if (!view) { |
453 if (!view) { |
435 view = new HbView(); |
454 view = new HbView(); |
436 view->setWidget(widget); |
455 view->setWidget(widget); |
437 } |
456 } |
438 } |
457 } |
|
458 |
439 d->mViewStackWidget->insertWidget(index, view); |
459 d->mViewStackWidget->insertWidget(index, view); |
|
460 |
|
461 // If the newly inserted view becomes the current one then emit the |
|
462 // viewReady signal (unless the delayed construction is still pending). |
|
463 if (d->mDelayedConstructionHandled && currentView() == view) { |
|
464 QMetaObject::invokeMethod(this, "_q_viewReady", Qt::QueuedConnection); |
|
465 } |
440 |
466 |
441 return view; |
467 return view; |
442 } |
468 } |
443 |
469 |
444 /*! |
470 /*! |
532 d->mViewStackWidget->runViewSwitchEffectHide(oldView, flags); |
558 d->mViewStackWidget->runViewSwitchEffectHide(oldView, flags); |
533 } else { |
559 } else { |
534 // If animation is disabled or there is no view set currently then change |
560 // If animation is disabled or there is no view set currently then change |
535 // without animation. |
561 // without animation. |
536 d->mViewStackWidget->setCurrentWidget(view); |
562 d->mViewStackWidget->setCurrentWidget(view); |
537 if (d->mDelayedConstructionHandled) |
563 if (d->mDelayedConstructionHandled) { |
538 QMetaObject::invokeMethod(this, "_q_viewReady", Qt::QueuedConnection); |
564 QMetaObject::invokeMethod(this, "_q_viewReady", Qt::QueuedConnection); |
|
565 } |
539 } |
566 } |
540 } |
567 } |
541 } |
568 } |
542 |
569 |
543 /*! |
570 /*! |
694 */ |
721 */ |
695 QString HbMainWindow::backgroundImageName(Qt::Orientation orientation) const |
722 QString HbMainWindow::backgroundImageName(Qt::Orientation orientation) const |
696 { |
723 { |
697 Q_D(const HbMainWindow); |
724 Q_D(const HbMainWindow); |
698 return d->mBgItem ? d->mBgItem->imageName(orientation) : QString(); |
725 return d->mBgItem ? d->mBgItem->imageName(orientation) : QString(); |
|
726 } |
|
727 |
|
728 /*! |
|
729 Sets the background image drawing mode. This setting controls how |
|
730 the background image is displayed. |
|
731 |
|
732 By default the mode is set to Hb::ScaleBackgroundToFit. |
|
733 |
|
734 \sa backgroundImageMode() |
|
735 \sa Hb::BackgroundImageMode |
|
736 */ |
|
737 void HbMainWindow::setBackgroundImageMode(Hb::BackgroundImageMode mode) |
|
738 { |
|
739 Q_D(HbMainWindow); |
|
740 if (d->mBgItem) { |
|
741 d->mBgItem->setImageMode(mode); |
|
742 } |
|
743 } |
|
744 |
|
745 /*! |
|
746 Returns the currently set background image drawing mode. |
|
747 |
|
748 \sa setBackgroundImageMode() |
|
749 \sa Hb::BackgroundImageMode |
|
750 */ |
|
751 Hb::BackgroundImageMode HbMainWindow::backgroundImageMode() const |
|
752 { |
|
753 Q_D(const HbMainWindow); |
|
754 return d->mBgItem ? d->mBgItem->imageMode() : Hb::ScaleBackgroundToFit; |
699 } |
755 } |
700 |
756 |
701 /*! |
757 /*! |
702 Sets the animations enabled when the orientation is changed automatically. |
758 Sets the animations enabled when the orientation is changed automatically. |
703 By default animations are enabled. |
759 By default animations are enabled. |
855 d->mTheTestUtility = new HbTheTestUtility(this); |
911 d->mTheTestUtility = new HbTheTestUtility(this); |
856 } |
912 } |
857 } |
913 } |
858 // get rid of the splash screen widget (it is not visible to the user anyway at this point) |
914 // get rid of the splash screen widget (it is not visible to the user anyway at this point) |
859 HbSplashScreen::destroy(); |
915 HbSplashScreen::destroy(); |
|
916 #ifdef Q_OS_SYMBIAN |
|
917 // disable surface transparency unless we were really asked to be transparent |
|
918 if (!testAttribute(Qt::WA_TranslucentBackground)) { |
|
919 RWindow *const window = static_cast<RWindow *>(effectiveWinId()->DrawableWindow()); |
|
920 window->SetSurfaceTransparency(false); |
|
921 } |
|
922 #endif |
860 } |
923 } |
861 // Notify that mainwindow is (most probably) ready. |
924 // Notify that mainwindow is (most probably) ready. |
862 // The signal must be emitted always, even when there was no need to do anything. |
925 // The signal must be emitted always, even when there was no need to do anything. |
863 emit d->idleEventDispatched(); |
926 emit d->idleEventDispatched(); |
864 } else if(event->type() == HbMainWindowPrivate::IdleOrientationEvent) { // complete the orientation change effect chain |
927 } else if(event->type() == HbMainWindowPrivate::IdleOrientationEvent) { // complete the orientation change effect chain |
913 } |
976 } |
914 |
977 |
915 QGraphicsView::paintEvent(event); |
978 QGraphicsView::paintEvent(event); |
916 } |
979 } |
917 |
980 |
|
981 void HbMainWindow::showEvent(QShowEvent *event) |
|
982 { |
|
983 #ifdef Q_OS_SYMBIAN |
|
984 // Enable surface transparency if QWidget did not do it already. This is a |
|
985 // workaround for having non-transparent surfaces filled automatically with |
|
986 // black color. The showEvent is a suitable place because the native control |
|
987 // is already created at this point, but it is not too late either. |
|
988 if (!testAttribute(Qt::WA_TranslucentBackground)) { |
|
989 RWindow *const window = static_cast<RWindow *>(effectiveWinId()->DrawableWindow()); |
|
990 window->SetSurfaceTransparency(true); |
|
991 } |
|
992 #endif |
|
993 QGraphicsView::showEvent(event); |
|
994 } |
|
995 |
918 /*! |
996 /*! |
919 Reimplemented from QAbstractScrollArea::scrollContentsBy(). |
997 Reimplemented from QAbstractScrollArea::scrollContentsBy(). |
920 */ |
998 */ |
921 void HbMainWindow::scrollContentsBy(int dx, int dy) |
999 void HbMainWindow::scrollContentsBy(int dx, int dy) |
922 { |
1000 { |