Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/tools/designer/src/lib/shared/qdesigner_menu.cpp

    r372 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information ([email protected])
     4** All rights reserved.
     5** Contact: Nokia Corporation ([email protected])
    56**
    67** This file is part of the Qt Designer of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    23 ** In addition, as a special exception, Nokia gives you certain
    24 ** additional rights. These rights are described in the Nokia Qt LGPL
    25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
    26 ** package.
     24** In addition, as a special exception, Nokia gives you certain additional
     25** rights.  These rights are described in the Nokia Qt LGPL Exception
     26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you
     37** @nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    7373
    7474using namespace qdesigner_internal;
     75
     76
     77
     78
     79
     80
     81
     82
     83
     84
     85
     86
     87
    7588
    7689QDesignerMenu::QDesignerMenu(QWidget *parent) :
     
    332345    if (action->menu() || hasSubMenuPixmap(action)) {
    333346        pm_rect = subMenuPixmapRect(action);
    334         pm_rect.setLeft(pm_rect.left() - 20); // give the user a little more
    335                                               // space to click
     347        extendClickableArea(&pm_rect, layoutDirection());
    336348    }
    337349
     
    388400    QAction *action = safeActionAt(index);
    389401    QRect pm_rect = subMenuPixmapRect(action);
    390     pm_rect.setLeft(pm_rect.left() - 20); // give the user a little more space to click
     402   
    391403
    392404    const int old_index = m_currentIndex;
     
    547559    static const QPixmap pm(QLatin1String(":/trolltech/formeditor/images/submenu.png"));
    548560    const QRect g = actionGeometry(action);
    549     const int x = g.right() - pm.width() - 2;
     561    const int x = 2;
    550562    const int y = g.top() + (g.height() - pm.height())/2 + 1;
    551563    return QRect(x, y, pm.width(), pm.height());
     
    876888}
    877889
    878 void QDesignerMenu::moveLeft()
     890// Close submenu using the left/right keys according to layoutDirection().
     891// Return false to indicate the event must be propagated to the menu bar.
     892bool QDesignerMenu::hideSubMenuOnCursorKey()
    879893{
    880894    if (parentMenu()) {
    881895        hide();
    882     } else {
     896        return true;
     897    }
     898    closeMenuChain();
     899    update();
     900    if (parentMenuBar())
     901        return false;
     902    return true;
     903}
     904
     905// Open a submenu using the left/right keys according to layoutDirection().
     906// Return false to indicate the event must be propagated to the menu bar.
     907bool QDesignerMenu::showSubMenuOnCursorKey()
     908{
     909    const QAction *action = currentAction();
     910
     911    if (qobject_cast<const SpecialMenuAction*>(action) || action->isSeparator()) {
    883912        closeMenuChain();
    884         if (QDesignerMenuBar *mb = parentMenuBar()) {
    885             if (QApplication::layoutDirection() == Qt::LeftToRight)
    886                 mb->moveLeft();
    887             else
    888                 mb->moveRight();
    889         }
    890     }
    891     update();
     913        if (parentMenuBar())
     914            return false;
     915        return true;
     916    }
     917    m_lastSubMenuIndex = -1; // force a refresh
     918    slotShowSubMenuNow();
     919    return true;
     920}
     921
     922void QDesignerMenu::moveLeft()
     923{
     924    const bool handled = layoutDirection() == Qt::LeftToRight ?
     925                         hideSubMenuOnCursorKey() : showSubMenuOnCursorKey();
     926    if (!handled)
     927        parentMenuBar()->moveLeft();
    892928}
    893929
    894930void QDesignerMenu::moveRight()
    895931{
    896     QAction *action = currentAction();
    897 
    898     if (qobject_cast<SpecialMenuAction*>(action) || action->isSeparator()) {
    899         closeMenuChain();
    900         if (QDesignerMenuBar *mb = parentMenuBar()) {
    901             if (QApplication::layoutDirection() == Qt::LeftToRight)
    902                 mb->moveRight();
    903             else
    904                 mb->moveLeft();
    905         }
    906     } else {
    907         m_lastSubMenuIndex = -1; // force a refresh
    908         slotShowSubMenuNow();
    909     }
     932    const bool handled = layoutDirection() == Qt::LeftToRight ?
     933                         showSubMenuOnCursorKey() : hideSubMenuOnCursorKey();
     934    if (!handled)
     935        parentMenuBar()->moveRight();
    910936}
    911937
     
    10661092                menu->setWindowFlags(Qt::Popup);
    10671093            const QRect g = actionGeometry(action);
    1068             menu->move(mapToGlobal(g.topRight()));
     1094            if (layoutDirection() == Qt::LeftToRight) {
     1095                menu->move(mapToGlobal(g.topRight()));
     1096            } else {
     1097                // The position is not initially correct due to the unknown width,
     1098                // causing it to overlap a bit the first time it is invoked.
     1099                const QSize menuSize = menu->size();
     1100                QPoint point = g.topLeft() - QPoint(menu->width() + 10, 0);
     1101                menu->move(mapToGlobal(point));
     1102            }
    10691103            menu->show();
    10701104            menu->setFocus();
Note: See TracChangeset for help on using the changeset viewer.