54 #include "hbeffectinternal_p.h" |
54 #include "hbeffectinternal_p.h" |
55 #endif |
55 #endif |
56 #include "hbthetestutility_p.h" |
56 #include "hbthetestutility_p.h" |
57 #include "hbglobal_p.h" |
57 #include "hbglobal_p.h" |
58 #include "hbevent.h" |
58 #include "hbevent.h" |
59 #include "hbsplashscreen_p.h" |
59 #include "hbsplashscreen.h" |
60 #include "hbcontentwidget_p.h" |
60 #include "hbcontentwidget_p.h" |
61 #include "hbscreen_p.h" |
61 #include "hbscreen_p.h" |
62 #include "hbmainwindoworientation_p.h" |
62 #include "hbmainwindoworientation_p.h" |
63 #include "hbfeaturemanager_p.h" |
63 #include "hbfeaturemanager_p.h" |
64 |
64 |
127 */ |
127 */ |
128 |
128 |
129 /*! |
129 /*! |
130 \fn void HbMainWindow::aboutToChangeOrientation(Qt::Orientation newOrientation, bool animated) |
130 \fn void HbMainWindow::aboutToChangeOrientation(Qt::Orientation newOrientation, bool animated) |
131 |
131 |
132 This signal is emitted when the orientation change starts. This version of aboutToChangeOrientation also includes the information |
132 This signal is emitted when the orientation change starts. This version of |
133 about the new orientation and whether the orientation change is animated or not. |
133 aboutToChangeOrientation also includes the information about the new |
134 This can be used for example by widgets who want to participate in the orientation change animation. |
134 orientation and whether the orientation change is animated or not. This can |
|
135 be used for example by widgets who want to participate in the orientation |
|
136 change animation. |
135 */ |
137 */ |
136 |
138 |
137 /*! |
139 /*! |
138 \fn void HbMainWindow::orientationChanged() |
140 \fn void HbMainWindow::orientationChanged() |
139 |
141 |
148 |
150 |
149 This signal is emitted when the current view index changes. |
151 This signal is emitted when the current view index changes. |
150 */ |
152 */ |
151 |
153 |
152 /*! |
154 /*! |
|
155 \fn void HbMainWindow::aboutToChangeView(HbView *oldView, HbView *newView) |
|
156 |
|
157 This signal is emitted before starting a view change. Note that it is only |
|
158 emitted when there is a real view change (i.e. when setCurrentView() is |
|
159 used), it will not be emitted when views are added to the main window via |
|
160 addView(). |
|
161 |
|
162 It is guaranteed that this signal is emitted before starting any view switch |
|
163 animation. |
|
164 */ |
|
165 |
|
166 /*! |
153 \fn void HbMainWindow::currentViewChanged(HbView *view) |
167 \fn void HbMainWindow::currentViewChanged(HbView *view) |
154 |
168 |
155 This signal is emitted when the current view changes. |
169 This signal is emitted when the current view changes. Do not make assumptions about |
|
170 the exact timing of this signal, it may be emitted at any time during the view switch |
|
171 (this is relevant if the view switch is animated, i.e. it is not guaranteed that the |
|
172 signal will be emitted at the end of the animation, in fact it is usually emitted |
|
173 already when the animation starts). |
|
174 |
|
175 \sa aboutToChangeView() |
|
176 \sa viewReady() |
156 */ |
177 */ |
157 |
178 |
158 /*! |
179 /*! |
159 \fn void HbMainWindow::viewReady() |
180 \fn void HbMainWindow::viewReady() |
160 |
181 |
161 This signal is emitted first time when window content is drawn on screen. |
182 This signal is emitted first time when window content is drawn on screen. |
162 It will only be emitted again when current view is changed and drawn on screen. |
183 It will only be emitted again when current view is changed and drawn on screen. |
163 |
184 |
164 If applicationlaunch or current view is switched with effect, signal is |
185 If the view switch is animated, the signal is emitted only after the effect has |
165 emitted after the effect has completed. |
186 completed. |
166 |
187 |
167 Application developers may connect to this signal to do lower priority construction tasks. When |
188 Application developers may connect to this signal to do lower priority construction |
168 thinking about the tasks, it's important to keep the UI responsive all the time. |
189 tasks. Note however that when thinking about the tasks, it is important to keep the UI |
|
190 responsive all the time. |
169 */ |
191 */ |
170 |
192 |
171 /*! |
193 /*! |
172 \class HbRootItem |
194 \class HbRootItem |
173 |
195 |
232 d->mAutomaticOrientationSwitch = false; |
254 d->mAutomaticOrientationSwitch = false; |
233 } else if (windowFlags & Hb::WindowFlagFixedHorizontal) { |
255 } else if (windowFlags & Hb::WindowFlagFixedHorizontal) { |
234 HbMainWindowOrientation::instance()->setFixedOrientation(Qt::Horizontal); |
256 HbMainWindowOrientation::instance()->setFixedOrientation(Qt::Horizontal); |
235 d->mOrientation = Qt::Horizontal; |
257 d->mOrientation = Qt::Horizontal; |
236 d->mAutomaticOrientationSwitch = false; |
258 d->mAutomaticOrientationSwitch = false; |
237 } else { |
259 } else if (HbMainWindowOrientation::instance()->isEnabled()) { |
238 d->mOrientation = HbMainWindowOrientation::instance()->sensorOrientation(); |
260 d->mOrientation = HbMainWindowOrientation::instance()->sensorOrientation(); |
239 d->mAutomaticOrientationSwitch = true; |
261 d->mAutomaticOrientationSwitch = true; |
|
262 } else { |
|
263 d->mOrientation = d->mDefaultOrientation; |
|
264 d->mAutomaticOrientationSwitch = false; |
240 } |
265 } |
241 |
266 |
242 #if defined(Q_WS_S60) || defined(HB_Q_WS_MAEMO) |
267 #if defined(Q_WS_S60) || defined(HB_Q_WS_MAEMO) |
243 setWindowState(Qt::WindowFullScreen); |
268 setWindowState(Qt::WindowFullScreen); |
244 #endif//Q_WS_S60 |
269 #endif//Q_WS_S60 |
290 // At this point the mainwindow is considered more or less fully constructed. |
315 // At this point the mainwindow is considered more or less fully constructed. |
291 HbInstancePrivate::d_ptr()->addWindow(this); |
316 HbInstancePrivate::d_ptr()->addWindow(this); |
292 |
317 |
293 QRectF rect(0,0,pSize.width(),pSize.height()); |
318 QRectF rect(0,0,pSize.width(),pSize.height()); |
294 resize(pSize); |
319 resize(pSize); |
|
320 d->mLayoutRect = rect; |
295 d->mRootItem->setGeometry(rect); |
321 d->mRootItem->setGeometry(rect); |
296 d->mClippingItem->setGeometry(rect); |
322 d->mClippingItem->setGeometry(rect); |
297 |
323 |
298 setSceneRect(0, 0, pSize.width(), pSize.height()); |
324 setSceneRect(0, 0, pSize.width(), pSize.height()); |
299 |
325 |
300 setTransformationAnchor(QGraphicsView::AnchorViewCenter); |
326 setTransformationAnchor(QGraphicsView::AnchorViewCenter); |
301 |
327 |
302 // Rest of the initialization is done later, see paintEvent(). |
328 // Rest of the initialization is done later, see paintEvent(). |
|
329 |
|
330 |
|
331 #ifdef HB_GESTURE_FW |
|
332 // @todo remove after view auto-subscribes to gestures |
|
333 viewport()->grabGesture(Qt::TapGesture); |
|
334 viewport()->grabGesture(Qt::TapAndHoldGesture); |
|
335 viewport()->grabGesture(Qt::PanGesture); |
|
336 viewport()->grabGesture(Qt::SwipeGesture); |
|
337 viewport()->grabGesture(Qt::PinchGesture); |
|
338 #endif |
|
339 |
303 } |
340 } |
304 |
341 |
305 /*! |
342 /*! |
306 Destructs the main window. |
343 Destructs the main window. |
307 */ |
344 */ |
496 { |
533 { |
497 Q_D(HbMainWindow); |
534 Q_D(HbMainWindow); |
498 HbView *oldView = currentView(); |
535 HbView *oldView = currentView(); |
499 // Switching to null view or to the one that is current will do nothing. |
536 // Switching to null view or to the one that is current will do nothing. |
500 if (view && oldView != view) { |
537 if (view && oldView != view) { |
|
538 emit aboutToChangeView(oldView, view); |
501 if (oldView && animate) { |
539 if (oldView && animate) { |
502 if (flags & Hb::ViewSwitchFullScreen) { |
540 if (flags & Hb::ViewSwitchFullScreen) { |
503 flags |= Hb::ViewSwitchSequential; |
541 flags |= Hb::ViewSwitchSequential; |
504 } |
542 } |
505 if (flags & Hb::ViewSwitchUseBackAnim) { |
543 if (flags & Hb::ViewSwitchUseBackAnim) { |
602 result.append(view); |
640 result.append(view); |
603 } |
641 } |
604 |
642 |
605 return result; |
643 return result; |
606 } |
644 } |
607 /*! |
645 |
608 \deprecated HbMainWindow::element(HbMainWindow::Element) const |
|
609 is deprecated. |
|
610 |
|
611 Returns user interface elements of mainwindow as QGraphicsWidgets. The term "element" here is used since each of these |
|
612 elements consist of one or multiple items. The term "item" is used since each element is represented by a single |
|
613 QGraphicsWidget (which is also a QGraphicsItem). |
|
614 |
|
615 The returned elements can be used for example to run effects using the HbEffect API. |
|
616 For example an application could use the ViewPortItem to do an effect on all the other parts of the UI except the background item. |
|
617 |
|
618 Currently supported elements are: |
|
619 - HbMainWindow::RootItem, this is an item that contains all other items including the background element. |
|
620 - HbMainWindow::ViewportItem, this contains all other items except the background, it can be thought as the viewport for widgets. |
|
621 This item gets resized when the orientation changes. |
|
622 - HbMainWindow::BackgroundItem, as the name says the enum represents the background item, nothing else. |
|
623 Note that in this case the returned pointer may be null if the main window was constructed with Hb::WindowFlagNoBackground. |
|
624 |
|
625 \param element Enumeration of the element. |
|
626 |
|
627 */ |
|
628 QGraphicsWidget *HbMainWindow::element(HbMainWindow::Element element) const |
|
629 { |
|
630 HB_DEPRECATED("HbMainWindow::element is deprecated!"); |
|
631 Q_D(const HbMainWindow); |
|
632 if( element == HbMainWindow::RootItem ) |
|
633 return d->mRootItem; |
|
634 else if( element == HbMainWindow::ViewportItem ) |
|
635 return d->mClippingItem; |
|
636 else if( element == HbMainWindow::BackgroundItem ) |
|
637 return d->mBgItem; |
|
638 |
|
639 return 0; |
|
640 } |
|
641 |
646 |
642 /*! |
647 /*! |
643 Returns orientation of the window. |
648 Returns orientation of the window. |
644 |
649 |
645 \sa setOrientation() unsetOrientation() |
650 \sa setOrientation() unsetOrientation() |
663 |
668 |
664 void HbMainWindow::setOrientation(Qt::Orientation orientation, bool animate) |
669 void HbMainWindow::setOrientation(Qt::Orientation orientation, bool animate) |
665 { |
670 { |
666 Q_D(HbMainWindow); |
671 Q_D(HbMainWindow); |
667 d->mAutomaticOrientationSwitch = false; |
672 d->mAutomaticOrientationSwitch = false; |
|
673 d->mUserOrientationSwitch = true; |
668 d->setTransformedOrientation(orientation, animate); |
674 d->setTransformedOrientation(orientation, animate); |
669 } |
|
670 |
|
671 /*! |
|
672 \deprecated HbMainWindow::toggleOrientation() |
|
673 is deprecated. |
|
674 |
|
675 @proto |
|
676 |
|
677 Switches orientation of main window. |
|
678 |
|
679 */ |
|
680 void HbMainWindow::toggleOrientation() |
|
681 { |
|
682 HB_DEPRECATED("HbMainWindow::toggleOrientation is deprecated!"); |
|
683 Q_D(HbMainWindow); |
|
684 d->mAutomaticOrientationSwitch = false; |
|
685 if (d->mOrientation == Qt::Horizontal) { |
|
686 d->setTransformedOrientation(Qt::Vertical,false); |
|
687 } else { |
|
688 d->setTransformedOrientation(Qt::Horizontal,false); |
|
689 } |
|
690 } |
675 } |
691 |
676 |
692 /*! |
677 /*! |
693 Unsets orientation of the window. Application will listen orientation events coming from system. |
678 Unsets orientation of the window. Application will listen orientation events coming from system. |
694 Orientation switch animation can be skipped by using the boolean parameter. |
679 Orientation switch animation can be skipped by using the boolean parameter. |
698 void HbMainWindow::unsetOrientation(bool animate) |
683 void HbMainWindow::unsetOrientation(bool animate) |
699 { |
684 { |
700 Q_D(HbMainWindow); |
685 Q_D(HbMainWindow); |
701 if (!d->mAutomaticOrientationSwitch) { |
686 if (!d->mAutomaticOrientationSwitch) { |
702 d->mAutomaticOrientationSwitch = true; |
687 d->mAutomaticOrientationSwitch = true; |
|
688 d->mUserOrientationSwitch = false; |
703 if(HbMainWindowOrientation::instance()->isEnabled()) |
689 if(HbMainWindowOrientation::instance()->isEnabled()) |
704 d->setTransformedOrientation(HbMainWindowOrientation::instance()->sensorOrientation(), animate); |
690 d->setTransformedOrientation(HbMainWindowOrientation::instance()->sensorOrientation(), animate); |
705 } |
691 } |
706 } |
692 } |
707 |
693 |
849 |
835 |
850 */ |
836 */ |
851 QRectF HbMainWindow::layoutRect() const |
837 QRectF HbMainWindow::layoutRect() const |
852 { |
838 { |
853 Q_D(const HbMainWindow); |
839 Q_D(const HbMainWindow); |
854 if (d->mClippingItem) { |
840 return d->mLayoutRect; |
855 return d->mClippingItem->geometry(); |
|
856 } |
|
857 return QRectF(); |
|
858 } |
841 } |
859 /*! |
842 /*! |
860 \deprecated HbMainWindow::setCurrentViewIndex(int) |
843 \deprecated HbMainWindow::setCurrentViewIndex(int) |
861 is deprecated. Use setCurrentView() instead. |
844 is deprecated. Use setCurrentView() instead. |
862 |
845 |
938 { |
921 { |
939 QGraphicsView::changeEvent(event); |
922 QGraphicsView::changeEvent(event); |
940 if (event->type() == QEvent::LayoutDirectionChange) { |
923 if (event->type() == QEvent::LayoutDirectionChange) { |
941 // Notify layout direction change to the icon framework |
924 // Notify layout direction change to the icon framework |
942 HbLayoutDirectionNotifier::instance()->notifyLayoutDirectionChange(); |
925 HbLayoutDirectionNotifier::instance()->notifyLayoutDirectionChange(); |
|
926 |
|
927 broadcastEvent( HbEvent::WindowLayoutDirectionChanged ); |
943 |
928 |
944 foreach (QGraphicsItem *item, items()) { |
929 foreach (QGraphicsItem *item, items()) { |
945 if (item->isWidget() && !item->parentItem() ) { |
930 if (item->isWidget() && !item->parentItem() ) { |
946 QGraphicsWidget *widget = static_cast<QGraphicsWidget *>(item); |
931 QGraphicsWidget *widget = static_cast<QGraphicsWidget *>(item); |
947 if (!widget->testAttribute(Qt::WA_SetLayoutDirection)){ |
932 if (!widget->testAttribute(Qt::WA_SetLayoutDirection)){ |
1071 if (d->mEffectItem && d->mOrientationChangeOngoing) { |
1056 if (d->mEffectItem && d->mOrientationChangeOngoing) { |
1072 HbEffect::start(d->mEffectItem, "rootItemFinalPhase", this, "rootItemFinalPhaseDone"); |
1057 HbEffect::start(d->mEffectItem, "rootItemFinalPhase", this, "rootItemFinalPhaseDone"); |
1073 } |
1058 } |
1074 } else if (event->type() == HbMainWindowPrivate::IdleOrientationFinalEvent) { |
1059 } else if (event->type() == HbMainWindowPrivate::IdleOrientationFinalEvent) { |
1075 if (d->mAnimateOrientationSwitch) { |
1060 if (d->mAnimateOrientationSwitch) { |
1076 HbEffect::start(d->mStatusBar, "statusbar", "appear_orient"); |
|
1077 HbEffect::start(d->mTitleBar, "titlebar", "appear_orient"); |
1061 HbEffect::start(d->mTitleBar, "titlebar", "appear_orient"); |
|
1062 HbEffect::start(d->mStatusBar, "statusbar", "appear_orient"); |
1078 if (d->mCurrentToolbar) { |
1063 if (d->mCurrentToolbar) { |
1079 HbToolBarPrivate *toolBarD = HbToolBarPrivate::d_ptr(d->mCurrentToolbar); |
1064 HbToolBarPrivate *toolBarD = HbToolBarPrivate::d_ptr(d->mCurrentToolbar); |
1080 toolBarD->startAppearOrientEffect(); |
1065 toolBarD->startAppearOrientEffect(); |
1081 } |
1066 } |
|
1067 d->mOrientationChangeOngoing = false; |
|
1068 if (d->mAutomaticOrientationSwitch && HbMainWindowOrientation::instance()->isEnabled()) { |
|
1069 d->setTransformedOrientation(HbMainWindowOrientation::instance()->sensorOrientation(), d->mAnimateOrientationSwitch); |
|
1070 } |
|
1071 else if (d->mRequestedOrientation != d->mOrientation) { |
|
1072 d->setTransformedOrientation(d->mRequestedOrientation, d->mAnimateOrientationSwitch); |
|
1073 } |
|
1074 } else { |
|
1075 // cancel() with clearEffect cannot be used because the effects may have already been canceled. |
|
1076 if (d->mTitleBar) { |
|
1077 d->mTitleBar->resetTransform(); |
|
1078 d->mTitleBar->setOpacity(1); |
|
1079 } |
|
1080 if (d->mStatusBar) { |
|
1081 d->mStatusBar->resetTransform(); |
|
1082 d->mStatusBar->setOpacity(1); |
|
1083 } |
|
1084 if (d->mCurrentToolbar) { |
|
1085 d->mCurrentToolbar->resetTransform(); |
|
1086 d->mCurrentToolbar->setOpacity(1); |
|
1087 d->mCurrentToolbar->show(); |
|
1088 } |
1082 } |
1089 } |
1083 } |
1090 } |
1084 |
|
1085 } |
1091 } |
1086 |
1092 |
1087 /*! |
1093 /*! |
1088 \reimp |
1094 \reimp |
1089 */ |
1095 */ |