diff options
author | Friedemann Kleint <Friedemann.Kleint@nokia.com> | 2009-08-06 14:19:18 (GMT) |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@nokia.com> | 2009-08-06 14:19:18 (GMT) |
commit | af44be42cfacb85ef783cdd051f5d106d25c6b50 (patch) | |
tree | af5c1fa48b837eab8636b734b70e1c8b97bf8d51 /tools/designer/src/lib/shared/qdesigner_menubar.cpp | |
parent | 443a7b6f3eb1191b20240b5068da386d669045fc (diff) | |
download | Qt-af44be42cfacb85ef783cdd051f5d106d25c6b50.zip Qt-af44be42cfacb85ef783cdd051f5d106d25c6b50.tar.gz Qt-af44be42cfacb85ef783cdd051f5d106d25c6b50.tar.bz2 |
Designer: Cannot edit menus in an RTL form when Designer uses LTR.
Use widget->layoutDirection() instead of QApplication::layoutDirection()
where applicable, which caused it to break for the case that Designer's
layoutDirection does not match that of a widget [property].
In addition, position the submenu correctly on the left side in the case
of RTL.
Reviewed-by: Jarek Kobus <jkobus@trolltech.com>
Task-number: 259238
Diffstat (limited to 'tools/designer/src/lib/shared/qdesigner_menubar.cpp')
-rw-r--r-- | tools/designer/src/lib/shared/qdesigner_menubar.cpp | 58 |
1 files changed, 36 insertions, 22 deletions
diff --git a/tools/designer/src/lib/shared/qdesigner_menubar.cpp b/tools/designer/src/lib/shared/qdesigner_menubar.cpp index b53bb8d..2b19142 100644 --- a/tools/designer/src/lib/shared/qdesigner_menubar.cpp +++ b/tools/designer/src/lib/shared/qdesigner_menubar.cpp @@ -219,18 +219,12 @@ bool QDesignerMenuBar::handleKeyPressEvent(QWidget *, QKeyEvent *e) case Qt::Key_Left: e->accept(); - if (QApplication::layoutDirection() == Qt::LeftToRight) - moveLeft(e->modifiers() & Qt::ControlModifier); - else - moveRight(e->modifiers() & Qt::ControlModifier); + moveLeft(e->modifiers() & Qt::ControlModifier); return true; case Qt::Key_Right: e->accept(); - if (QApplication::layoutDirection() == Qt::LeftToRight) - moveRight(e->modifiers() & Qt::ControlModifier); - else - moveLeft(e->modifiers() & Qt::ControlModifier); + moveRight(e->modifiers() & Qt::ControlModifier); return true; // no update case Qt::Key_Up: @@ -741,28 +735,48 @@ int QDesignerMenuBar::realActionCount() const return actions().count() - 1; // 1 fake actions } -void QDesignerMenuBar::moveLeft(bool ctrl) +bool QDesignerMenuBar::dragging() const { - if (ctrl) - (void) swap(m_currentIndex, m_currentIndex - 1); - - m_currentIndex = qMax(0, --m_currentIndex); - // Always re-select, swapping destroys order - updateCurrentAction(true); + return m_dragging; } -bool QDesignerMenuBar::dragging() const +void QDesignerMenuBar::moveLeft(bool ctrl) { - return m_dragging; + if (layoutDirection() == Qt::LeftToRight) { + movePrevious(ctrl); + } else { + moveNext(ctrl); + } } void QDesignerMenuBar::moveRight(bool ctrl) { - if (ctrl) - (void) swap(m_currentIndex + 1, m_currentIndex); + if (layoutDirection() == Qt::LeftToRight) { + moveNext(ctrl); + } else { + movePrevious(ctrl); + } +} + +void QDesignerMenuBar::movePrevious(bool ctrl) +{ + const bool swapped = ctrl && swapActions(m_currentIndex, m_currentIndex - 1); + const int newIndex = qMax(0, m_currentIndex - 1); + // Always re-select, swapping destroys order + if (swapped || newIndex != m_currentIndex) { + m_currentIndex = newIndex; + updateCurrentAction(true); + } +} - m_currentIndex = qMin(actions().count() - 1, ++m_currentIndex); - updateCurrentAction(!ctrl); +void QDesignerMenuBar::moveNext(bool ctrl) +{ + const bool swapped = ctrl && swapActions(m_currentIndex + 1, m_currentIndex); + const int newIndex = qMin(actions().count() - 1, m_currentIndex + 1); + if (swapped || newIndex != m_currentIndex) { + m_currentIndex = newIndex; + updateCurrentAction(!ctrl); + } } void QDesignerMenuBar::moveUp() @@ -869,7 +883,7 @@ QAction *QDesignerMenuBar::safeActionAt(int index) const return actions().at(index); } -bool QDesignerMenuBar::swap(int a, int b) +bool QDesignerMenuBar::swapActions(int a, int b) { const int left = qMin(a, b); int right = qMax(a, b); |