QTextLayout: Reconsider cursor drawing on TextObject
Revert:bb10e99a883bd3Revert:33238ea2c6These 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>
parent
df82396123
commit
de16300661
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue