src/hbcore/gui/hbmenu.cpp
changeset 21 4633027730f5
parent 6 c3690ec91ef8
child 23 e6ad4ef83b23
equal deleted inserted replaced
7:923ff622b8b9 21:4633027730f5
   134     }	
   134     }	
   135 }
   135 }
   136 
   136 
   137 void HbMenuPrivate::delayedLayout()
   137 void HbMenuPrivate::delayedLayout()
   138 {
   138 {
   139     createMenuView();
   139     if (delayMenuConstruction) {
   140     if(menuItemView)
   140         createMenuView();
   141         menuItemView->doDelayedLayout();
   141         if(menuItemView)
   142     delayMenuConstruction = false;
   142             menuItemView->doDelayedLayout();
       
   143         delayMenuConstruction = false;
       
   144     }
   143 }
   145 }
   144 
   146 
   145 void HbMenuPrivate::changeToOptionsMenu()
   147 void HbMenuPrivate::changeToOptionsMenu()
   146 {
   148 {
   147     menuType = HbMenu::OptionsMenu;
   149     menuType = HbMenu::OptionsMenu;
   208     if (menuItemView)
   210     if (menuItemView)
   209         menuItemView->updateActionItem(actionEvent->action());
   211         menuItemView->updateActionItem(actionEvent->action());
   210 }
   212 }
   211 
   213 
   212 /*
   214 /*
   213    Returns current focusable action based on current row of the menuItemView or index if specified.
   215     Returns current focusable action based on current row of the menuItemView or index if specified.
   214    If there is no focusable action it returns 0.
   216     If there is no focusable action it returns 0.
   215    Also returns the active item representing the active action or 0.
   217     Also returns the active item representing the active action or 0.
   216 */
   218 */
   217 HbAction *HbMenuPrivate::activeAction(HbMenuItem *&activeItem) const
   219 HbAction *HbMenuPrivate::activeAction(HbMenuItem *&activeItem) const
   218 {
   220 {
   219     if(!menuItemView)
   221     if(!menuItemView)
   220         return 0;
   222         return 0;
   227     }
   229     }
   228     return action;
   230     return action;
   229 }
   231 }
   230 
   232 
   231 /*
   233 /*
   232   Convenience overload
   234     Convenience overload
   233 */
   235 */
   234 HbAction *HbMenuPrivate::activeAction() const
   236 HbAction *HbMenuPrivate::activeAction() const
   235 {
   237 {
   236     HbMenuItem* activeItem = 0;
   238     HbMenuItem* activeItem = 0;
   237     return activeAction(activeItem);
   239     return activeAction(activeItem);
   238 }
   240 }
   239 
   241 
   240 /*
   242 /*
   241   Opens a submenu for activeItem. If activeItem is 0 it uses activeAction() to determine active item
   243     Opens a submenu for activeItem. If activeItem is 0 it uses activeAction() to determine active item
   242   and opens submenu for it if active action has submenu.
   244     and opens submenu for it if active action has submenu.
   243 */
   245 */
   244 void HbMenuPrivate::openSubmenu(HbMenuItem *activeItem)
   246 void HbMenuPrivate::openSubmenu(HbMenuItem *activeItem)
   245 {
   247 {
   246     Q_Q(HbMenu);
   248     Q_Q(HbMenu);
   247 
   249 
   296         }
   298         }
   297         q->close();
   299         q->close();
   298     }
   300     }
   299 }
   301 }
   300 
   302 
   301 /*!
   303 /*
   302  Handles menu close
   304     Handles menu close
   303 */
   305 */
   304 void HbMenuPrivate::closeMenu()
   306 void HbMenuPrivate::closeMenu()
   305 {
   307 {
   306     Q_Q(HbMenu);
   308     Q_Q(HbMenu);
   307     HbMainWindow* w(q->mainWindow());
   309     HbMainWindow* w(q->mainWindow());
   375 
   377 
   376 /*!
   378 /*!
   377     @beta
   379     @beta
   378     @hbcore
   380     @hbcore
   379     \class HbMenu
   381     \class HbMenu
   380     \brief HbMenu is a menu widget for use in HbView.
   382     \brief The HbMenu class provides a widget that shows a list of options.
   381 
   383 
   382     \image html hbmenu.png A menu with checkable items and a sub-menu.
   384     A menu consists of a list of options that the user can select. When the user selects
   383 
   385     an option, it triggers a command. Menus are hidden by default and open in response
   384     Use an HbMenu to show a list of options. There are two main types of menus:
   386     to an action from the user. For this reason, the toolbar (HbToolBar class) usually
   385 
   387     provides access to the most important commands (called first order commands) and
   386     - The view options menu
   388     menus provide access to second order commands.
   387     - Context menus (popup menus)
   389 
   388 
   390     \image html hbmenu.png An options menu with a submenu that has checkable actions
   389     There is one view options menu for each view.
   391 
   390     It is shown by tapping the title bar. You can access the view options menu by calling
   392     You can use the %HbMenu class to create the following:
   391     HbView::menu() which returns a pointer to a new empty menu if one does not already exist.
   393 
   392 
   394     - An \b options \b menu, which shows options that relate to the whole view. It is
   393     You can create any number of context menus.
   395     a drop-down menu that is directly owned by the view (HbView object). It opens when the
   394     Context menus are usually invoked by a user action, such as tapping a widget.
   396     user taps on the view's title bar. You can access a view's options menu by calling
   395 
   397     HbView::menu(). This returns a pointer to a new empty menu if the menu does not
   396     A menu contains a list of items. You can add three kinds of items to a menu:
   398     already exist. A view can have only one options menu.
   397 
   399 
   398     - Actions
   400     - A \b context \b menu, which is a pop-up menu that shows options that relate to a
   399     - Sub-menus
   401     specific item, rather than to the entire view. It typically opens in response to a
   400     - Separators
   402     UI event, such as a tap on a widget or a particular point within the view. You can
   401 
   403     create any number of context menus.
   402     An action is an object of class HbAction that performs an action when it is triggered.
   404 
   403     Use addAction() to add an action to a menu. Actions can be checkable (QAction::setCheckable).
   405     A menu is a list of actions, which are objects of class HbAction. A menu can contain:
   404     Use clearActions() to clear all actions from a menu.
   406 
   405     Use removeAction() to remove individual actions from a menu.
   407     - \b Separators, which are actions that group related items. Use addSeparator() or
   406 
   408     insertSeparator() to create a separator and add it to a menu.
   407     A sub-menu is a menu that is nested within another menu. Use addMenu() or insertMenu() to add a sub-menu to a menu.
   409 
   408     Sub-menus can be nested within sub-menus.
   410     - Actions that trigger a \b submenu to open. Submenus are menus that are nested within
   409 
   411     another menu. Use addMenu() or insertMenu() to add a submenu to a menu. Although it is
   410     Separators group related items in a menu.
   412     possible to nest submenus within other submenus, generally this is not considered good
   411     Use addSeparator() or insertSeparator() to create and add a separator to a menu.
   413     design practice.
   412 
   414 
   413     \image html hbmenu.png A menu with checkable actions and a sub-menu.
   415     - \b Action \b items, which represent the menu options. Use addAction() and insertAction() to
   414 
   416     add an action to a menu. Use addActions() and insertActions() to add and insert multiple
   415     After you add an action to your menu, you specify a receiver object and its slot (you can also
   417     actions in one operation. Use clearActions() to clear all of the actions from a menu and
   416     add an action and specify a receiver slot at the same time).
   418     removeAction() to remove individual actions from a menu.
   417     The receiver is notifed when the action is triggered (QAction::triggered()).
   419 
   418     HbMenu also has a triggered() menu signal, which signals which HbAction was triggered in the menu.
   420     The order of the actions within the menu controls the order of the options that the user sees.
   419 
   421     When you add the actions directly to the menu, addAction() and addActions() append the actions
   420     An example of how to create an option menu.
   422     to the end of the menu and insertAction() and insertActions() enable you to specify the position.
       
   423     For options menus, however, there is an alternative approach to ordering the action items.
       
   424     This is to call HbView::addAction() to add actions to the \b view and let the view distribute
       
   425     them to the options menu or toolbar, depending on the preference set, the UI command distribution
       
   426     template, and taking into account the available space in the toolbar. The menu and toolbar
       
   427     then order the actions according to their defined roles and the UI command container template.
       
   428     This approach makes it easier to create consistent user interfaces and applications that
       
   429     work well on a variety of different devices.
       
   430 
       
   431     An action item can be checkable, which means that it has an on/off state. You specify that an
       
   432     action item is checkable by calling \c setCheckable() on the action. Use \c isChecked()
       
   433     to discover if an action is checked. You can also use the QAction::toggled(bool) signal to
       
   434     receive notification of a change in the checked status.
       
   435 
       
   436     After you add an action item to a menu, you can connect its \link HbAction::triggered()
       
   437     triggered()\endlink signal to a slot on a receiver object. Alternatively you can use the
       
   438     addAction(const QString &, const QObject *, const char *) overload to add an action item and
       
   439     specify a receiver slot at the same time. The receiver is notified when the action item
       
   440     is \link HbAction::triggered() triggered()\endlink.
       
   441 
       
   442     You can also connect the HbMenu::triggered(HbAction*) signal to a receiver object's slot. This
       
   443     signal is emitted when any menu action is triggered. You can find out which action was
       
   444     triggered from the HbAction parameter.
       
   445 
       
   446     \section _usecases_hbmenu Using the HbMenu class
       
   447 
       
   448     \subsection _uc_001_hbmenu Creating an options menu
       
   449 
       
   450     The following example creates an options menu for a view.
   421     \snippet{ultimatecodesnippet/ultimatecodesnippet.cpp,2}
   451     \snippet{ultimatecodesnippet/ultimatecodesnippet.cpp,2}
   422 
   452 
   423     An example of how to create and show a context menu from the gesture.
   453     \subsection _uc_002_hbmenu Creating a context menu
       
   454 
       
   455     The following example creates a context menu and shows it in response to a tap and hold gesture.
   424     \snippet{ultimatecodesnippet/ultimatecodesnippet.cpp,54}
   456     \snippet{ultimatecodesnippet/ultimatecodesnippet.cpp,54}
   425 
   457 
   426     \sa HbDialog, HbView
   458     \subsection _uc_004_hbmenu Adding actions to the view
       
   459 
       
   460     The following example creates two action items, specifies their command roles, and then
       
   461     adds them to the view. The view places them in the menu or toolbar according to the
       
   462     priorities of the actions and the space available in the toolbar and the menu orders them
       
   463     according to their roles and priorities.
       
   464 
       
   465     \code
       
   466     HbAction* actionExit = new HbAction(tr("Exit"));
       
   467     actionExit->setCommandRole(HbAction::ExitRole);
       
   468 
       
   469     HbAction* actionHelp = new HbAction(tr("Help"));
       
   470     actionHelp->setCommandRole(HbAction::HelpRole);
       
   471 
       
   472     // Add actions to the view.
       
   473     myView->addAction(actionExit);
       
   474     myView->addAction(actionHelp);
       
   475     \endcode
       
   476 
       
   477     \subsection _uc_003_hbmenu Creating action items that are checkable
       
   478 
       
   479     You can create a menu that contains multiple checkable actions (actions with checkbox behavior).
       
   480     For simple checkbox behavior, just set the actions to be checkable by calling \c setCheckable(true).
       
   481     For example:
       
   482 
       
   483     \code
       
   484     ...
       
   485     checkAction1->setCheckable(true);
       
   486     checkAction2->setCheckable(true);
       
   487     checkAction3->setCheckable(true);
       
   488     ...
       
   489     \endcode
       
   490 
       
   491     \subsection _uc_005_hbmenu Creating radio button style options
       
   492 
       
   493     To create a group of related actions, only one of which can be checked (radio button behavior),
       
   494     create a QActionGroup object and add the actions to that. For example:
       
   495 
       
   496     \code
       
   497     HbAction *redAction = menu->addAction(tr("Red"));
       
   498     HbAction *blueAction = menu->addAction(tr("Blue"));
       
   499 
       
   500     redAction->setCheckable(true);
       
   501     blueAction->setCheckable(true);
       
   502 
       
   503     QActionGroup *actionGroup = new QActionGroup(view);
       
   504     actionGroup->addAction(redAction);
       
   505     actionGroup->addAction(blueAction);
       
   506     \endcode
       
   507 
       
   508     \sa HbView, HbToolBar, HbAction
   427 */
   509 */
   428 
   510 
   429 /*!
   511 /*!
   430     \property HbMenu::menuType
   512     \property HbMenu::menuType
   431     \brief
   513     \brief
   432 */
   514 */
   433 
   515 
   434 /*!
   516 /*!
   435     \fn void HbMenu::triggered(HbAction *action)
   517     \fn void HbMenu::triggered(HbAction *action)
   436 
   518 
   437     This signal is emitted when one of the action items is selected.
   519     This signal is emitted when one of the menu options is selected.
   438     \param action the action that was triggered in the menu.
   520     \param action The action that was selected.
   439  */
   521 */
   440 
   522 
   441 /*!
   523 /*!
   442     \enum HbMenu::MenuType
   524     \enum HbMenu::MenuType
   443 
   525 
   444     This enum describes different types of HbMenu.
   526     The MenuType enum identifies the possible HbMenu types.
   445 */
   527 */
   446 /*!
   528 /*!
   447     \var HbMenu::ContextMenu
   529     \var HbMenu::ContextMenu
   448 
   530     A popup menu.
   449     ContextMenu is a menu which position is set by user.
   531 */
   450 */
   532 /*!
   451 /*!
   533     \var HbMenu::OptionsMenu
   452     \var HbMenu::OptionMenu
   534     The main options menu in a view. Its position cannot be changed.
   453 
       
   454     OptionMenu is set by HbView. Its position cannot be changed.
       
   455 */
   535 */
   456 /*!
   536 /*!
   457     \var HbMenu::SubMenu
   537     \var HbMenu::SubMenu
   458 
   538     A submenu, which is a menu that has been added to another menu.
   459     Menu becomes SubMenu when it is added to another menu.
       
   460 */
   539 */
   461 
   540 
   462 /*!
   541 /*!
   463     Constructs a menu with \a parent graphics item.
   542     Constructs a menu with \a parent graphics item.
   464 
       
   465     \param parent is the parent graphics item.
       
   466 */
   543 */
   467 HbMenu::HbMenu(QGraphicsItem *parent) :
   544 HbMenu::HbMenu(QGraphicsItem *parent) :
   468         HbPopup(*new HbMenuPrivate, parent)
   545         HbPopup(*new HbMenuPrivate, parent)
   469 {
   546 {
   470     Q_D(HbMenu);
   547     Q_D(HbMenu);
   473     setModal(true);
   550     setModal(true);
   474 }
   551 }
   475 
   552 
   476 /*!
   553 /*!
   477     Constructs a menu with \a title and \a parent graphics item.
   554     Constructs a menu with \a title and \a parent graphics item.
   478     \param title is the menu title.
       
   479     \param parent is the parent graphics item.
       
   480 */
   555 */
   481 HbMenu::HbMenu(const QString &title, QGraphicsItem *parent) :
   556 HbMenu::HbMenu(const QString &title, QGraphicsItem *parent) :
   482         HbPopup(*new HbMenuPrivate, parent)
   557         HbPopup(*new HbMenuPrivate, parent)
   483 {
   558 {
   484     Q_D(HbMenu);
   559     Q_D(HbMenu);
   496     Q_D(HbMenu);
   571     Q_D(HbMenu);
   497     d->q_ptr = this;
   572     d->q_ptr = this;
   498     d->init();
   573     d->init();
   499 }
   574 }
   500 
   575 
       
   576 /*!
       
   577     Destructor
       
   578 */
   501 HbMenu::~HbMenu()
   579 HbMenu::~HbMenu()
   502 {
   580 {
   503     if (!scene() || !scene()->property("destructed").isValid()) {
   581     if (!scene() || !scene()->property("destructed").isValid()) {
   504         foreach (QAction *action, actions()) {// krazy:exclude=qclasses
   582         foreach (QAction *action, actions()) {// krazy:exclude=qclasses
   505             HbAction* hbAction = qobject_cast<HbAction *>(action);
   583             HbAction* hbAction = qobject_cast<HbAction *>(action);
   525 
   603 
   526     HbPopup::showEvent(event);
   604     HbPopup::showEvent(event);
   527 }
   605 }
   528 
   606 
   529 /*!
   607 /*!
   530     Creates a new action with title \a text. It adds the newly created action to the menu's list of actions.
   608     Creates a new action and adds it to the end of the menu.
   531     \param text is the text for the new action.
   609 
   532     \return the new action.
   610     \overload
       
   611 
       
   612     \param text The menu text for the new action.
       
   613     \return The new action.
   533 */
   614 */
   534 HbAction *HbMenu::addAction(const QString &text)
   615 HbAction *HbMenu::addAction(const QString &text)
   535 {
   616 {
   536     HbAction *action = new HbAction(text, this);
   617     HbAction *action = new HbAction(text, this);
   537     addAction(action);
   618     addAction(action);
   538     return action;
   619     return action;
   539 }
   620 }
   540 
   621 
   541 /*!
   622 /*!
   542     Creates a new action with \a text.
   623     Creates a new action, adds it to the end of the menu and connects the action's
   543     The action's triggered() signal is connected to the
   624     \link HbAction::triggered() triggered()\endlink signal to a receiver's slot.
   544     \a receiver's \a member slot. The function adds the newly created
   625 
   545     action to the menu's list of actions.
   626     \overload
   546     \return the new action.
   627 
   547  */
   628     \param text The menu text for the new action.
       
   629     \param receiver The object that is to receive the new action's signal.
       
   630     \param member The slot on the receiver to which the action's signal is to connect.
       
   631     \return The new action.
       
   632 */
   548 HbAction *HbMenu::addAction(const QString &text, const QObject *receiver, const char *member)
   633 HbAction *HbMenu::addAction(const QString &text, const QObject *receiver, const char *member)
   549 {
   634 {
   550     HbAction *action = new HbAction(text, this);
   635     HbAction *action = new HbAction(text, this);
   551     connect(action, SIGNAL(triggered(bool)), receiver, member);
   636     connect(action, SIGNAL(triggered(bool)), receiver, member);
   552     addAction(action);
   637     addAction(action);
   553     return action;
   638     return action;
   554 }
   639 }
   555 
   640 
   556 /*!
   641 /*!
   557     Adds \a menu as a sub-menu.
   642     Adds \a menu to the current menu as a submenu.
   558     \param menu is the menu that is added to this one.
   643 
   559     \return the action for the added sub-menu.
   644     \return  The action for the added submenu.
   560  */
   645 */
   561 HbAction *HbMenu::addMenu(HbMenu *menu)
   646 HbAction *HbMenu::addMenu(HbMenu *menu)
   562 {
   647 {
   563     return insertMenu(0, menu);
   648     return insertMenu(0, menu);
   564 }
   649 }
   565 
   650 
   566 /*!
   651 /*!
   567     Creates a new HbMenu with \a title and adds it to this menu.
   652     Creates a new HbMenu with \a title and adds it to the current menu as a submenu.
   568     \param title is the menu title.
   653 
   569     \return the new menu.
   654     \return The new menu.
   570 */
   655 */
   571 HbMenu *HbMenu::addMenu(const QString &title)
   656 HbMenu *HbMenu::addMenu(const QString &title)
   572 {
   657 {
   573     HbMenu *menu = new HbMenu(title);
   658     HbMenu *menu = new HbMenu(title);
   574     addMenu(menu);
   659     if ( menu ) {
       
   660         menu->setParent(this);
       
   661         addMenu(menu);
       
   662     }
   575     return menu;
   663     return menu;
   576 }
   664 }
   577 
   665 
   578 /*!
   666 /*!
   579     Inserts \a menu before action \a before.
   667     Inserts \a menu into the current menu as a submenu before the \a before action.
   580     \param before is the action before which this new menu is inserted.
   668 
   581     \param menu is the menu that is inserted.
       
   582     \return the action associated with the inserted menu.
   669     \return the action associated with the inserted menu.
   583  */
   670 */
   584 HbAction *HbMenu::insertMenu(HbAction *before, HbMenu *menu)
   671 HbAction *HbMenu::insertMenu(HbAction *before, HbMenu *menu)
   585 {    
   672 {    
   586     QObject::connect(menu, SIGNAL(triggered(HbAction*)), this, SLOT(_q_subMenuItemTriggered(HbAction*)));
   673     QObject::connect(menu, SIGNAL(triggered(HbAction*)), this, SLOT(_q_subMenuItemTriggered(HbAction*)));
   587     QObject::connect(menu, SIGNAL(triggered(HbAction*)), this, SIGNAL(triggered(HbAction*)));
   674     QObject::connect(menu, SIGNAL(triggered(HbAction*)), this, SIGNAL(triggered(HbAction*)));
   588 
   675 
   590     insertAction(before, menu->menuAction());
   677     insertAction(before, menu->menuAction());
   591     return menu->menuAction();
   678     return menu->menuAction();
   592 }
   679 }
   593 
   680 
   594 /*!
   681 /*!
   595     \return the action associated with this menu.
   682     Returns the action that is directly associated with a menu (rather than actions that are contained
   596  */
   683     within the menu). Although all menus have an assoicated action, it is only actually used for submenus.
       
   684     The parent menu uses a submenu's action to trigger the opening of the submenu. A submenu's action
       
   685     also defines the submenu's title.
       
   686 */
   597 HbAction *HbMenu::menuAction() const
   687 HbAction *HbMenu::menuAction() const
   598 {
   688 {
   599     Q_D(const HbMenu);
   689     Q_D(const HbMenu);
   600     return d->subMenuAction;
   690     return d->subMenuAction;
   601 }
   691 }
   602 
   692 
   603 /*!
   693 /*!
   604     Creates a new separator action, which is an action that returns \c true from HbAction::isSeparator(),
   694     Creates a new separator and adds it to the current menu's list of actions. A separator
   605     and adds it to this menu's list of actions.
   695     is an action for which HbAction::isSeparator() returns \c true.
   606     \return the new separator action
   696 
   607 
   697     \return The new separator action.
   608     \sa insertSeparator
   698 
   609  */
   699     \sa insertSeparator()
       
   700 */
   610 HbAction *HbMenu::addSeparator()
   701 HbAction *HbMenu::addSeparator()
   611 {
   702 {
   612     //functionality removed for now
   703         //functionality removed for now
   613     //return insertSeparator(0);
   704     //return insertSeparator(0);
   614     return 0;
   705     return 0;
   615 }
   706 }
   616 
   707 
   617 /*!
   708 /*!
   618     Inserts a new separator action and inserts it into this menu's list of actions before \a action.
   709     Creates a new separator and inserts it into the current menu's list of actions before \a before.
   619     \param before is the action before which the separator is inserted.
   710     A separator is an action for which HbAction::isSeparator() returns \c true.
   620     \return the new action.
   711 
   621 
   712     \return The new separator action.
   622     \sa addSeparator
   713     \sa addSeparator()
   623  */
   714 */
   624 HbAction *HbMenu::insertSeparator(HbAction *before)
   715 HbAction *HbMenu::insertSeparator(HbAction *before)
   625 {
   716 {
   626     Q_UNUSED(before);
   717     Q_UNUSED(before);
   627     //functionality removed for now
   718     //functionality removed for now
   628     /*HbAction *action = new HbAction(this);
   719     /*HbAction *action = new HbAction(this);
   633     return action;*/
   724     return action;*/
   634     return 0;
   725     return 0;
   635 }
   726 }
   636 
   727 
   637 /*!
   728 /*!
   638     \return the current active action, or 0 if no action item is currently active.
   729     Returns the active action or 0 if no action item is currently active. The active action is
   639  */
   730     the last action that was triggered, unless this has been overridden by a call to setActiveAction().
       
   731 */
   640 HbAction *HbMenu::activeAction() const
   732 HbAction *HbMenu::activeAction() const
   641 {
   733 {
   642     Q_D(const HbMenu);
   734     Q_D(const HbMenu);
   643     return d->activeAction();
   735     return d->activeAction();
   644 }
   736 }
   645 
   737 
   646 /*!
   738 /*!
   647     Sets the active action in menu. If \a action is not found from the list of
   739     Sets \a action as the current active action in the menu. If \a action is not
   648     menu actions then the current active action remains active.
   740     found in the list of menu actions, the action that is currently active remains active.
   649 
   741 
   650     \sa activeAction()
   742     \sa activeAction()
   651 */
   743 */
   652 void HbMenu::setActiveAction(HbAction *action)
   744 void HbMenu::setActiveAction(HbAction *action)
   653 {
   745 {
   656         d->menuItemView->setCurrentItem(action);
   748         d->menuItemView->setCurrentItem(action);
   657     }
   749     }
   658 }
   750 }
   659 
   751 
   660 /*!
   752 /*!
   661     \return \c true if the menu is empty (contains no actions) and \c false otherwise.
   753     Returns \c true if the menu contains no actions and \c false otherwise.
   662 
   754 
   663     \sa clear()
   755     \sa clearActions()
   664  */
   756 */
   665 bool HbMenu::isEmpty() const
   757 bool HbMenu::isEmpty() const
   666 {
   758 {
   667     return actions().isEmpty();
   759     return actions().isEmpty();
   668 }
   760 }
   669 
   761 
   670 /*!
   762 /*!
   671     Sets the menu title. For a sub-menu, the title is the sub-menu action text.
   763     Sets the menu title. For a submenu, the title is the submenu's action text.
   672 
   764 
   673     \sa title()
   765     \sa title()
   674 */
   766 */
   675 void HbMenu::setTitle(const QString &title)
   767 void HbMenu::setTitle(const QString &title)
   676 {
   768 {
   677     menuAction()->setText(title);
   769     menuAction()->setText(title);
   678 }
   770 }
   679 
   771 
   680 /*!
   772 /*!
   681     Returns the menu title. For a sub-menu, the title is the sub-menu action text.
   773     Returns the menu title. For a submenu, the title is the submenu's action text.
   682 
       
   683     \return the menu title.
       
   684 
   774 
   685     \sa setTitle()
   775     \sa setTitle()
   686 */
   776 */
   687 QString HbMenu::title() const
   777 QString HbMenu::title() const
   688 {
   778 {
   689     return menuAction()->text();
   779     return menuAction()->text();
   690 }
   780 }
   691 
   781 
   692 /*!
   782 /*!
   693     Returns the menu type. By default a menu is a context menu.
   783     Returns the menu type. The default menu type is context menu.
   694 
   784 
   695     \return the menu type.
       
   696 */
   785 */
   697 HbMenu::MenuType HbMenu::menuType() const
   786 HbMenu::MenuType HbMenu::menuType() const
   698 {
   787 {
   699     Q_D(const HbMenu);
   788     Q_D(const HbMenu);
   700     return d->menuType;
   789     return d->menuType;
   701 }
   790 }
   702 
   791 
   703 /*!
       
   704     \reimp
       
   705  */
       
   706 QVariant HbMenu::itemChange( GraphicsItemChange change, const QVariant & value )
   792 QVariant HbMenu::itemChange( GraphicsItemChange change, const QVariant & value )
   707 {
   793 {
   708     Q_D(HbMenu);
   794     Q_D(HbMenu);
   709 
   795 
   710     if (change == QGraphicsItem::ItemSceneHasChanged) {
   796     if (change == QGraphicsItem::ItemSceneHasChanged) {
   711         d->closeMenu();
   797         d->closeMenu();
   712     }
   798     }
   713     if (change == QGraphicsItem::ItemVisibleChange) {
   799     if (change == QGraphicsItem::ItemVisibleChange) {
   714         if (value.toBool() && d->delayMenuConstruction) {
   800         if (value.toBool() && d->polished) {
   715             d->delayedLayout();
   801             d->delayedLayout();
   716         }
   802         }
   717         if (value.toBool()) {
   803         if (value.toBool()) {
   718             d->actionTriggered = false;
   804             d->actionTriggered = false;
   719         }
   805         }
   722         }
   808         }
   723     }
   809     }
   724     return HbPopup::itemChange(change,value);
   810     return HbPopup::itemChange(change,value);
   725 }
   811 }
   726 
   812 
   727 /*!
       
   728    \reimp
       
   729 */
       
   730 bool HbMenu::event(QEvent *event)
   813 bool HbMenu::event(QEvent *event)
   731 {
   814 {
   732     Q_D(HbMenu);
   815     Q_D(HbMenu);
   733 
   816 
   734     if(!d->inDestruction) {
   817     if(!d->inDestruction) {
   752     }
   835     }
   753 
   836 
   754     return HbPopup::event(event);
   837     return HbPopup::event(event);
   755 }
   838 }
   756 
   839 
   757 /*!
       
   758   \reimp
       
   759   */
       
   760 void HbMenu::polish(HbStyleParameters &params)
   840 void HbMenu::polish(HbStyleParameters &params)
   761 {
   841 {
   762     Q_D(HbMenu);
   842     if (isVisible()) {
   763     const QString NumberOfCols = "number-of-columns";
   843         Q_D(HbMenu);
   764     params.addParameter(NumberOfCols);
   844         const QLatin1String NumberOfCols("number-of-columns");
   765 
   845         params.addParameter(NumberOfCols);
   766     if (d->mSubMenuItem) {
   846 
   767         const QString RightMargin = "submenu-right-offset";
   847         if (d->mSubMenuItem) {
   768         const QString DownMargin = "submenu-bottom-margin";
   848             const QLatin1String RightMargin("submenu-right-offset");
   769         params.addParameter(RightMargin);
   849             const QLatin1String DownMargin("submenu-bottom-margin");
   770         params.addParameter(DownMargin);
   850             params.addParameter(RightMargin);
   771 
   851             params.addParameter(DownMargin);
   772         HbPopup::polish(params);
   852 
   773 
   853             HbPopup::polish(params);
   774         if (!params.value(RightMargin).isNull()) {
   854 
   775             d->mRightMargin = params.value(RightMargin).toDouble();
   855             if (!params.value(RightMargin).isNull()) {
   776         }
   856                 d->mRightMargin = params.value(RightMargin).toDouble();
   777         if (!params.value(DownMargin).isNull()) {
   857             }
   778             d->mDownMargin = params.value(DownMargin).toDouble();
   858             if (!params.value(DownMargin).isNull()) {
   779         }
   859                 d->mDownMargin = params.value(DownMargin).toDouble();
   780         d->setSubMenuPosition();
   860             }
       
   861             d->setSubMenuPosition();
       
   862         } else {
       
   863             HbPopup::polish(params);
       
   864         }
       
   865 
       
   866         if (!params.value(NumberOfCols).isNull()) {
       
   867             int cols = params.value(NumberOfCols).toInt();
       
   868             if (d->mNumberOfColumns != cols) {
       
   869                 d->mNumberOfColumns = cols;
       
   870                 if (d->menuItemView) {
       
   871                     d->menuItemView->updateContainer();
       
   872                 }
       
   873             }
       
   874         }
       
   875         d->delayedLayout();
   781     } else {
   876     } else {
   782         HbPopup::polish(params);
   877         HbPopup::polish(params);
   783     }
   878     }
   784 
   879 }
   785     if (!params.value(NumberOfCols).isNull()) {
   880 
   786         int cols = params.value(NumberOfCols).toInt();
   881 /*!
   787         if (d->mNumberOfColumns != cols) {
   882     Returns the shape of this item as a QPainterPath.
   788             d->mNumberOfColumns = cols;
   883 */
   789             if (d->menuItemView) {
       
   790                 d->menuItemView->updateContainer();
       
   791             }
       
   792         }
       
   793     }
       
   794 }
       
   795 
       
   796 /*!
       
   797   \reimp
       
   798   Returns the shape of this item as a QPainterPath.
       
   799  */
       
   800 QPainterPath HbMenu::shape() const
   884 QPainterPath HbMenu::shape() const
   801 {
   885 {
   802     /*QRectF rect = QRectF(-1.0, -1.0, boundingRect().width() + 1.0, boundingRect().height() + 1.0);
   886     /*QRectF rect = QRectF(-1.0, -1.0, boundingRect().width() + 1.0, boundingRect().height() + 1.0);
   803     QRectF clipRect = rect.intersected(mapRectFromParent(QRectF(pos().x() - 1.0, pos().y() - 1.0, size().width() + 1.0, size().height() + 1.0)));
   887     QRectF clipRect = rect.intersected(mapRectFromParent(QRectF(pos().x() - 1.0, pos().y() - 1.0, size().width() + 1.0, size().height() + 1.0)));
   804 
   888 
   808     return path;*/
   892     return path;*/
   809     return HbPopup::shape();
   893     return HbPopup::shape();
   810 }
   894 }
   811 
   895 
   812 /*!
   896 /*!
   813  
   897     Displays the menu on the screen and returns immediately. It can also connect the HbMenu::triggered()
   814   Opens the menu and returns immediately.
   898     signal to a specified slot. The signal is disconnected when the menu closes.
   815  
   899 
   816   Connects triggered(HbAction*) signal to the slot specified by \a
   900     \param receiver The object that is to receive the signal.
   817   receiver and \a member. The signal will be disconnected when menu
   901     \param member The slot on the receiver to which the signal is to connect.
   818   is closed.
   902 */
   819  
       
   820    An example of how to create a simple context menu and show it
       
   821    \snippet{ultimatecodesnippet/ultimatecodesnippet.cpp,54}
       
   822  
       
   823  
       
   824  */
       
   825 void HbMenu::open( QObject *receiver, const char *member )
   903 void HbMenu::open( QObject *receiver, const char *member )
   826 {
   904 {
   827     Q_D(HbMenu);
   905     Q_D(HbMenu);
   828     if ( d->receiverToDisconnectOnClose ) { // cant do on closeevent
   906     if ( d->receiverToDisconnectOnClose ) { // cant do on closeevent
   829         disconnect(this, SIGNAL(triggered(HbAction*)),
   907         disconnect(this, SIGNAL(triggered(HbAction*)),