127 |
127 |
128 void HbMenuPrivate::createMenuView() |
128 void HbMenuPrivate::createMenuView() |
129 { |
129 { |
130 Q_Q(HbMenu); |
130 Q_Q(HbMenu); |
131 if (!menuItemView && q->actions().count()){ |
131 if (!menuItemView && q->actions().count()){ |
132 menuItemView = new HbMenuListView(q, q); |
132 menuItemView = new HbMenuListView(q, q); |
133 HbStyle::setItemName(menuItemView, "content"); |
133 HbStyle::setItemName(menuItemView, "content"); |
134 //This optimises case of options menu which otherwise updates its primitives twice. |
134 //This optimises case of options menu which otherwise updates its primitives twice. |
135 if (menuType == HbMenu::OptionsMenu) |
135 if (menuType == HbMenu::OptionsMenu) |
136 q->setFrameType(HbPopup::Strong); |
136 q->setFrameType(HbPopup::Strong); |
137 else |
137 else |
188 |
188 |
189 void HbMenuPrivate::actionAdded(QActionEvent *actionEvent) |
189 void HbMenuPrivate::actionAdded(QActionEvent *actionEvent) |
190 { |
190 { |
191 if (delayMenuConstruction) |
191 if (delayMenuConstruction) |
192 return; |
192 return; |
193 if (actionEvent->action()->isVisible()){ |
193 Q_Q(HbMenu); |
194 Q_Q(HbMenu); |
194 QObject::connect(actionEvent->action(), SIGNAL(triggered()), q, SLOT(_q_onActionTriggered())); |
195 createMenuView(); |
195 if (actionEvent->action()->isVisible()){ |
196 QObject::connect(actionEvent->action(), SIGNAL(triggered()), q, SLOT(_q_onActionTriggered())); |
196 createMenuView(); |
197 menuItemView->addActionItem(actionEvent->action()); |
197 menuItemView->addActionItem(actionEvent->action()); |
198 } |
198 } |
199 } |
199 } |
200 |
200 |
201 void HbMenuPrivate::actionRemoved(QActionEvent *actionEvent) |
201 void HbMenuPrivate::actionRemoved(QActionEvent *actionEvent) |
253 Q_Q(HbMenu); |
253 Q_Q(HbMenu); |
254 |
254 |
255 if (!activeItem) { |
255 if (!activeItem) { |
256 activeAction(activeItem); |
256 activeAction(activeItem); |
257 } |
257 } |
258 |
|
259 if (activeItem && activeItem->action() && activeItem->action()->isEnabled()) { |
258 if (activeItem && activeItem->action() && activeItem->action()->isEnabled()) { |
260 HbAction *hbAction = qobject_cast<HbAction *>(activeItem->action()); |
259 HbAction *hbAction = qobject_cast<HbAction *>(activeItem->action()); |
|
260 q->setActiveAction(hbAction); |
261 if (!hbAction) |
261 if (!hbAction) |
262 return; |
262 return; |
263 HbMenu *subMenu = hbAction->menu(); |
263 HbMenu *subMenu = hbAction->menu(); |
264 if ( subMenu ) { |
264 if ( subMenu ) { |
265 subMenu->setLayoutDirection(q->layoutDirection()); |
265 subMenu->setLayoutDirection(q->layoutDirection()); |
516 } |
519 } |
517 } |
520 } |
518 } |
521 } |
519 } |
522 } |
520 |
523 |
521 /*! |
|
522 \deprecated HbMenu::exec(HbAction*) |
|
523 is deprecated. Please use |
|
524 void HbMenu::open( QObject *receiver, const char *member ) or |
|
525 HbMenu::show() instead. |
|
526 |
|
527 Executes the menu synchronously so that given \a action |
|
528 is active. |
|
529 |
|
530 \param action is the action that is active when the menu is shown. |
|
531 |
|
532 Example usage: |
|
533 \code |
|
534 void MyGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
535 { |
|
536 HbMenu menu(); |
|
537 menu.addAction(...); |
|
538 ... |
|
539 menu.setPreferredPos(event->scenePos(), HbPopup::BottomEdgeCenter); |
|
540 menu.exec(); |
|
541 } |
|
542 \endcode |
|
543 |
|
544 \return the triggered HbAction in either the popup menu or one |
|
545 of its sub-menus, or 0 if no item was triggered (normally because |
|
546 the user closed or cancelled the menu). |
|
547 */ |
|
548 HbAction *HbMenu::exec(HbAction *action) |
|
549 { |
|
550 HB_DEPRECATED("HbMenu::exec is deprecated. Use HbMenu::show() or HbMenu::open() instead!"); |
|
551 Q_D(HbMenu); |
|
552 if (actions().count() == 0) { |
|
553 return 0; |
|
554 } |
|
555 |
|
556 if(!action) |
|
557 action = qobject_cast<HbAction*>(actions().first()); |
|
558 |
|
559 setActiveAction(action); |
|
560 |
|
561 // Reset state variables |
|
562 d->resultAction = 0; |
|
563 d->actionTriggered = false; |
|
564 |
|
565 if (d->menuType == SubMenu && d->polished) { |
|
566 d->setSubMenuPosition(); |
|
567 } |
|
568 QPointer<HbMenu> menuAlive(this); |
|
569 HbPopup::exec(); |
|
570 |
|
571 // HbMenu can be deleted while exec |
|
572 if (menuAlive) { |
|
573 return d->resultAction; |
|
574 } else { |
|
575 return 0; |
|
576 } |
|
577 } |
|
578 |
|
579 /*! |
|
580 \deprecated HbMenu::exec(const QPointF&, HbAction*) |
|
581 is deprecated. Please use |
|
582 void HbMenu::open( QObject *receiver, const char *member ) or |
|
583 HbMenu::show() and setPreferredPos() instead. |
|
584 |
|
585 Executes the menu synchronously at \a pos so that given \a action |
|
586 is active. |
|
587 |
|
588 \param pos is the position at which the menu is shown. |
|
589 \param action is the action that is active when the menu is shown. |
|
590 |
|
591 Example usage: |
|
592 \code |
|
593 void MyGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
594 { |
|
595 HbMenu menu(); |
|
596 menu.addAction(...); |
|
597 ... |
|
598 menu.exec(event->scenePos()); |
|
599 } |
|
600 \endcode |
|
601 |
|
602 \return the triggered HbAction in either the popup menu or one |
|
603 of its sub-menus, or 0 if no item was triggered (normally because |
|
604 the user closed or cancelled the menu). |
|
605 */ |
|
606 HbAction *HbMenu::exec(const QPointF &pos, HbAction *action ) |
|
607 { |
|
608 Q_D(HbMenu); |
|
609 if (d->menuType == ContextMenu) { |
|
610 setPreferredPos(pos); |
|
611 } |
|
612 return exec(action); |
|
613 } |
|
614 |
|
615 void HbMenu::showEvent(QShowEvent *event) |
524 void HbMenu::showEvent(QShowEvent *event) |
616 { |
525 { |
617 Q_UNUSED(event); |
526 Q_UNUSED(event); |
618 Q_D(HbMenu); |
527 Q_D(HbMenu); |
619 d->actionTriggered = false; |
528 d->actionTriggered = false; |
720 */ |
629 */ |
721 HbAction *HbMenu::insertSeparator(HbAction *before) |
630 HbAction *HbMenu::insertSeparator(HbAction *before) |
722 { |
631 { |
723 HbAction *action = new HbAction(this); |
632 HbAction *action = new HbAction(this); |
724 action->setSeparator(true); |
633 action->setSeparator(true); |
725 action->setEnabled(false); |
634 action->setEnabled(true); |
726 action->setVisible(false); |
635 action->setVisible(true); |
727 insertAction(before, action); |
636 insertAction(before, action); |
728 return action; |
637 return action; |
729 } |
638 } |
730 |
639 |
731 /*! |
640 /*! |
835 QActionEvent *actionEvent = static_cast<QActionEvent *>(event); |
744 QActionEvent *actionEvent = static_cast<QActionEvent *>(event); |
836 d->actionChanged(actionEvent); |
745 d->actionChanged(actionEvent); |
837 return true; |
746 return true; |
838 } |
747 } |
839 } |
748 } |
840 if (event->type() == QEvent::LayoutRequest) { |
749 if (event->type() == QEvent::GraphicsSceneResize){ |
841 if(d->menuItemView) |
|
842 d->menuItemView->contentWidget()->adjustSize(); |
|
843 } else if (event->type() == QEvent::GraphicsSceneResize){ |
|
844 if (d->mSubMenuItem) |
750 if (d->mSubMenuItem) |
845 d->setSubMenuPosition(); |
751 d->setSubMenuPosition(); |
846 } |
752 } |
847 |
753 |
848 return HbPopup::event(event); |
754 return HbPopup::event(event); |
871 } |
777 } |
872 } |
778 } |
873 |
779 |
874 QPainterPath HbMenu::shape() const |
780 QPainterPath HbMenu::shape() const |
875 { |
781 { |
|
782 /* |
876 QRectF sceneRect = mapRectToScene(QRectF(-0.5, -0.5, boundingRect().width() + 0.5, boundingRect().height() + 0.5)); |
783 QRectF sceneRect = mapRectToScene(QRectF(-0.5, -0.5, boundingRect().width() + 0.5, boundingRect().height() + 0.5)); |
877 QRectF clipRect = sceneRect.intersected(QRectF(pos().x() - 0.5, pos().y() - 0.5, size().width() + 0.5, size().height() + 0.5)); |
784 QRectF clipRect = sceneRect.intersected(QRectF(pos().x() - 0.5, pos().y() - 0.5, size().width() + 0.5, size().height() + 0.5)); |
878 |
785 |
879 QPainterPath path; |
786 QPainterPath path; |
880 path.addRect(mapRectFromScene(clipRect)); |
787 path.addRect(mapRectFromScene(clipRect)); |
881 |
788 |
882 return path.intersected(HbPopup::shape()); |
789 return path.intersected(HbPopup::shape()); |
883 } |
790 */ |
884 |
791 |
885 /*! @alpha |
792 return HbPopup::shape(); |
886 * |
793 } |
887 * Opens the menu and returns immediately. |
794 |
|
795 /*! |
|
796 |
|
797 Opens the menu and returns immediately. |
|
798 |
|
799 Connects triggered(HbAction*) signal to the slot specified by \a |
|
800 receiver and \a member. The signal will be disconnected when menu |
|
801 is closed. |
|
802 |
|
803 An example of how to create a simple context menu and show it |
|
804 \snippet{ultimatecodesnippet/ultimatecodesnippet.cpp,54} |
|
805 |
|
806 |
888 */ |
807 */ |
889 void HbMenu::open( QObject *receiver, const char *member ) |
808 void HbMenu::open( QObject *receiver, const char *member ) |
890 { |
809 { |
891 Q_D(HbMenu); |
810 Q_D(HbMenu); |
892 if ( d->receiverToDisconnectOnClose ) { // cant do on closeevent |
811 if ( d->receiverToDisconnectOnClose ) { // cant do on closeevent |