summaryrefslogtreecommitdiffstats
path: root/src/gui/text/qtextlayout.cpp
diff options
context:
space:
mode:
authorTang Haixiang <tanghaixiang@uniontech.com>2022-10-14 10:42:07 +0800
committerShawn Rutledge <shawn.rutledge@qt.io>2022-11-11 07:41:39 +0100
commitde16300661bc498eb02d8d5b36ccc07ebe595ca2 (patch)
tree13dc0b3c0ee34569c31e50d9fabc4a20aa9c00de /src/gui/text/qtextlayout.cpp
parentdf82396123350b67c4696673eea09d3cec995ae9 (diff)
QTextLayout: Reconsider cursor drawing on TextObject
Revert: e99a883bd382ca950192bd66cafb2a1de6394ce7 Revert: 33238ea2c63b372ee8795eaafbfc5a859a778f8d These two commits made the drawing of the cursor incomprehensible, but their purpose was to fix the problem of abnormal cursor drawing when QScriptAnalysis::Object is present. Because objects require some special handling, they can be specially aligned or floated. Anyway, the alignment is already reflected by ascent and descent, and when drawing, y = position.y() + (sl.y + sl.base() - base).toReal(); works fine. So roll them back now. We just need to specially consider the case where the QScriptItem is a QScriptAnalysis::Object, keeping the base and descent the same as the row. Task-number: QTBUG-92468 Task-number: QTBUG-86823 Task-number: QTBUG-96288 Pick-to: 6.2 6.4 Change-Id: I6d9a0e00fbc3823e0cc8e0e8bd061da5782d1f8a Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'src/gui/text/qtextlayout.cpp')
-rw-r--r--src/gui/text/qtextlayout.cpp20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp
index 14cd773834..e4281b78e6 100644
--- a/src/gui/text/qtextlayout.cpp
+++ b/src/gui/text/qtextlayout.cpp
@@ -1303,7 +1303,6 @@ void QTextLayout::drawCursor(QPainter *p, const QPointF &pos, int cursorPosition
QFixed base = sl.base();
QFixed descent = sl.descent;
- QFixed cursorDescent = descent;
bool rightToLeft = d->isRightToLeft();
const int realCursorPosition = cursorPosition;
@@ -1332,15 +1331,16 @@ void QTextLayout::drawCursor(QPainter *p, const QPointF &pos, int cursorPosition
si = &d->layoutData->items[itm];
}
}
- if (si->ascent >= 0)
- base = si->ascent;
- if (si->descent == 0)
- descent = si->descent;
- else if (si->descent > 0 && si->descent < descent)
- cursorDescent = si->descent;
+ // objects need some special treatment as they can have special alignment or be floating
+ if (si->analysis.flags != QScriptAnalysis::Object) {
+ if (si->ascent > 0)
+ base = si->ascent;
+ if (si->descent > 0)
+ descent = si->descent;
+ }
rightToLeft = si->analysis.bidiLevel % 2;
}
- qreal y = position.y() + (sl.y + sl.base() + sl.descent - base - descent).toReal();
+ qreal y = position.y() + (sl.y + sl.base() - base).toReal();
bool toggleAntialiasing = !(p->renderHints() & QPainter::Antialiasing)
&& (p->transform().type() > QTransform::TxTranslate);
if (toggleAntialiasing)
@@ -1351,7 +1351,7 @@ void QTextLayout::drawCursor(QPainter *p, const QPointF &pos, int cursorPosition
const QTransform &deviceTransform = p->deviceTransform();
const qreal xScale = deviceTransform.m11();
if (deviceTransform.type() != QTransform::TxScale || std::trunc(xScale) == xScale) {
- p->fillRect(QRectF(x, y, qreal(width), (base + cursorDescent).toReal()), p->pen().brush());
+ p->fillRect(QRectF(x, y, qreal(width), (base + descent).toReal()), p->pen().brush());
} else {
// Ensure consistently rendered cursor width under fractional scaling
const QPen origPen = p->pen();
@@ -1359,7 +1359,7 @@ void QTextLayout::drawCursor(QPainter *p, const QPointF &pos, int cursorPosition
pen.setCosmetic(true);
const qreal center = x + qreal(width) / 2;
p->setPen(pen);
- p->drawLine(QPointF(center, y), QPointF(center, y + (base + cursorDescent).toReal()));
+ p->drawLine(QPointF(center, y), QPointF(center, y + (base + descent).toReal()));
p->setPen(origPen);
}
p->setCompositionMode(origCompositionMode);