Support more items for QTextCharFormat::VerticalAlignment enum for custom text objects.
* QTextCharFormat::AlignNormal - support text format descent, place text object bottom on (baseline - descent). * QTextCharFormat::AlignBottom - place text object bottom on baseline. * QTextCharFormat::AlignTop - Still not supported. * Any other vertical alignment is mapped QTextCharFormat::AlignBottom. Add new enum AlignBaseline for custom inline objects to take into account font baseline. Merge-request: 2578 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com> (cherry picked from commit ee9455ed2a83084692d969c398ecb91bcd4fc33a)
This commit is contained in:
parent
774527dd1e
commit
f26c4ba80d
@ -2996,10 +2996,19 @@ void QTextDocumentLayout::resizeInlineObject(QTextInlineObject item, int posInDo
|
|||||||
|
|
||||||
QSizeF inlineSize = (pos == QTextFrameFormat::InFlow ? intrinsic : QSizeF(0, 0));
|
QSizeF inlineSize = (pos == QTextFrameFormat::InFlow ? intrinsic : QSizeF(0, 0));
|
||||||
item.setWidth(inlineSize.width());
|
item.setWidth(inlineSize.width());
|
||||||
if (f.verticalAlignment() == QTextCharFormat::AlignMiddle) {
|
|
||||||
|
QFontMetrics m(f.font());
|
||||||
|
switch (f.verticalAlignment())
|
||||||
|
{
|
||||||
|
case QTextCharFormat::AlignMiddle:
|
||||||
item.setDescent(inlineSize.height() / 2);
|
item.setDescent(inlineSize.height() / 2);
|
||||||
item.setAscent(inlineSize.height() / 2 - 1);
|
item.setAscent(inlineSize.height() / 2 - 1);
|
||||||
} else {
|
break;
|
||||||
|
case QTextCharFormat::AlignBaseline:
|
||||||
|
item.setDescent(m.descent());
|
||||||
|
item.setAscent(inlineSize.height() - m.descent() - 1);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
item.setDescent(0);
|
item.setDescent(0);
|
||||||
item.setAscent(inlineSize.height() - 1);
|
item.setAscent(inlineSize.height() - 1);
|
||||||
}
|
}
|
||||||
|
@ -378,7 +378,8 @@ public:
|
|||||||
AlignSubScript,
|
AlignSubScript,
|
||||||
AlignMiddle,
|
AlignMiddle,
|
||||||
AlignTop,
|
AlignTop,
|
||||||
AlignBottom
|
AlignBottom,
|
||||||
|
AlignBaseline
|
||||||
};
|
};
|
||||||
enum UnderlineStyle { // keep in sync with Qt::PenStyle!
|
enum UnderlineStyle { // keep in sync with Qt::PenStyle!
|
||||||
NoUnderline,
|
NoUnderline,
|
||||||
|
Loading…
Reference in New Issue
Block a user