From 952635dabe24acf3d222acad3f959c9d33b760aa Mon Sep 17 00:00:00 2001 From: Oliver Eftevaag Date: Fri, 9 Jul 2021 13:26:31 +0200 Subject: [PATCH] Fix QTextFormat::FullWidthSelection for right-to-left text layouts Using the QTextFormat::FullWidthSelection property to select a line would previously not take into account right-to-left text layouts. With this patch, the whole line should now be drawn correctly for both left-to-right, and right-to-left layouts. Fixes: QTBUG-91125 Change-Id: Ide7b340cd7b4060e7c00e55e0011a86ffdfb5eb4 Done-with: Volker Hilsheimer Reviewed-by: Dmitry Shachnev Reviewed-by: Volker Hilsheimer (cherry picked from commit a7894855f2f59028bea9cd1aef07ec1e2c713c90) Reviewed-by: Qt Cherry-pick Bot --- src/gui/text/qtextlayout.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp index b6338516266..35513741b9c 100644 --- a/src/gui/text/qtextlayout.cpp +++ b/src/gui/text/qtextlayout.cpp @@ -1143,10 +1143,17 @@ void QTextLayout::draw(QPainter *p, const QPointF &pos, const QList QRectF fullLineRect(tl.rect()); fullLineRect.translate(position); fullLineRect.setRight(QFIXED_MAX); - if (!selectionEndInLine) - region.addRect(clipIfValid(QRectF(lineRect.topRight(), fullLineRect.bottomRight()), clip)); - if (!selectionStartInLine) - region.addRect(clipIfValid(QRectF(fullLineRect.topLeft(), lineRect.bottomLeft()), clip)); + + const bool rightToLeft = d->isRightToLeft(); + + if (!selectionEndInLine) { + region.addRect(clipIfValid(rightToLeft ? QRectF(fullLineRect.topLeft(), lineRect.bottomLeft()) + : QRectF(lineRect.topRight(), fullLineRect.bottomRight()), clip)); + } + if (!selectionStartInLine) { + region.addRect(clipIfValid(rightToLeft ? QRectF(lineRect.topRight(), fullLineRect.bottomRight()) + : QRectF(fullLineRect.topLeft(), lineRect.bottomLeft()), clip)); + } } else if (!selectionEndInLine && isLastLineInBlock &&!(d->option.flags() & QTextOption::ShowLineAndParagraphSeparators)) {