| 5 | #include <QFontMetrics> |
| 6 | |
| 7 | int WizDrawTextSingleLine(QPainter* p, const QRect& rc, QString& str, int flags, QColor color, bool elidedText) |
| 8 | { |
| 9 | if (rc.width() <= 0) |
| 10 | return 0; |
| 11 | |
| 12 | if (str.isEmpty()) |
| 13 | return 0; |
| 14 | |
| 15 | p->setPen(color); |
| 16 | |
| 17 | if (elidedText) { |
| 18 | CString strRet = p->fontMetrics().elidedText(str, Qt::ElideRight, rc.width()); |
| 19 | p->drawText(rc, flags, strRet); |
| 20 | return p->fontMetrics().width(strRet); |
| 21 | } else { |
| 22 | QTextLayout textLayout(str, p->font()); |
| 23 | textLayout.beginLayout(); |
| 24 | |
| 25 | int width = 0; |
| 26 | QTextLine line = textLayout.createLine(); |
| 27 | if (line.isValid()) |
| 28 | { |
| 29 | line.setLineWidth(rc.width()); |
| 30 | |
| 31 | CString lineText = str.left(line.textLength()); |
| 32 | str.remove(0, line.textLength()); |
| 33 | p->drawText(rc, flags, lineText); |
| 34 | width = line.width(); |
| 35 | } |
| 36 | |
| 37 | textLayout.endLayout(); |
| 38 | return width; |
| 39 | } |
| 40 | } |