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_menubar.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**
     
    105105
    106106    setAcceptDrops(true); // ### fake
     107
     108
    107109
    108110    m_addMenu->setText(tr("Type Here"));
     
    220222        case Qt::Key_Left:
    221223            e->accept();
    222             if (QApplication::layoutDirection() == Qt::LeftToRight)
    223                 moveLeft(e->modifiers() & Qt::ControlModifier);
    224             else
    225                 moveRight(e->modifiers() & Qt::ControlModifier);
     224            moveLeft(e->modifiers() & Qt::ControlModifier);
    226225            return true;
    227226
    228227        case Qt::Key_Right:
    229228            e->accept();
    230             if (QApplication::layoutDirection() == Qt::LeftToRight)
    231                 moveRight(e->modifiers() & Qt::ControlModifier);
    232             else
    233                 moveLeft(e->modifiers() & Qt::ControlModifier);
     229            moveRight(e->modifiers() & Qt::ControlModifier);
    234230            return true; // no update
    235231
     
    754750}
    755751
     752
     753
     754
     755
     756
    756757void QDesignerMenuBar::moveLeft(bool ctrl)
    757758{
    758     if (ctrl)
    759         (void) swap(m_currentIndex, m_currentIndex - 1);
    760 
    761     m_currentIndex = qMax(0, --m_currentIndex);
     759    if (layoutDirection() == Qt::LeftToRight) {
     760        movePrevious(ctrl);
     761    } else {
     762        moveNext(ctrl);
     763    }
     764}
     765
     766void QDesignerMenuBar::moveRight(bool ctrl)
     767{
     768    if (layoutDirection() == Qt::LeftToRight) {
     769        moveNext(ctrl);
     770    } else {
     771        movePrevious(ctrl);
     772    }
     773}
     774
     775void QDesignerMenuBar::movePrevious(bool ctrl)
     776{
     777    const bool swapped = ctrl && swapActions(m_currentIndex, m_currentIndex - 1);
     778    const int newIndex = qMax(0, m_currentIndex - 1);
    762779    // Always re-select, swapping destroys order
    763     updateCurrentAction(true);
    764 }
    765 
    766 bool QDesignerMenuBar::dragging() const
    767 {
    768     return m_dragging;
    769 }
    770 
    771 void QDesignerMenuBar::moveRight(bool ctrl)
    772 {
    773     if (ctrl)
    774         (void) swap(m_currentIndex + 1, m_currentIndex);
    775 
    776     m_currentIndex = qMin(actions().count() - 1, ++m_currentIndex);
    777     updateCurrentAction(!ctrl);
     780    if (swapped || newIndex != m_currentIndex) {
     781        m_currentIndex = newIndex;
     782        updateCurrentAction(true);
     783    }
     784}
     785
     786void QDesignerMenuBar::moveNext(bool ctrl)
     787{
     788    const bool swapped = ctrl && swapActions(m_currentIndex + 1, m_currentIndex);
     789    const int newIndex = qMin(actions().count() - 1, m_currentIndex + 1);
     790    if (swapped || newIndex != m_currentIndex) {
     791        m_currentIndex = newIndex;
     792        updateCurrentAction(!ctrl);
     793    }
    778794}
    779795
     
    864880                menu->setWindowFlags(Qt::Popup);
    865881            menu->adjustSize();
    866             menu->move(mapToGlobal(g.bottomLeft()));
     882            if (layoutDirection() == Qt::LeftToRight) {
     883                menu->move(mapToGlobal(g.bottomLeft()));
     884            } else {
     885                // The position is not initially correct due to the unknown width,
     886                // causing it to overlap a bit the first time it is invoked.
     887                const QSize menuSize = menu->size();
     888                QPoint point = g.bottomRight() - QPoint(menu->width(), 0);
     889                menu->move(mapToGlobal(point));
     890            }
    867891            menu->setFocus(Qt::MouseFocusReason);
    868892            menu->raise();
     
    882906}
    883907
    884 bool QDesignerMenuBar::swap(int a, int b)
     908bool QDesignerMenuBar::swap(int a, int b)
    885909{
    886910    const int left = qMin(a, b);
Note: See TracChangeset for help on using the changeset viewer.