src/hbcore/gui/hbmainwindow.cpp
branchGCC_SURGE
changeset 15 f378acbc9cfb
parent 7 923ff622b8b9
child 21 4633027730f5
child 34 ed14f46c0e55
equal deleted inserted replaced
9:730c025d4b77 15:f378acbc9cfb
    21 ** If you have questions regarding the use of this file, please contact
    21 ** If you have questions regarding the use of this file, please contact
    22 ** Nokia at developer.feedback@nokia.com.
    22 ** Nokia at developer.feedback@nokia.com.
    23 **
    23 **
    24 ****************************************************************************/
    24 ****************************************************************************/
    25 
    25 
       
    26 #include "hbmainwindow.h"
       
    27 #include "hbmainwindow_p.h"
       
    28 
    26 #include <QGraphicsView>
    29 #include <QGraphicsView>
    27 #include <QGraphicsWidget>
    30 #include <QGraphicsWidget>
    28 #include <QGraphicsItem>
    31 #include <QGraphicsItem>
    29 #include <QGraphicsScene>
    32 #include <QGraphicsScene>
    30 
    33 
    33 #include "hbdeviceprofile_p.h"
    36 #include "hbdeviceprofile_p.h"
    34 #include "hbindicatorgroup_p.h"
    37 #include "hbindicatorgroup_p.h"
    35 #include "hbinstance.h"
    38 #include "hbinstance.h"
    36 #include "hbinstance_p.h"
    39 #include "hbinstance_p.h"
    37 #include "hbgraphicsscene.h"
    40 #include "hbgraphicsscene.h"
    38 #include "hbmainwindow.h"
       
    39 #include "hbmainwindow_p.h"
       
    40 #include "hbnamespace.h"
    41 #include "hbnamespace.h"
    41 #include "hbnamespace_p.h"
    42 #include "hbnamespace_p.h"
    42 #include "hbtitlebar_p.h"
    43 #include "hbtitlebar_p.h"
    43 #include "hbstatusbar_p.h"
    44 #include "hbstatusbar_p.h"
    44 #include "hbstyle.h"
    45 #include "hbstyle.h"
    56 #include "hbevent.h"
    57 #include "hbevent.h"
    57 #include "hbsplashscreen.h"
    58 #include "hbsplashscreen.h"
    58 #include "hbcontentwidget_p.h"
    59 #include "hbcontentwidget_p.h"
    59 #include "hbscreen_p.h"
    60 #include "hbscreen_p.h"
    60 #include "hbmainwindoworientation_p.h"
    61 #include "hbmainwindoworientation_p.h"
    61 #include "hbfeaturemanager_p.h"
    62 #include "hbfeaturemanager_r.h"
    62 #include "hboogmwatcher_p.h"
    63 #include "hboogmwatcher_p.h"
       
    64 #include "hbwindowobscured_p.h"
       
    65 #include "hbsleepmodelistener_p.h"
    63 
    66 
    64 #ifdef Q_OS_SYMBIAN
    67 #ifdef Q_OS_SYMBIAN
    65 #include <coecntrl.h>
    68 #include <coecntrl.h>
       
    69 #include <w32std.h>
    66 #include "hbnativewindow_sym_p.h"
    70 #include "hbnativewindow_sym_p.h"
    67 #endif
    71 #endif
    68 
    72 
    69 /*!
    73 /*!
    70     @stable
    74     @stable
    90     Hb::WindowFlagNoBackground flag is set for the HbMainWindow. Normally the
    94     Hb::WindowFlagNoBackground flag is set for the HbMainWindow. Normally the
    91     standard background item fills the entire screen so the background is not
    95     standard background item fills the entire screen so the background is not
    92     really visible.
    96     really visible.
    93 
    97 
    94     HbMainWindow has a signalling mechanism for helping control the
    98     HbMainWindow has a signalling mechanism for helping control the
    95     application's view construction. viewReady()-signal is emitted
    99     application's view construction. The viewReady() signal is emitted when a
    96     when view's internal construction is completed and basic parts of
   100     view's internal construction is completed and basic parts of view are
    97     view are already drawn. Same signal is also emitted when current
   101     already drawn. Same signal is also emitted when current view has
    98     view is switched. This helps applications to split the view
   102     changed. This helps applications to split the view construction to
    99     construction to reasonable tasks.  For example the lower priority
   103     reasonable tasks.  For example the lower priority tasks like opening network
   100     tasks like opening network connection or preparing other currently
   104     connection or preparing other currently hidden application views can happen
   101     hidden application views can happen on background when first view
   105     on background when first view is already drawn.
   102     is already drawn.
       
   103 
   106 
   104     Example of simple Hb application constructing HbMainWindow:
   107     Example of simple Hb application constructing HbMainWindow:
   105 
   108 
   106     \include mainwindow1/main.cpp
   109     \include mainwindow1/main.cpp
   107 
   110 
   170     \fn void HbMainWindow::viewReady()
   173     \fn void HbMainWindow::viewReady()
   171 
   174 
   172     This signal is emitted first time when window content is drawn on screen.
   175     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.
   176     It will only be emitted again when current view is changed and drawn on screen.
   174 
   177 
       
   178     This means that this signal is emitted in the following cases:
       
   179 
       
   180     - When the mainwindow is fully constructed, this happens shortly after
       
   181       painting it for the first time.
       
   182 
       
   183     - When a new view is added using addView() or insertView() after the
       
   184       mainwindow is fully constructed and the newly added view becomes the
       
   185       current view. It will not be emitted when calling addView() or
       
   186       insertView() before showing the mainwindow or entering the event loop
       
   187       because in that case the signal will anyway be emitted later, when the
       
   188       mainwindow becomes ready. It is also not emitted when the newly added view
       
   189       does not become the current view.
       
   190 
       
   191     - When the current view is changed using setCurrentView().
       
   192 
   175     If the view switch is animated, the signal is emitted only after the effect has
   193     If the view switch is animated, the signal is emitted only after the effect has
   176     completed.
   194     completed.
   177 
   195 
   178     Application developers may connect to this signal to do lower priority construction
   196     Application developers may connect to this signal to do lower priority construction
   179     tasks. Note however that when thinking about the tasks, it is important to keep the UI
   197     tasks. Note however that when thinking about the tasks, it is important to keep the UI
   180     responsive all the time.
   198     responsive all the time.
   181  */
   199  */
   182 
   200 
   183 /*!
   201 /*!
       
   202     \fn void HbMainWindow::obscured()
       
   203 
       
   204     This signal is emited whenever the window is completely overlaped by another
       
   205     window.
       
   206 
       
   207     Application developers can use this signal to pause or stop painting when
       
   208     the window is not visible to the user at all.
       
   209 
       
   210     This signal has real implementation only for Symbian and X11 platforms. On
       
   211     desktop platforms it is simulated via a settings window option.
       
   212 
       
   213     The typical use case is to use the obscured() and revealed() signals in
       
   214     connection with device dialogs (global pop-ups): When such a dialog is
       
   215     shown, the application loses foreground (focus), but it may still be
       
   216     partially visible because the dialogs will not fill the entire screen. To
       
   217     get notified about such cases, combine your application's
       
   218     foreground-background handling with handling also these signals.
       
   219 
       
   220     Consider this as a best-effort solution only, the exact behavior depends on
       
   221     the platform and may have limitations. For example on Symbian transparent
       
   222     windows will never obscure another window, regardless of the content.
       
   223 
       
   224     These signals are not a replacement to the focus-based ApplicationActivate
       
   225     and ApplicationDeactivate events. An application may lose the focus
       
   226     completely (i.e. lose foreground) even when it is still partially visible to
       
   227     the user.
       
   228 
       
   229     \sa revealed()
       
   230     \sa isObscured()
       
   231 */
       
   232 
       
   233 /*!
       
   234     \fn void HbMainWindow::revealed()
       
   235 
       
   236     This signal is emited whenever the window is visible to the user partially
       
   237     or completely.
       
   238 
       
   239     This signal has real implementation only for Symbian and X11 platforms. On
       
   240     desktop platforms it is simulated via the settings option.
       
   241 
       
   242     Consider this as a best-effort solution only, the exact behavior depends on
       
   243     the platform and may have limitations. For example on Symbian transparent
       
   244     windows may cause the revealed signal to be emitted even when the content is
       
   245     not really visible.
       
   246 
       
   247     These signals are not a replacement to the focus-based ApplicationActivate
       
   248     and ApplicationDeactivate events. An application may lose the focus
       
   249     completely (i.e. lose foreground) even when it is still partially visible to
       
   250     the user.
       
   251 
       
   252     \sa obscured()
       
   253     \sa isObscured()
       
   254 */
       
   255 
       
   256 /*!
   184   \class HbRootItem
   257   \class HbRootItem
   185 
   258 
   186   \brief The parent of all graphics items (including the clipping item (HbScreen)
   259   \brief The parent of all graphics items (including the clipping item (HbScreen)
   187   and the background item). Basically it is a HbWidget with polishing disabled
   260   and the background item). Basically it is a HbWidget with polishing disabled
   188   (so we won't waste time with that).
   261   (so we won't waste time with that).
   191  */
   264  */
   192 
   265 
   193 class HbRootItem : public HbWidget
   266 class HbRootItem : public HbWidget
   194 {
   267 {
   195 public:
   268 public:
   196     explicit  HbRootItem( QGraphicsItem *parent = 0 );
   269     explicit  HbRootItem(QGraphicsItem *parent = 0);
   197     ~HbRootItem() {}
   270     ~HbRootItem() {}
   198 private:
   271 private:
   199     bool event(QEvent *event);
   272     bool event(QEvent *event);
   200 };
   273 };
   201 
   274 
   202 /*!
   275 /*!
   203     Constructs an HbMainWindow object with \a parent.
   276     Constructs an HbMainWindow object with \a parent.
   204     
   277 
   205     \a windowFlags can be used for specifying special functionality to HbMainWindow.
   278     \a windowFlags can be used for specifying special functionality to HbMainWindow.
   206     
   279 
   207     \sa Hb::WindowFlag
   280     \sa Hb::WindowFlag
   208 */
   281 */
   209 HbMainWindow::HbMainWindow(QWidget *parent, Hb::WindowFlags windowFlags):
   282 HbMainWindow::HbMainWindow(QWidget *parent, Hb::WindowFlags windowFlags):
   210         QGraphicsView(parent), d_ptr(new HbMainWindowPrivate)
   283     QGraphicsView(parent), d_ptr(new HbMainWindowPrivate)
   211 {
   284 {
   212     Q_D(HbMainWindow);
   285     Q_D(HbMainWindow);
   213     d->q_ptr = this;
   286     d->q_ptr = this;
   214 
   287 
   215     // No need for any default (e.g. blank white) background for this window.
   288     // 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);
   289     setAttribute(Qt::WA_NoSystemBackground);
       
   290     setOptimizationFlag(QGraphicsView::DontSavePainterState);
   219 
   291 
   220     // Continue with basic initialization. Note: Prefer doing everything that is
   292     // Continue with basic initialization. Note: Prefer doing everything that is
   221     // not absolutely compulsory in _q_delayedConstruction instead.
   293     // not absolutely compulsory in _q_delayedConstruction instead.
   222 
   294 
   223     d->init();
   295     d->init();
   249     } else if (HbMainWindowOrientation::instance()->isEnabled()) {
   321     } else if (HbMainWindowOrientation::instance()->isEnabled()) {
   250         d->mOrientation = HbMainWindowOrientation::instance()->sensorOrientation();
   322         d->mOrientation = HbMainWindowOrientation::instance()->sensorOrientation();
   251         d->mAutomaticOrientationSwitch = true;
   323         d->mAutomaticOrientationSwitch = true;
   252     } else {
   324     } else {
   253         d->mOrientation = d->mDefaultOrientation;
   325         d->mOrientation = d->mDefaultOrientation;
   254         d->mAutomaticOrientationSwitch = false; 
   326         d->mAutomaticOrientationSwitch = false;
   255     }
   327     }
   256 
   328 
   257 #if defined(Q_WS_S60) || defined(HB_Q_WS_MAEMO)
   329 #if defined(Q_WS_S60) || defined(HB_Q_WS_MAEMO)
   258     setWindowState(Qt::WindowFullScreen);
   330     setWindowState(Qt::WindowFullScreen);
   259 #endif//Q_WS_S60
   331 #endif//Q_WS_S60
   260 
   332 
   261     setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
   333     setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
   262     setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
   334     setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
   263     setFrameShape(QFrame::NoFrame);
   335     setFrameStyle(QFrame::NoFrame);
   264 
   336 
   265     // create scene and style
   337     // create scene and style
   266     d->mScene = new HbGraphicsScene(this);
   338     d->mScene = new HbGraphicsScene(this);
   267 
   339 
   268     // workaround for problems with BSP tree implementation in Qt
   340     // workaround for problems with BSP tree implementation in Qt
   269     d->mScene->setItemIndexMethod(QGraphicsScene::NoIndex);
   341     d->mScene->setItemIndexMethod(QGraphicsScene::NoIndex);
   270 
   342 
   271     d->mScene->setSceneRect(0, 0, pSize.width(), pSize.height()); 
   343     d->mScene->setSceneRect(0, 0, pSize.width(), pSize.height());
   272     setScene(d->mScene);
   344     setScene(d->mScene);
   273 
   345 
   274     // add root item
   346     // add root item
   275     d->mRootItem = new HbRootItem;
   347     d->mRootItem = new HbRootItem;
   276     d->mRootItem->setZValue(HbPrivate::RootItemZValue);
   348     d->mRootItem->setZValue(HbPrivate::RootItemZValue);
   290     d->mViewStackWidget = new HbContentWidget(this, d->mClippingItem);
   362     d->mViewStackWidget = new HbContentWidget(this, d->mClippingItem);
   291     d->mEffectItem = d->mViewStackWidget;
   363     d->mEffectItem = d->mViewStackWidget;
   292     d->mClippingItem->setStackWidget(d->mViewStackWidget);
   364     d->mClippingItem->setStackWidget(d->mViewStackWidget);
   293     connect(d->mViewStackWidget, SIGNAL(currentChanged(int)),
   365     connect(d->mViewStackWidget, SIGNAL(currentChanged(int)),
   294             this, SLOT(_q_viewChanged()));
   366             this, SLOT(_q_viewChanged()));
   295     connect(d->mViewStackWidget, SIGNAL(widgetRemoved(QGraphicsWidget*)),
   367     connect(d->mViewStackWidget, SIGNAL(widgetRemoved(QGraphicsWidget *)),
   296             this, SLOT(_q_viewRemoved(QGraphicsWidget*)));
   368             this, SLOT(_q_viewRemoved(QGraphicsWidget *)));
   297 
   369 
   298     // create Titlebar (container for indicators, titlepane and secondary softkey
   370     // create Titlebar (container for indicator button, titlepane and navigation button
   299     d->mTitleBar = new HbTitleBar(this, d->mClippingItem);
   371     d->mTitleBar = new HbTitleBar(this, d->mClippingItem);
   300     d->mTitleBar->setZValue(HbPrivate::TitleBarZValue);
   372     d->mTitleBar->setZValue(HbPrivate::TitleBarZValue);
   301 
   373 
   302     // create StatusBar (container for clock, indicators, and battery and signal icons)
   374     // create StatusBar (container for clock, indicators, and battery and signal icons)
   303     d->mStatusBar = new HbStatusBar(this, d->mClippingItem);
   375     d->mStatusBar = new HbStatusBar(this, d->mClippingItem);
   304     d->mStatusBar->setZValue(HbPrivate::StatusBarZValue);
   376     d->mStatusBar->setZValue(HbPrivate::StatusBarZValue);
   305 
   377 
   306     // At this point the mainwindow is considered more or less fully constructed.
   378     // At this point the mainwindow is considered more or less fully constructed.
   307     HbInstancePrivate::d_ptr()->addWindow(this);
   379     HbInstancePrivate::d_ptr()->addWindow(this);
   308 
   380 
   309     QRectF rect(0,0,pSize.width(),pSize.height());
   381     QRectF rect(0, 0, pSize.width(), pSize.height());
   310     resize(pSize);
   382     resize(pSize);
   311 	d->mLayoutRect = rect;
   383     d->mLayoutRect = rect;
   312     d->mRootItem->setGeometry(rect);
   384     d->mRootItem->setGeometry(rect);
   313     d->mClippingItem->setGeometry(rect);
   385     d->mClippingItem->setGeometry(rect);
   314     setSceneRect(0, 0, pSize.width(), pSize.height());
   386     setSceneRect(0, 0, pSize.width(), pSize.height());
   315     setTransformationAnchor(QGraphicsView::AnchorViewCenter);
   387     setTransformationAnchor(QGraphicsView::AnchorViewCenter);
   316 
   388 
   320     d->initTranslations();
   392     d->initTranslations();
   321 
   393 
   322     // Make sure the oogm watcher is initialized (so that wserv events
   394     // Make sure the oogm watcher is initialized (so that wserv events
   323     // are routed to it properly).
   395     // are routed to it properly).
   324     HbOogmWatcher::instance();
   396     HbOogmWatcher::instance();
       
   397 
       
   398     // Make sure the sleep mode listener instance is created.
       
   399     HbSleepModeListener::instance();
       
   400 
       
   401     HbWindowObscured::installWindowEventFilter();
   325 
   402 
   326 #ifdef HB_GESTURE_FW
   403 #ifdef HB_GESTURE_FW
   327     // @todo remove after view auto-subscribes to gestures
   404     // @todo remove after view auto-subscribes to gestures
   328     viewport()->grabGesture(Qt::TapGesture);
   405     viewport()->grabGesture(Qt::TapGesture);
   329     viewport()->grabGesture(Qt::TapAndHoldGesture);
   406     viewport()->grabGesture(Qt::TapAndHoldGesture);
   359 
   436 
   360     HbInstancePrivate::d_ptr()->removeWindow(this);
   437     HbInstancePrivate::d_ptr()->removeWindow(this);
   361     delete d_ptr;
   438     delete d_ptr;
   362 
   439 
   363     // to workaround problem when creating/destroying multiple hbmainwindow's in unit tests (win env)
   440     // to workaround problem when creating/destroying multiple hbmainwindow's in unit tests (win env)
   364     #ifdef Q_OS_WIN
   441 #ifdef Q_OS_WIN
   365         destroy();
   442     destroy();
   366     #endif
   443 #endif
   367 }
   444 }
   368 
   445 
   369 /*!
   446 /*!
   370     Adds a \a widget to the HbMainWindow object. Passing 0 in
   447     Adds a \a widget to the HbMainWindow object. Passing 0 in
   371     \a widget creates an empty HbView.
   448     \a widget creates an empty HbView.
   372 
   449 
   373     The \a widget can be either a HbView or QGraphicsWidget. If it is
   450     The \a widget can be either a HbView or QGraphicsWidget. If it is
   374     the QGraphicsWidget then HbMainWindow will create a HbView and set
   451     a QGraphicsWidget (or any subclass that is not HbView) then
   375     \a widget as the new HbView's content widget.
   452     HbMainWindow will create a HbView and set \a widget as the new
       
   453     HbView's content widget.
       
   454 
       
   455     When \a widget is a HbView, use HbView::setWidget() to set the content
       
   456     widget for the view. Note that you should never attach child items or set a layout
       
   457     directly to the HbView instance, even though HbView is also a HbWidget.
       
   458     Instead, create a content widget, set it to the view via HbView::setWidget(),
       
   459     and attach children or set a layout to that.
       
   460 
       
   461     Use setCurrentView() to switch between the added views. (only one of them is visible at a time)
       
   462     The view-specific decorators (toolbar, Options menu, title in the titlebar) and of course
       
   463     the visibility of the view's content widgets will be updated and managed automatically by the framework
       
   464     when switching views.
       
   465 
       
   466     For a detailed description of views see the HbView class.
       
   467 
       
   468     Note that using view switching (i.e. several HbView instances, setCurrentView(), etc.) in
       
   469     Hb applications is not mandatory, it is purely optional. For applications that are not really
       
   470     view based (e.g. because they only have one screen of content or because they have more "fluid" UI where
       
   471     the traditional view separation does not make that much sense) it may sometimes be better (and may provide more freedom)
       
   472     to have just one view and manage the content entirely via the content widget of that one view.
       
   473     (one can still use HbStackedLayout and manual visibility management of child widgets to achieve a traditional view-like look,
       
   474     even when the Hb view management is not used)
       
   475 
       
   476     After calling addView() the caller does not need to care about
       
   477     destroying \a widget, the framework will take care of that by
       
   478     reparenting \a widget if needed.
   376 
   479 
   377     A HbMainWindow should only have one of each view and adding a view
   480     A HbMainWindow should only have one of each view and adding a view
   378     it already has will not cause the same view to be in the
   481     it already has will not cause the same view to be in the
   379     HbMainWindow twice.
   482     HbMainWindow twice.
   380 
   483 
   381     After calling addView() the caller does not need to care about
       
   382     destroying \a widget, the framework will take care of that by
       
   383     reparenting \a widget if needed.
       
   384 
       
   385     \return the new view
   484     \return the new view
   386 
   485 
   387     \sa insertView removeView
   486     \sa insertView() removeView() setCurrentView()
       
   487     \sa HbView HbStackedLayout
   388 */
   488 */
   389 HbView *HbMainWindow::addView(QGraphicsWidget *widget)
   489 HbView *HbMainWindow::addView(QGraphicsWidget *widget)
   390 {
   490 {
   391     Q_D(HbMainWindow);
   491     Q_D(HbMainWindow);
   392     HbView *view = 0;
   492     HbView *view = 0;
   406         d->mViewStackWidget->removeAt(index);
   506         d->mViewStackWidget->removeAt(index);
   407     }
   507     }
   408 
   508 
   409     d->mViewStackWidget->insertWidget(-1, view);
   509     d->mViewStackWidget->insertWidget(-1, view);
   410 
   510 
       
   511     // If the newly added view becomes the current one then emit the viewReady
       
   512     // signal (unless the delayed construction is still pending).
       
   513     if (d->mDelayedConstructionHandled && currentView() == view) {
       
   514         QMetaObject::invokeMethod(this, "_q_viewReady", Qt::QueuedConnection);
       
   515     }
       
   516 
   411     return view;
   517     return view;
   412 }
   518 }
   413 
   519 
   414 /*!
   520 /*!
   415     Inserts a \a widget to a given \a index to the HbMainWindow object.
   521     Inserts a \a widget to a given \a index to the HbMainWindow object.
   422     \return the new view.
   528     \return the new view.
   423 
   529 
   424     \sa addView removeView
   530     \sa addView removeView
   425 */
   531 */
   426 HbView *HbMainWindow::insertView(int index, QGraphicsWidget *widget)
   532 HbView *HbMainWindow::insertView(int index, QGraphicsWidget *widget)
   427 {    
   533 {
   428     Q_D(HbMainWindow);
   534     Q_D(HbMainWindow);
   429     HbView *view = 0;
   535     HbView *view = 0;
   430     if (!widget) {
   536     if (!widget) {
   431         view = new HbView(d->mViewStackWidget);
   537         view = new HbView(d->mViewStackWidget);
   432     } else {
   538     } else {
   434         if (!view) {
   540         if (!view) {
   435             view = new HbView();
   541             view = new HbView();
   436             view->setWidget(widget);
   542             view->setWidget(widget);
   437         }
   543         }
   438     }
   544     }
       
   545 
   439     d->mViewStackWidget->insertWidget(index, view);
   546     d->mViewStackWidget->insertWidget(index, view);
       
   547 
       
   548     // If the newly inserted view becomes the current one then emit the
       
   549     // viewReady signal (unless the delayed construction is still pending).
       
   550     if (d->mDelayedConstructionHandled && currentView() == view) {
       
   551         QMetaObject::invokeMethod(this, "_q_viewReady", Qt::QueuedConnection);
       
   552     }
   440 
   553 
   441     return view;
   554     return view;
   442 }
   555 }
   443 
   556 
   444 /*!
   557 /*!
   464     HbView *view = qobject_cast<HbView *>(widget);
   577     HbView *view = qobject_cast<HbView *>(widget);
   465     if (view) {
   578     if (view) {
   466         d->mViewStackWidget->removeWidget(view);
   579         d->mViewStackWidget->removeWidget(view);
   467     } else {
   580     } else {
   468         // Check if it is a widget inside a view and delete that view
   581         // Check if it is a widget inside a view and delete that view
   469         for (int n=0; n<d->mViewStackWidget->count(); n++) {
   582         for (int n = 0; n < d->mViewStackWidget->count(); n++) {
   470             HbView *tempView = qobject_cast<HbView*>(d->mViewStackWidget->widgetAt(n));
   583             HbView *tempView = qobject_cast<HbView *>(d->mViewStackWidget->widgetAt(n));
   471             if (tempView->widget() == widget) {
   584             if (tempView->widget() == widget) {
   472                 d->mViewStackWidget->removeWidget(tempView);
   585                 d->mViewStackWidget->removeWidget(tempView);
   473                 // Take a widget out from the view, before deleting it.
   586                 // Take a widget out from the view, before deleting it.
   474                 tempView->takeWidget();
   587                 tempView->takeWidget();
   475                 delete tempView;
   588                 delete tempView;
   532             d->mViewStackWidget->runViewSwitchEffectHide(oldView, flags);
   645             d->mViewStackWidget->runViewSwitchEffectHide(oldView, flags);
   533         } else {
   646         } else {
   534             // If animation is disabled or there is no view set currently then change
   647             // If animation is disabled or there is no view set currently then change
   535             // without animation.
   648             // without animation.
   536             d->mViewStackWidget->setCurrentWidget(view);
   649             d->mViewStackWidget->setCurrentWidget(view);
   537             if (d->mDelayedConstructionHandled)
   650             if (d->mDelayedConstructionHandled) {
   538                 QMetaObject::invokeMethod(this, "_q_viewReady", Qt::QueuedConnection);
   651                 QMetaObject::invokeMethod(this, "_q_viewReady", Qt::QueuedConnection);
       
   652             }
   539         }
   653         }
   540     }
   654     }
   541 }
   655 }
   542 
   656 
   543 /*!
   657 /*!
   546  */
   660  */
   547 QList<HbView *> HbMainWindow::views() const
   661 QList<HbView *> HbMainWindow::views() const
   548 {
   662 {
   549     Q_D(const HbMainWindow);
   663     Q_D(const HbMainWindow);
   550     HbContentWidget *stackWidget = d->mViewStackWidget;
   664     HbContentWidget *stackWidget = d->mViewStackWidget;
   551     
   665 
   552     const int n = stackWidget->count();
   666     const int n = stackWidget->count();
   553     QList<HbView *> result;
   667     QList<HbView *> result;
   554     for ( int i=0; i<n; ++i ) {
   668     for (int i = 0; i < n; ++i) {
   555         HbView *view = qobject_cast<HbView *>(stackWidget->widgetAt(i));
   669         HbView *view = qobject_cast<HbView *>(stackWidget->widgetAt(i));
   556         Q_ASSERT_X(view, "HbMainWindow::views()", "HbView was expected");
   670         Q_ASSERT_X(view, "HbMainWindow::views()", "HbView was expected");
   557         result.append(view);
   671         result.append(view);
   558     }
   672     }
   559     
   673 
   560     return result;
   674     return result;
   561 }
   675 }
   562 
   676 
   563 
   677 
   564 /*!
   678 /*!
   601 {
   715 {
   602     Q_D(HbMainWindow);
   716     Q_D(HbMainWindow);
   603     if (!d->mAutomaticOrientationSwitch) {
   717     if (!d->mAutomaticOrientationSwitch) {
   604         d->mAutomaticOrientationSwitch = true;
   718         d->mAutomaticOrientationSwitch = true;
   605         d->mUserOrientationSwitch = false;
   719         d->mUserOrientationSwitch = false;
   606         if(HbMainWindowOrientation::instance()->isEnabled())
   720         if (HbMainWindowOrientation::instance()->isEnabled()) {
   607             d->setTransformedOrientation(HbMainWindowOrientation::instance()->sensorOrientation(), animate);
   721             d->setTransformedOrientation(HbMainWindowOrientation::instance()->sensorOrientation(), animate);
       
   722         }
   608     }
   723     }
   609 }
   724 }
   610 
   725 
   611 /*!
   726 /*!
   612     Returns empty drawable window.
   727     Returns empty drawable window.
   659 #endif
   774 #endif
   660 }
   775 }
   661 
   776 
   662 /*!
   777 /*!
   663     Returns the rectangle which is used for layouting HbMainWindow contents. Updates on orientation change and is up to date
   778     Returns the rectangle which is used for layouting HbMainWindow contents. Updates on orientation change and is up to date
   664     after HbMainWindow orientationChanged() signal. Note that this is not the same thing as QGraphicsView (HbMainWindow) geometry. 
   779     after HbMainWindow orientationChanged() signal. Note that this is not the same thing as QGraphicsView (HbMainWindow) geometry.
   665     HbMainWindow geometry does not update on orientation change since the contents are only transformed with a rotate transform.
   780     HbMainWindow geometry does not update on orientation change since the contents are only transformed with a rotate transform.
   666     
   781 
   667 */
   782 */
   668 QRectF HbMainWindow::layoutRect() const
   783 QRectF HbMainWindow::layoutRect() const
   669 {
   784 {
   670     Q_D(const HbMainWindow);
   785     Q_D(const HbMainWindow);
   671 	return d->mLayoutRect;
   786     return d->mLayoutRect;
   672 }
   787 }
   673 
   788 
   674 /*!
   789 /*!
   675   Sets the \a name for the background image for the given \a orientation.  If
   790   Sets the \a name for the background image for the given \a orientation.  If
   676   the default image from the theme is suitable then there is no need to call
   791   the default image from the theme is suitable then there is no need to call
   697     Q_D(const HbMainWindow);
   812     Q_D(const HbMainWindow);
   698     return d->mBgItem ? d->mBgItem->imageName(orientation) : QString();
   813     return d->mBgItem ? d->mBgItem->imageName(orientation) : QString();
   699 }
   814 }
   700 
   815 
   701 /*!
   816 /*!
       
   817   Sets the background image drawing mode. This setting controls how
       
   818   the background image is displayed.
       
   819 
       
   820   By default the mode is set to Hb::ScaleBackgroundToFit.
       
   821 
       
   822   \sa backgroundImageMode()
       
   823   \sa Hb::BackgroundImageMode
       
   824  */
       
   825 void HbMainWindow::setBackgroundImageMode(Hb::BackgroundImageMode mode)
       
   826 {
       
   827     Q_D(HbMainWindow);
       
   828     if (d->mBgItem) {
       
   829         d->mBgItem->setImageMode(mode);
       
   830     }
       
   831 }
       
   832 
       
   833 /*!
       
   834   Returns the currently set background image drawing mode.
       
   835 
       
   836   \sa setBackgroundImageMode()
       
   837   \sa Hb::BackgroundImageMode
       
   838  */
       
   839 Hb::BackgroundImageMode HbMainWindow::backgroundImageMode() const
       
   840 {
       
   841     Q_D(const HbMainWindow);
       
   842     return d->mBgItem ? d->mBgItem->imageMode() : Hb::ScaleBackgroundToFit;
       
   843 }
       
   844 
       
   845 /*!
   702   Sets the animations enabled when the orientation is changed automatically.
   846   Sets the animations enabled when the orientation is changed automatically.
   703   By default animations are enabled.
   847   By default animations are enabled.
   704   
   848 
   705   \sa automaticOrientationEffectEnabled()
   849   \sa automaticOrientationEffectEnabled()
   706  */
   850  */
   707 
   851 
   708 void HbMainWindow::setAutomaticOrientationEffectEnabled(bool enabled)
   852 void HbMainWindow::setAutomaticOrientationEffectEnabled(bool enabled)
   709 {
   853 {
   710     Q_D(HbMainWindow);
   854     Q_D(HbMainWindow);
   711     d->mAutomaticOrientationChangeAnimation = enabled;
   855     d->mAutomaticOrientationChangeAnimation = enabled;
   712 }
   856 }
   713 
   857 
   714 /*!
   858 /*!
   715   Returns boolean value to signify whether animations enabled/disabled during 
   859   Returns boolean value to signify whether animations enabled/disabled during
   716   automatic orientation change. By default animations are enabled.
   860   automatic orientation change. By default animations are enabled.
   717 
   861 
   718   \sa setAutomaticOrientationEffectEnabled()
   862   \sa setAutomaticOrientationEffectEnabled()
   719  */
   863  */
   720 bool HbMainWindow::automaticOrientationEffectEnabled() const
   864 bool HbMainWindow::automaticOrientationEffectEnabled() const
   731     QGraphicsView::changeEvent(event);
   875     QGraphicsView::changeEvent(event);
   732     if (event->type() == QEvent::LayoutDirectionChange) {
   876     if (event->type() == QEvent::LayoutDirectionChange) {
   733         // Notify layout direction change to the icon framework
   877         // Notify layout direction change to the icon framework
   734         HbLayoutDirectionNotifier::instance()->notifyLayoutDirectionChange();
   878         HbLayoutDirectionNotifier::instance()->notifyLayoutDirectionChange();
   735 
   879 
   736         broadcastEvent( HbEvent::WindowLayoutDirectionChanged );
   880         broadcastEvent(HbEvent::WindowLayoutDirectionChanged);
   737 
   881 
   738         foreach (QGraphicsItem *item, items()) {
   882         foreach(QGraphicsItem * item, items()) {
   739             if (item->isWidget() && !item->parentItem() ) {
   883             if (item->isWidget() && !item->parentItem()) {
   740                 QGraphicsWidget *widget = static_cast<QGraphicsWidget *>(item);
   884                 QGraphicsWidget *widget = static_cast<QGraphicsWidget *>(item);
   741                 if (!widget->testAttribute(Qt::WA_SetLayoutDirection)){
   885                 if (!widget->testAttribute(Qt::WA_SetLayoutDirection)) {
   742                     widget->setLayoutDirection(layoutDirection());
   886                     widget->setLayoutDirection(layoutDirection());
   743                     widget->setAttribute(Qt::WA_SetLayoutDirection, false);
   887                     widget->setAttribute(Qt::WA_SetLayoutDirection, false);
   744                 }
   888                 }
   745             }
   889             }
   746         }
   890         }
   762 void HbMainWindow::keyPressEvent(QKeyEvent *event)
   906 void HbMainWindow::keyPressEvent(QKeyEvent *event)
   763 {
   907 {
   764     // pass the soft key press into the soft key decorator class
   908     // pass the soft key press into the soft key decorator class
   765     HbAction *action = 0;
   909     HbAction *action = 0;
   766 
   910 
   767     switch(event->key()) {
   911     switch (event->key()) {
   768 
   912 
   769 #ifdef Q_OS_SYMBIAN
   913 #ifdef Q_OS_SYMBIAN
   770     case Qt::Key_Context1:
   914     case Qt::Key_Context1:
   771 #else
   915 #else
   772     case Hb::Key_SoftKeyPrimary:
   916     case Hb::Key_SoftKeyPrimary:
   818 */
   962 */
   819 void HbMainWindow::resizeEvent(QResizeEvent *event)
   963 void HbMainWindow::resizeEvent(QResizeEvent *event)
   820 {
   964 {
   821     Q_D(HbMainWindow);
   965     Q_D(HbMainWindow);
   822 
   966 
   823     if ( !HbMainWindowPrivate::dragToResizeEnabled ) {
   967     if (!HbMainWindowPrivate::dragToResizeEnabled) {
   824         // determine the default orientation width < height -> portrait
   968         // determine the default orientation width < height -> portrait
   825         if (event->size().width() < event->size().height())
   969         if (event->size().width() < event->size().height()) {
   826             d->mDefaultOrientation = Qt::Vertical;
   970             d->mDefaultOrientation = Qt::Vertical;
   827         else
   971         } else {
   828             d->mDefaultOrientation = Qt::Horizontal;
   972             d->mDefaultOrientation = Qt::Horizontal;
       
   973         }
   829         d->mForceSetOrientation = true;
   974         d->mForceSetOrientation = true;
   830         d->setTransformedOrientation(d->mOrientation, false);
   975         d->setTransformedOrientation(d->mOrientation, false);
   831         d->mForceSetOrientation = false;
   976         d->mForceSetOrientation = false;
   832     } else {
   977     } else {
   833         // RnD feature for resizing the window by dragging
   978         // RnD feature for resizing the window by dragging
   834         QSize newSize(event->size());
   979         QSize newSize(event->size());
   835         setSceneRect(0,0,newSize.width(),newSize.height());
   980         setSceneRect(0, 0, newSize.width(), newSize.height());
   836         d->mClippingItem->resize(newSize);
   981         d->mClippingItem->resize(newSize);
   837         if (d->mBgItem) {
   982         if (d->mBgItem) {
   838             d->mBgItem->resize(newSize);
   983             d->mBgItem->resize(newSize);
   839         }
   984         }
   840     }
   985     }
   841 }
   986 }
   842 
   987 
   843 /*!
   988 /*!
   844     Reimplemented from QObject::customEvent().
   989     Reimplemented from QObject::customEvent().
   845 */
   990 */
   846 void HbMainWindow::customEvent( QEvent *event )
   991 void HbMainWindow::customEvent(QEvent *event)
   847 {
   992 {
   848     Q_D(HbMainWindow);
   993     Q_D(HbMainWindow);
   849     if (event->type() == HbMainWindowPrivate::IdleEvent) { // called asyncronously after the application start-up
   994     if (event->type() == HbMainWindowPrivate::IdleEvent) { // called asyncronously after the application start-up
   850         if (!d->mIdleEventHandled) {
   995         if (!d->mIdleEventHandled) {
   851             d->mIdleEventHandled = true;
   996             d->mIdleEventHandled = true;
   852             if ( HbFeatureManager::instance()->featureStatus( HbFeatureManager::TheTestUtility ) ) {
   997             if (HbFeatureManager::instance()->featureStatus(HbFeatureManager::TheTestUtility)) {
   853                 // create the test utility
   998                 // create the test utility
   854                 if ( !d->mTheTestUtility ) {
   999                 if (!d->mTheTestUtility) {
   855                     d->mTheTestUtility = new HbTheTestUtility(this);
  1000                     d->mTheTestUtility = new HbTheTestUtility(this);
   856                 }
  1001                 }
   857             }
  1002             }
   858             // get rid of the splash screen widget (it is not visible to the user anyway at this point)
  1003 #ifdef Q_OS_SYMBIAN
       
  1004             // Disable surface transparency unless we were really asked to be transparent.
       
  1005             // Must be done before destroying the splash screen widget.
       
  1006             if (!testAttribute(Qt::WA_TranslucentBackground)) {
       
  1007                 RWindow *const window = static_cast<RWindow *>(effectiveWinId()->DrawableWindow());
       
  1008                 window->SetSurfaceTransparency(false);
       
  1009             }
       
  1010 #endif
       
  1011             // Get rid of the splash screen widget. (it is not visible to the user anyway at this point)
   859             HbSplashScreen::destroy();
  1012             HbSplashScreen::destroy();
   860         }
  1013         }
   861         // Notify that mainwindow is (most probably) ready.
  1014         // Notify that mainwindow is (most probably) ready.
   862         // The signal must be emitted always, even when there was no need to do anything.
  1015         // The signal must be emitted always, even when there was no need to do anything.
   863         emit d->idleEventDispatched();
  1016         emit d->idleEventDispatched();
   864     } else if(event->type() == HbMainWindowPrivate::IdleOrientationEvent) { // complete the orientation change effect chain
  1017     } else if (event->type() == HbMainWindowPrivate::IdleOrientationEvent) { // complete the orientation change effect chain
   865         if (d->mEffectItem && d->mOrientationChangeOngoing) {
  1018         if (d->mEffectItem && d->mOrientationChangeOngoing && d->mOrientationEffectFinished) {
   866             HbEffect::start(d->mEffectItem, "rootItemFinalPhase", this, "rootItemFinalPhaseDone");
  1019             HbEffect::start(d->mEffectItem, "rootItemFinalPhase", this, "rootItemFinalPhaseDone");
   867         }
  1020         }
   868     } else if (event->type() == HbMainWindowPrivate::IdleOrientationFinalEvent) {
  1021     } else if (event->type() == HbMainWindowPrivate::IdleOrientationFinalEvent) {
   869         if (d->mAnimateOrientationSwitch) {
  1022         if (d->mAnimateOrientationSwitch) {
   870             HbEffect::start(d->mTitleBar, "titlebar", "appear_orient");
  1023             HbEffect::start(d->mTitleBar, "titlebar", "appear_orient");
   871             HbEffect::start(d->mStatusBar, "statusbar", "appear_orient");
  1024             HbEffect::start(d->mStatusBar, "statusbar", "appear_orient");
   872             if (d->mCurrentToolbar) {         
  1025             if (d->mCurrentToolbar) {
   873                 HbToolBarPrivate *toolBarD = HbToolBarPrivate::d_ptr(d->mCurrentToolbar);
  1026                 HbToolBarPrivate *toolBarD = HbToolBarPrivate::d_ptr(d->mCurrentToolbar);
   874                 toolBarD->startAppearOrientEffect();
  1027                 toolBarD->startAppearOrientEffect();
   875             }
  1028             } else {
   876             d->mOrientationChangeOngoing = false;
  1029                 foreach(HbView * view, views()) {
       
  1030                     view->toolBar()->resetTransform();
       
  1031                     view->toolBar()->setOpacity(1);
       
  1032                     view->toolBar()->show();
       
  1033                     HbToolBarPrivate::d_ptr(view->toolBar())->mOrientationEffectsRunning = false;
       
  1034                 }
       
  1035             }
       
  1036             d->updateOrientationChangeStatus();
   877             if (d->mAutomaticOrientationSwitch && HbMainWindowOrientation::instance()->isEnabled()) {
  1037             if (d->mAutomaticOrientationSwitch && HbMainWindowOrientation::instance()->isEnabled()) {
   878                 d->setTransformedOrientation(HbMainWindowOrientation::instance()->sensorOrientation(), d->mAnimateOrientationSwitch);
  1038                 d->setTransformedOrientation(HbMainWindowOrientation::instance()->sensorOrientation(), d->mAnimateOrientationSwitch);
   879             }
  1039             } else if (d->mRequestedOrientation != d->mOrientation) {
   880             else if (d->mRequestedOrientation != d->mOrientation) {
       
   881                 d->setTransformedOrientation(d->mRequestedOrientation, d->mAnimateOrientationSwitch);
  1040                 d->setTransformedOrientation(d->mRequestedOrientation, d->mAnimateOrientationSwitch);
   882             }
  1041             }
   883         } else {
  1042         } else {
   884             // cancel() with clearEffect cannot be used because the effects may have already been canceled.
  1043             // cancel() with clearEffect cannot be used because the effects may have already been canceled.
   885             if (d->mTitleBar) {
  1044             if (d->mTitleBar) {
   913     }
  1072     }
   914 
  1073 
   915     QGraphicsView::paintEvent(event);
  1074     QGraphicsView::paintEvent(event);
   916 }
  1075 }
   917 
  1076 
       
  1077 void HbMainWindow::showEvent(QShowEvent *event)
       
  1078 {
       
  1079 #ifdef Q_OS_SYMBIAN
       
  1080     // Enable surface transparency if QWidget did not do it already. This is a
       
  1081     // workaround for having non-transparent surfaces filled automatically with
       
  1082     // black color. The showEvent is a suitable place because the native control
       
  1083     // is already created at this point, but it is not too late either.
       
  1084     if (!testAttribute(Qt::WA_TranslucentBackground)) {
       
  1085         RWindow *const window = static_cast<RWindow *>(effectiveWinId()->DrawableWindow());
       
  1086         window->SetSurfaceTransparency(true);
       
  1087     }
       
  1088 #endif
       
  1089 
       
  1090 #if defined(Q_WS_X11)
       
  1091     Q_D(HbMainWindow);
       
  1092     d->x11HandleShowEvent(event);
       
  1093 #endif // defined(Q_WS_X11)
       
  1094 
       
  1095     QGraphicsView::showEvent(event);
       
  1096 }
       
  1097 
   918 /*!
  1098 /*!
   919     Reimplemented from QAbstractScrollArea::scrollContentsBy().
  1099     Reimplemented from QAbstractScrollArea::scrollContentsBy().
   920 */
  1100 */
   921 void HbMainWindow::scrollContentsBy(int dx, int dy)
  1101 void HbMainWindow::scrollContentsBy(int dx, int dy)
   922 {
  1102 {
   930 
  1110 
   931     Visible widgets will receive the event synchronously and invisble widgets
  1111     Visible widgets will receive the event synchronously and invisble widgets
   932     asynchronously.
  1112     asynchronously.
   933 
  1113 
   934     If the receiving widget has abstract items as child items, these will be informed
  1114     If the receiving widget has abstract items as child items, these will be informed
   935     after the widget has received the event. 
  1115     after the widget has received the event.
   936 */
  1116 */
   937 void HbMainWindow::broadcastEvent( int eventType )
  1117 void HbMainWindow::broadcastEvent(int eventType)
   938 {
  1118 {
   939     Q_D(HbMainWindow);
  1119     Q_D(HbMainWindow);
   940     d->broadcastEvent( eventType );
  1120     d->broadcastEvent(eventType);
       
  1121 }
       
  1122 
       
  1123 /*!
       
  1124     True if the window is not visible to the user.  False if one or more pixels are visible.
       
  1125 */
       
  1126 bool HbMainWindow::isObscured() const
       
  1127 {
       
  1128     Q_D(const HbMainWindow);
       
  1129 
       
  1130     return d->mObscuredState;
       
  1131 }
       
  1132 
       
  1133 /*
       
  1134     // reimplemented from QWidget
       
  1135 */
       
  1136 bool HbMainWindow::event(QEvent *event)
       
  1137 {
       
  1138     Q_D(HbMainWindow);
       
  1139     if (event->type() == HbEvent::WindowObscuredChanged) {
       
  1140         HbWindowObscuredChangedEvent *wosEvent = static_cast<HbWindowObscuredChangedEvent *>(event);
       
  1141         d->setObscuredState(wosEvent->obscuredState());
       
  1142     }
       
  1143     return QGraphicsView::event(event);
   941 }
  1144 }
   942 
  1145 
   943 HbRootItem::HbRootItem(QGraphicsItem *parent)
  1146 HbRootItem::HbRootItem(QGraphicsItem *parent)
   944     : HbWidget(parent)
  1147     : HbWidget(parent)
   945 {
  1148 {