#include <qmenu.h>
Inheritance diagram for QMenu:


A menu widget is a selection menu. It can be either a pull-down menu in a menu bar or a standalone context menu. Pull-down menus are shown by the menu bar when the user clicks on the respective item or presses the specified shortcut key. Use QMenuBar::addMenu() to insert a menu into a menu bar. Context menus are usually invoked by some special keyboard key or by right-clicking. They can be executed either asynchronously with popup() or synchronously with exec(). Menus can also be invoked in response to button presses; these are just like context menus except for how they are invoked.
A menu consists of a list of action items. Actions are added with addAction(). An action is represented vertically and rendered by QStyle. In addition, actions can have a text label, an optional icon drawn on the very left side, and shortcut key sequence such as "Ctrl+X".
There are three kinds of action items: separators, actions that show a submenu, and actions that perform an action. Separators are inserted with addSeparator(). For submenus use addMenu(). All other items are considered action items.
When inserting action items you usually specify a receiver and a slot. The receiver will be notifed whenever the item is {QAction::triggered()}{triggered()}. In addition, QMenu provides two signals, activated() and highlighted(), which signal the QAction that was triggered from the menu.
You clear a menu with clear() and remove individual action items with removeAction().
A QMenu can also provide a tear-off menu. A tear-off menu is a top-level window that contains a copy of the menu. This makes it possible for the user to "tear off" frequently used menus and position them in a convenient place on the screen. If you want this functionality for a particular menu, insert a tear-off handle with setTearOffEnabled(). When using tear-off menus, bear in mind that the concept isn't typically used on Microsoft Windows so some users may not be familiar with it. Consider using a QToolBar instead.
See the {mainwindows/menus}{Menus} example for an example of how to use QMenuBar and QMenu in your application.
Important inherited functions: addAction(), removeAction(), clear(), addSeparator(), and addMenu().
Definition at line 44 of file qmenu.h.
Signals | |
| void | aboutToShow () |
| void | aboutToHide () |
| void | triggered (QAction *action) |
| void | hovered (QAction *action) |
Public Member Functions | |
| QMenu (QWidget *parent=0) | |
| QMenu (const QString &title, QWidget *parent=0) | |
| ~QMenu () | |
| QAction * | addAction (const QString &text) |
| QAction * | addAction (const QIcon &icon, const QString &text) |
| QAction * | addAction (const QString &text, const QObject *receiver, const char *member, const QKeySequence &shortcut=0) |
| QAction * | addAction (const QIcon &icon, const QString &text, const QObject *receiver, const char *member, const QKeySequence &shortcut=0) |
| QAction * | addMenu (QMenu *menu) |
| QMenu * | addMenu (const QString &title) |
| QMenu * | addMenu (const QIcon &icon, const QString &title) |
| QAction * | addSeparator () |
| QAction * | insertMenu (QAction *before, QMenu *menu) |
| QAction * | insertSeparator (QAction *before) |
| bool | isEmpty () const |
| void | clear () |
| void | setTearOffEnabled (bool) |
| bool | isTearOffEnabled () const |
| bool | isTearOffMenuVisible () const |
| void | hideTearOffMenu () |
| void | setDefaultAction (QAction *) |
| QAction * | defaultAction () const |
| void | setActiveAction (QAction *act) |
| QAction * | activeAction () const |
| void | popup (const QPoint &pos, QAction *at=0) |
| QAction * | exec () |
| QAction * | exec (const QPoint &pos, QAction *at=0) |
| QSize | sizeHint () const |
| QRect | actionGeometry (QAction *) const |
| QAction * | actionAt (const QPoint &) const |
| QAction * | menuAction () const |
| QString | title () const |
| void | setTitle (const QString &title) |
| QIcon | icon () const |
| void | setIcon (const QIcon &icon) |
| void | setNoReplayFor (QWidget *widget) |
| bool | separatorsCollapsible () const |
| void | setSeparatorsCollapsible (bool collapse) |
Static Public Member Functions | |
| static QAction * | exec (QList< QAction * > actions, const QPoint &pos, QAction *at=0) |
Protected Member Functions | |
| int | columnCount () const |
| void | changeEvent (QEvent *) |
| void | keyPressEvent (QKeyEvent *) |
| void | mouseReleaseEvent (QMouseEvent *) |
| void | mousePressEvent (QMouseEvent *) |
| void | mouseMoveEvent (QMouseEvent *) |
| void | wheelEvent (QWheelEvent *) |
| void | enterEvent (QEvent *) |
| void | leaveEvent (QEvent *) |
| void | hideEvent (QHideEvent *) |
| void | paintEvent (QPaintEvent *) |
| void | actionEvent (QActionEvent *) |
| void | timerEvent (QTimerEvent *) |
| bool | event (QEvent *) |
| bool | focusNextPrevChild (bool next) |
Private Slots | |
| void | internalSetSloppyAction () |
| void | internalDelayedPopup () |
Private Member Functions | |
| Q_PRIVATE_SLOT (d_func(), void _q_actionTriggered()) Q_PRIVATE_SLOT(d_func() | |
Private Attributes | |
| void friend class()) private | QMenuBarPrivate |
Friends | |
| class | QTornOffMenu |
| class | Q3PopupMenu |
| class | QComboBox |
| QMenu::QMenu | ( | QWidget * | parent = 0 |
) | [explicit] |
Constructs a menu with parent parent.
Although a popup menu is always a top-level widget, if a parent is passed the popup menu will be deleted when that parent is destroyed (as with any other QObject).
Definition at line 947 of file qmenu.cpp.
References d, QMenuPrivate::QMenuScroller::ScrollNone, QWidget::setAttribute(), QWidget::setMouseTracking(), QStyle::SH_Menu_MouseTracking, QStyle::SH_Menu_Scrollable, QWidget::style(), styleHint(), and Qt::WA_CustomWhatsThis.
Referenced by addMenu().
00948 : QWidget(*new QMenuPrivate, parent, Qt::Popup) 00949 { 00950 Q_D(QMenu); 00951 #ifndef QT_NO_WHATSTHIS 00952 setAttribute(Qt::WA_CustomWhatsThis); 00953 #endif 00954 setMouseTracking(style()->styleHint(QStyle::SH_Menu_MouseTracking, 0, this)); 00955 if (style()->styleHint(QStyle::SH_Menu_Scrollable, 0, this)) { 00956 d->scroll = new QMenuPrivate::QMenuScroller; 00957 d->scroll->scrollFlags = QMenuPrivate::QMenuScroller::ScrollNone; 00958 } 00959 d->menuAction = new QAction(this); 00960 d->menuAction->d_func()->menu = this; 00961 }
Here is the call graph for this function:

Constructs a menu with a title and a parent.
Although a popup menu is always a top-level widget, if a parent is passed the popup menu will be deleted when that parent is destroyed (as with any other QObject).
Definition at line 972 of file qmenu.cpp.
References d, QMenuPrivate::QMenuScroller::ScrollNone, QWidget::setAttribute(), QWidget::setMouseTracking(), QStyle::SH_Menu_MouseTracking, QStyle::SH_Menu_Scrollable, QWidget::style(), styleHint(), title(), and Qt::WA_CustomWhatsThis.
00973 : QWidget(*new QMenuPrivate, parent, Qt::Popup) 00974 { 00975 Q_D(QMenu); 00976 #ifndef QT_NO_WHATSTHIS 00977 setAttribute(Qt::WA_CustomWhatsThis); 00978 #endif 00979 setMouseTracking(style()->styleHint(QStyle::SH_Menu_MouseTracking)); 00980 if (style()->styleHint(QStyle::SH_Menu_Scrollable, 0, this)) { 00981 d->scroll = new QMenuPrivate::QMenuScroller; 00982 d->scroll->scrollFlags = QMenuPrivate::QMenuScroller::ScrollNone; 00983 } 00984 d->menuAction = new QAction(title, this); 00985 d->menuAction->d_func()->menu = this; 00986 }
Here is the call graph for this function:

| QMenu::~QMenu | ( | ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This convenience function creates a new action with text. The function adds the newly created action to the menu's list of actions, and returns it.
Definition at line 1009 of file qmenu.cpp.
Referenced by QFileDialogPrivate::_q_showContextMenu(), addAction(), addAction(), QDesignerWorkbench::addFormWindow(), addMenu(), addSeparator(), MainWindow::addToMenu(), QtWindowListMenu::addWindow(), QDesignerMenu::adjustSpecialActions(), ColorSwatch::ColorSwatch(), MainWindow::contextMenuEvent(), SourceTextEdit::contextMenuEvent(), qdesigner_internal::QtBrushEditor::contextMenuEvent(), QScrollBar::contextMenuEvent(), qdesigner_internal::WidgetBoxTreeView::contextMenuEvent(), QPixelTool::contextMenuEvent(), qdesigner_internal::QtGradientStopsWidget::contextMenuEvent(), MainWindow::createDockWindows(), QVFb::createFileMenu(), QCalendarWidgetPrivate::createHeader(), MainWindow::createMenu(), Dialog::createMenu(), ImageViewer::createMenus(), MainWindow::createMenus(), qdesigner_internal::FormWindow::createPopupMenu(), QMainWindow::createPopupMenu(), Window::createPushButtonGroup(), QTextControl::createStandardContextMenu(), QLineEdit::createStandardContextMenu(), Window::createTrayIcon(), QVFb::createViewMenu(), exec(), QDesignerToolBar::handleContextMenuEvent(), QDesignerMenuBar::handleContextMenuEvent(), QDesignerMenu::handleContextMenuEvent(), QWorkspacePrivate::init(), QDesignerWorkbench::initialize(), HelpDialog::initialize(), Main::Main(), main(), MainWindow::MainWindow(), Q3MainWindow::menuAboutToShow(), QMultiInputContext::QMultiInputContext(), QTornOffMenu::QTornOffMenu(), QtWindowListMenu::QtWindowListMenu(), QUnicodeControlCharacterMenu::QUnicodeControlCharacterMenu(), QToolBar::resizeEvent(), MainWindow::setupDockWidgets(), TextEdit::setupEditActions(), TextEdit::setupFileActions(), MainWindow::setupFileMenu(), MainWindow::setupHelpMenu(), MainWindow::setupMenuBar(), TrWindow::setupMenuBar(), SpreadSheet::setupMenuBar(), MainWindow::setupMenus(), TextEdit::setupTextActions(), QDBusViewer::showContextMenu(), TextEdit::TextEdit(), ToolBar::ToolBar(), ColorSwatch::updateContextMenu(), and MainWindow::updateWindowMenu().
01010 { 01011 QAction *ret = new QAction(text, this); 01012 addAction(ret); 01013 return ret; 01014 }
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This convenience function creates a new action with an icon and some text. The function adds the newly created action to the menu's list of actions, and returns it.
Definition at line 1025 of file qmenu.cpp.
References addAction(), and icon().
01026 { 01027 QAction *ret = new QAction(icon, text, this); 01028 addAction(ret); 01029 return ret; 01030 }
Here is the call graph for this function:

| QAction * QMenu::addAction | ( | const QString & | text, | |
| const QObject * | receiver, | |||
| const char * | member, | |||
| const QKeySequence & | shortcut = 0 | |||
| ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This convenience function creates a new action with the text text and an optional shortcut shortcut. The action's {QAction::triggered()}{triggered()} signal is connected to the receiver's member slot. The function adds the newly created action to the menu's list of actions and returns it.
Definition at line 1043 of file qmenu.cpp.
References addAction(), QObject::connect(), QAction::setShortcut(), SIGNAL, and triggered().
01044 { 01045 QAction *action = new QAction(text, this); 01046 #ifdef QT_NO_SHORTCUT 01047 Q_UNUSED(shortcut); 01048 #else 01049 action->setShortcut(shortcut); 01050 #endif 01051 QObject::connect(action, SIGNAL(triggered()), receiver, member); 01052 addAction(action); 01053 return action; 01054 }
Here is the call graph for this function:

| QAction * QMenu::addAction | ( | const QIcon & | icon, | |
| const QString & | text, | |||
| const QObject * | receiver, | |||
| const char * | member, | |||
| const QKeySequence & | shortcut = 0 | |||
| ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This convenience function creates a new action with an icon and some text and an optional shortcut shortcut. The action's {QAction::triggered()}{triggered()} signal is connected to the member slot of the receiver object. The function adds the newly created action to the menu's list of actions, and returns it.
Definition at line 1067 of file qmenu.cpp.
References addAction(), QObject::connect(), icon(), QAction::setShortcut(), SIGNAL, and triggered().
01069 { 01070 QAction *action = new QAction(icon, text, this); 01071 #ifdef QT_NO_SHORTCUT 01072 Q_UNUSED(shortcut); 01073 #else 01074 action->setShortcut(shortcut); 01075 #endif 01076 QObject::connect(action, SIGNAL(triggered()), receiver, member); 01077 addAction(action); 01078 return action; 01079 }
Here is the call graph for this function:

This convenience function adds menu as a submenu to this menu. It returns the menus menuAction().
Definition at line 1086 of file qmenu.cpp.
References addAction(), and menuAction().
Referenced by QFileDialogPrivate::_q_showContextMenu(), ColorSwatch::ColorSwatch(), QTextControl::createStandardContextMenu(), QLineEdit::createStandardContextMenu(), QDesignerWorkbench::initialize(), QToolBar::resizeEvent(), and MainWindow::setupDockWidgets().
01087 { 01088 QAction *action = menu->menuAction(); 01089 addAction(action); 01090 return action; 01091 }
Here is the call graph for this function:

Appends a new QMenu with title to the menu. The menu takes ownership of the menu. Returns the new menu.
Definition at line 1099 of file qmenu.cpp.
References addAction(), menuAction(), QMenu(), and title().
01100 { 01101 QMenu *menu = new QMenu(title, this); 01102 addAction(menu->menuAction()); 01103 return menu; 01104 }
Here is the call graph for this function:

Appends a new QMenu with icon and title to the menu. The menu takes ownership of the menu. Returns the new menu.
Definition at line 1112 of file qmenu.cpp.
References addAction(), icon(), menuAction(), QMenu(), setIcon(), and title().
01113 { 01114 QMenu *menu = new QMenu(title, this); 01115 menu->setIcon(icon); 01116 addAction(menu->menuAction()); 01117 return menu; 01118 }
Here is the call graph for this function:

| QAction * QMenu::addSeparator | ( | ) |
This convenience function creates a new separator action, i.e. an action with QAction::isSeparator() returning true, and adds the new action to this menu's list of actions. It returns the newly created action.
Definition at line 1128 of file qmenu.cpp.
References addAction(), and QAction::setSeparator().
Referenced by QFileDialogPrivate::_q_showContextMenu(), QDesignerWorkbench::addFormWindow(), ColorSwatch::ColorSwatch(), QScrollBar::contextMenuEvent(), QPixelTool::contextMenuEvent(), QVFb::createFileMenu(), MainWindow::createMenu(), ImageViewer::createMenus(), MainWindow::createMenus(), QMainWindow::createPopupMenu(), QTextControl::createStandardContextMenu(), QLineEdit::createStandardContextMenu(), Window::createTrayIcon(), QVFb::createViewMenu(), QDesignerToolBar::handleContextMenuEvent(), QDesignerMenuBar::handleContextMenuEvent(), QWorkspacePrivate::init(), QDesignerWorkbench::initialize(), Main::Main(), main(), Q3MainWindow::menuAboutToShow(), QtWindowListMenu::QtWindowListMenu(), MainWindow::setupDockWidgets(), TextEdit::setupEditActions(), TextEdit::setupFileActions(), MainWindow::setupMenuBar(), SpreadSheet::setupMenuBar(), TextEdit::setupTextActions(), ToolBar::ToolBar(), and MainWindow::updateWindowMenu().
01129 { 01130 QAction *action = new QAction(this); 01131 action->setSeparator(true); 01132 addAction(action); 01133 return action; 01134 }
Here is the call graph for this function:

This convenience function inserts menu before action before and returns the menus menuAction().
Definition at line 1142 of file qmenu.cpp.
References QWidget::insertAction(), and menuAction().
Referenced by QDesignerWorkbench::initialize().
01143 { 01144 QAction *action = menu->menuAction(); 01145 insertAction(before, action); 01146 return action; 01147 }
Here is the call graph for this function:

This convenience function creates a new separator action, i.e. an action with QAction::isSeparator() returning true. The function inserts the newly created action into this menu's list of actions before action before and returns it.
Definition at line 1157 of file qmenu.cpp.
References QWidget::insertAction(), and QAction::setSeparator().
Referenced by Main::Main(), and Q3FileDialog::popupContextMenu().
01158 { 01159 QAction *action = new QAction(this); 01160 action->setSeparator(true); 01161 insertAction(before, action); 01162 return action; 01163 }
Here is the call graph for this function:

| bool QMenu::isEmpty | ( | ) | const |
Definition at line 1274 of file qmenu.cpp.
References QWidget::actions(), and QList< T >::isEmpty().
Here is the call graph for this function:

| void QMenu::clear | ( | ) |
Removes all the menu's actions. Actions owned by the menu and not shown in any other widget are deleted.
Definition at line 1285 of file qmenu.cpp.
References QWidget::actions(), i, QList< T >::isEmpty(), QObject::parent(), QWidget::removeAction(), and QList< T >::size().
Referenced by Q3ComboBox::clear(), Q3ToolBar::createPopup(), Q3MainWindow::menuAboutToShow(), Q3ComboBox::popup(), QToolBar::resizeEvent(), ColorSwatch::updateContextMenu(), and MainWindow::updateWindowMenu().
01286 { 01287 QList<QAction*> acts = actions(); 01288 for(int i = 0; i < acts.size(); i++) { 01289 removeAction(acts[i]); 01290 if (acts[i]->parent() == this && acts[i]->d_func()->widgets.isEmpty()) 01291 delete acts[i]; 01292 } 01293 }
Here is the call graph for this function:

| void QMenu::setTearOffEnabled | ( | bool | ) |
Definition at line 1198 of file qmenu.cpp.
References d, QWidget::isVisible(), QWidget::resize(), and sizeHint().
01199 { 01200 Q_D(QMenu); 01201 if (d->tearoff == b) 01202 return; 01203 if (!b && d->tornPopup) 01204 d->tornPopup->close(); 01205 d->tearoff = b; 01206 01207 d->itemsDirty = true; 01208 if (isVisible()) 01209 resize(sizeHint()); 01210 }
Here is the call graph for this function:

| bool QMenu::isTearOffEnabled | ( | ) | const |
| bool QMenu::isTearOffMenuVisible | ( | ) | const |
When a menu is torn off a second menu is shown to display the menu contents in a new window. When the menu is in this mode and the menu is visible returns true; otherwise false.
Definition at line 1224 of file qmenu.cpp.
01225 { 01226 if (d_func()->tornPopup) 01227 return d_func()->tornPopup->isVisible(); 01228 return false; 01229 }
| void QMenu::hideTearOffMenu | ( | ) |
This function will forcibly hide the torn off menu making it disappear from the users desktop.
Definition at line 1237 of file qmenu.cpp.
| void QMenu::setDefaultAction | ( | QAction * | act | ) |
This will set the default action to act. The default action may have a visual queue depending on the current QStyle. A default action is usually meant to indicate what will defaultly happen on a drop, as shown in a context menu.
Definition at line 1173 of file qmenu.cpp.
| QAction * QMenu::defaultAction | ( | ) | const |
Returns the current default action.
Definition at line 1183 of file qmenu.cpp.
| void QMenu::setActiveAction | ( | QAction * | act | ) |
Sets the currently highlighted action to act.
Definition at line 1247 of file qmenu.cpp.
References d, and QMenuPrivate::QMenuScroller::ScrollCenter.
Referenced by QAccessibleMenu::doAction().
01248 { 01249 Q_D(QMenu); 01250 d->setCurrentAction(act, 0); 01251 if (d->scroll) 01252 d->scrollMenu(act, QMenuPrivate::QMenuScroller::ScrollCenter); 01253 }
| QAction * QMenu::activeAction | ( | ) | const |
Displays the menu so that the action atAction will be at the specified global position p. To translate a widget's local coordinates into global coordinates, use QWidget::mapToGlobal().
When positioning a menu with exec() or popup(), bear in mind that you cannot rely on the menu's current size(). For performance reasons, the menu adapts its size only when necessary, so in many cases, the size before and after the show is different. Instead, use sizeHint() which calculates the proper size depending on the menu's current contents.
Definition at line 1377 of file qmenu.cpp.
References aboutToShow(), QRect::bottom(), d, QApplication::desktop(), QEffects::DownScroll, emit, QWidget::ensurePolished(), QWidget::height(), QRect::height(), QSize::height(), i, int, QApplication::isEffectEnabled(), QRect::left(), QEffects::LeftScroll, m, p, QStyle::pixelMetric(), QStyle::PM_MenuDesktopFrameWidth, QAccessible::PopupMenuStart, QCursor::pos(), QWidget::pos(), qApp, qFadeEffect(), qMax(), qMin(), qScrollEffect(), QRect::right(), QEffects::RightScroll, Qt::RightToLeft, QMenuPrivate::QMenuScroller::ScrollDown, QMenuPrivate::QMenuScroller::ScrollNone, QMenuPrivate::QMenuScroller::ScrollUp, QWidget::setGeometry(), QSize::setHeight(), QPoint::setX(), QPoint::setY(), QStyle::SH_Menu_FillScreenWithScroll, QWidget::show(), QWidget::size(), sizeHint(), QWidget::style(), styleHint(), QRect::top(), Qt::UI_AnimateMenu, Qt::UI_FadeMenu, QAccessible::updateAccessibility(), QEffects::UpScroll, QSize::width(), QPoint::x(), QRect::y(), QPoint::y(), and QWidget::y().
Referenced by QWorkspacePrivate::_q_popupOperationMenu(), QWorkspacePrivate::_q_showOperationMenu(), SourceTextEdit::contextMenuEvent(), exec(), Q3ComboBox::popup(), and Q3ActionGroupPrivate::update().
01378 { 01379 Q_D(QMenu); 01380 if (d->scroll) { //reset scroll state from last popup 01381 d->scroll->scrollOffset = 0; 01382 d->scroll->scrollFlags = QMenuPrivate::QMenuScroller::ScrollNone; 01383 } 01384 d->tearoffHighlighted = 0; 01385 d->motions = 0; 01386 d->doChildEffects = true; 01387 01388 ensurePolished(); // Get the right font 01389 emit aboutToShow(); 01390 d->updateActions(); 01391 QPoint pos = p; 01392 QSize size = sizeHint(); 01393 QRect screen = d->popupGeometry(QApplication::desktop()->screenNumber(p)); 01394 const int desktopFrame = style()->pixelMetric(QStyle::PM_MenuDesktopFrameWidth, 0, this); 01395 if (d->ncols > 1) { 01396 pos.setY(screen.top()+desktopFrame); 01397 } else if (atAction) { 01398 for(int i=0, above_height=0; i<(int)d->actionList.count(); i++) { 01399 QAction *action = d->actionList.at(i); 01400 if (action == atAction) { 01401 int newY = pos.y()-above_height; 01402 if (d->scroll && newY < desktopFrame) { 01403 d->scroll->scrollFlags = d->scroll->scrollFlags 01404 | QMenuPrivate::QMenuScroller::ScrollUp; 01405 d->scroll->scrollOffset = newY; 01406 newY = desktopFrame; 01407 } 01408 pos.setY(newY); 01409 01410 if (d->scroll && d->scroll->scrollFlags != QMenuPrivate::QMenuScroller::ScrollNone 01411 && !style()->styleHint(QStyle::SH_Menu_FillScreenWithScroll, 0, this)) { 01412 int below_height = above_height + d->scroll->scrollOffset; 01413 for(int i2 = i; i2 < (int)d->actionList.count(); i2++) 01414 below_height += d->actionRects.value(d->actionList.at(i2)).height(); 01415 size.setHeight(below_height); 01416 } 01417 break; 01418 } else { 01419 above_height += d->actionRects.value(action).height(); 01420 } 01421 } 01422 } 01423 01424 QPoint mouse = QCursor::pos(); 01425 const bool snapToMouse = (p == mouse); 01426 01427 //handle popup falling "off screen" 01428 if (qApp->layoutDirection() == Qt::RightToLeft) { 01429 if(snapToMouse) //position flowing left from the mouse 01430 pos.setX(mouse.x()-size.width()); 01431 01432 if (pos.x() < screen.left()+desktopFrame) 01433 pos.setX(qMax(p.x(), screen.left()+desktopFrame)); 01434 if (pos.x()+size.width() > screen.right()-desktopFrame) 01435 pos.setX(qMax(p.x()-size.width(), screen.right()-desktopFrame-size.width())); 01436 } else { 01437 if (pos.x()+size.width() > screen.right()-desktopFrame) 01438 pos.setX(qMin(p.x()-size.width(), screen.right()-desktopFrame-size.width())); 01439 if (pos.x() < screen.left()+desktopFrame) 01440 pos.setX(qMax(p.x(), screen.left() + desktopFrame)); 01441 } 01442 if (pos.y() + size.height() > screen.bottom() - desktopFrame) { 01443 if(snapToMouse) 01444 pos.setY(qMin(mouse.y() - (size.height() + desktopFrame), screen.bottom()-desktopFrame-size.height())); 01445 else 01446 pos.setY(qMax(p.y() - (size.height() + desktopFrame), screen.bottom()-desktopFrame-size.height())); 01447 } else if (pos.y() < screen.top()) { 01448 pos.setY(screen.top()); 01449 } 01450 01451 if (pos.y() < screen.top()) 01452 pos.setY(screen.top()); 01453 if (pos.y()+size.height() > screen.bottom() - desktopFrame) { 01454 if (d->scroll) { 01455 d->scroll->scrollFlags |= uint(QMenuPrivate::QMenuScroller::ScrollDown); 01456 int y = qMax(screen.y(),pos.y()); 01457 size.setHeight(screen.height()-desktopFrame*2-y); 01458 } else { 01459 // Too big for screen, bias to see bottom of menu (for some reason) 01460 pos.setY(screen.bottom()-size.height()); 01461 } 01462 } 01463 setGeometry(QRect(pos, size)); 01464 01465 #ifndef QT_NO_EFFECTS 01466 int hGuess = qApp->layoutDirection() == Qt::RightToLeft ? QEffects::LeftScroll : QEffects::RightScroll; 01467 int vGuess = QEffects::DownScroll; 01468 if (qApp->layoutDirection() == Qt::RightToLeft) { 01469 if ((snapToMouse && (pos.x() + size.width()/2 > mouse.x())) || 01470 (qobject_cast<QMenu*>(d->causedPopup.widget) && pos.x() + size.width()/2 > d->causedPopup.widget->x())) 01471 hGuess = QEffects::RightScroll; 01472 } else { 01473 if ((snapToMouse && (pos.x() + size.width()/2 < mouse.x())) || 01474 (qobject_cast<QMenu*>(d->causedPopup.widget) && pos.x() + size.width()/2 < d->causedPopup.widget->x())) 01475 hGuess = QEffects::LeftScroll; 01476 } 01477 01478 #ifndef QT_NO_MENUBAR 01479 if ((snapToMouse && (pos.y() + size.height()/2 < mouse.y())) || 01480 (qobject_cast<QMenuBar*>(d->causedPopup.widget) && 01481 pos.y() + size.width()/2 < d->causedPopup.widget->mapToGlobal(d->causedPopup.widget->pos()).y())) 01482 vGuess = QEffects::UpScroll; 01483 #endif 01484 if (QApplication::isEffectEnabled(Qt::UI_AnimateMenu)) { 01485 bool doChildEffects = true; 01486 #ifndef QT_NO_MENUBAR 01487 if (QMenuBar *mb = qobject_cast<QMenuBar*>(d->causedPopup.widget)) { 01488 doChildEffects = mb->d_func()->doChildEffects; 01489 mb->d_func()->doChildEffects = false; 01490 } else 01491 #endif 01492 if (QMenu *m = qobject_cast<QMenu*>(d->causedPopup.widget)) { 01493 doChildEffects = m->d_func()->doChildEffects; 01494 m->d_func()->doChildEffects = false; 01495 } 01496 01497 if (doChildEffects) { 01498 if (QApplication::isEffectEnabled(Qt::UI_FadeMenu)) 01499 qFadeEffect(this); 01500 else if (d->causedPopup.widget) 01501 qScrollEffect(this, qobject_cast<QMenu*>(d->causedPopup.widget) ? hGuess : vGuess); 01502 else 01503 qScrollEffect(this, hGuess | vGuess); 01504 } else { 01505 // kill any running effect 01506 qFadeEffect(0); 01507 qScrollEffect(0); 01508 01509 show(); 01510 } 01511 } else 01512 #endif 01513 { 01514 show(); 01515 } 01516 01517 #ifndef QT_NO_ACCESSIBILITY 01518 QAccessible::updateAccessibility(this, 0, QAccessible::PopupMenuStart); 01519 #endif 01520 }
Here is the call graph for this function:

| QAction * QMenu::exec | ( | ) |
Executes this menu synchronously.
This is equivalent to {exec(pos())}.
This returns the triggered QAction in either the popup menu or one of its submenus, or 0 if no item was triggered (normally because the user pressed Esc).
In most situations you'll want to specify the position yourself, for example, the current mouse position:
exec(QCursor::pos());
exec(e->globalPos());
Definition at line 1545 of file qmenu.cpp.
References QWidget::createWinId(), and QWidget::pos().
Referenced by QFileDialogPrivate::_q_showContextMenu(), QMainWindow::contextMenuEvent(), QTextControlPrivate::contextMenuEvent(), MainWindow::contextMenuEvent(), QMessageBoxDetailsText::TextEdit::contextMenuEvent(), ColorSwatch::contextMenuEvent(), qdesigner_internal::QtBrushEditor::contextMenuEvent(), QScrollBar::contextMenuEvent(), qdesigner_internal::WidgetBoxTreeView::contextMenuEvent(), QPixelTool::contextMenuEvent(), qdesigner_internal::QtGradientStopsWidget::contextMenuEvent(), QLabel::contextMenuEvent(), QWidget::event(), exec(), Q3PopupMenu::exec(), QDesignerToolBar::handleContextMenuEvent(), QDesignerMenuBar::handleContextMenuEvent(), QDesignerMenu::handleContextMenuEvent(), Q3TextEdit::pickSpecial(), QVFb::popupMenu(), QDBusViewer::showContextMenu(), HelpDialog::showIndexItemMenu(), HelpDialog::showListItemMenu(), and HelpDialog::showTreeItemMenu().
01546 { 01547 createWinId(); 01548 return exec(pos()); 01549 }
Here is the call graph for this function:

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Executes this menu synchronously.
Pops up the menu so that the action action will be at the specified global position p. To translate a widget's local coordinates into global coordinates, use QWidget::mapToGlobal().
This returns the triggered QAction in either the popup menu or one of its submenus, or 0 if no item was triggered (normally because the user pressed Esc).
Note that all signals are emitted as usual. If you connect a QAction to a slot and call the menu's exec(), you get the result both via the signal-slot connection and in the return value of exec().
Common usage is to position the menu at the current mouse position:
exec(QCursor::pos());
exec(e->globalPos());
When positioning a menu with exec() or popup(), bear in mind that you cannot rely on the menu's current size(). For performance reasons, the menu adapts its size only when necessary. So in many cases, the size before and after the show is different. Instead, use sizeHint() which calculates the proper size depending on the menu's current contents.
Definition at line 1593 of file qmenu.cpp.
References d, QEventLoop::exec(), QPointer< T >::isNull(), p, and popup().
01594 { 01595 Q_D(QMenu); 01596 QEventLoop eventLoop; 01597 d->eventLoop = &eventLoop; 01598 popup(p, action); 01599 01600 QPointer<QObject> guard = this; 01601 (void) eventLoop.exec(); 01602 if (guard.isNull()) 01603 return 0; 01604 01605 action = d->syncAction; 01606 d->syncAction = 0; 01607 d->eventLoop = 0; 01608 return action; 01609 }
Here is the call graph for this function:

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Executes this menu synchronously.
The menu's actions are specified by the list of actions. The menu will pop up so that the specified action, at, appears at global position pos. If at is not specified then the menu appears at position pos.
The function returns the triggered QAction in either the popup menu or one of its submenus, or 0 if no item was triggered (normally because the user pressed Esc).
This is equivalent to:
QMenu menu; QAction *at = actions[0]; // Assumes actions is not empty foreach (QAction *a, actions) menu.addAction(a); menu.exec(pos, at);
Definition at line 1636 of file qmenu.cpp.
References QWidget::actions(), addAction(), QList< T >::begin(), QList< T >::end(), exec(), and QWidget::pos().
01637 { 01638 QMenu menu; 01639 for(QList<QAction*>::Iterator it = actions.begin(); it != actions.end(); ++it) 01640 menu.addAction((*it)); 01641 return menu.exec(pos, at); 01642 }
Here is the call graph for this function:

| QSize QMenu::sizeHint | ( | ) | const [virtual] |
Reimplemented from QWidget.
Definition at line 1328 of file qmenu.cpp.
References QMap< Key, T >::constBegin(), QMap< Key, T >::constEnd(), QStyle::CT_Menu, d, QWidget::ensurePolished(), QApplication::globalStrut(), i, QWidget::palette(), QStyleOption::palette, QStyle::pixelMetric(), QStyle::PM_MenuHMargin, QStyle::PM_MenuPanelWidth, QStyle::PM_MenuTearoffHeight, QStyle::PM_MenuVMargin, QStyleOption::rect, QWidget::rect(), s, QStyle::sizeFromContents(), QStyleOption::state, QStyle::State_None, and QWidget::style().
Referenced by QWorkspacePrivate::_q_showOperationMenu(), QTornOffMenu::actionEvent(), actionEvent(), changeEvent(), Q3ToolBar::createPopup(), popup(), setTearOffEnabled(), and Q3ComboBox::sizeHint().
01329 { 01330 Q_D(const QMenu); 01331 ensurePolished(); 01332 QMap<QAction*, QRect> actionRects; 01333 QList<QAction*> actionList; 01334 d->calcActionRects(actionRects, actionList); 01335 01336 QSize s; 01337 QStyleOption opt(0); 01338 opt.rect = rect(); 01339 opt.palette = palette(); 01340 opt.state = QStyle::State_None; 01341 for (QMap<QAction*, QRect>::const_iterator i = actionRects.constBegin(); 01342 i != actionRects.constEnd(); ++i) { 01343 if (i.value().bottom() > s.height()) 01344 s.setHeight(i.value().y()+i.value().height()); 01345 if (i.value().right() > s.width()) 01346 s.setWidth(i.value().right()); 01347 } 01348 if (d->tearoff) 01349 s.rheight() += style()->pixelMetric(QStyle::PM_MenuTearoffHeight, &opt, this); 01350 if (const int fw = style()->pixelMetric(QStyle::PM_MenuPanelWidth, &opt, this)) { 01351 s.rwidth() += fw*2; 01352 s.rheight() += fw*2; 01353 } 01354 s.rwidth() += 2 * style()->pixelMetric(QStyle::PM_MenuHMargin, &opt, this); 01355 s.rheight() += 2 * style()->pixelMetric(QStyle::PM_MenuVMargin, &opt, this); 01356 01357 s += QSize(d->leftmargin + d->rightmargin, d->topmargin + d->bottommargin); 01358 01359 return style()->sizeFromContents(QStyle::CT_Menu, &opt, 01360 s.expandedTo(QApplication::globalStrut()), this); 01361 }
Here is the call graph for this function:

Returns the geometry of action act.
Definition at line 1320 of file qmenu.cpp.
Referenced by QDesignerMenu::actionAtPosition(), QDesignerMenu::dragMoveEvent(), QDesignerMenu::paintEvent(), QAccessibleMenu::rect(), QDesignerMenu::showLineEdit(), QDesignerMenu::slotShowSubMenuNow(), and QDesignerMenu::subMenuPixmapRect().
Returns the item at pt; returns 0 if there is no item there.
Definition at line 1310 of file qmenu.cpp.
Referenced by QAccessibleMenu::childAt().
| QAction * QMenu::menuAction | ( | ) | const |
Returns the action associated with this menu.
Definition at line 453 of file qmenu.cpp.
Referenced by QMultiInputContext::actions(), QMenuBar::addMenu(), addMenu(), Q3ActionGroup::addTo(), qdesigner_internal::QDesignerResource::create(), QDesignerMenu::createRealMenuAction(), QMenuBar::insertMenu(), insertMenu(), QDesignerMenu::safeMenuAction(), QToolButton::setMenu(), MainWindow::setup(), and ToolBar::ToolBar().
| QString QMenu::title | ( | ) | const |
Definition at line 465 of file qmenu.cpp.
Referenced by addMenu(), QDesignerMenu::createRealMenuAction(), and QMenu().
| void QMenu::setTitle | ( | const QString & | title | ) |
Definition at line 470 of file qmenu.cpp.
Referenced by QtWindowListMenu::addTo(), ColorSwatch::ColorSwatch(), QDesignerMenu::createRealMenuAction(), and QUnicodeControlCharacterMenu::QUnicodeControlCharacterMenu().
| QIcon QMenu::icon | ( | ) | const |
Definition at line 482 of file qmenu.cpp.
Referenced by addAction(), addMenu(), QtWindowListMenu::addWindow(), QtWindowListMenu::setCascadeIcon(), QtWindowListMenu::setCloseAllIcon(), QtWindowListMenu::setCloseIcon(), QtWindowListMenu::setDefaultIcon(), setIcon(), QtWindowListMenu::setTileIcon(), and QtWindowListMenu::setWindowIcon().
| void QMenu::setIcon | ( | const QIcon & | icon | ) |
Definition at line 487 of file qmenu.cpp.
References icon().
Referenced by QMenuBar::addMenu(), addMenu(), and ToolBar::ToolBar().
00488 { 00489 d_func()->menuAction->setIcon(icon); 00490 }
Here is the call graph for this function:

| void QMenu::setNoReplayFor | ( | QWidget * | widget | ) |
| bool QMenu::separatorsCollapsible | ( | ) | const |
| void QMenu::setSeparatorsCollapsible | ( | bool | collapse | ) |
Definition at line 2558 of file qmenu.cpp.
References d, QWidget::isVisible(), and QWidget::update().
02559 { 02560 Q_D(QMenu); 02561 d->collapsibleSeparators = collapse; 02562 d->itemsDirty = 1; 02563 if (isVisible()) { 02564 d->updateActions(); 02565 update(); 02566 } 02567 }
Here is the call graph for this function:

| void QMenu::aboutToShow | ( | ) | [signal] |
This signal is emitted just before the menu is shown to the user.
Referenced by popup().
| void QMenu::aboutToHide | ( | ) | [signal] |
Referenced by hideEvent().
| void QMenu::triggered | ( | QAction * | action | ) | [signal] |
This signal is emitted when a menu action is triggered; action is the action that caused the signal to be emitted.
Normally, you connect each menu action's {QAction::}{triggered()} signal to its own custom slot, but sometimes you will want to connect several actions to a single slot, for example, when you have a group of closely related actions, such as "left justify", "center", "right justify".
Referenced by actionEvent(), addAction(), QtWindowListMenu::addWindow(), and QDesignerMenu::handleContextMenuEvent().
| void QMenu::hovered | ( | QAction * | action | ) | [signal] |
This signal is emitted when a menu action is highlighted; action is the action that caused the signal to be emitted.
Often this is used to update status information.
Referenced by actionEvent().
| int QMenu::columnCount | ( | ) | const [protected] |
| void QMenu::changeEvent | ( | QEvent * | e | ) | [protected, virtual] |
Reimplemented from QWidget.
Definition at line 1837 of file qmenu.cpp.
References QWidget::changeEvent(), d, QEvent::EnabledChange, QEvent::FontChange, QWidget::isEnabled(), QWidget::isVisible(), QEvent::LayoutDirectionChange, QWidget::resize(), QMenuPrivate::QMenuScroller::ScrollNone, QWidget::setMouseTracking(), QStyle::SH_Menu_MouseTracking, QStyle::SH_Menu_Scrollable, sizeHint(), QWidget::style(), QEvent::StyleChange, styleHint(), and QEvent::type().
01838 { 01839 Q_D(QMenu); 01840 if (e->type() == QEvent::StyleChange || e->type() == QEvent::FontChange || 01841 e->type() == QEvent::LayoutDirectionChange) { 01842 d->itemsDirty = 1; 01843 setMouseTracking(style()->styleHint(QStyle::SH_Menu_MouseTracking, 0, this)); 01844 if (isVisible()) 01845 resize(sizeHint()); 01846 if (!style()->styleHint(QStyle::SH_Menu_Scrollable, 0, this)) { 01847 delete d->scroll; 01848 d->scroll = 0; 01849 } else if (!d->scroll) { 01850 d->scroll = new QMenuPrivate::QMenuScroller; 01851 d->scroll->scrollFlags = QMenuPrivate::QMenuScroller::ScrollNone; 01852 } 01853 } else if (e->type() == QEvent::EnabledChange) { 01854 if (d->tornPopup) // torn-off menu 01855 d->tornPopup->setEnabled(isEnabled()); 01856 d->menuAction->setEnabled(isEnabled()); 01857 } 01858 QWidget::changeEvent(e); 01859 }
Here is the call graph for this function:

| void QMenu::keyPressEvent | ( | QKeyEvent * | e | ) | [protected, virtual] |
Reimplemented from QWidget.
Definition at line 1913 of file qmenu.cpp.
References QEvent::accept(), Qt::AltModifier, QString::at(), c, Qt::CaseInsensitive, QRect::center(), QWidget::close(), d, QWhatsThis::enterWhatsThisMode(), QWidget::height(), QWidget::hide(), i, QEvent::ignore(), QString::indexOf(), int, QWidget::isRightToLeft(), QKeyEvent::key(), key, Qt::Key_Alt, Qt::Key_Back, Qt::Key_Control, Qt::Key_Down, Qt::Key_End, Qt::Key_Enter, Qt::Key_Escape, Qt::Key_F1, Qt::Key_Home, Qt::Key_Left, Qt::Key_Meta, Qt::Key_PageDown, Qt::Key_PageUp, Qt::Key_Return, Qt::Key_Right, Qt::Key_Select, Qt::Key_Shift, Qt::Key_Space, Qt::Key_Tab, Qt::Key_Up, QRect::left(), QString::length(), m, QAction::menu(), QKeySequence::mnemonic(), QKeyEvent::modifiers(), next, QStyle::pixelMetric(), QStyle::PM_MenuScrollerHeight, QStyle::PM_MenuTearoffHeight, qApp, QRect::right(), QMenuPrivate::QMenuScroller::ScrollBottom, QMenuPrivate::QMenuScroller::ScrollDown, QMenuPrivate::QMenuScroller::ScrollStay, QMenuPrivate::QMenuScroller::ScrollTop, QMenuPrivate::QMenuScroller::ScrollUp, QMenuPrivate::SelectedFromElsewhere, QMenuPrivate::SelectedFromKeyboard, QCoreApplication::sendEvent(), QStyle::SH_Menu_AllowActiveAndDisabled, QStyle::SH_Menu_KeyboardSearch, QStyle::SH_Menu_SelectionWrap, QStyle::SH_Menu_SpaceActivatesItem, QStyle::SH_MenuBar_AltKeyNavigation, Qt::ShiftModifier, QWidget::style(), QStyle::styleHint(), styleHint(), QKeyEvent::text(), QAction::text(), QChar::toUpper(), QAction::Trigger, QWidget::width(), QWidget::x(), QPoint::y(), and QWidget::y().
Referenced by event(), and focusNextPrevChild().
01914 { 01915 Q_D(QMenu); 01916 int key = e->key(); 01917 if (isRightToLeft()) { // in reverse mode open/close key for submenues are reversed 01918 if (key == Qt::Key_Left) 01919 key = Qt::Key_Right; 01920 else if (key == Qt::Key_Right) 01921 key = Qt::Key_Left; 01922 } 01923 if (key == Qt::Key_Tab) //means down 01924 key = Qt::Key_Down; 01925 01926 bool key_consumed = false; 01927 switch(key) { 01928 #ifdef Q_WS_MAC 01929 case Qt::Key_PageUp: 01930 #endif 01931 case Qt::Key_Home: 01932 key_consumed = true; 01933 if (d->scroll) { 01934 for(int i = 0; i < d->actionList.size(); ++i) { 01935 QAction *act = d->actionList.at(i); 01936 if (!act->isSeparator() && 01937 (style()->styleHint(QStyle::SH_Menu_AllowActiveAndDisabled, 0, this) 01938 || act->isEnabled())) { 01939 if(d->scroll->scrollFlags & QMenuPrivate::QMenuScroller::ScrollUp) 01940 d->scrollMenu(act, QMenuPrivate::QMenuScroller::ScrollTop, true); 01941 else 01942 d->setCurrentAction(act, /*popup*/-1, QMenuPrivate::SelectedFromKeyboard); 01943 break; 01944 } 01945 } 01946 } 01947 break; 01948 #ifdef Q_WS_MAC 01949 case Qt::Key_PageDown: 01950 #endif 01951 case Qt::Key_End: 01952 key_consumed = true; 01953 if (d->scroll) { 01954 for(int i = d->actionList.size()-1; i >= 0; --i) { 01955 QAction *act = d->actionList.at(i); 01956 if (!act->isSeparator() && 01957 (style()->styleHint(QStyle::SH_Menu_AllowActiveAndDisabled, 0, this) 01958 || act->isEnabled())) { 01959 if(d->scroll->scrollFlags & QMenuPrivate::QMenuScroller::ScrollDown) 01960 d->scrollMenu(act, QMenuPrivate::QMenuScroller::ScrollBottom, true); 01961 else 01962 d->setCurrentAction(act, /*popup*/-1, QMenuPrivate::SelectedFromKeyboard); 01963 break; 01964 } 01965 } 01966 } 01967 break; 01968 #ifndef Q_WS_MAC 01969 case Qt::Key_PageUp: 01970 key_consumed = true; 01971 if (d->currentAction && d->scroll) 01972 d->scrollMenu(QMenuPrivate::QMenuScroller::ScrollUp, true, true); 01973 break; 01974 case Qt::Key_PageDown: 01975 key_consumed = true; 01976 if (d->currentAction && d->scroll) 01977 d->scrollMenu(QMenuPrivate::QMenuScroller::ScrollDown, true, true); 01978 break; 01979 #endif 01980 case Qt::Key_Up: 01981 case Qt::Key_Down: { 01982 key_consumed = true; 01983 QAction *nextAction = 0; 01984 QMenuPrivate::QMenuScroller::ScrollLocation scroll_loc = QMenuPrivate::QMenuScroller::ScrollStay; 01985 if (!d->currentAction) { 01986 if(key == Qt::Key_Down) { 01987 for(int i = 0; i < d->actionList.size(); ++i) { 01988 QAction *act = d->actionList.at(i); 01989 if (!act->isSeparator() && 01990 (style()->styleHint(QStyle::SH_Menu_AllowActiveAndDisabled, 0, this) 01991 || act->isEnabled())) { 01992 nextAction = act; 01993 break; 01994 } 01995 } 01996 } else { 01997 for(int i = d->actionList.size()-1; i >= 0; --i) { 01998 QAction *act = d->actionList.at(i); 01999 if (!act->isSeparator() && 02000 (style()->styleHint(QStyle::SH_Menu_AllowActiveAndDisabled, 0, this) 02001 || act->isEnabled())) { 02002 nextAction = act; 02003 break; 02004 } 02005 } 02006 } 02007 } else { 02008 for(int i=0, y=0; !nextAction && i < (int)d->actionList.count(); i++) { 02009 QAction *act = d->actionList.at(i); 02010 if (act == d->currentAction) { 02011 if (key == Qt::Key_Up) { 02012 for(int next_i = i-1; true; next_i--) { 02013 if (next_i == -1) { 02014 if(!style()->styleHint(QStyle::SH_Menu_SelectionWrap, 0, this)) 02015 break; 02016 if (d->scroll) 02017 scroll_loc = QMenuPrivate::QMenuScroller::ScrollBottom; 02018 next_i = d->actionList.count()-1; 02019 } 02020 QAction *next = d->actionList.at(next_i); 02021 if (next == d->currentAction) 02022 break; 02023 if (next->isSeparator() || 02024 (!next->isEnabled() && 02025 !style()->styleHint(QStyle::SH_Menu_AllowActiveAndDisabled, 0, this))) 02026 continue; 02027 nextAction = next; 02028 if (d->scroll && (d->scroll->scrollFlags & QMenuPrivate::QMenuScroller::ScrollUp)) { 02029 int topVisible = style()->pixelMetric(QStyle::PM_MenuScrollerHeight, 0, this); 02030 if (d->tearoff) 02031 topVisible += style()->pixelMetric(QStyle::PM_MenuTearoffHeight, 0, this); 02032 if (((y + d->scroll->scrollOffset) - topVisible) <= d->actionRects.value(nextAction).height()) 02033 scroll_loc = QMenuPrivate::QMenuScroller::ScrollTop; 02034 } 02035 break; 02036 } 02037 if (!nextAction && d->tearoff) 02038 d->tearoffHighlighted = 1; 02039 } else { 02040 y += d->actionRects.value(act).height(); 02041 for(int next_i = i+1; true; next_i++) { 02042 if (next_i == d->actionList.count()) { 02043 if(!style()->styleHint(QStyle::SH_Menu_SelectionWrap, 0, this)) 02044 break; 02045 if (d->scroll) 02046 scroll_loc = QMenuPrivate::QMenuScroller::ScrollTop; 02047 next_i = 0; 02048 } 02049 QAction *next = d->actionList.at(next_i); 02050 if (next == d->currentAction) 02051 break; 02052 if (next->isSeparator() || 02053 (!next->isEnabled() && 02054 !style()->styleHint(QStyle::SH_Menu_AllowActiveAndDisabled, 0, this))) 02055 continue; 02056 nextAction = next; 02057 if (d->scroll && (d->scroll->scrollFlags & QMenuPrivate::QMenuScroller::ScrollDown)) { 02058 const int scrollerHeight = style()->pixelMetric(QStyle::PM_MenuScrollerHeight, 0, this); 02059 int bottomVisible = height()-scrollerHeight; 02060 if (d->scroll->scrollFlags & QMenuPrivate::QMenuScroller::ScrollUp) 02061 bottomVisible -= scrollerHeight; 02062 if (d->tearoff) 02063 bottomVisible -= style()->pixelMetric(QStyle::PM_MenuTearoffHeight, 0, this); 02064 if ((y + d->scroll->scrollOffset + d->actionRects.value(nextAction).height()) > bottomVisible) 02065 scroll_loc = QMenuPrivate::QMenuScroller::ScrollBottom; 02066 } 02067 break; 02068 } 02069 } 02070 break; 02071 } 02072 y += d->actionRects.value(act).height(); 02073 } 02074 } 02075 if (nextAction) { 02076 if (d->scroll && scroll_loc != QMenuPrivate::QMenuScroller::ScrollStay) { 02077 if (d->scroll->scrollTimer) 02078 d->scroll->scrollTimer->stop(); 02079 d->scrollMenu(nextAction, scroll_loc); 02080 } 02081 d->setCurrentAction(nextAction, /*popup*/-1, QMenuPrivate::SelectedFromKeyboard); 02082 } 02083 break; } 02084 02085 case Qt::Key_Right: 02086 if (!d->currentAction) { 02087 d->setFirstActionActive(); 02088 key_consumed = true; 02089 break; 02090 } 02091 if (d->currentAction && d->currentAction->isEnabled() && d->currentAction->menu()) { 02092 d->popupAction(d->currentAction, 0, true); 02093 key_consumed = true; 02094 break; 02095 } 02096 //FALL THROUGH 02097 case Qt::Key_Left: { 02098 if (d->currentAction && !d->scroll) { 02099 QAction *nextAction = 0; 02100 if (key == Qt::Key_Left) { 02101 QRect actionR = d->actionRect(d->currentAction); 02102 for(int x = actionR.left()-1; !nextAction && x >= 0; x--) 02103 nextAction = d->actionAt(QPoint(x, actionR.center().y())); 02104 } else { 02105 QRect actionR = d->actionRect(d->currentAction); 02106 for(int x = actionR.right()+1; !nextAction && x < width(); x++) 02107 nextAction = d->actionAt(QPoint(x, actionR.center().y())); 02108 } 02109 if (nextAction) { 02110 d->setCurrentAction(nextAction, /*popup*/-1, QMenuPrivate::SelectedFromKeyboard); 02111 key_consumed = true; 02112 } 02113 } 02114 if (!key_consumed && key == Qt::Key_Left && d->causedPopup.widget && 02115 qobject_cast<QMenu*>(d->causedPopup.widget)) { 02116 QPointer<QWidget> caused = d->causedPopup.widget; 02117 hide(); 02118 if (caused) 02119 caused->setFocus(); 02120 key_consumed = true; 02121 } 02122 break; } 02123 02124 case Qt::Key_Alt: 02125 key_consumed = true; 02126 if ( style()->styleHint(QStyle::SH_MenuBar_AltKeyNavigation, 0, this)) 02127 { 02128 hide(); 02129 #ifndef QT_NO_MENUBAR 02130 if (QMenuBar *mb = qobject_cast<QMenuBar*>(qApp->focusWidget())) { 02131 mb->d_func()->setKeyboardMode(false); 02132 } 02133 #endif 02134 } 02135 break; 02136 02137 case Qt::Key_Escape: 02138 #ifdef QT_KEYPAD_NAVIGATION 02139 case Qt::Key_Back: 02140 #endif 02141 key_consumed = true; 02142 if (d->tornoff) { 02143 close(); 02144 return; 02145 } 02146 { 02147 QPointer<QWidget> caused = d->causedPopup.widget; 02148 hide(); //hide after getting causedPopup 02149 #ifndef QT_NO_MENUBAR 02150 if (QMenuBar *mb = qobject_cast<QMenuBar*>(caused)) { 02151 mb->d_func()->setCurrentAction(d->menuAction); 02152 mb->d_func()->setKeyboardMode(true); 02153 } 02154 #endif 02155 } 02156 break; 02157 02158 case Qt::Key_Space: 02159 if (!style()->styleHint(QStyle::SH_Menu_SpaceActivatesItem, 0, this)) 02160 break; 02161 // for motif, fall through 02162 #ifdef QT_KEYPAD_NAVIGATION 02163 case Qt::Key_Select: 02164 #endif 02165 case Qt::Key_Return: 02166 case Qt::Key_Enter: { 02167 if (!d->currentAction) { 02168 d->setFirstActionActive(); 02169 key_consumed = true; 02170 break; 02171 } 02172 02173 for(QWidget *caused = this; caused;) { 02174 if (QMenu *m = qobject_cast<QMenu*>(caused)) { 02175 QAction *currentAction = d->currentAction; 02176 if(currentAction && (!currentAction->isEnabled() || currentAction->menu() || currentAction->isSeparator())) 02177 currentAction = 0; 02178 caused = m->d_func()->causedPopup.widget; 02179 if (m->d_func()->eventLoop) 02180 m->d_func()->syncAction = currentAction; // synchronous operation 02181 } else { 02182 break; 02183 } 02184 } 02185 02186 if (d->currentAction->menu()) 02187 d->popupAction(d->currentAction, 0, true); 02188 else 02189 d->activateAction(d->currentAction, QAction::Trigger); 02190 key_consumed = true; 02191 break; } 02192 02193 #ifndef QT_NO_WHATSTHIS 02194 case Qt::Key_F1: 02195 if (!d->currentAction || d->currentAction->whatsThis().isNull()) 02196 break; 02197 QWhatsThis::enterWhatsThisMode(); 02198 d->activateAction(d->currentAction, QAction::Trigger); 02199 return; 02200 #endif 02201 default: 02202 key_consumed = false; 02203 } 02204 02205 if (!key_consumed) { // send to menu bar 02206 if ((!e->modifiers() || e->modifiers() == Qt::AltModifier || e->modifiers() == Qt::ShiftModifier) && 02207 e->text().length()==1) { 02208 bool activateAction = false; 02209 QAction *nextAction = 0; 02210 if (style()->styleHint(QStyle::SH_Menu_KeyboardSearch, 0, this) && !e->modifiers()) { 02211 int best_match_count = 0; 02212 d->searchBufferTimer.start(2000, this); 02213 d->searchBuffer += e->text(); 02214 for(int i = 0; i < d->actionList.size(); ++i) { 02215 int match_count = 0; 02216 register QAction *act = d->actionList.at(i); 02217 const QString act_text = act->text(); 02218 for(int c = 0; c < d->searchBuffer.size(); ++c) { 02219 if(act_text.indexOf(d->searchBuffer.at(c), 0, Qt::CaseInsensitive) != -1) 02220 ++match_count; 02221 } 02222 if(match_count > best_match_count) { 02223 best_match_count = match_count; 02224 nextAction = act; 02225 } 02226 } 02227 } 02228 #ifndef QT_NO_SHORTCUT 02229 else { 02230 int clashCount = 0; 02231 QAction *first = 0, *currentSelected = 0, *firstAfterCurrent = 0; 02232 QChar c = e->text().at(0).toUpper(); 02233 for(int i = 0; i < d->actionList.size(); ++i) { 02234 register QAction *act = d->actionList.at(i); 02235 QKeySequence sequence = QKeySequence::mnemonic(act->text()); 02236 int key = sequence[0] & 0xffff; 02237 if (key == c.unicode()) { 02238 clashCount++; 02239 if (!first) 02240 first = act; 02241 if (act == d->currentAction) 02242 currentSelected = act; 02243 else if (!firstAfterCurrent && currentSelected) 02244 firstAfterCurrent = act; 02245 } 02246 } 02247 if (clashCount == 1) 02248 activateAction = true; 02249 if (clashCount >= 1) { 02250 if (clashCount == 1 || !currentSelected || !firstAfterCurrent) 02251 nextAction = first; 02252 else 02253 nextAction = firstAfterCurrent; 02254 } 02255 } 02256 #endif 02257 if (nextAction) { 02258 key_consumed = true; 02259 d->setCurrentAction(nextAction, 20, QMenuPrivate::SelectedFromElsewhere, true); 02260 if (!nextAction->menu() && activateAction) 02261 d->activateAction(nextAction, QAction::Trigger); 02262 } 02263 } 02264 if (!key_consumed) { 02265 if (QWidget *caused = d->causedPopup.widget) { 02266 while(QMenu *m = qobject_cast<QMenu*>(caused)) 02267 caused = m->d_func()->causedPopup.widget; 02268 #ifndef QT_NO_MENUBAR 02269 if (QMenuBar *mb = qobject_cast<QMenuBar*>(caused)) { 02270 QAction *oldAct = mb->d_func()->currentAction; 02271 QApplication::sendEvent(mb, e); 02272 if (mb->d_func()->currentAction != oldAct) 02273 key_consumed = true; 02274 } 02275 #endif 02276 } 02277 } 02278 02279 #ifdef Q_OS_WIN32 02280 if (key_consumed && (e->key() == Qt::Key_Control || e->key() == Qt::Key_Shift || e->key() == Qt::Key_Meta)) 02281 qApp->beep(); 02282 #endif // Q_OS_WIN32 02283 } 02284 if (key_consumed) 02285 e->accept(); 02286 else 02287 e->ignore(); 02288 }
Here is the call graph for this function:

| void QMenu::mouseReleaseEvent | ( | QMouseEvent * | e | ) | [protected, virtual] |
Reimplemented from QWidget.
Definition at line 1804 of file qmenu.cpp.
References d, m, QAction::menu(), QMouseEvent::pos(), and QAction::Trigger.
01805 { 01806 Q_D(QMenu); 01807 if (d->mouseEventTaken(e)) 01808 return; 01809 01810 d->mouseDown = false; 01811 QAction *action = d->actionAt(e->pos()); 01812 for(QWidget *caused = this; caused;) { 01813 if (QMenu *m = qobject_cast<QMenu*>(caused)) { 01814 QAction *currentAction = d->currentAction; 01815 if(currentAction && (!currentAction->isEnabled() || currentAction->menu() || currentAction->isSeparator())) 01816 currentAction = 0; 01817 caused = m->d_func()->causedPopup.widget; 01818 if (m->d_func()->eventLoop) 01819 m->d_func()->syncAction = currentAction; // synchronous operation 01820 } else { 01821 break; 01822 } 01823 } 01824 if (action && action == d->currentAction) { 01825 if (action->menu()) 01826 action->menu()->d_func()->setFirstActionActive(); 01827 else 01828 d->activateAction(action, QAction::Trigger); 01829 } else if (d->motions > 6) { 01830 d->hideUpToMenuBar(); 01831 } 01832 }
Here is the call graph for this function:

| void QMenu::mousePressEvent | ( | QMouseEvent * | e | ) | [protected, virtual] |
Reimplemented from QWidget.
Definition at line 1780 of file qmenu.cpp.
References d, QMouseEvent::globalPos(), QMouseEvent::pos(), QWidget::rect(), QWidget::setAttribute(), QWidget::update(), and Qt::WA_NoMouseReplay.
01781 { 01782 Q_D(QMenu); 01783 if (d->mouseEventTaken(e)) 01784 return; 01785 if (!rect().contains(e->pos())) { 01786 if (d->noReplayFor 01787 && QRect(d->noReplayFor->mapToGlobal(QPoint()), d->noReplayFor->size()).contains(e->globalPos())) 01788 setAttribute(Qt::WA_NoMouseReplay); 01789 if (d->eventLoop) // synchronous operation 01790 d->syncAction = 0; 01791 d->hideUpToMenuBar(); 01792 return; 01793 } 01794 d->mouseDown = true; 01795 01796 QAction *action = d->actionAt(e->pos()); 01797 d->setCurrentAction(action, 20); 01798 update(); 01799 }
Here is the call graph for this function:

| void QMenu::mouseMoveEvent | ( | QMouseEvent * | e | ) | [protected, virtual] |
Reimplemented from QWidget.
Definition at line 2293 of file qmenu.cpp.
References QMouseEvent::buttons(), QRect::contains(), d, QWidget::isVisible(), Qt::LeftButton, QMouseEvent::pos(), QWidget::rect(), QStyle::SH_Menu_SubMenuPopupDelay, QMenuPrivate::sloppyDelayTimer, QBasicTimer::start(), QWidget::style(), and styleHint().
02294 { 02295 Q_D(QMenu); 02296 if (!isVisible() || d->mouseEventTaken(e)) 02297 return; 02298 d->motions++; 02299 if (d->motions == 0) // ignore first mouse move event (see enterEvent()) 02300 return; 02301 d->hasHadMouse |= rect().contains(e->pos()); 02302 02303 QAction *action = d->actionAt(e->pos()); 02304 if (!action) { 02305 if (d->hasHadMouse && !rect().contains(e->pos())) 02306 d->setCurrentAction(0); 02307 return; 02308 } else { 02309 d->mouseDown = e->buttons() & Qt::LeftButton; 02310 } 02311 if (d->sloppyRegion.contains(e->pos())) { 02312 d->sloppyAction = action; 02313 QMenuPrivate::sloppyDelayTimer.start(style()->styleHint(QStyle::SH_Menu_SubMenuPopupDelay, 0, this)*6, this); 02314 } else { 02315 d->setCurrentAction(action, style()->styleHint(QStyle::SH_Menu_SubMenuPopupDelay, 0, this)); 02316 } 02317 }
Here is the call graph for this function:

| void QMenu::wheelEvent | ( | QWheelEvent * | e | ) | [protected, virtual] |
Reimplemented from QWidget.
Definition at line 1768 of file qmenu.cpp.
References d, QWheelEvent::delta(), QWheelEvent::pos(), QWidget::rect(), QMenuPrivate::QMenuScroller::ScrollDown, and QMenuPrivate::QMenuScroller::ScrollUp.
01769 { 01770 Q_D(QMenu); 01771 if (d->scroll && rect().contains(e->pos())) 01772 d->scrollMenu(e->delta() > 0 ? 01773 QMenuPrivate::QMenuScroller::ScrollUp : QMenuPrivate::QMenuScroller::ScrollDown); 01774 }
Here is the call graph for this function:

| void QMenu::enterEvent | ( | QEvent * | ) | [protected, virtual] |
| void QMenu::leaveEvent | ( | QEvent * | ) | [protected, virtual] |
| void QMenu::hideEvent | ( | QHideEvent * | ) | [protected, virtual] |
Reimplemented from QWidget.
Definition at line 1647 of file qmenu.cpp.
References aboutToHide(), d, emit, QAccessible::PopupMenuEnd, and QAccessible::updateAccessibility().
01648 { 01649 Q_D(QMenu); 01650 emit aboutToHide(); 01651 if (d->eventLoop) 01652 d->eventLoop->exit(); 01653 d->setCurrentAction(0); 01654 #ifndef QT_NO_ACCESSIBILITY 01655 QAccessible::updateAccessibility(this, 0, QAccessible::PopupMenuEnd); 01656 #endif 01657 #ifndef QT_NO_MENUBAR 01658 if (QMenuBar *mb = qobject_cast<QMenuBar*>(d->causedPopup.widget)) 01659 mb->d_func()->setCurrentAction(0); 01660 #endif 01661 d->mouseDown = false; 01662 d->hasHadMouse = false; 01663 d->causedPopup.widget = 0; 01664 d->causedPopup.action = 0; 01665 }
Here is the call graph for this function:

| void QMenu::paintEvent | ( | QPaintEvent * | e | ) | [protected, virtual] |
Reimplemented from QWidget.
Definition at line 1670 of file qmenu.cpp.
References QStyle::CE_MenuEmptyArea, QStyle::CE_MenuItem, QStyle::CE_MenuScroller, QStyle::CE_MenuTearoff, QStyleOptionMenuItem::checkType, d, QStyle::drawControl(), QStyle::drawPrimitive(), QStyleOptionMenuItem::EmptyArea, QWidget::height(), i, QStyleOption::initFrom(), QRect::intersects(), QStyleOptionFrame::lineWidth, QStyleOptionMenuItem::maxIconWidth, QStyleOptionMenuItem::menuItemType, QStyleOptionMenuItem::menuRect, QStyleOptionFrame::midLineWidth, QStyleOptionMenuItem::NotCheckable, p, QWidget::palette(), QStyleOption::palette, QStyle::PE_FrameMenu, QStyle::pixelMetric(), QStyle::PM_MenuPanelWidth, QStyle::PM_MenuScrollerHeight, QStyle::PM_MenuTearoffHeight, QPaintEvent::rect(), QStyleOption::rect, QWidget::rect(), QMenuPrivate::QMenuScroller::ScrollDown, QStyleOptionMenuItem::Scroller, QMenuPrivate::QMenuScroller::ScrollUp, QRect::setRect(), QStyleOption::state, QStyle::State_DownArrow, QStyle::State_Enabled, QStyle::State_None, QStyle::State_Selected, QWidget::style(), QStyleOptionMenuItem::tabWidth, QStyleOptionMenuItem::TearOff, QRect::translate(), and QWidget::width().
Referenced by QDesignerMenu::paintEvent().
01671 { 01672 Q_D(QMenu); 01673 QPainter p(this); 01674 QRegion emptyArea = QRegion(rect()); 01675 01676 //draw the items that need updating.. 01677 for (int i = 0; i < d->actionList.count(); ++i) { 01678 QAction *action = d->actionList.at(i); 01679 QRect adjustedActionRect = d->actionRect(action); 01680 if (!e->rect().intersects(adjustedActionRect) 01681 || d->widgetItems.value(action)) 01682 continue; 01683 //set the clip region to be extra safe (and adjust for the scrollers) 01684 QRegion adjustedActionReg(adjustedActionRect); 01685 emptyArea -= adjustedActionReg; 01686 p.setClipRegion(adjustedActionReg); 01687 01688 QStyleOptionMenuItem opt = d->getStyleOption(action); 01689 opt.rect = adjustedActionRect; 01690 style()->drawControl(QStyle::CE_MenuItem, &opt, &p, this); 01691 } 01692 01693 const int fw = style()->pixelMetric(QStyle::PM_MenuPanelWidth, 0, this); 01694 QStyleOptionMenuItem menuOpt; 01695 menuOpt.initFrom(this); 01696 menuOpt.palette = palette(); 01697 menuOpt.state = QStyle::State_None; 01698 menuOpt.checkType = QStyleOptionMenuItem::NotCheckable; 01699 menuOpt.menuRect = rect(); 01700 menuOpt.maxIconWidth = 0; 01701 menuOpt.tabWidth = 0; 01702 //draw the scroller regions.. 01703 if (d->scroll) { 01704 const int scrollerHeight = style()->pixelMetric(QStyle::PM_MenuScrollerHeight, 0, this); 01705 menuOpt.menuItemType = QStyleOptionMenuItem::Scroller; 01706 menuOpt.state |= QStyle::State_Enabled; 01707 if (d->scroll->scrollFlags & QMenuPrivate::QMenuScroller::ScrollUp) { 01708 menuOpt.rect.setRect(fw, fw, width() - (fw * 2), scrollerHeight); 01709 emptyArea -= QRegion(menuOpt.rect); 01710 p.setClipRect(menuOpt.rect); 01711 style()->drawControl(QStyle::CE_MenuScroller, &menuOpt, &p, this); 01712 } 01713 if (d->scroll->scrollFlags & QMenuPrivate::QMenuScroller::ScrollDown) { 01714 menuOpt.rect.setRect(fw, height() - scrollerHeight - fw, width() - (fw * 2), 01715 scrollerHeight); 01716 emptyArea -= QRegion(menuOpt.rect); 01717 menuOpt.state |= QStyle::State_DownArrow; 01718 p.setClipRect(menuOpt.rect); 01719 style()->drawControl(QStyle::CE_MenuScroller, &menuOpt, &p, this); 01720 } 01721 } 01722 //paint the tear off.. 01723 if (d->tearoff) { 01724 menuOpt.menuItemType = QStyleOptionMenuItem::TearOff; 01725 menuOpt.rect.setRect(fw, fw, width() - (fw * 2), 01726 style()->pixelMetric(QStyle::PM_MenuTearoffHeight, 0, this)); 01727 if (d->scroll && d->scroll->scrollFlags & QMenuPrivate::QMenuScroller::ScrollUp) 01728 menuOpt.rect.translate(0, style()->pixelMetric(QStyle::PM_MenuScrollerHeight, 0, this)); 01729 emptyArea -= QRegion(menuOpt.rect); 01730 p.setClipRect(menuOpt.rect); 01731 menuOpt.state = QStyle::State_None; 01732 if (d->tearoffHighlighted) 01733 menuOpt.state |= QStyle::State_Selected; 01734 style()->drawControl(QStyle::CE_MenuTearoff, &menuOpt, &p, this); 01735 } 01736 //draw border 01737 if (fw) { 01738 QRegion borderReg; 01739 borderReg += QRect(0, 0, fw, height()); //left 01740 borderReg += QRect(width()-fw, 0, fw, height()); //right 01741 borderReg += QRect(0, 0, width(), fw); //top 01742 borderReg += QRect(0, height()-fw, width(), fw); //bottom 01743 p.setClipRegion(borderReg); 01744 emptyArea -= borderReg; 01745 QStyleOptionFrame frame; 01746 frame.rect = rect(); 01747 frame.palette = palette(); 01748 frame.state = QStyle::State_None; 01749 frame.lineWidth = style()->pixelMetric(QStyle::PM_MenuPanelWidth); 01750 frame.midLineWidth = 0; 01751 style()->drawPrimitive(QStyle::PE_FrameMenu, &frame, &p, this); 01752 } 01753 01754 //finally the rest of the space 01755 p.setClipRegion(emptyArea); 01756 menuOpt.state = QStyle::State_None; 01757 menuOpt.menuItemType = QStyleOptionMenuItem::EmptyArea; 01758 menuOpt.checkType = QStyleOptionMenuItem::NotCheckable; 01759 menuOpt.rect = rect(); 01760 menuOpt.menuRect = rect(); 01761 style()->drawControl(QStyle::CE_MenuEmptyArea, &menuOpt, &p, this); 01762 }
Here is the call graph for this function:

| void QMenu::actionEvent | ( | QActionEvent * | e | ) | [protected, virtual] |
Reimplemented from QWidget.
Definition at line 2363 of file qmenu.cpp.
References QActionEvent::action(), QEvent::ActionAdded, QEvent::ActionChanged, QEvent::ActionRemoved, QActionEvent::before(), QObject::connect(), d, QObject::disconnect(), hovered(), QWidget::isVisible(), QWidget::resize(), QWidget::setAttribute(), SIGNAL, sizeHint(), SLOT, triggered(), QEvent::type(), QWidget::update(), and Qt::WA_Resized.
Referenced by QDesignerMenu::actionEvent(), and QTornOffMenu::actionEvent().
02364 { 02365 Q_D(QMenu); 02366 d->itemsDirty = 1; 02367 setAttribute(Qt::WA_Resized, false); 02368 if (d->tornPopup) 02369 d->tornPopup->syncWithMenu(this, e); 02370 if (e->type() == QEvent::ActionAdded) { 02371 connect(e->action(), SIGNAL(triggered()), this, SLOT(_q_actionTriggered())); 02372 connect(e->action(), SIGNAL(hovered()), this, SLOT(_q_actionHovered())); 02373 02374 if (QWidgetAction *wa = qobject_cast<QWidgetAction *>(e->action())) { 02375 QWidget *widget = wa->requestWidget(this); 02376 if (widget) 02377 d->widgetItems.insert(wa, widget); 02378 } 02379 } else if (e->type() == QEvent::ActionRemoved) { 02380 d->actionRects.clear(); 02381 d->actionList.clear(); 02382 e->action()->disconnect(this); 02383 if (e->action() == d->currentAction) 02384 d->currentAction = 0; 02385 if (QWidgetAction *wa = qobject_cast<QWidgetAction *>(e->action())) { 02386 QWidget *widget = d->widgetItems.take(wa); 02387 if (widget) 02388 wa->releaseWidget(widget); 02389 } 02390 } 02391 02392 #ifdef Q_WS_MAC 02393 if (d->mac_menu) { 02394 if (e->type() == QEvent::ActionAdded) 02395 d->mac_menu->addAction(e->action(), d->mac_menu->findAction(e->before()), d); 02396 else if (e->type() == QEvent::ActionRemoved) 02397 d->mac_menu->removeAction(e->action()); 02398 else if (e->type() == QEvent::ActionChanged) 02399 d->mac_menu->syncAction(e->action()); 02400 } 02401 #endif 02402 02403 if (isVisible()) { 02404 d->updateActions(); 02405 resize(sizeHint()); 02406 update(); 02407 } 02408 }
Here is the call graph for this function:

| void QMenu::timerEvent | ( | QTimerEvent * | e | ) | [protected, virtual] |
Reimplemented from QObject.
Definition at line 2342 of file qmenu.cpp.
References d, internalDelayedPopup(), internalSetSloppyAction(), QMenuPrivate::menuDelayTimer, QMenuPrivate::QMenuScroller::ScrollNone, QMenuPrivate::sloppyDelayTimer, QTimerEvent::timerId(), and timerId.
02343 { 02344 Q_D(QMenu); 02345 if (d->scroll && d->scroll->scrollTimer && d->scroll->scrollTimer->timerId() == e->timerId()) { 02346 d->scrollMenu((QMenuPrivate::QMenuScroller::ScrollDirection)d->scroll->scrollDirection); 02347 if (d->scroll->scrollFlags == QMenuPrivate::QMenuScroller::ScrollNone) 02348 d->scroll->scrollTimer->stop(); 02349 } else if(QMenuPrivate::menuDelayTimer.timerId() == e->timerId()) { 02350 QMenuPrivate::menuDelayTimer.stop(); 02351 internalDelayedPopup(); 02352 } else if(QMenuPrivate::sloppyDelayTimer.timerId() == e->timerId()) { 02353 QMenuPrivate::sloppyDelayTimer.stop(); 02354 internalSetSloppyAction(); 02355 } else if(d->searchBufferTimer.timerId() == e->timerId()) { 02356 d->searchBuffer.clear(); 02357 } 02358 }
Here is the call graph for this function:

| bool QMenu::event | ( | QEvent * | e | ) | [protected, virtual] |
Reimplemented from QWidget.
Definition at line 1866 of file qmenu.cpp.
References d, QWidget::event(), Qt::Key_Backtab, Qt::Key_Tab, QEvent::KeyPress, keyPressEvent(), QEvent::QueryWhatsThis, QEvent::Resize, QEvent::setAccepted(), QEvent::Show, and QEvent::type().
Referenced by QDesignerMenu::actionEvent(), QDesignerMenu::dragEnterEvent(), QDesignerMenu::dragMoveEvent(), QDesignerMenu::dropEvent(), QDesignerMenu::eventFilter(), QDesignerMenu::handleContextMenuEvent(), QDesignerMenu::handleEvent(), QDesignerMenu::handleMouseDoubleClickEvent(), QDesignerMenu::handleMouseMoveEvent(), QDesignerMenu::handleMousePressEvent(), QDesignerMenu::handleMouseReleaseEvent(), QDesignerMenu::keyPressEvent(), QDesignerMenu::keyReleaseEvent(), and QDesignerMenu::paintEvent().
01867 { 01868 Q_D(QMenu); 01869 switch (e->type()) { 01870 case QEvent::KeyPress: { 01871 QKeyEvent *ke = (QKeyEvent*)e; 01872 if (ke->key() == Qt::Key_Tab || ke->key() == Qt::Key_Backtab) { 01873 keyPressEvent(ke); 01874 return true; 01875 } 01876 } break; 01877 case QEvent::Resize: 01878 d->itemsDirty = 1; 01879 d->updateActions(); 01880 break; 01881 case QEvent::Show: 01882 d->updateActions(); 01883 break; 01884 #ifndef QT_NO_WHATSTHIS 01885 case QEvent::QueryWhatsThis: 01886 e->setAccepted(d->whatsThis.size()); 01887 if (QAction *action = d->actionAt(static_cast<QHelpEvent*>(e)->pos())) { 01888 if (action->whatsThis().size() || action->menu()) 01889 e->accept(); 01890 } 01891 return true; 01892 #endif 01893 default: 01894 break; 01895 } 01896 return QWidget::event(e); 01897 }
Here is the call graph for this function:

| bool QMenu::focusNextPrevChild | ( | bool | next | ) | [protected, virtual] |
Reimplemented from QWidget.
Definition at line 1902 of file qmenu.cpp.
References Qt::Key_Backtab, Qt::Key_Tab, QEvent::KeyPress, keyPressEvent(), Qt::NoModifier, and QWidget::setFocus().
01903 { 01904 setFocus(); 01905 QKeyEvent ev(QEvent::KeyPress, next ? Qt::Key_Tab : Qt::Key_Backtab, Qt::NoModifier); 01906 keyPressEvent(&ev); 01907 return true; 01908 }
Here is the call graph for this function:

| void QMenu::internalSetSloppyAction | ( | ) | [private, slot] |
Definition at line 2413 of file qmenu.cpp.
Referenced by timerEvent().
02414 { 02415 if (d_func()->sloppyAction) 02416 d_func()->setCurrentAction(d_func()->sloppyAction, 0); 02417 }
| void QMenu::internalDelayedPopup | ( | ) | [private, slot] |
Definition at line 2422 of file qmenu.cpp.
References d, QApplication::desktop(), QWidget::geometry(), i, QWidget::isRightToLeft(), QWidget::mapFromGlobal(), QWidget::mapToGlobal(), QCursor::pos(), QWidget::pos(), right(), QDesktopWidget::screenNumber(), QStyle::SH_Menu_SloppySubMenus, QWidget::style(), styleHint(), QPoint::x(), QWidget::x(), and QPoint::y().
Referenced by timerEvent().
02423 { 02424 Q_D(QMenu); 02425 02426 //hide the current item 02427 if (QMenu *menu = d->activeMenu) { 02428 d->activeMenu = 0; 02429 menu->hide(); 02430 } 02431 02432 if (!d->currentAction || !d->currentAction->isEnabled() || !d->currentAction->menu() || 02433 !d->currentAction->menu()->isEnabled() || d->currentAction->menu()->isVisible()) 02434 return; 02435 02436 //setup 02437 d->activeMenu = d->currentAction->menu(); 02438 d->activeMenu->d_func()->causedPopup.widget = this; 02439 d->activeMenu->d_func()->causedPopup.action = d->currentAction; 02440 02441 const QRect actionRect(d->actionRect(d->currentAction)); 02442 const QSize menuSize(d->activeMenu->sizeHint()); 02443 const QPoint rightPos(mapToGlobal(QPoint(actionRect.right(), actionRect.top()))); 02444 const QPoint leftPos(mapToGlobal(QPoint(actionRect.left() - menuSize.width(), actionRect.top()))); 02445 02446 QPoint pos(rightPos); 02447 QMenu *caused = qobject_cast<QMenu*>(d->activeMenu->d_func()->causedPopup.widget); 02448 const QRect availGeometry(d->popupGeometry(QApplication::desktop()->screenNumber(caused))); 02449 if (isRightToLeft()) { 02450 pos = leftPos; 02451 if (caused && caused->x() < x() || pos.x() < availGeometry.left()) { 02452 if(rightPos.x() + menuSize.width() < availGeometry.right()) 02453 pos = rightPos; 02454 else 02455 pos.rx() = availGeometry.left(); 02456 } 02457 } else { 02458 if (caused && caused->x() > x() || pos.x() + menuSize.width() > availGeometry.right()) { 02459 if(leftPos.x() < availGeometry.left()) 02460 pos.rx() = availGeometry.right() - menuSize.width(); 02461 else 02462 pos = leftPos; 02463 } 02464 } 02465 02466 //calc sloppy focus buffer 02467 if (style()->styleHint(QStyle::SH_Menu_SloppySubMenus, 0, this)) { 02468 QPoint cur = QCursor::pos(); 02469 if (actionRect.contains(mapFromGlobal(cur))) { 02470 QPoint pts[4]; 02471 pts[0] = QPoint(cur.x(), cur.y() - 2); 02472 pts[3] = QPoint(cur.x(), cur.y() + 2); 02473 if (pos.x() >= cur.x()) { 02474 pts[1] = QPoint(geometry().right(), pos.y()); 02475 pts[2] = QPoint(geometry().right(), pos.y() + menuSize.height()); 02476 } else { 02477 pts[1] = QPoint(pos.x() + menuSize.width(), pos.y()); 02478 pts[2] = QPoint(pos.x() + menuSize.width(), pos.y() + menuSize.height()); 02479 } 02480 QPolygon points(4); 02481 for(int i = 0; i < 4; i++) 02482 points.setPoint(i, mapFromGlobal(pts[i])); 02483 d->sloppyRegion = QRegion(points); 02484 } 02485 } 02486 02487 //do the popup 02488 d->activeMenu->popup(pos); 02489 }
| QMenu::Q_PRIVATE_SLOT | ( | d_func() | , | |
| void | _q_actionTriggered() | |||
| ) | [private] |
Reimplemented from QWidget.
friend class QTornOffMenu [friend] |
friend class Q3PopupMenu [friend] |
void friend class ()) private QMenu::QMenuBarPrivate [private] |
1.5.1