summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@digia.com>2013-08-01 11:44:50 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-08-13 19:15:20 +0200
commitc4008e9f7e19cea0d36c979ea680a07486cc9184 (patch)
tree4819f88c2070a3f163710feead969cbb48d76f7d /src
parent3d0e27a2deb6ab9a0c68b19dbf3e41211967acd4 (diff)
Menus: add RTL support
Change-Id: I60f997e545076feb5b72fb9eb4a03b050db5f511 Reviewed-by: Caroline Chao <caroline.chao@digia.com> Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/controls/Button.qml5
-rw-r--r--src/controls/ComboBox.qml5
-rw-r--r--src/controls/Menu.qml8
-rw-r--r--src/controls/MenuBar.qml7
-rw-r--r--src/controls/qquickmenu.cpp5
-rw-r--r--src/controls/qquickmenupopupwindow.cpp8
-rw-r--r--src/controls/qquickmenupopupwindow_p.h1
-rw-r--r--src/styles/Base/MenuStyle.qml9
8 files changed, 38 insertions, 10 deletions
diff --git a/src/controls/Button.qml b/src/controls/Button.qml
index 0e51b7a29..028607722 100644
--- a/src/controls/Button.qml
+++ b/src/controls/Button.qml
@@ -114,7 +114,10 @@ BasicButton {
interval: 10
onTriggered: {
__behavior.keyPressed = false
- menu.__popup(0, button.height, 0)
+ if (Qt.application.layoutDirection === Qt.RightToLeft)
+ menu.__popup(button.width, button.height, 0)
+ else
+ menu.__popup(0, button.height, 0)
}
}
}
diff --git a/src/controls/ComboBox.qml b/src/controls/ComboBox.qml
index 76a8442a7..75af9844d 100644
--- a/src/controls/ComboBox.qml
+++ b/src/controls/ComboBox.qml
@@ -223,7 +223,10 @@ Control {
if (items[__selectedIndex])
items[__selectedIndex].checked = true
__currentIndex = comboBox.currentIndex
- __popup(0, y, isPopup ? __selectedIndex : 0)
+ if (Qt.application.layoutDirection === Qt.RightToLeft)
+ __popup(comboBox.width, y, isPopup ? __selectedIndex : 0)
+ else
+ __popup(0, y, isPopup ? __selectedIndex : 0)
}
}
diff --git a/src/controls/Menu.qml b/src/controls/Menu.qml
index e89099db4..61c9daa92 100644
--- a/src/controls/Menu.qml
+++ b/src/controls/Menu.qml
@@ -296,8 +296,12 @@ MenuPrivate {
function showSubMenu(immediately) {
if (immediately) {
- if (root.__currentIndex === menuItemIndex)
- menuItem.__popup(menuFrameLoader.subMenuXPos, 0, -1)
+ if (root.__currentIndex === menuItemIndex) {
+ if (Qt.application.layoutDirection === Qt.RightToLeft)
+ menuItem.__popup(0, 0, -1)
+ else
+ menuItem.__popup(menuFrameLoader.subMenuXPos, 0, -1)
+ }
} else {
openMenuTimer.start()
}
diff --git a/src/controls/MenuBar.qml b/src/controls/MenuBar.qml
index 65af1c124..ea8844a9a 100644
--- a/src/controls/MenuBar.qml
+++ b/src/controls/MenuBar.qml
@@ -167,6 +167,8 @@ MenuBarPrivate {
Row {
id: row
+ width: parent.width
+ LayoutMirroring.enabled: Qt.application.layoutDirection === Qt.RightToLeft
Repeater {
id: itemsRepeater
@@ -185,7 +187,10 @@ MenuBarPrivate {
target: menuBarLoader
onOpenedMenuIndexChanged: {
if (menuBarLoader.openedMenuIndex === index) {
- menuItem.__popup(0, menuBarLoader.height, 0)
+ if (row.LayoutMirroring.enabled)
+ menuItem.__popup(menuItemLoader.width, menuBarLoader.height, 0)
+ else
+ menuItem.__popup(0, menuBarLoader.height, 0)
if (menuBarLoader.preselectMenuItem)
menuItem.__currentIndex = 0
} else {
diff --git a/src/controls/qquickmenu.cpp b/src/controls/qquickmenu.cpp
index bb0ddae9a..01fd30be2 100644
--- a/src/controls/qquickmenu.cpp
+++ b/src/controls/qquickmenu.cpp
@@ -368,8 +368,11 @@ void QQuickMenu::__popup(qreal x, qreal y, int atItemIndex)
if (m_platformMenu) {
QPointF screenPosition(x + m_xOffset, y + m_yOffset);
- if (visualItem())
+ if (visualItem()) {
+ if (qGuiApp->isRightToLeft())
+ screenPosition.rx() -= qMax(static_cast<qreal>(m_minimumWidth), m_menuContentItem->width());
screenPosition = visualItem()->mapToScene(screenPosition);
+ }
m_platformMenu->showPopup(parentWindow, screenPosition.toPoint(), atItem ? atItem->platformItem() : 0);
} else {
m_popupWindow = new QQuickMenuPopupWindow();
diff --git a/src/controls/qquickmenupopupwindow.cpp b/src/controls/qquickmenupopupwindow.cpp
index b44b082cf..19d85de07 100644
--- a/src/controls/qquickmenupopupwindow.cpp
+++ b/src/controls/qquickmenupopupwindow.cpp
@@ -84,6 +84,8 @@ void QQuickMenuPopupWindow::show()
posy -= pos.y();
}
+ m_initialPos = QPointF(posx, posy);
+
if (m_menuContentItem) {
qreal initialWidth = qMax(qreal(1), m_menuContentItem->width());
qreal initialHeight = qMax(qreal(1), m_menuContentItem->height());
@@ -180,7 +182,11 @@ void QQuickMenuPopupWindow::dismissMenu()
void QQuickMenuPopupWindow::updateSize()
{
QSize contentSize = contentItem()->childrenRect().size().toSize();
- setGeometry(position().x(), position().y(), contentSize.width(), contentSize.height());
+ qreal x = m_initialPos.x();
+ qreal y = m_initialPos.y();
+ if (qGuiApp->layoutDirection() == Qt::RightToLeft)
+ x -= contentSize.width();
+ setGeometry(x, y, contentSize.width(), contentSize.height());
}
void QQuickMenuPopupWindow::updatePosition()
diff --git a/src/controls/qquickmenupopupwindow_p.h b/src/controls/qquickmenupopupwindow_p.h
index aead2bd8c..30a71fb20 100644
--- a/src/controls/qquickmenupopupwindow_p.h
+++ b/src/controls/qquickmenupopupwindow_p.h
@@ -90,6 +90,7 @@ private:
QPointF m_oldItemPos;
QQuickItem *m_parentItem;
QQuickItem *m_menuContentItem;
+ QPointF m_initialPos;
};
QT_END_NAMESPACE
diff --git a/src/styles/Base/MenuStyle.qml b/src/styles/Base/MenuStyle.qml
index ae8f6e757..4b2099f8e 100644
--- a/src/styles/Base/MenuStyle.qml
+++ b/src/styles/Base/MenuStyle.qml
@@ -91,10 +91,11 @@ Style {
}
readonly property string itemText: parent ? parent.text : ""
+ readonly property bool mirrored: Qt.application.layoutDirection === Qt.RightToLeft
Loader {
id: checkMark
- x: 4
+ x: mirrored ? parent.width - width - 4 : 4
y: 6
active: __menuItemType === "menuitem" && !!menuItem && !!menuItem["checkable"]
sourceComponent: exclusive ? exclusiveCheckMark : nonExclusiveCheckMark
@@ -162,7 +163,8 @@ Style {
id: text
visible: !isSeparator
text: StyleHelpers.stylizeMnemonics(itemText)
- x: __menuItemType === "menuitem" ? 24 : 6
+ readonly property real offset: __menuItemType === "menuitem" ? 24 : 6
+ x: mirrored ? parent.width - width - offset : offset
anchors.verticalCenter: parent.verticalCenter
renderType: Text.NativeRendering
color: selected && enabled ? "white" : syspal.text
@@ -172,8 +174,9 @@ Style {
id: rightDecoration
readonly property string shortcut: !!menuItem && menuItem["shortcut"] || ""
visible: isSubmenu || shortcut !== ""
- text: isSubmenu ? "\u25b8" // BLACK RIGHT-POINTING SMALL TRIANGLE
+ text: isSubmenu ? mirrored ? "\u25c2" : "\u25b8" // BLACK LEFT/RIGHT-POINTING SMALL TRIANGLE
: shortcut
+ LayoutMirroring.enabled: mirrored
anchors {
right: parent.right
rightMargin: 6