Changeset 846 for trunk/src/gui/widgets/qmenu.cpp
- Timestamp:
- May 5, 2011, 5:36:53 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.7.2 (added) merged: 845 /branches/vendor/nokia/qt/current merged: 844 /branches/vendor/nokia/qt/4.6.3 removed
- Property svn:mergeinfo changed
-
trunk/src/gui/widgets/qmenu.cpp
r769 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation (qt-info@nokia.com) … … 86 86 QT_BEGIN_NAMESPACE 87 87 88 QPointer<QMenu> QMenuPrivate::mouseDown; 89 QBasicTimer QMenuPrivate::menuDelayTimer; 90 QBasicTimer QMenuPrivate::sloppyDelayTimer; 88 QMenu *QMenuPrivate::mouseDown = 0; 89 int QMenuPrivate::sloppyDelayTimer = 0; 91 90 92 91 /* QMenu code */ … … 264 263 const int tearoffHeight = tearoff ? style->pixelMetric(QStyle::PM_MenuTearoffHeight, &opt, q) : 0; 265 264 266 //for compat ability now - will have to refactor this away..265 //for compatibility now - will have to refactor this away 267 266 tabWidth = 0; 268 267 maxIconWidth = 0; … … 489 488 if (!delay) 490 489 q->internalDelayedPopup(); 491 else 492 QMenuPrivate::menuDelayTimer.start(delay, q);490 else if (!menuDelayTimer.isActive() && (!action->menu() || !action->menu()->isVisible())) 491 menuDelayTimer.start(delay, q); 493 492 if (activateFirst && action->menu()) 494 493 action->menu()->d_func()->setFirstActionActive(); … … 545 544 Q_Q(QMenu); 546 545 tearoffHighlighted = 0; 547 if (action == currentAction) {548 if (!action || !action->menu() || action->menu() == activeMenu) {549 if(QMenu *menu = qobject_cast<QMenu*>(causedPopup.widget)) {550 if(causedPopup.action && menu->d_func()->activeMenu == q)551 menu->d_func()->setCurrentAction(causedPopup.action, 0, reason, false);552 }553 }554 return;555 }556 546 if (currentAction) 557 547 q->update(actionRect(currentAction)); … … 567 557 emitHighlighted = action; 568 558 #endif 559 569 560 currentAction = action; 570 561 if (action) { … … 1164 1155 bool QMenuPrivate::hasMouseMoved(const QPoint &globalPos) 1165 1156 { 1166 //determines if the mouse has moved (ie its in tial position has1157 //determines if the mouse has moved (ie its initial position has 1167 1158 //changed by more than QApplication::startDragDistance() 1168 1159 //or if there were at least 6 mouse motions) … … 1330 1321 addActions() and insertAction() functions. 1331 1322 1323 \warning To make QMenu visible on the screen, exec() or popup() should be 1324 used instead of show(). 1325 1332 1326 \section1 QMenu on Qt for Windows CE 1333 1327 … … 1805 1799 { 1806 1800 Q_D(QMenu); 1807 if (d->scroll) { //reset scroll state from last popup 1801 #ifndef Q_OS_SYMBIAN 1802 if (d->scroll) { // reset scroll state from last popup 1808 1803 d->scroll->scrollOffset = 0; 1809 1804 d->scroll->scrollFlags = QMenuPrivate::QMenuScroller::ScrollNone; 1810 1805 } 1806 #endif 1811 1807 d->tearoffHighlighted = 0; 1812 1808 d->motions = 0; … … 1834 1830 QRect screen; 1835 1831 #ifndef QT_NO_GRAPHICSVIEW 1836 bool isEmbedded = d->nearestGraphicsProxyWidget(this);1832 bool isEmbedded = !bypassGraphicsProxyWidget(this) && d->nearestGraphicsProxyWidget(this); 1837 1833 if (isEmbedded) 1838 1834 screen = d->popupGeometry(this); … … 1860 1856 #endif 1861 1857 if (d->ncols > 1) { 1862 pos.setY(screen.top() +desktopFrame);1858 pos.setY(screen.top() + desktopFrame); 1863 1859 } else if (atAction) { 1864 for (int i = 0, above_height = 0; i < d->actions.count(); i++) {1860 for (int i = 0, above_height = 0; i < d->actions.count(); i++) { 1865 1861 QAction *action = d->actions.at(i); 1866 1862 if (action == atAction) { … … 1877 1873 && !style()->styleHint(QStyle::SH_Menu_FillScreenWithScroll, 0, this)) { 1878 1874 int below_height = above_height + d->scroll->scrollOffset; 1879 for (int i2 = i; i2 < d->actionRects.count(); i2++)1875 for (int i2 = i; i2 < d->actionRects.count(); i2++) 1880 1876 below_height += d->actionRects.at(i2).height(); 1881 1877 size.setHeight(below_height); … … 1890 1886 QPoint mouse = QCursor::pos(); 1891 1887 d->mousePopupPos = mouse; 1892 const bool snapToMouse = (QRect(p.x() -3, p.y()-3, 6, 6).contains(mouse));1888 const bool snapToMouse = (QRect(p.x() - 3, p.y() - 3, 6, 6).contains(mouse)); 1893 1889 1894 1890 if (adjustToDesktop) { 1895 // handle popup falling "off screen"1891 // handle popup falling "off screen" 1896 1892 if (isRightToLeft()) { 1897 if (snapToMouse) //position flowing left from the mouse1898 pos.setX(mouse.x() -size.width());1893 if (snapToMouse) // position flowing left from the mouse 1894 pos.setX(mouse.x() - size.width()); 1899 1895 1900 1896 #ifndef QT_NO_MENUBAR 1901 // if in a menubar, it should be right-aligned1897 // if in a menubar, it should be right-aligned 1902 1898 if (qobject_cast<QMenuBar*>(d->causedPopup.widget)) 1903 1899 pos.rx() -= size.width(); 1904 1900 #endif //QT_NO_MENUBAR 1905 1901 1906 if (pos.x() < screen.left() +desktopFrame)1907 pos.setX(qMax(p.x(), screen.left() +desktopFrame));1908 if (pos.x() +size.width()-1 > screen.right()-desktopFrame)1909 pos.setX(qMax(p.x() -size.width(), screen.right()-desktopFrame-size.width()+1));1902 if (pos.x() < screen.left() + desktopFrame) 1903 pos.setX(qMax(p.x(), screen.left() + desktopFrame)); 1904 if (pos.x() + size.width() - 1 > screen.right() - desktopFrame) 1905 pos.setX(qMax(p.x() - size.width(), screen.right() - desktopFrame - size.width() + 1)); 1910 1906 } else { 1911 if (pos.x() +size.width()-1 > screen.right()-desktopFrame)1912 pos.setX(screen.right() -desktopFrame-size.width()+1);1913 if (pos.x() < screen.left() +desktopFrame)1907 if (pos.x() + size.width() - 1 > screen.right() - desktopFrame) 1908 pos.setX(screen.right() - desktopFrame - size.width() + 1); 1909 if (pos.x() < screen.left() + desktopFrame) 1914 1910 pos.setX(screen.left() + desktopFrame); 1915 1911 } … … 1925 1921 if (pos.y() < screen.top() + desktopFrame) 1926 1922 pos.setY(screen.top() + desktopFrame); 1927 if (pos.y() +size.height()-1 > screen.bottom() - desktopFrame) {1923 if (pos.y() + size.height() - 1 > screen.bottom() - desktopFrame) { 1928 1924 if (d->scroll) { 1929 1925 d->scroll->scrollFlags |= uint(QMenuPrivate::QMenuScroller::ScrollDown); 1930 1926 int y = qMax(screen.y(),pos.y()); 1931 size.setHeight(screen.bottom() -(desktopFrame*2)-y);1927 size.setHeight(screen.bottom() - (desktopFrame * 2) - y); 1932 1928 } else { 1933 1929 // Too big for screen, bias to see bottom of menu (for some reason) 1934 pos.setY(screen.bottom() -size.height()+1);1930 pos.setY(screen.bottom() - size.height() + 1); 1935 1931 } 1936 1932 } … … 1941 1937 int vGuess = QEffects::DownScroll; 1942 1938 if (isRightToLeft()) { 1943 if ((snapToMouse && (pos.x() + size.width() /2 > mouse.x())) ||1944 (qobject_cast<QMenu*>(d->causedPopup.widget) && pos.x() + size.width() /2 > d->causedPopup.widget->x()))1939 if ((snapToMouse && (pos.x() + size.width() / 2 > mouse.x())) || 1940 (qobject_cast<QMenu*>(d->causedPopup.widget) && pos.x() + size.width() / 2 > d->causedPopup.widget->x())) 1945 1941 hGuess = QEffects::RightScroll; 1946 1942 } else { 1947 if ((snapToMouse && (pos.x() + size.width() /2 < mouse.x())) ||1948 (qobject_cast<QMenu*>(d->causedPopup.widget) && pos.x() + size.width() /2 < d->causedPopup.widget->x()))1943 if ((snapToMouse && (pos.x() + size.width() / 2 < mouse.x())) || 1944 (qobject_cast<QMenu*>(d->causedPopup.widget) && pos.x() + size.width() / 2 < d->causedPopup.widget->x())) 1949 1945 hGuess = QEffects::LeftScroll; 1950 1946 } 1951 1947 1952 1948 #ifndef QT_NO_MENUBAR 1953 if ((snapToMouse && (pos.y() + size.height() /2 < mouse.y())) ||1949 if ((snapToMouse && (pos.y() + size.height() / 2 < mouse.y())) || 1954 1950 (qobject_cast<QMenuBar*>(d->causedPopup.widget) && 1955 pos.y() + size.width() /2 < d->causedPopup.widget->mapToGlobal(d->causedPopup.widget->pos()).y()))1951 pos.y() + size.width() / 2 < d->causedPopup.widget->mapToGlobal(d->causedPopup.widget->pos()).y())) 1956 1952 vGuess = QEffects::UpScroll; 1957 1953 #endif … … 2303 2299 2304 2300 if (action && action == d->currentAction) { 2305 if (action->menu()) 2306 action->menu()->d_func()->setFirstActionActive(); 2307 else { 2301 if (!action->menu()){ 2308 2302 #if defined(Q_WS_WIN) 2309 2303 //On Windows only context menus can be activated with the right button … … 2379 2373 } break; 2380 2374 case QEvent::ContextMenu: 2381 if( QMenuPrivate::menuDelayTimer.isActive()) {2382 QMenuPrivate::menuDelayTimer.stop();2375 if(d->menuDelayTimer.isActive()) { 2376 d->menuDelayTimer.stop(); 2383 2377 internalDelayedPopup(); 2384 2378 } … … 2815 2809 if (d->sloppyRegion.contains(e->pos())) { 2816 2810 d->sloppyAction = action; 2817 QMenuPrivate::sloppyDelayTimer .start(style()->styleHint(QStyle::SH_Menu_SubMenuPopupDelay, 0, this)*6, this);2811 QMenuPrivate::sloppyDelayTimer = startTimer(style()->styleHint(QStyle::SH_Menu_SubMenuPopupDelay, 0, this)*6); 2818 2812 } else { 2819 2813 d->setCurrentAction(action, style()->styleHint(QStyle::SH_Menu_SubMenuPopupDelay, 0, this)); … … 2853 2847 if (d->scroll->scrollFlags == QMenuPrivate::QMenuScroller::ScrollNone) 2854 2848 d->scroll->scrollTimer.stop(); 2855 } else if( QMenuPrivate::menuDelayTimer.timerId() == e->timerId()) {2856 QMenuPrivate::menuDelayTimer.stop();2849 } else if(d->menuDelayTimer.timerId() == e->timerId()) { 2850 d->menuDelayTimer.stop(); 2857 2851 internalDelayedPopup(); 2858 } else if(QMenuPrivate::sloppyDelayTimer.timerId() == e->timerId()) { 2859 QMenuPrivate::sloppyDelayTimer.stop(); 2852 } else if(QMenuPrivate::sloppyDelayTimer == e->timerId()) { 2853 killTimer(QMenuPrivate::sloppyDelayTimer); 2854 QMenuPrivate::sloppyDelayTimer = 0; 2860 2855 internalSetSloppyAction(); 2861 2856 } else if(d->searchBufferTimer.timerId() == e->timerId()) {
Note:
See TracChangeset
for help on using the changeset viewer.