While using right-to-left languages most of Dolphin is mirrored.
However, the logic of what happens when the arrow keys are pressed to
move between items in the main view was never adapted to account for
that. Basically nothing works as expected because of this. It's more
like dealing with a psychopath who misinterprets every command you give:
Left is right, right is left, up is most of the time right but sometimes
not, down is most the time left but sometimes not.
This commit fixes and adapts the logic if a right-to-left layout is used.
This fully fixes icon view mode and improves compact view mode, though
compact view mode still has more issues which aren't addressed here.
This work for the benefit of the minority that use right-to-left
languages both in Europe and the world is sponsored by NLnet and the
European Commission which I think is beautfiul.
BUG: 453933
+ // For right to left languages, exchange right and left arrow keys.
+ if (m_view->layoutDirection() == Qt::RightToLeft) {
+ switch (key) {
+ case Qt::Key_Left:
+ key = Qt::Key_Right;
+ break;
+ case Qt::Key_Right:
+ key = Qt::Key_Left;
+ break;
+ default:
+ break;
+ }
+ }
+
const bool selectSingleItem = m_selectionBehavior != NoSelection && itemCount == 1 && navigationPressed;
if (selectSingleItem) {
const bool selectSingleItem = m_selectionBehavior != NoSelection && itemCount == 1 && navigationPressed;
if (selectSingleItem) {
+ const bool leftToRight = m_view->layoutDirection() != Qt::RightToLeft;
+
// Calculate the index of the last column inside the row of the current index
int lastColumnIndex = index;
// Calculate the index of the last column inside the row of the current index
int lastColumnIndex = index;
- while (keyboardAnchorPos(lastColumnIndex + 1) > keyboardAnchorPos(lastColumnIndex)) {
+ while ((leftToRight && keyboardAnchorPos(lastColumnIndex + 1) > keyboardAnchorPos(lastColumnIndex))
+ || (!leftToRight && keyboardAnchorPos(lastColumnIndex + 1) < keyboardAnchorPos(lastColumnIndex))) {
++lastColumnIndex;
if (lastColumnIndex >= maxIndex) {
return index;
++lastColumnIndex;
if (lastColumnIndex >= maxIndex) {
return index;
int nextRowIndex = lastColumnIndex + 1;
int searchIndex = nextRowIndex;
qreal minDiff = qAbs(m_keyboardAnchorPos - keyboardAnchorPos(nextRowIndex));
int nextRowIndex = lastColumnIndex + 1;
int searchIndex = nextRowIndex;
qreal minDiff = qAbs(m_keyboardAnchorPos - keyboardAnchorPos(nextRowIndex));
- while (searchIndex < maxIndex && keyboardAnchorPos(searchIndex + 1) > keyboardAnchorPos(searchIndex)) {
+ while (searchIndex < maxIndex
+ && ((leftToRight && keyboardAnchorPos(searchIndex + 1) > keyboardAnchorPos(searchIndex))
+ || (!leftToRight && keyboardAnchorPos(searchIndex + 1) < keyboardAnchorPos(searchIndex)))) {
++searchIndex;
const qreal searchDiff = qAbs(m_keyboardAnchorPos - keyboardAnchorPos(searchIndex));
if (searchDiff < minDiff) {
++searchIndex;
const qreal searchDiff = qAbs(m_keyboardAnchorPos - keyboardAnchorPos(searchIndex));
if (searchDiff < minDiff) {
+ const bool leftToRight = m_view->layoutDirection() != Qt::RightToLeft;
+
// Calculate the index of the first column inside the row of the current index
int firstColumnIndex = index;
// Calculate the index of the first column inside the row of the current index
int firstColumnIndex = index;
- while (keyboardAnchorPos(firstColumnIndex - 1) < keyboardAnchorPos(firstColumnIndex)) {
+ while ((leftToRight && keyboardAnchorPos(firstColumnIndex - 1) < keyboardAnchorPos(firstColumnIndex))
+ || (!leftToRight && keyboardAnchorPos(firstColumnIndex - 1) > keyboardAnchorPos(firstColumnIndex))) {
--firstColumnIndex;
if (firstColumnIndex <= 0) {
return index;
--firstColumnIndex;
if (firstColumnIndex <= 0) {
return index;
int previousRowIndex = firstColumnIndex - 1;
int searchIndex = previousRowIndex;
qreal minDiff = qAbs(m_keyboardAnchorPos - keyboardAnchorPos(previousRowIndex));
int previousRowIndex = firstColumnIndex - 1;
int searchIndex = previousRowIndex;
qreal minDiff = qAbs(m_keyboardAnchorPos - keyboardAnchorPos(previousRowIndex));
- while (searchIndex > 0 && keyboardAnchorPos(searchIndex - 1) < keyboardAnchorPos(searchIndex)) {
+ while (searchIndex > 0
+ && ((leftToRight && keyboardAnchorPos(searchIndex - 1) < keyboardAnchorPos(searchIndex))
+ || (!leftToRight && keyboardAnchorPos(searchIndex - 1) > keyboardAnchorPos(searchIndex)))) {
--searchIndex;
const qreal searchDiff = qAbs(m_keyboardAnchorPos - keyboardAnchorPos(searchIndex));
if (searchDiff < minDiff) {
--searchIndex;
const qreal searchDiff = qAbs(m_keyboardAnchorPos - keyboardAnchorPos(searchIndex));
if (searchDiff < minDiff) {