2014-01-29 05:50:19 +05:30
|
|
|
#include "Common.h"
|
|
|
|
|
|
|
|
// Origin: Qt
|
2022-07-15 06:53:41 +05:30
|
|
|
// More specifically, this is a trimmed down version on the algorithm in:
|
|
|
|
// https://code.woboq.org/qt5/qtbase/src/widgets/styles/qcommonstyle.cpp.html#846
|
|
|
|
QList<std::pair<qreal, QString>> viewItemTextLayout(QTextLayout& textLayout, int lineWidth, qreal& height)
|
2014-01-29 05:50:19 +05:30
|
|
|
{
|
2022-07-15 06:53:41 +05:30
|
|
|
QList<std::pair<qreal, QString>> lines;
|
2018-07-15 18:21:05 +05:30
|
|
|
height = 0;
|
2022-07-15 06:53:41 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
textLayout.beginLayout();
|
2022-07-15 06:53:41 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
QString str = textLayout.text();
|
2022-07-15 06:53:41 +05:30
|
|
|
while (true) {
|
2018-07-15 18:21:05 +05:30
|
|
|
QTextLine line = textLayout.createLine();
|
2022-07-15 06:53:41 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
if (!line.isValid())
|
|
|
|
break;
|
|
|
|
if (line.textLength() == 0)
|
|
|
|
break;
|
2022-07-15 06:53:41 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
line.setLineWidth(lineWidth);
|
|
|
|
line.setPosition(QPointF(0, height));
|
2022-07-15 06:53:41 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
height += line.height();
|
2022-07-15 06:53:41 +05:30
|
|
|
|
|
|
|
lines.append(std::make_pair(line.naturalTextWidth(), str.mid(line.textStart(), line.textLength())));
|
2018-07-15 18:21:05 +05:30
|
|
|
}
|
2022-07-15 06:53:41 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
textLayout.endLayout();
|
2022-07-15 06:53:41 +05:30
|
|
|
|
2018-07-15 18:21:05 +05:30
|
|
|
return lines;
|
2014-01-29 05:50:19 +05:30
|
|
|
}
|