src/hbcore/gui/hbview.cpp
changeset 0 16d8024aca5e
child 1 f7ac710697a9
equal deleted inserted replaced
-1:000000000000 0:16d8024aca5e
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (developer.feedback@nokia.com)
       
     6 **
       
     7 ** This file is part of the HbCore module of the UI Extensions for Mobile.
       
     8 **
       
     9 ** GNU Lesser General Public License Usage
       
    10 ** This file may be used under the terms of the GNU Lesser General Public
       
    11 ** License version 2.1 as published by the Free Software Foundation and
       
    12 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
       
    13 ** Please review the following information to ensure the GNU Lesser General
       
    14 ** Public License version 2.1 requirements will be met:
       
    15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    16 **
       
    17 ** In addition, as a special exception, Nokia gives you certain additional
       
    18 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    20 **
       
    21 ** If you have questions regarding the use of this file, please contact
       
    22 ** Nokia at developer.feedback@nokia.com.
       
    23 **
       
    24 ****************************************************************************/
       
    25 
       
    26 #include "hbview.h"
       
    27 #include "hbview_p.h"
       
    28 #include "hbinstance.h"
       
    29 #include "hbmenu.h"
       
    30 #include "hbmenu_p.h"
       
    31 #include "hbtoolbar.h"
       
    32 #include "hbstackedlayout.h"
       
    33 #include "hbdockwidget.h"
       
    34 #include "hbwidget_p.h"
       
    35 #include "hbmainwindow_p.h"
       
    36 #include "hbtitlebar_p.h"
       
    37 #include "hbstatusbar_p.h"
       
    38 #include "hbsoftkeygroup_p.h"
       
    39 #include "hbscreen_p.h"
       
    40 #include "hbviewactionmanager_p.h"
       
    41 #include "hbglobal_p.h"
       
    42 #include <QPointer>
       
    43 
       
    44 /*!
       
    45     @beta
       
    46     @hbcore
       
    47 	\class HbView
       
    48 	\brief HbView is a base class for all the views that can be set to HbMainWindow.
       
    49 	
       
    50 	HbView is a QGraphicsWidget, which contains a title, an icon, a menu and
       
    51 	a tool bar for one view in HbMainWindow.
       
    52 	
       
    53 	HbMainWindow will handle updating title, icon, menu and tool bar, when
       
    54 	the view is activated. Title is used in application's title pane area.
       
    55 	
       
    56 	HbView handles the visibility of tool bar, though HbMainWindow will
       
    57 	reparent it when ever view comes active.
       
    58 	
       
    59 	Example 1 for creating a simple view
       
    60 	
       
    61 	\include view1/main.cpp
       
    62 	
       
    63 	Example 2 for creating view with title, icon, menu, toolbar and a widget.
       
    64 	
       
    65 	\include view2/main.cpp
       
    66 
       
    67     \sa HbMenu
       
    68  */
       
    69 /*!
       
    70     \deprecated HbView::HbTitleBarFlag
       
    71         is deprecated. Use HbView::::HbViewFlag instead.
       
    72     \enum HbView::HbTitleBarFlag
       
    73     Defines policy for showing the HbTitleBar in the current HbView.
       
    74 */
       
    75 /*!
       
    76     \var HbView::TitleBarFlagNone 
       
    77     Titlebar is shown with the default attributes.
       
    78 */
       
    79 /*!
       
    80     \var HbView::TitleBarMinimizable When this flag is set, there will be an
       
    81     indication in titlebar showing the possibility to minimize (swipe out of the
       
    82     screen) titlebar.  */
       
    83 /*!
       
    84     \var HbView::TitleBarMinimized
       
    85     When this flag is set, the titlebar is shown in minimized state.
       
    86 */
       
    87 /*!
       
    88     \var HbView::TitleBarHidden When this flag is set, the titlebar is not shown
       
    89     at all, so that even the titlebar handle is not shown and it is not possible
       
    90     to maximize the titlebar.  */
       
    91 /*!
       
    92     \var HbView::TitleBarTransparent When this flag is set, the titlebar is
       
    93     shown normally, but as transparent. This flag is normally used in
       
    94     combination with TitleBarFloating flag.  */
       
    95 /*!
       
    96     \var HbView::TitleBarFloating When this flag is set, the titlebar is shown
       
    97     on top of underlying content. Setting this flag also changes application
       
    98     area to start from the top of the screen. This flag is normally used in
       
    99     combination with TitleBarTransparent flag.  */
       
   100 
       
   101 /*!
       
   102     \enum HbView::HbViewFlag
       
   103     Defines policy for showing the HbTitleBar in the current HbView.
       
   104 */
       
   105 /*!
       
   106     \var HbView::ViewFlagNone 
       
   107     Titlebar and statusbar is shown with the default attributes.
       
   108 */
       
   109 /*!
       
   110     \var HbView::ViewTitleBarMinimizable
       
   111     When this flag is set, there will be an indication in titlebar showing the possibility to minimize (swipe out of the screen) titlebar.
       
   112 */
       
   113 /*!
       
   114     \var HbView::ViewTitleBarMinimized
       
   115     When this flag is set, the titlebar is shown in minimized state.
       
   116 */
       
   117 /*!
       
   118     \var HbView::ViewTitleBarHidden
       
   119     When this flag is set, the titlebar is not shown at all, so that even the titlebar handle is not shown and it is not possible to maximize the titlebar.
       
   120 */
       
   121 /*!
       
   122     \var HbView::ViewTitleBarTransparent
       
   123     When this flag is set, the titlebar is shown normally, but as transparent. This flag is normally used in combination with ViewTitleBarFloating flag.
       
   124 */
       
   125 /*!
       
   126     \var HbView::ViewTitleBarFloating
       
   127     When this flag is set, the titlebar is shown on top of underlying content. Setting this flag also changes application area to start from the top of the screen. This flag is normally used in combination with TitleBarTransparent flag.
       
   128 */
       
   129 /*!
       
   130     \var HbView::ViewStatusBarHidden
       
   131     When this flag is set, the statusbar is not shown at all. This flag is normally used in combination with ViewTitleBarHidden flag.
       
   132 */
       
   133 /*!
       
   134     \var HbView::ViewStatusBarTransparent
       
   135     When this flag is set, the statusbar is shown normally, but as transparent. This flag is normally used in combination with ViewStatusBarFloating flag.
       
   136 */
       
   137 /*!
       
   138     \var HbView::ViewStatusBarFloating
       
   139     When this flag is set, the statusbar is shown on top of underlying content. Setting this flag also changes application area to start from the top of the screen. This flag is normally used in combination with ViewStatusBarTransparent flag.
       
   140 */
       
   141 
       
   142 /*!
       
   143     \fn void HbView::titleChanged(const QString &title)
       
   144 
       
   145     This signal is emitted when the title changes.
       
   146  */
       
   147 
       
   148 /*!
       
   149     \fn void HbView::iconChanged(const HbIcon &icon)
       
   150 
       
   151     This signal is emitted when the icon changes.
       
   152  */
       
   153 
       
   154 /*!
       
   155     \fn void HbView::toolBarChanged()
       
   156 
       
   157     This signal is emitted when tool bar changes.
       
   158  */
       
   159 
       
   160 /*!
       
   161     \reimp
       
   162     \fn int HbView::type() const
       
   163  */
       
   164 
       
   165 HbViewPrivate::HbViewPrivate()
       
   166     : mLayout(0), 
       
   167       menu(0), 
       
   168       toolBar(0), 
       
   169       dockWidget(0),
       
   170       widget(0),
       
   171       mVisibleItems(Hb::AllItems),
       
   172       mVisibleItemsSet(false),
       
   173       mFullscreen(false),
       
   174       mVisited(false),
       
   175       mTitleBarFlags(HbView::TitleBarFlagNone),
       
   176       mViewFlags(HbView::ViewFlagNone),
       
   177       actionManager(0),
       
   178       preferredActionContainer(HbView::NotSpecified),
       
   179       mNavigationAction(0),
       
   180       mNavigationActionSet(false)
       
   181 {
       
   182 }
       
   183 
       
   184 HbViewPrivate::~HbViewPrivate()
       
   185 {
       
   186 }
       
   187 
       
   188 /*!
       
   189     Constructs a view with given \a parent.
       
   190 */
       
   191 HbView::HbView(QGraphicsItem *parent) :
       
   192     HbWidget(*new HbViewPrivate, parent)
       
   193 {
       
   194     Q_D(HbView);
       
   195     d->q_ptr = this;
       
   196 }
       
   197 
       
   198 /*!
       
   199     \internal
       
   200  */
       
   201 HbView::HbView( HbViewPrivate &dd, QGraphicsItem *parent ):
       
   202     HbWidget(dd, parent)
       
   203 {
       
   204     Q_D(HbView);
       
   205     d->q_ptr = this; 
       
   206 }
       
   207 
       
   208 /*!
       
   209     Destructs the view.
       
   210 */
       
   211 HbView::~HbView()
       
   212 {
       
   213     Q_D(HbView);
       
   214     if (d->menu) {
       
   215         d->menu->deleteLater();
       
   216     }
       
   217     if (d->toolBar) {
       
   218         d->toolBar->deleteLater();
       
   219     }
       
   220     if (d->dockWidget) {
       
   221         d->dockWidget->deleteLater();
       
   222     }
       
   223 }
       
   224 
       
   225 /*!
       
   226     Returns the title of the view.
       
   227 
       
   228     The default value is a null string.
       
   229 
       
   230     \sa setTitle()
       
   231  */
       
   232 QString HbView::title() const
       
   233 {
       
   234     Q_D(const HbView);
       
   235     return d->title;
       
   236 }
       
   237 
       
   238 /*!
       
   239     Sets the title of the view.
       
   240 
       
   241     \sa title()
       
   242  */
       
   243 void HbView::setTitle(const QString &title)
       
   244 {
       
   245     Q_D(HbView);
       
   246     if (d->title != title) {
       
   247         d->title = title;
       
   248         emit titleChanged(title);
       
   249     }
       
   250 }
       
   251 
       
   252 /*!
       
   253     Returns the icon of the view.
       
   254 
       
   255     The default value is a null icon.
       
   256 
       
   257     \sa setIcon(), HbIcon::isNull()
       
   258  */
       
   259 HbIcon HbView::icon() const
       
   260 {
       
   261     Q_D(const HbView);
       
   262     return d->icon;
       
   263 }
       
   264 
       
   265 /*!
       
   266     Sets the icon of the view. The icon is associated with view.
       
   267 
       
   268     \sa icon()
       
   269  */
       
   270 void HbView::setIcon(const HbIcon &icon)
       
   271 {
       
   272     Q_D(HbView);
       
   273     if (d->icon != icon) {
       
   274         d->icon = icon;
       
   275         emit iconChanged(icon);
       
   276     }
       
   277 }
       
   278 
       
   279 /*!
       
   280     Returns the menu for the view. This function creates and returns an empty menu if it does not exist.
       
   281 
       
   282     Ownership is not transferred.
       
   283 
       
   284     \sa HbMenu setMenu()
       
   285 */
       
   286 HbMenu *HbView::menu() const
       
   287 {
       
   288     Q_D(const HbView);
       
   289     if (!d->menu) {
       
   290         const_cast<HbView *>(this)->setMenu(new HbMenu());
       
   291     }
       
   292     if (mainWindow()) {
       
   293         d->menu->setLayoutDirection(mainWindow()->layoutDirection());
       
   294     }
       
   295     return d->menu;
       
   296 }
       
   297 
       
   298 /*!
       
   299     Sets the menu for the view. Setting the menu to 0 will remove it from the view.
       
   300 
       
   301     Takes the ownership of the \a menu.
       
   302 
       
   303     \sa HbMenu menu()
       
   304 */
       
   305 void HbView::setMenu(HbMenu *menu)
       
   306 {
       
   307     Q_D(HbView);
       
   308     if (d->menu != menu) {
       
   309         if(d->menu) {
       
   310             d->menu->deleteLater();
       
   311         }
       
   312         d->menu = menu;
       
   313         if (d->menu) {
       
   314             HbMenuPrivate::d_ptr(d->menu)->changeToOptionsMenu();
       
   315             if (mainWindow()) {
       
   316                 d->menu->setLayoutDirection(mainWindow()->layoutDirection());
       
   317             }
       
   318         }
       
   319     }
       
   320 }
       
   321 
       
   322 /*!
       
   323     Returns the tool bar for the view. This function creates and returns an empty tool bar if it does not exist.
       
   324     The toolBarChanged() signal is not emitted if a new tool bar is created.
       
   325 
       
   326     Ownership is not transferred.
       
   327 
       
   328     \sa HbToolBar setToolBar()
       
   329 */
       
   330 HbToolBar *HbView::toolBar() const
       
   331 {
       
   332     Q_D(const HbView);
       
   333     if (!d->toolBar) {
       
   334         HbView *that = const_cast<HbView *>(this);
       
   335         that->setToolBar(new HbToolBar);
       
   336     }
       
   337     return d->toolBar;
       
   338 }
       
   339 
       
   340 /*!
       
   341     Sets the toolbar for the view. Setting the tool bar to 0 will remove it from the view.
       
   342 
       
   343     Takes the ownership of the \a toolBar, though it is not a parent.
       
   344 
       
   345     \sa HbToolBar toolBar()
       
   346 */
       
   347 void HbView::setToolBar(HbToolBar *toolBar)
       
   348 {
       
   349     Q_D(HbView);
       
   350     if (d->toolBar != toolBar) {
       
   351         if (d->toolBar) {
       
   352             d->toolBar->deleteLater();
       
   353         }
       
   354         d->toolBar = toolBar;
       
   355         emit toolBarChanged();
       
   356     }
       
   357 }
       
   358 
       
   359 /*!
       
   360 Removes the HbToolBar, which is set to view and returns it.
       
   361 The ownership of the \a HbToolBar is transferred to the caller.
       
   362 
       
   363 \note This function is particularly useful if one wants to switch between
       
   364 different views without deleting previous toolbar.
       
   365 
       
   366     \sa setToolBar()
       
   367 */
       
   368 HbToolBar* HbView::takeToolBar()
       
   369 {
       
   370     Q_D(HbView);
       
   371     HbToolBar* toolBar = d->toolBar;
       
   372     d->toolBar = 0;
       
   373 
       
   374     // Reset the ownership
       
   375     if (toolBar) {
       
   376         toolBar->setParentItem(0);
       
   377     }
       
   378 
       
   379     return toolBar;
       
   380 }
       
   381 
       
   382 
       
   383 /*!
       
   384     Returns the dock widget for the view. This function creates and returns an empty dock widget if it does not exist.
       
   385     The dockWidgetChanged() signal is not emitted if a new dock widget is created.
       
   386 
       
   387     Ownership is not transferred.
       
   388 
       
   389     \sa HbDockWidget setDockWidget()
       
   390 */
       
   391 HbDockWidget *HbView::dockWidget() const
       
   392 {
       
   393     Q_D(const HbView);
       
   394     if (!d->dockWidget) {
       
   395         HbView *that = const_cast<HbView *>(this);
       
   396         that->setDockWidget(new HbDockWidget);
       
   397     }
       
   398     return d->dockWidget;
       
   399 }
       
   400 
       
   401 /*!
       
   402     Sets the dock widget for the view. Setting the dock widget to 0 will remove it from the view.
       
   403 
       
   404     Takes the ownership of the \a dockWidget, though it is not a parent.
       
   405 
       
   406     \sa HbDockWidget dockWidget()
       
   407 */
       
   408 void HbView::setDockWidget(HbDockWidget *dockWidget)
       
   409 {
       
   410     Q_D(HbView);
       
   411     if (d->dockWidget != dockWidget) {
       
   412         if (d->dockWidget) {
       
   413             d->dockWidget->deleteLater();
       
   414         }
       
   415         d->dockWidget = dockWidget;
       
   416         emit dockWidgetChanged();
       
   417     }
       
   418 }
       
   419 
       
   420 /*!
       
   421     Returns the widget if set, otherwise \c 0.
       
   422 
       
   423     \sa setWidget widget takeWidget
       
   424 */
       
   425 QGraphicsWidget *HbView::widget() const
       
   426 {
       
   427     Q_D(const HbView);
       
   428     return d->widget;
       
   429 }
       
   430 
       
   431 /*!
       
   432     Sets the widget to be \a widget. Setting the widget to 0 will remove it from the view. Already set
       
   433     widget is deleted.
       
   434 
       
   435     Takes the ownership of the \a widget.
       
   436 
       
   437     \sa widget takeWidget
       
   438 */
       
   439 void HbView::setWidget(QGraphicsWidget *widget)
       
   440 {
       
   441     Q_D(HbView);
       
   442     if (d->widget != widget) {
       
   443         if (widget) {
       
   444             if (!d->mLayout) {
       
   445                 d->mLayout = new HbStackedLayout;
       
   446                 d->mLayout->setContentsMargins( 0.0, 0.0, 0.0, 0.0 );
       
   447                 d->mLayout->setMinimumSize( 0.0, 0.0 );
       
   448                 setLayout( d->mLayout );
       
   449             } else {
       
   450                 Q_ASSERT(d->mLayout->count() == 1);
       
   451                 d->mLayout->removeAt( 0 );
       
   452             }
       
   453             d->mLayout->addItem( widget );
       
   454         } else {
       
   455             if (d->mLayout) {
       
   456                 // "setLayout( 0 )" deletes the existing layout.
       
   457                 setLayout( 0 );
       
   458                 d->mLayout = 0;
       
   459             }
       
   460         }
       
   461         delete d->widget;
       
   462         d->widget = widget;            
       
   463     }
       
   464 }
       
   465 
       
   466 /*!
       
   467 Removes the QGraphicsWidget, which is set to view and returns it. 
       
   468 The ownership of the \a widget is transferred to the caller.
       
   469 
       
   470 \note This function is particularly useful if one wants to switch between
       
   471 different widgets inside a view without deleting them.
       
   472 
       
   473 \sa widget() setWidget()
       
   474 */
       
   475 
       
   476 QGraphicsWidget *HbView::takeWidget()
       
   477 {
       
   478     Q_D(HbView);
       
   479     QGraphicsWidget *widget = d->widget;
       
   480     if ( d->mLayout ) {
       
   481         d->mLayout->removeAt( 0 );
       
   482         // "setLayout( 0 )" deletes the existing layout.
       
   483         setLayout( 0 );
       
   484         d->mLayout = 0;
       
   485     }
       
   486     d->widget = 0;
       
   487     // Reset the ownership
       
   488     if (widget) {
       
   489         widget->setParentItem(0);
       
   490     }
       
   491     return widget;
       
   492 }
       
   493 
       
   494 /*!
       
   495     Sets \a items to be visible in this view. Changes will be visible
       
   496     instantly if the view is currently active, otherwise next time when
       
   497     view is activated. View's visibility flag overrides the similar
       
   498     setting in HbMainWindow.
       
   499     
       
   500     \sa hideItems() setItemVisible() isItemVisible() unsetVisibleItems() visibleItems() isContentFullScreen() setContentFullScreen()
       
   501 */
       
   502 void HbView::showItems(Hb::SceneItems items)
       
   503 {
       
   504     Q_D(HbView);
       
   505     d->mVisibleItems |= items;
       
   506     d->mVisibleItemsSet = true;
       
   507 
       
   508     if (items & Hb::TitleBarItem) {
       
   509         d->mViewFlags &= ~HbView::ViewTitleBarHidden;
       
   510         d->mTitleBarFlags &= ~HbView::TitleBarHidden;
       
   511     }
       
   512     if (items & Hb::StatusBarItem) {
       
   513         d->mViewFlags &= ~HbView::ViewStatusBarHidden;
       
   514     }
       
   515 
       
   516     emit visibleItemsChanged();
       
   517 }
       
   518 
       
   519 /*!
       
   520     Sets \a items to be invisible in this view. Changes will be visible
       
   521     instantly if the view is currently active, otherwise next time when
       
   522     view is activated. View's visibility flag overrides the similar
       
   523     setting in HbMainWindow.
       
   524     
       
   525     \sa showItems() setItemVisible() isItemVisible() unsetVisibleItems() visibleItems() isContentFullScreen() setContentFullScreen()
       
   526 */
       
   527 void HbView::hideItems(Hb::SceneItems items)
       
   528 {
       
   529     Q_D(HbView);
       
   530     d->mVisibleItems &= ~items;
       
   531     d->mVisibleItemsSet = true;
       
   532 
       
   533     if (items & Hb::TitleBarItem) {
       
   534         d->mViewFlags |= HbView::ViewTitleBarHidden;
       
   535         d->mTitleBarFlags |= HbView::TitleBarHidden;
       
   536     }
       
   537     if (items & Hb::StatusBarItem) {
       
   538         d->mViewFlags |= HbView::ViewStatusBarHidden;
       
   539     }
       
   540 
       
   541     emit visibleItemsChanged();
       
   542 }
       
   543 
       
   544 /*!
       
   545     Returns visible items of this view.
       
   546 
       
   547     \sa isItemVisible() setItemVisible() hideItems() showItems() unsetVisibleItems() isContentFullScreen() setContentFullScreen()
       
   548     
       
   549 */
       
   550 Hb::SceneItems HbView::visibleItems() const
       
   551 {
       
   552     Q_D(const HbView);
       
   553     if (d->mVisibleItemsSet) {
       
   554         return d->mVisibleItems;
       
   555     } else {
       
   556         return HbMainWindowPrivate::d_ptr(mainWindow())->mVisibleItems;
       
   557     }
       
   558 }
       
   559 
       
   560 /*!
       
   561     Returns \c true if \a item is set to be visible.
       
   562 
       
   563     \sa setItemVisible() hideItems() showItems() unsetVisibleItems() visibleItems() isContentFullScreen() setContentFullScreen()
       
   564     
       
   565 */
       
   566 bool HbView::isItemVisible(Hb::SceneItem item) const
       
   567 {
       
   568     Q_D(const HbView);
       
   569     return d->mVisibleItems & item;
       
   570 }
       
   571 
       
   572 /*!
       
   573     Sets \a item to be \a visible in this view. Changes will be visible
       
   574     instantly if the view is currently active, otherwise next time when
       
   575     view is activated. View's visibility flag overrides the similar
       
   576     setting in HbMainWindow.
       
   577     
       
   578     \sa isItemVisible() hideItems() showItems() unsetVisibleItems() visibleItems() isContentFullScreen() setContentFullScreen()
       
   579 */
       
   580 void HbView::setItemVisible(Hb::SceneItem item, bool visible)
       
   581 {
       
   582     Q_D(HbView);
       
   583     visible ? d->mVisibleItems |= item : d->mVisibleItems &= ~item;
       
   584     d->mVisibleItemsSet = true;
       
   585 
       
   586     emit visibleItemsChanged();
       
   587 }
       
   588 
       
   589 /*!
       
   590     \deprecated HbView::unsetVisibleItems()
       
   591         is deprecated.
       
   592 
       
   593     Resets the view specific definition of visible items and
       
   594     uses the HbMainWindow's default visible items. Changes will be visible
       
   595     instantly if the view is currently active, otherwise next time when
       
   596     view is activated.
       
   597     
       
   598     \sa setItemVisible() isItemVisible() hideItems() showItems() visibleItems() isContentFullScreen() setContentFullScreen()
       
   599 */
       
   600 void HbView::unsetVisibleItems()
       
   601 {
       
   602     HB_DEPRECATED("HbMainWindow::unsetVisibleItems is deprecated!");
       
   603     Q_D(HbView);
       
   604     d->mVisibleItemsSet = false;
       
   605 
       
   606     emit visibleItemsChanged();
       
   607 }
       
   608 
       
   609 /*!
       
   610     Returns \c true if view is set to use fullscreen.
       
   611 
       
   612     \sa setContentFullScreen() setItemVisible() isItemVisible() hideItems() showItems() visibleItems()
       
   613 */
       
   614 bool HbView::isContentFullScreen() const
       
   615 {
       
   616     Q_D(const HbView);
       
   617     return d->mFullscreen;
       
   618 }
       
   619 
       
   620 /*!
       
   621     Sets the view to use full content area for drawing. Decorators like
       
   622     signal bar, title pane etc can be shown on top of view content area.
       
   623     Changes will be visible instantly if the view is currently active, 
       
   624     otherwise next time when view is activated.
       
   625 
       
   626     \sa isContentFullScreen() setItemVisible() isItemVisible() hideItems() showItems() visibleItems()
       
   627 */
       
   628 void HbView::setContentFullScreen(bool enable)
       
   629 {
       
   630     Q_D(HbView);
       
   631     if (d->mFullscreen != enable) {
       
   632         d->mFullscreen = enable;
       
   633         emit contentFullScreenChanged();
       
   634     }
       
   635 }
       
   636 
       
   637 /*!
       
   638     \deprecated HbView::titleBarFlags()
       
   639         is deprecated. Use HbView::viewFlags() instead.
       
   640 
       
   641     Returns titlebar flags bit vector.
       
   642     It consists of bits specified in HbTitleBarFlag.
       
   643 
       
   644     \sa setTitleBarFlags()
       
   645 */
       
   646 HbView::HbTitleBarFlags HbView::titleBarFlags() const
       
   647 {
       
   648     Q_D(const HbView);
       
   649     int statusBarFlagMask = ViewStatusBarHidden | ViewStatusBarTransparent | ViewStatusBarFloating;
       
   650     int flags(d->mViewFlags & ~statusBarFlagMask);
       
   651     return HbView::HbTitleBarFlags(flags);
       
   652 }
       
   653 
       
   654 /*!
       
   655     Returns view flags bit vector.
       
   656     It consists of bits specified in HbViewFlag.
       
   657 
       
   658     \sa setTitleBarFlags()
       
   659 */
       
   660 HbView::HbViewFlags HbView::viewFlags() const
       
   661 {
       
   662     Q_D(const HbView);
       
   663     return d->mViewFlags;
       
   664 }
       
   665 
       
   666 /*!
       
   667     \deprecated HbView::setTitleBarFlags(HbView::HbTitleBarFlags flags)
       
   668         is deprecated. Use HbView::setViewFlags(HbView::HbViewFlags flags) instead.
       
   669 
       
   670     Sets the titlebar flags bit vector. It consists of bits specified
       
   671     in HbTitleBarFlag. These flags can be set before the view is
       
   672     added to the main window or while the view is active.
       
   673 
       
   674     \sa titleBarFlags()
       
   675 */
       
   676 void HbView::setTitleBarFlags(HbView::HbTitleBarFlags flags)
       
   677 {
       
   678     const int statusBarFlagMask = ViewStatusBarHidden | ViewStatusBarTransparent | ViewStatusBarFloating;
       
   679 
       
   680     Q_D(HbView);
       
   681     setViewFlags(HbView::HbViewFlags((d->mViewFlags & statusBarFlagMask) | flags));
       
   682 }
       
   683 
       
   684 /*!
       
   685     Sets the view flags bit vector. It consists of bits specified
       
   686     in HbViewFlag. These flags can be set before the view is
       
   687     added to the main window or while the view is active.
       
   688 
       
   689     \sa viewFlags()
       
   690 */
       
   691 void HbView::setViewFlags(HbView::HbViewFlags flags)
       
   692 {
       
   693     if (!mainWindow()) {
       
   694         return;
       
   695     }
       
   696     Q_D(HbView);
       
   697     HbView::HbViewFlags originalFlags(d->mViewFlags);
       
   698     d->mViewFlags = flags;
       
   699     if (mainWindow()) {
       
   700         bool statusBarAnimating = false;
       
   701         HbStatusBar *statusBar = HbMainWindowPrivate::d_ptr(mainWindow())->mStatusBar;
       
   702         if ((d->mViewFlags & HbView::ViewStatusBarHidden) && statusBar->isVisible()) {
       
   703              HbEffect::start(statusBar, "statusbar", "disappear", this, "statusBarEffectFinished"); 
       
   704              statusBarAnimating = true;
       
   705         } else if (!(d->mViewFlags & HbView::ViewStatusBarHidden) && !statusBar->isVisible()) {
       
   706              HbEffect::start(statusBar, "statusbar", "appear", this, "statusBarEffectFinished");
       
   707              statusBarAnimating = true;
       
   708         }
       
   709         bool titleBarAnimating = false;
       
   710         HbTitleBar *titleBar = HbMainWindowPrivate::d_ptr(mainWindow())->mTitleBar;
       
   711         if ((d->mViewFlags & HbView::ViewTitleBarHidden) && titleBar->isVisible()) {
       
   712              HbEffect::start(titleBar, "titleBar", "disappear", this, "titleBarEffectFinished");
       
   713              titleBarAnimating = true;
       
   714         } else if (!(d->mViewFlags & HbView::ViewTitleBarHidden) && !titleBar->isVisible()) {
       
   715              HbEffect::start(titleBar, "titleBar", "appear", this, "titleBarEffectFinished");
       
   716              titleBarAnimating = true;
       
   717         }
       
   718         if (!statusBarAnimating) {
       
   719             statusBar->setVisible(!(d->mViewFlags & HbView::ViewStatusBarHidden));
       
   720             statusBar->propertiesChanged();
       
   721         }
       
   722         if (!titleBarAnimating) {
       
   723             titleBar->setVisible(!(d->mViewFlags & HbView::ViewTitleBarHidden));
       
   724             if (d->mNavigationActionSet) {
       
   725                 titleBar->setNavigationAction(d->mNavigationAction);
       
   726             } else {
       
   727                 titleBar->setDefaultNavigationAction();
       
   728             }
       
   729             titleBar->propertiesChanged();
       
   730         }
       
   731        
       
   732         // Repolish the screen if needed
       
   733         int visibilityFlags = HbView::ViewTitleBarMinimized | HbView::ViewTitleBarFloating 
       
   734             | HbView::ViewTitleBarMinimizable | HbView::ViewStatusBarHidden | HbView::ViewStatusBarFloating;
       
   735         if ((d->mViewFlags & visibilityFlags) != (originalFlags & visibilityFlags)) {
       
   736             HbMainWindowPrivate::d_ptr(mainWindow())->mClippingItem->decoratorVisibilityChanged();
       
   737         }
       
   738     }
       
   739 }
       
   740 
       
   741 /*!
       
   742     Changes titlebar's visibility with pre-defined effect.
       
   743 */
       
   744 void HbView::setTitleBarVisible(bool visible)
       
   745 {
       
   746     Q_D(HbView);
       
   747     if (visible) {
       
   748         setViewFlags(d->mViewFlags &~ HbView::ViewTitleBarHidden);
       
   749         d->mVisibleItems |= Hb::TitleBarItem;
       
   750         d->mVisibleItemsSet = true;
       
   751     } else {
       
   752         setViewFlags(d->mViewFlags | HbView::ViewTitleBarHidden);
       
   753         d->mVisibleItems &= ~Hb::TitleBarItem;
       
   754         d->mVisibleItemsSet = true;
       
   755     }  
       
   756 }
       
   757 
       
   758 /*!
       
   759     Changes statusbar's visibility with pre-defined effect.
       
   760 */
       
   761 void HbView::setStatusBarVisible(bool visible)
       
   762 {
       
   763     Q_D(HbView);
       
   764     if (visible) {
       
   765         setViewFlags(d->mViewFlags &~ HbView::ViewStatusBarHidden);
       
   766         d->mVisibleItems |= Hb::StatusBarItem;
       
   767         d->mVisibleItemsSet = true;
       
   768     } else {
       
   769         setViewFlags(d->mViewFlags | HbView::ViewStatusBarHidden);
       
   770         d->mVisibleItems &= ~Hb::StatusBarItem;
       
   771         d->mVisibleItemsSet = true;
       
   772     }
       
   773 }
       
   774 
       
   775 /*!
       
   776     \overload
       
   777 
       
   778     The function adds \a action to preferred container's list of actions.  The
       
   779     ownership of \a action is not transferred.  The preferred container
       
   780     specifies the action container (options menu, toolbar) where the action is
       
   781     placed. If the container is the toolbar and the maximum toolbar button count
       
   782     is exceeded then the action may be moved to the options menu (if there are
       
   783     enough more prioritized actions).
       
   784 */
       
   785 void HbView::addAction(HbAction *action, ActionContainer preferredActionContainer)
       
   786 {
       
   787     Q_D(HbView);
       
   788     d->preferredActionContainer = preferredActionContainer;
       
   789     addAction(action);
       
   790 }
       
   791 
       
   792 /*!
       
   793     \reimp
       
   794  */
       
   795 bool HbView::event(QEvent *event)
       
   796 {
       
   797     Q_D(HbView);
       
   798     if (event->type() == QEvent::ActionRemoved) {
       
   799         // Create action manager if needed
       
   800         if (!d->actionManager) {
       
   801             d->actionManager = new HbViewActionManager(this);
       
   802         }
       
   803         QActionEvent *actionEvent = static_cast<QActionEvent *>(event);
       
   804         HbAction *hbAction = qobject_cast<HbAction *>(actionEvent->action());
       
   805         // Forward command to action manager
       
   806         d->actionManager->removeAction(hbAction); 
       
   807         return true;
       
   808     }
       
   809     else if (event->type() == QEvent::ActionAdded) {
       
   810         // Create action manager if needed
       
   811         if (!d->actionManager) {
       
   812             d->actionManager = new HbViewActionManager(this);
       
   813         }
       
   814         QActionEvent *actionEvent = static_cast<QActionEvent *>(event);
       
   815         HbAction *hbAction = qobject_cast<HbAction *>(actionEvent->action());
       
   816         // Forward command to action manager
       
   817         d->actionManager->addAction(hbAction, d->preferredActionContainer); 
       
   818         // Clear the variable after used
       
   819         d->preferredActionContainer = HbView::NotSpecified;
       
   820         return true;
       
   821     }
       
   822     return HbWidget::event(event);
       
   823 }
       
   824 
       
   825 /*!
       
   826 Removes the HbMenu, which is set to view and returns it. 
       
   827 The ownership of the \a HbMenu is transferred to the caller.
       
   828 
       
   829 \note This function is particularly useful if one wants to switch between
       
   830 different views without deleting previous menu.
       
   831 
       
   832     \sa setMenu()
       
   833 */
       
   834 HbMenu* HbView::takeMenu()
       
   835 {
       
   836     Q_D(HbView);
       
   837     HbMenu* menu = d->menu;
       
   838     d->menu = 0;
       
   839 
       
   840     // Reset the ownership
       
   841     if (menu) {
       
   842         menu->setParentItem(0);
       
   843     }
       
   844 
       
   845     return menu;
       
   846 }
       
   847 
       
   848 /*
       
   849     Handles effect finished event for title bar animation    
       
   850  */
       
   851 void HbView::titleBarEffectFinished(const HbEffect::EffectStatus &status)
       
   852 {   
       
   853     if (status.reason == Hb::EffectFinished || status.reason == Hb::EffectCancelled
       
   854         || status.reason == Hb::EffectNotStarted) {
       
   855         HbMainWindowPrivate::d_ptr(mainWindow())->mTitleBar->propertiesChanged();
       
   856         HbMainWindowPrivate::d_ptr(mainWindow())->mClippingItem->decoratorVisibilityChanged();
       
   857     }
       
   858     if (mainWindow()) {
       
   859         HbTitleBar *titleBar = HbMainWindowPrivate::d_ptr(mainWindow())->mTitleBar;
       
   860         if (titleBar) {
       
   861             if (status.effectEvent == "disappear") {
       
   862                 titleBar->setVisible(false);
       
   863             } else {
       
   864                 titleBar->setVisible(true);
       
   865             }
       
   866         }
       
   867     }
       
   868 }
       
   869 
       
   870 /*
       
   871     Handles effect finished event for title bar animation    
       
   872  */
       
   873 void HbView::statusBarEffectFinished(const HbEffect::EffectStatus &status)
       
   874 {   
       
   875     HbStatusBar *statusBar = HbMainWindowPrivate::d_ptr(mainWindow())->mStatusBar;
       
   876     if (!statusBar) {
       
   877         return;
       
   878     }
       
   879 
       
   880     if (status.reason == Hb::EffectFinished || status.reason == Hb::EffectCancelled
       
   881         || status.reason == Hb::EffectNotStarted) {
       
   882         statusBar->propertiesChanged();
       
   883         HbMainWindowPrivate::d_ptr(mainWindow())->mClippingItem->decoratorVisibilityChanged();
       
   884     }
       
   885     if (mainWindow()) {    
       
   886         if (status.effectEvent == "disappear") {
       
   887             statusBar->setVisible(false);
       
   888         } else {
       
   889             statusBar->setVisible(true);
       
   890         }
       
   891     }
       
   892 }
       
   893 
       
   894 /*!
       
   895   Returns the currently set navigation action or 0 if there is none.
       
   896 
       
   897   If setNavigationAction() was not called before for this view at all then the
       
   898   default action will be returned.
       
   899   
       
   900   \sa setNavigationAction()
       
   901  */
       
   902 HbAction *HbView::navigationAction() const
       
   903 {
       
   904     Q_D(const HbView);
       
   905     if (d->mNavigationActionSet) {
       
   906         return d->mNavigationAction;
       
   907     } else {
       
   908         HbMainWindow *mw = mainWindow();
       
   909         if (!mw) {
       
   910             QList<HbMainWindow *> mainWindows = hbInstance->allMainWindows();
       
   911             if (!mainWindows.isEmpty()) {
       
   912                 mw = mainWindows.at(0);
       
   913             }
       
   914         }
       
   915         return mw ? HbMainWindowPrivate::d_ptr(mw)->mTitleBar->navigationAction() : 0;
       
   916     }
       
   917 }
       
   918 
       
   919 /*!
       
   920   Sets the navigation action, that is, the action that is associated with the
       
   921   button that is typically located in the top-right corner. By default the
       
   922   action is the "quit" action.
       
   923 
       
   924   \a action can also be 0 in which case the previous navigation action is
       
   925   unset and no new one will be set.
       
   926 
       
   927   Ownership of \a action is not taken.
       
   928 
       
   929   \sa navigationAction()
       
   930  */
       
   931 void HbView::setNavigationAction(HbAction *action)
       
   932 {
       
   933     Q_D(HbView);
       
   934     d->mNavigationAction = action;
       
   935     d->mNavigationActionSet = true;
       
   936     HbMainWindow *mw = mainWindow();
       
   937     if (isVisible() && mw && mw->currentView() == this) {
       
   938         HbMainWindowPrivate::d_ptr(mw)->mTitleBar->setNavigationAction(action);
       
   939     }
       
   940 }
       
   941 
       
   942 // end of file