74 } |
74 } |
75 |
75 |
76 void HbMenuPrivate::addPopupEffects() |
76 void HbMenuPrivate::addPopupEffects() |
77 { |
77 { |
78 #ifdef HB_EFFECTS |
78 #ifdef HB_EFFECTS |
79 effectType = "HB_MENU"; |
79 if (menuType == HbMenu::OptionsMenu) { |
|
80 effectType = "HB_MENU"; |
|
81 } else { |
|
82 effectType = "HB_SUBMENU"; |
|
83 } |
80 hasEffects = menuEffectsLoaded; |
84 hasEffects = menuEffectsLoaded; |
81 if (menuEffectsLoaded) |
85 if (menuEffectsLoaded) |
82 return; |
86 return; |
83 menuEffectsLoaded = true; |
87 menuEffectsLoaded = true; |
84 hasEffects = HbEffectInternal::add("HB_MENU", "menu_appear", "appear"); |
88 hasEffects = HbEffectInternal::add("HB_MENU", "menu_appear", "appear"); |
85 if (hasEffects) { |
89 if (hasEffects) { |
86 //We load the disappear effect only if appear effect was also loaded |
|
87 hasEffects = HbEffectInternal::add("HB_MENU", "menu_disappear", "disappear"); |
90 hasEffects = HbEffectInternal::add("HB_MENU", "menu_disappear", "disappear"); |
88 |
91 |
89 if (hasEffects) { |
92 if (hasEffects) { |
90 hasEffects = HbEffectInternal::add("HB_menuitem", "menuitem_press", "clicked"); |
93 hasEffects = HbEffectInternal::add("HB_menuitem", "menuitem_press", "clicked"); |
|
94 } |
|
95 if (hasEffects) { |
|
96 hasEffects = HbEffectInternal::add("HB_SUBMENU", "submenu_appear", "appear"); |
|
97 } |
|
98 if (hasEffects) { |
|
99 hasEffects = HbEffectInternal::add("HB_SUBMENU", "submenu_disappear", "disappear"); |
91 } |
100 } |
92 } |
101 } |
93 #endif |
102 #endif |
94 } |
103 } |
95 |
104 |
102 if (hasEffects) { |
111 if (hasEffects) { |
103 HbEffect::start(currentItem, "HB_menuitem", "clicked"); |
112 HbEffect::start(currentItem, "HB_menuitem", "clicked"); |
104 } |
113 } |
105 #endif |
114 #endif |
106 HbAction *hbAction = qobject_cast<HbAction *>(currentItem->action()); |
115 HbAction *hbAction = qobject_cast<HbAction *>(currentItem->action()); |
107 q->setActiveAction(hbAction); |
|
108 if (hbAction && hbAction->menu() && !actionTriggered) { |
116 if (hbAction && hbAction->menu() && !actionTriggered) { |
109 hbAction->trigger(); |
117 hbAction->trigger(); |
110 stopTimeout(); |
118 stopTimeout(); |
111 openSubmenu(currentItem); |
119 openSubmenu(currentItem); |
112 } else { |
120 } else { |
161 } |
170 } |
162 |
171 |
163 void HbMenuPrivate::_q_onActionTriggered() |
172 void HbMenuPrivate::_q_onActionTriggered() |
164 { |
173 { |
165 Q_Q(HbMenu); |
174 Q_Q(HbMenu); |
166 HbAction *action = qobject_cast<HbAction *>(q->sender()); |
175 HbAction *action = qobject_cast<HbAction *>(q->sender()); |
167 if (action && !action->menu() ) { // do not trigger from opening submenu |
176 if (action) { |
168 emit q->triggered(action); |
177 q->setActiveAction(action); |
|
178 if (!action->menu()) { // do not trigger from opening submenu |
|
179 emit q->triggered(action); |
|
180 } |
169 } |
181 } |
170 } |
182 } |
171 |
183 |
172 void HbMenuPrivate::_q_subMenuItemTriggered(HbAction *action) |
184 void HbMenuPrivate::_q_subMenuItemTriggered(HbAction *action) |
173 { |
185 { |
413 if ((windowSize.width() - q->size().width()) < leftEdge) { |
425 if ((windowSize.width() - q->size().width()) < leftEdge) { |
414 leftEdge = mSubMenuItem->scenePos().x() + |
426 leftEdge = mSubMenuItem->scenePos().x() + |
415 mSubMenuItem->size().width() + |
427 mSubMenuItem->size().width() + |
416 mRightMargin - q->size().width(); |
428 mRightMargin - q->size().width(); |
417 } |
429 } |
418 q->setPreferredPos(QPointF(leftEdge, upperEdge)); |
430 q->setPreferredPos(QPointF(leftEdge, upperEdge), HbPopup::TopLeftCorner); |
419 } else { |
431 } else { |
420 qreal rightEdge = mSubMenuItem->scenePos().x() + mRightMargin; |
432 qreal rightEdge = mSubMenuItem->scenePos().x() + mRightMargin; |
421 if ((rightEdge - q->size().width()) < 0) { |
433 if ((rightEdge - q->size().width()) < 0) { |
422 rightEdge = mSubMenuItem->scenePos().x() - mRightMargin + |
434 rightEdge = mSubMenuItem->scenePos().x() - mRightMargin + |
423 q->size().width(); |
435 q->size().width(); |
970 d->receiverToDisconnectOnClose = 0; |
982 d->receiverToDisconnectOnClose = 0; |
971 } |
983 } |
972 HbMenu::show(); |
984 HbMenu::show(); |
973 } |
985 } |
974 |
986 |
|
987 /*! |
|
988 Overidden from popup. Sets the preferred position of the menu. |
|
989 |
|
990 \param preferredPos Defines the coordinates of preferred position on the screen where |
|
991 the menu is to open. |
|
992 \param placement The corner or edge of the dialog that is to be placed at \a preferredPos. |
|
993 |
|
994 \b Example: |
|
995 \code |
|
996 HbMenu *menu = new HbMenu(); |
|
997 |
|
998 menu->setPreferredPos( QPointF(x,y), HbPopup::BottomEdgeCenter ); |
|
999 menu->show(); |
|
1000 \endcode |
|
1001 */ |
|
1002 void HbMenu::setPreferredPos( const QPointF& preferredPos, |
|
1003 HbPopup::Placement placement ) |
|
1004 { |
|
1005 Q_D(HbMenu); |
|
1006 bool layoutFlag = false; |
|
1007 if (d->preferredPos != preferredPos ) { |
|
1008 d->preferredPos = preferredPos; |
|
1009 layoutFlag = true; |
|
1010 } |
|
1011 if (d->placement != placement) { |
|
1012 d->placement = placement; |
|
1013 layoutFlag = true; |
|
1014 } |
|
1015 d->preferredPosSet = true; |
|
1016 //If position updated, informing layoutproxy with layoutrequest |
|
1017 if (layoutFlag) { |
|
1018 QEvent layoutRequest = QEvent::LayoutRequest; |
|
1019 QApplication::sendEvent(this, &layoutRequest); |
|
1020 } |
|
1021 } |
|
1022 |
|
1023 |
975 #include "moc_hbmenu.cpp" |
1024 #include "moc_hbmenu.cpp" |