┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/kitemviews/private/kitemlistviewlayouter.cpp
diff options
context:
space:
mode:
authorEugene Popov <[email protected]>2024-03-27 10:28:15 +0000
committerMéven Car <[email protected]>2024-03-27 10:28:15 +0000
commit240d33ce17fc531e8bc6638af8f71454fe7c05e6 (patch)
tree11eea661f23034830e9358df1ced907b95b9f0a7 /src/kitemviews/private/kitemlistviewlayouter.cpp
parent7a7cab61b6fd8d058ca47887f90fa5cd12a3ccca (diff)
Better support for RTL
This MR fixes some issues related to RTL scripts: - wrong layout in Compact View mode - broken horizontal scrolling in Icon View and Details View modes - broken navigation with left and right arrow keys in Details View mode BUG: 484012 BUG: 449493
Diffstat (limited to 'src/kitemviews/private/kitemlistviewlayouter.cpp')
-rw-r--r--src/kitemviews/private/kitemlistviewlayouter.cpp30
1 files changed, 20 insertions, 10 deletions
diff --git a/src/kitemviews/private/kitemlistviewlayouter.cpp b/src/kitemviews/private/kitemlistviewlayouter.cpp
index 5b0df0bd0..a2d92f0de 100644
--- a/src/kitemviews/private/kitemlistviewlayouter.cpp
+++ b/src/kitemviews/private/kitemlistviewlayouter.cpp
@@ -226,8 +226,12 @@ QRectF KItemListViewLayouter::itemRect(int index) const
// Rotate the logical direction which is always vertical by 90°
// to get the physical horizontal direction
QPointF pos(y, x);
- pos.rx() -= m_scrollOffset;
sizeHint.transpose();
+ if (QGuiApplication::isRightToLeft()) {
+ pos.rx() = m_size.width() + m_scrollOffset - pos.x() - sizeHint.width();
+ } else {
+ pos.rx() -= m_scrollOffset;
+ }
return QRectF(pos, sizeHint);
}
@@ -361,7 +365,7 @@ void KItemListViewLayouter::doLayout()
const bool grouped = createGroupHeaders();
- const bool horizontalScrolling = (m_scrollOrientation == Qt::Horizontal);
+ const bool horizontalScrolling = m_scrollOrientation == Qt::Horizontal;
if (horizontalScrolling) {
// Flip everything so that the layout logically can work like having
// a vertical scrolling
@@ -377,8 +381,9 @@ void KItemListViewLayouter::doLayout()
}
}
+ const bool isRightToLeft = QGuiApplication::isRightToLeft();
m_columnWidth = itemSize.width() + itemMargin.width();
- const qreal widthForColumns = size.width() - itemMargin.width();
+ const qreal widthForColumns = std::max(size.width() - itemMargin.width(), m_columnWidth);
m_columnCount = qMax(1, int(widthForColumns / m_columnWidth));
m_xPosInc = itemMargin.width();
@@ -397,7 +402,7 @@ void KItemListViewLayouter::doLayout()
// Calculate the offset of each column, i.e., the x-coordinate where the column starts.
m_columnOffsets.resize(m_columnCount);
- qreal currentOffset = QGuiApplication::isRightToLeft() ? widthForColumns : m_xPosInc;
+ qreal currentOffset = isRightToLeft ? widthForColumns : m_xPosInc;
if (grouped && horizontalScrolling) {
// All group headers will always be aligned on the top and not
@@ -405,16 +410,21 @@ void KItemListViewLayouter::doLayout()
currentOffset += m_groupHeaderHeight;
}
- if (QGuiApplication::isLeftToRight())
+ if (isRightToLeft) {
for (int column = 0; column < m_columnCount; ++column) {
- m_columnOffsets[column] = currentOffset;
- currentOffset += m_columnWidth;
+ if (horizontalScrolling) {
+ m_columnOffsets[column] = column * m_columnWidth;
+ } else {
+ currentOffset -= m_columnWidth;
+ m_columnOffsets[column] = currentOffset;
+ }
}
- else
+ } else {
for (int column = 0; column < m_columnCount; ++column) {
- m_columnOffsets[column] = currentOffset - m_columnWidth;
- currentOffset -= m_columnWidth;
+ m_columnOffsets[column] = currentOffset;
+ currentOffset += m_columnWidth;
}
+ }
// Prepare the QVector which stores the y-coordinate for each new row.
int numberOfRows = (itemCount + m_columnCount - 1) / m_columnCount;