src/hbcore/gui/hbcontentwidget.cpp
changeset 21 4633027730f5
parent 7 923ff622b8b9
child 28 b7da29130b0e
equal deleted inserted replaced
7:923ff622b8b9 21:4633027730f5
    28 #include "hbmainwindow_p.h"
    28 #include "hbmainwindow_p.h"
    29 #include "hbview.h"
    29 #include "hbview.h"
    30 #include "hbeffectinternal_p.h"
    30 #include "hbeffectinternal_p.h"
    31 #include "hbwidgetfeedback.h"
    31 #include "hbwidgetfeedback.h"
    32 #include "hbscreen_p.h"
    32 #include "hbscreen_p.h"
       
    33 #include "hbscreenshotitem_p.h"
    33 #include <QEvent>
    34 #include <QEvent>
    34 #include <QGraphicsSceneMouseEvent>
    35 #include <QGraphicsSceneMouseEvent>
    35 
    36 
    36 /*!
    37 /*!
    37   \class HbContentWidget
    38   \class HbContentWidget
    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),
   127     // special start() version from HbEffectInternal. Also, some views
   132     // special start() version from HbEffectInternal. Also, some views
   128     // may not have a content widget, in this case use the HbView as
   133     // may not have a content widget, in this case use the HbView as
   129     // the effect target.
   134     // the effect target.
   130     QGraphicsWidget *viewWidget = view->widget();
   135     QGraphicsWidget *viewWidget = view->widget();
   131     QGraphicsWidget *effectTarget = viewWidget ? viewWidget : view;
   136     QGraphicsWidget *effectTarget = viewWidget ? viewWidget : view;
       
   137     HbMainWindowPrivate *mwd = HbMainWindowPrivate::d_ptr(mMainWindow);
   132     if (flags & Hb::ViewSwitchFullScreen) {
   138     if (flags & Hb::ViewSwitchFullScreen) {
   133         effectTarget = HbMainWindowPrivate::d_ptr(mMainWindow)->mClippingItem;
   139         effectTarget = mwd->mClippingItem;
   134         if (!(flags & Hb::ViewSwitchSequential)) {
   140         if (!(flags & Hb::ViewSwitchSequential)) {
   135             // The Parallel+FullScreen combination does not make sense
   141             // The Parallel+FullScreen combination does not make sense
   136             // (e.g. cannot animate the one and only titlebar
   142             // (e.g. cannot animate the one and only titlebar
   137             // concurrently).
   143             // concurrently).
   138             qWarning("HbMainWindow: parallel fullscreen view switch is not supported");
   144             qWarning("HbMainWindow: parallel fullscreen view switch is not supported");
   139             effectTarget = 0;
   145             effectTarget = 0;
   140         }
   146         }
       
   147     } else if (flags & Hb::ViewSwitchCachedFullScreen) {
       
   148         // This version supports sequential effects too, but in the
       
   149         // hiding case the effect must run on the special graphics
       
   150         // item that will show a screenshot of the mainwindow.
       
   151         if (flags & Hiding) {
       
   152             effectTarget = mwd->screenshotItem();
       
   153         } else {
       
   154             effectTarget = mwd->mClippingItem;
       
   155         }
   141     }
   156     }
   142     return effectTarget;
   157     return effectTarget;
   143 }
   158 }
   144 
   159 
   145 /*!
   160 /*!
   150     // Make sure the old view is hidden. The effect does this too due to
   165     // Make sure the old view is hidden. The effect does this too due to
   151     // HideRegItemBeforeClearingEffect so no matter which comes first (clearing
   166     // HideRegItemBeforeClearingEffect so no matter which comes first (clearing
   152     // of the effect or this notification), the item is hidden properly before
   167     // of the effect or this notification), the item is hidden properly before
   153     // resetting the transform etc. and thus there is no flicker.
   168     // resetting the transform etc. and thus there is no flicker.
   154     mHidingView->setVisible(false);
   169     mHidingView->setVisible(false);
       
   170     if (mViewSwitchFlags & Hb::ViewSwitchCachedFullScreen) {
       
   171         HbMainWindowPrivate *mwd = HbMainWindowPrivate::d_ptr(mMainWindow);
       
   172         mwd->screenshotItem()->releaseAndHide();
       
   173         if (mViewSwitchFlags & Hb::ViewSwitchSequential) {
       
   174             mwd->mClippingItem->show();
       
   175         }
       
   176     }
   155     // Start the "show" phase if not yet started.
   177     // Start the "show" phase if not yet started.
   156     if (mViewSwitchFlags & Hb::ViewSwitchSequential) {
   178     if (mViewSwitchFlags & Hb::ViewSwitchSequential) {
   157         // Do not show targetView yet, leave it to the effect in order to
   179         // Do not show targetView yet, leave it to the effect in order to
   158         // prevent flickering.
   180         // prevent flickering.
   159         if (status.reason != Hb::EffectCancelled) {
   181         if (status.reason != Hb::EffectCancelled) {
   188     // Cancel all on-going effects. Relying on the cancel() calls made by the
   210     // Cancel all on-going effects. Relying on the cancel() calls made by the
   189     // start() functions would not be enough in all situations.
   211     // 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
   212     HbEffectInternal::cancelAll(0, true); // ignore looping effects, those are not view switch effects and must not be stopped here
   191     mViewSwitchRunning = true;
   213     mViewSwitchRunning = true;
   192 
   214 
   193     // Make the new view the current one right away. This must be done asap to prevent
   215     bool hideOld = false;
   194     // messed up state in mainwindow, the stack widget, etc. due to events coming during
   216     if (flags & Hb::ViewSwitchCachedFullScreen) {
   195     // the view switch animation.
   217         // 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).
   218         // 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).
   219         // hiding view.
   198     setCurrentWidget(mTargetView, false, false);
   220         HbMainWindowPrivate::d_ptr(mMainWindow)->screenshotItem()->takeAndShowScreenshot();
       
   221         hideOld = true;
       
   222     }
       
   223 
       
   224     // Make the new view the current one right away. This must be done asap to
       
   225     // prevent messed up state in mainwindow, the stack widget, etc. due to
       
   226     // events coming during the view switch animation.
       
   227     //
       
   228     // 2nd param (hideOld): We still want to see the old view (normally
       
   229     // setCurrentWidget would hide it), except in the cached case.
       
   230     //
       
   231     // 3rd param (showNew): The new view is not yet needed (the effect will take
       
   232     // care of making it visible).
       
   233     setCurrentWidget(mTargetView, hideOld, false);
   199 
   234 
   200     mHidingView = viewToHide;
   235     mHidingView = viewToHide;
   201     mViewSwitchFlags = flags;
   236     mViewSwitchFlags = flags;
   202 
   237 
   203     QGraphicsWidget *effectTarget = getEffectTarget(viewToHide, flags);
   238     QGraphicsWidget *effectTarget = getEffectTarget(viewToHide, (Hb::ViewSwitchFlags) (flags | Hiding));
   204     if (effectTarget) {
   239     if (effectTarget) {
   205         mMainWindow->setInteractive(false); // disable input while the effects are running
   240         mMainWindow->setInteractive(false); // disable input while the effects are running
       
   241         if ((flags & Hb::ViewSwitchCachedFullScreen) && (flags & Hb::ViewSwitchSequential)) {
       
   242             // Get rid of decorators for the duration of the hide effect
       
   243             // otherwise they would show up under the screenshot item when
       
   244             // it disappears.
       
   245             HbMainWindowPrivate::d_ptr(mMainWindow)->mClippingItem->hide();
       
   246         }
   206         QString event = getEffectEvent("hide", flags, viewToHide, mTargetView);
   247         QString event = getEffectEvent("hide", flags, viewToHide, mTargetView);
   207         HbEffectInternal::EffectFlags effectFlags =
   248         HbEffectInternal::EffectFlags effectFlags =
   208             HbEffectInternal::ClearEffectWhenFinished // the effect must not be persistent
   249             HbEffectInternal::ClearEffectWhenFinished // the effect must not be persistent
   209             | HbEffectInternal::HideRegItemBeforeClearingEffect; // to prevent unlikely, but possible flicker
   250             | HbEffectInternal::HideRegItemBeforeClearingEffect; // to prevent unlikely, but possible flicker
   210         HbEffectInternal::start(viewToHide, effectTarget, effectFlags,
   251         HbEffectInternal::start(viewToHide, effectTarget, effectFlags,