Ignore:
Timestamp:
May 5, 2011, 5:36:53 AM (14 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/gui/widgets/qmenu.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    8686QT_BEGIN_NAMESPACE
    8787
    88 QPointer<QMenu> QMenuPrivate::mouseDown;
    89 QBasicTimer QMenuPrivate::menuDelayTimer;
    90 QBasicTimer QMenuPrivate::sloppyDelayTimer;
     88QMenu *QMenuPrivate::mouseDown = 0;
     89int QMenuPrivate::sloppyDelayTimer = 0;
    9190
    9291/* QMenu code */
     
    264263    const int tearoffHeight = tearoff ? style->pixelMetric(QStyle::PM_MenuTearoffHeight, &opt, q) : 0;
    265264
    266     //for compatability now - will have to refactor this away..
     265    //for compatibility now - will have to refactor this away
    267266    tabWidth = 0;
    268267    maxIconWidth = 0;
     
    489488        if (!delay)
    490489            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);
    493492        if (activateFirst && action->menu())
    494493            action->menu()->d_func()->setFirstActionActive();
     
    545544    Q_Q(QMenu);
    546545    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     }
    556546    if (currentAction)
    557547        q->update(actionRect(currentAction));
     
    567557    emitHighlighted = action;
    568558#endif
     559
    569560    currentAction = action;
    570561    if (action) {
     
    11641155bool QMenuPrivate::hasMouseMoved(const QPoint &globalPos)
    11651156{
    1166     //determines if the mouse has moved (ie its intial position has
     1157    //determines if the mouse has moved (ie its initial position has
    11671158    //changed by more than QApplication::startDragDistance()
    11681159    //or if there were at least 6 mouse motions)
     
    13301321    addActions() and insertAction() functions.
    13311322
     1323    \warning To make QMenu visible on the screen, exec() or popup() should be
     1324    used instead of show().
     1325
    13321326    \section1 QMenu on Qt for Windows CE
    13331327
     
    18051799{
    18061800    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
    18081803        d->scroll->scrollOffset = 0;
    18091804        d->scroll->scrollFlags = QMenuPrivate::QMenuScroller::ScrollNone;
    18101805    }
     1806#endif
    18111807    d->tearoffHighlighted = 0;
    18121808    d->motions = 0;
     
    18341830    QRect screen;
    18351831#ifndef QT_NO_GRAPHICSVIEW
    1836     bool isEmbedded = d->nearestGraphicsProxyWidget(this);
     1832    bool isEmbedded = !bypassGraphicsProxyWidget(this) && d->nearestGraphicsProxyWidget(this);
    18371833    if (isEmbedded)
    18381834        screen = d->popupGeometry(this);
     
    18601856#endif
    18611857    if (d->ncols > 1) {
    1862         pos.setY(screen.top()+desktopFrame);
     1858        pos.setY(screen.top() + desktopFrame);
    18631859    } 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++) {
    18651861            QAction *action = d->actions.at(i);
    18661862            if (action == atAction) {
     
    18771873                    && !style()->styleHint(QStyle::SH_Menu_FillScreenWithScroll, 0, this)) {
    18781874                    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++)
    18801876                        below_height += d->actionRects.at(i2).height();
    18811877                    size.setHeight(below_height);
     
    18901886    QPoint mouse = QCursor::pos();
    18911887    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));
    18931889
    18941890    if (adjustToDesktop) {
    1895         //handle popup falling "off screen"
     1891        // handle popup falling "off screen"
    18961892        if (isRightToLeft()) {
    1897             if(snapToMouse) //position flowing left from the mouse
    1898                 pos.setX(mouse.x()-size.width());
     1893            if (snapToMouse) // position flowing left from the mouse
     1894                pos.setX(mouse.x() - size.width());
    18991895
    19001896#ifndef QT_NO_MENUBAR
    1901             //if in a menubar, it should be right-aligned
     1897            // if in a menubar, it should be right-aligned
    19021898            if (qobject_cast<QMenuBar*>(d->causedPopup.widget))
    19031899                pos.rx() -= size.width();
    19041900#endif //QT_NO_MENUBAR
    19051901
    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));
    19101906        } 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)
    19141910                pos.setX(screen.left() + desktopFrame);
    19151911        }
     
    19251921        if (pos.y() < screen.top() + desktopFrame)
    19261922            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) {
    19281924            if (d->scroll) {
    19291925                d->scroll->scrollFlags |= uint(QMenuPrivate::QMenuScroller::ScrollDown);
    19301926                int y = qMax(screen.y(),pos.y());
    1931                 size.setHeight(screen.bottom()-(desktopFrame*2)-y);
     1927                size.setHeight(screen.bottom() - (desktopFrame * 2) - y);
    19321928            } else {
    19331929                // 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);
    19351931            }
    19361932        }
     
    19411937    int vGuess = QEffects::DownScroll;
    19421938    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()))
    19451941            hGuess = QEffects::RightScroll;
    19461942    } 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()))
    19491945            hGuess = QEffects::LeftScroll;
    19501946    }
    19511947
    19521948#ifndef QT_NO_MENUBAR
    1953     if ((snapToMouse && (pos.y() + size.height()/2 < mouse.y())) ||
     1949    if ((snapToMouse && (pos.y() + size.height() / 2 < mouse.y())) ||
    19541950       (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()))
    19561952       vGuess = QEffects::UpScroll;
    19571953#endif
     
    23032299
    23042300    if (action && action == d->currentAction) {
    2305         if (action->menu())
    2306             action->menu()->d_func()->setFirstActionActive();
    2307         else {
     2301        if (!action->menu()){
    23082302#if defined(Q_WS_WIN)
    23092303            //On Windows only context menus can be activated with the right button
     
    23792373    } break;
    23802374    case QEvent::ContextMenu:
    2381         if(QMenuPrivate::menuDelayTimer.isActive()) {
    2382             QMenuPrivate::menuDelayTimer.stop();
     2375        if(d->menuDelayTimer.isActive()) {
     2376            d->menuDelayTimer.stop();
    23832377            internalDelayedPopup();
    23842378        }
     
    28152809    if (d->sloppyRegion.contains(e->pos())) {
    28162810        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);
    28182812    } else {
    28192813        d->setCurrentAction(action, style()->styleHint(QStyle::SH_Menu_SubMenuPopupDelay, 0, this));
     
    28532847        if (d->scroll->scrollFlags == QMenuPrivate::QMenuScroller::ScrollNone)
    28542848            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();
    28572851        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;
    28602855        internalSetSloppyAction();
    28612856    } else if(d->searchBufferTimer.timerId() == e->timerId()) {
Note: See TracChangeset for help on using the changeset viewer.