From efbae76afebaf80f85edf61047e87644f3557a3a Mon Sep 17 00:00:00 2001 From: Eugene Popov Date: Sat, 30 Mar 2024 12:21:58 +0000 Subject: [PATCH] Fix layout in Compact View mode for RTL This MR fixes the layout in Compact View mode when items are grouped. --- src/kitemviews/kitemlistgroupheader.cpp | 2 +- src/kitemviews/kitemlistview.cpp | 2 +- src/kitemviews/kstandarditemlistgroupheader.cpp | 3 ++- src/kitemviews/private/kitemlistviewlayouter.cpp | 14 ++++++++++---- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/kitemviews/kitemlistgroupheader.cpp b/src/kitemviews/kitemlistgroupheader.cpp index 0604f2da0..20cbc681f 100644 --- a/src/kitemviews/kitemlistgroupheader.cpp +++ b/src/kitemviews/kitemlistgroupheader.cpp @@ -190,7 +190,7 @@ void KItemListGroupHeader::updateSize() const int y = (m_scrollOrientation == Qt::Vertical) ? padding : horizontalMargin; - m_roleBounds = QRectF(horizontalMargin + padding, y, size().width() - 2 * padding - horizontalMargin, roleHeight); + m_roleBounds = QRectF(horizontalMargin + padding, y, size().width() - 2 * (padding + horizontalMargin), roleHeight); update(); } diff --git a/src/kitemviews/kitemlistview.cpp b/src/kitemviews/kitemlistview.cpp index e291ee5ec..afc392810 100644 --- a/src/kitemviews/kitemlistview.cpp +++ b/src/kitemviews/kitemlistview.cpp @@ -551,7 +551,7 @@ void KItemListView::scrollToItem(int index, ViewItemPosition viewItemPosition) QRectF currentRect = itemRect(index); if (layoutDirection() == Qt::RightToLeft && scrollOrientation() == Qt::Horizontal) { - currentRect.moveTo(m_layouter->size().width() - currentRect.right(), 0); + currentRect.moveLeft(m_layouter->size().width() - currentRect.right()); } // Fix for Bug 311099 - View the underscore when using Ctrl + PageDown diff --git a/src/kitemviews/kstandarditemlistgroupheader.cpp b/src/kitemviews/kstandarditemlistgroupheader.cpp index 00b255a9d..0960084a3 100644 --- a/src/kitemviews/kstandarditemlistgroupheader.cpp +++ b/src/kitemviews/kstandarditemlistgroupheader.cpp @@ -51,7 +51,8 @@ void KStandardItemListGroupHeader::paintSeparator(QPainter *painter, const QColo painter->setPen(color); if (scrollOrientation() == Qt::Horizontal) { - painter->drawLine(0, 0, 0, size().height() - 1); + const qreal x = layoutDirection() == Qt::RightToLeft ? size().width() - 1 : 0; + painter->drawLine(x, 0, x, size().height() - 1); } else { if (layoutDirection() == Qt::LeftToRight) { painter->drawLine(0, 0, size().width() - 1, 0); diff --git a/src/kitemviews/private/kitemlistviewlayouter.cpp b/src/kitemviews/private/kitemlistviewlayouter.cpp index a2d92f0de..99a95d98c 100644 --- a/src/kitemviews/private/kitemlistviewlayouter.cpp +++ b/src/kitemviews/private/kitemlistviewlayouter.cpp @@ -228,7 +228,7 @@ QRectF KItemListViewLayouter::itemRect(int index) const QPointF pos(y, x); sizeHint.transpose(); if (QGuiApplication::isRightToLeft()) { - pos.rx() = m_size.width() + m_scrollOffset - pos.x() - sizeHint.width(); + pos.rx() = m_size.width() - 1 + m_scrollOffset - pos.x() - sizeHint.width(); } else { pos.rx() -= m_scrollOffset; } @@ -260,7 +260,6 @@ QRectF KItemListViewLayouter::groupHeaderRect(int index) const pos.ry() -= m_groupHeaderHeight; size = QSizeF(m_size.width(), m_groupHeaderHeight); } else { - pos.rx() -= m_itemMargin.width(); pos.ry() = 0; // Determine the maximum width used in the current column. As the @@ -286,7 +285,14 @@ QRectF KItemListViewLayouter::groupHeaderRect(int index) const } size = QSizeF(headerWidth, m_size.height()); + + if (QGuiApplication::isRightToLeft()) { + pos.setX(firstItemRect.right() + m_itemMargin.width() - size.width()); + } else { + pos.rx() -= m_itemMargin.width(); + } } + return QRectF(pos, size); } @@ -402,7 +408,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 = isRightToLeft ? widthForColumns : m_xPosInc; + qreal currentOffset = isRightToLeft && !horizontalScrolling ? widthForColumns : m_xPosInc; if (grouped && horizontalScrolling) { // All group headers will always be aligned on the top and not @@ -413,7 +419,7 @@ void KItemListViewLayouter::doLayout() if (isRightToLeft) { for (int column = 0; column < m_columnCount; ++column) { if (horizontalScrolling) { - m_columnOffsets[column] = column * m_columnWidth; + m_columnOffsets[column] = currentOffset + column * m_columnWidth; } else { currentOffset -= m_columnWidth; m_columnOffsets[column] = currentOffset; -- 2.47.3