39 \brief Container for views in a mainwindow. Extends HbStackedWidget with view |
40 \brief Container for views in a mainwindow. Extends HbStackedWidget with view |
40 switch effects and other features. |
41 switch effects and other features. |
41 |
42 |
42 \internal |
43 \internal |
43 */ |
44 */ |
|
45 |
|
46 // An internal view switch flag, it is used to indicate the type of |
|
47 // the effect (show/hide) to getEffectTarget. |
|
48 const int Hiding = 0x1000000; |
44 |
49 |
45 HbContentWidget::HbContentWidget(HbMainWindow *mainWindow, QGraphicsItem *parent /*= 0*/): |
50 HbContentWidget::HbContentWidget(HbMainWindow *mainWindow, QGraphicsItem *parent /*= 0*/): |
46 HbStackedWidget(parent), |
51 HbStackedWidget(parent), |
47 mViewSwitchRunning(false), |
52 mViewSwitchRunning(false), |
48 mTargetView(0), |
53 mTargetView(0), |
49 mHidingView(0), |
54 mHidingView(0), |
50 mMainWindow(mainWindow) |
55 mMainWindow(mainWindow) |
51 { |
56 { |
52 // Do not defer this, it causes invalidation and updating. |
57 // Do not defer this, it causes invalidation and updating. |
53 setFocusPolicy(Qt::StrongFocus); |
58 setFocusPolicy(Qt::StrongFocus); |
|
59 |
|
60 setAcceptTouchEvents(true); |
54 } |
61 } |
55 |
62 |
56 QSizeF HbContentWidget::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
63 QSizeF HbContentWidget::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
57 { |
64 { |
58 Q_UNUSED(constraint); |
65 Q_UNUSED(constraint); |
127 // special start() version from HbEffectInternal. Also, some views |
134 // special start() version from HbEffectInternal. Also, some views |
128 // may not have a content widget, in this case use the HbView as |
135 // may not have a content widget, in this case use the HbView as |
129 // the effect target. |
136 // the effect target. |
130 QGraphicsWidget *viewWidget = view->widget(); |
137 QGraphicsWidget *viewWidget = view->widget(); |
131 QGraphicsWidget *effectTarget = viewWidget ? viewWidget : view; |
138 QGraphicsWidget *effectTarget = viewWidget ? viewWidget : view; |
|
139 HbMainWindowPrivate *mwd = HbMainWindowPrivate::d_ptr(mMainWindow); |
132 if (flags & Hb::ViewSwitchFullScreen) { |
140 if (flags & Hb::ViewSwitchFullScreen) { |
133 effectTarget = HbMainWindowPrivate::d_ptr(mMainWindow)->mClippingItem; |
141 effectTarget = mwd->mClippingItem; |
134 if (!(flags & Hb::ViewSwitchSequential)) { |
142 if (!(flags & Hb::ViewSwitchSequential)) { |
135 // The Parallel+FullScreen combination does not make sense |
143 // The Parallel+FullScreen combination does not make sense |
136 // (e.g. cannot animate the one and only titlebar |
144 // (e.g. cannot animate the one and only titlebar |
137 // concurrently). |
145 // concurrently). |
138 qWarning("HbMainWindow: parallel fullscreen view switch is not supported"); |
146 qWarning("HbMainWindow: parallel fullscreen view switch is not supported"); |
139 effectTarget = 0; |
147 effectTarget = 0; |
140 } |
148 } |
|
149 } else if (flags & Hb::ViewSwitchCachedFullScreen) { |
|
150 // This version supports sequential effects too, but in the |
|
151 // hiding case the effect must run on the special graphics |
|
152 // item that will show a screenshot of the mainwindow. |
|
153 if (flags & Hiding) { |
|
154 effectTarget = mwd->screenshotItem(); |
|
155 } else { |
|
156 effectTarget = mwd->mClippingItem; |
|
157 } |
141 } |
158 } |
142 return effectTarget; |
159 return effectTarget; |
143 } |
160 } |
144 |
161 |
145 /*! |
162 /*! |
150 // Make sure the old view is hidden. The effect does this too due to |
167 // Make sure the old view is hidden. The effect does this too due to |
151 // HideRegItemBeforeClearingEffect so no matter which comes first (clearing |
168 // HideRegItemBeforeClearingEffect so no matter which comes first (clearing |
152 // of the effect or this notification), the item is hidden properly before |
169 // of the effect or this notification), the item is hidden properly before |
153 // resetting the transform etc. and thus there is no flicker. |
170 // resetting the transform etc. and thus there is no flicker. |
154 mHidingView->setVisible(false); |
171 mHidingView->setVisible(false); |
|
172 if (mViewSwitchFlags & Hb::ViewSwitchCachedFullScreen) { |
|
173 HbMainWindowPrivate *mwd = HbMainWindowPrivate::d_ptr(mMainWindow); |
|
174 mwd->screenshotItem()->releaseAndHide(); |
|
175 if (mViewSwitchFlags & Hb::ViewSwitchSequential) { |
|
176 mwd->mClippingItem->show(); |
|
177 } |
|
178 } |
155 // Start the "show" phase if not yet started. |
179 // Start the "show" phase if not yet started. |
156 if (mViewSwitchFlags & Hb::ViewSwitchSequential) { |
180 if (mViewSwitchFlags & Hb::ViewSwitchSequential) { |
157 // Do not show targetView yet, leave it to the effect in order to |
181 // Do not show targetView yet, leave it to the effect in order to |
158 // prevent flickering. |
182 // prevent flickering. |
159 if (status.reason != Hb::EffectCancelled) { |
183 if (status.reason != Hb::EffectCancelled) { |
188 // Cancel all on-going effects. Relying on the cancel() calls made by the |
212 // Cancel all on-going effects. Relying on the cancel() calls made by the |
189 // start() functions would not be enough in all situations. |
213 // start() functions would not be enough in all situations. |
190 HbEffectInternal::cancelAll(0, true); // ignore looping effects, those are not view switch effects and must not be stopped here |
214 HbEffectInternal::cancelAll(0, true); // ignore looping effects, those are not view switch effects and must not be stopped here |
191 mViewSwitchRunning = true; |
215 mViewSwitchRunning = true; |
192 |
216 |
193 // Make the new view the current one right away. This must be done asap to prevent |
217 bool hideOld = false; |
194 // messed up state in mainwindow, the stack widget, etc. due to events coming during |
218 if (flags & Hb::ViewSwitchCachedFullScreen) { |
195 // the view switch animation. |
219 // Take a screenshot (must be done before touching anything in the view |
196 // 2nd param (hideOld): We still want to see the old view (normally setCurrentWidget would hide it). |
220 // stack) and show it. The screenshot will effectively replace the |
197 // 3rd param (showNew): The new view is not yet needed (the effect will take care of making it visible). |
221 // hiding view. |
198 setCurrentWidget(mTargetView, false, false); |
222 HbMainWindowPrivate::d_ptr(mMainWindow)->screenshotItem()->takeAndShowScreenshot(); |
|
223 hideOld = true; |
|
224 } |
|
225 |
|
226 // Make the new view the current one right away. This must be done asap to |
|
227 // prevent messed up state in mainwindow, the stack widget, etc. due to |
|
228 // events coming during the view switch animation. |
|
229 // |
|
230 // 2nd param (hideOld): We still want to see the old view (normally |
|
231 // setCurrentWidget would hide it), except in the cached case. |
|
232 // |
|
233 // 3rd param (showNew): The new view is not yet needed (the effect will take |
|
234 // care of making it visible). |
|
235 setCurrentWidget(mTargetView, hideOld, false); |
199 |
236 |
200 mHidingView = viewToHide; |
237 mHidingView = viewToHide; |
201 mViewSwitchFlags = flags; |
238 mViewSwitchFlags = flags; |
202 |
239 |
203 QGraphicsWidget *effectTarget = getEffectTarget(viewToHide, flags); |
240 QGraphicsWidget *effectTarget = getEffectTarget(viewToHide, (Hb::ViewSwitchFlags) (flags | Hiding)); |
204 if (effectTarget) { |
241 if (effectTarget) { |
205 mMainWindow->setInteractive(false); // disable input while the effects are running |
242 mMainWindow->setInteractive(false); // disable input while the effects are running |
|
243 if ((flags & Hb::ViewSwitchCachedFullScreen) && (flags & Hb::ViewSwitchSequential)) { |
|
244 // Get rid of decorators for the duration of the hide effect |
|
245 // otherwise they would show up under the screenshot item when |
|
246 // it disappears. |
|
247 HbMainWindowPrivate::d_ptr(mMainWindow)->mClippingItem->hide(); |
|
248 } |
206 QString event = getEffectEvent("hide", flags, viewToHide, mTargetView); |
249 QString event = getEffectEvent("hide", flags, viewToHide, mTargetView); |
207 HbEffectInternal::EffectFlags effectFlags = |
250 HbEffectInternal::EffectFlags effectFlags = |
208 HbEffectInternal::ClearEffectWhenFinished // the effect must not be persistent |
251 HbEffectInternal::ClearEffectWhenFinished // the effect must not be persistent |
209 | HbEffectInternal::HideRegItemBeforeClearingEffect; // to prevent unlikely, but possible flicker |
252 | HbEffectInternal::HideRegItemBeforeClearingEffect; // to prevent unlikely, but possible flicker |
210 HbEffectInternal::start(viewToHide, effectTarget, effectFlags, |
253 HbEffectInternal::start(viewToHide, effectTarget, effectFlags, |