MCPcopy Create free account
hub / github.com/altairwei/WizNotePlus / WizDrawTextSingleLine

Function WizDrawTextSingleLine

src/share/WizDrawTextHelper.cpp:7–40  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5#include <QFontMetrics>
6
7int 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}

Callers 2

drawExtraBadgeMethod · 0.85

Calls 5

widthMethod · 0.80
isEmptyMethod · 0.80
drawTextMethod · 0.80
fontMethod · 0.80
removeMethod · 0.45

Tested by 1