11using namespace Qt::StringLiterals;
14 : pr(printer), nextRule(
NoRule), page(0)
17 QFont f(QStringList{u"Arial"_s});
23 fmetrics =
new QFontMetrics(p.fontMetrics());
24 hmargin = 5 * printer->width() / printer->widthMM();
25 vmargin = 5 * printer->height() / printer->heightMM();
26 hsize = printer->width() - 2 * hmargin;
27 vsize = printer->height() - vmargin;
28 dateTime = QDateTime::currentDateTime();
30 cp = Paragraph(QPoint(hmargin, voffset));
59 if (voffset + cp.rect.height() > vsize)
61 else if (!firstParagraph)
64 for (
int i = 0; i < cp.boxes.size(); ++i) {
66 b.rect.translate(0, voffset);
69 p.drawText(r, b.text, b.options);
71 voffset += cp.rect.height();
74 cp = Paragraph(QPoint(hmargin, voffset));
75 firstParagraph =
false;
81 options.setAlignment(halign | Qt::AlignTop);
82 options.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
88 int wd = hsize * percent / 100;
89 QRect r(cp.rect.x() + cp.rect.width(), 0, wd, vsize);
90 const int ht =
static_cast<
int>(p.boundingRect(r, text, options).height());
92 Box b(r, text, f, options);
94 cp.rect.setSize(QSize(cp.rect.width() + wd, qMax(cp.rect.height(), ht)));
100 static const int LeftAlign = Qt::AlignLeft | Qt::AlignTop;
101 static const int RightAlign = Qt::AlignRight | Qt::AlignTop;
115 r1 = QRect(hmargin, voffset, 3 * hsize / 4, vsize);
116 r2 = QRect(r1.x() + r1.width(), voffset, hsize - r1.width(), vsize);
117 h1 = p.boundingRect(r1, LeftAlign, pr->docName()).height();
119 p.drawText(r1, LeftAlign, pr->docName());
120 h2 = p.boundingRect(r2, RightAlign, QString::number(page)).height();
122 p.drawText(r2, RightAlign, QString::number(page));
123 voffset += qMax(h1, h2 );
125 r1 = QRect(hmargin, voffset, hsize / 2, LeftAlign);
127 h1 = p.boundingRect(r1, LeftAlign, dateTime.toString()).height();
129 p.drawText(r1, LeftAlign, dateTime.toString());
131 voffset += qMax(h1, h2);
135 p.drawLine(QPoint(hmargin, voffset), QPoint(hmargin + hsize, voffset));
138 firstParagraph =
true;
156 pen.setColor(QColor(192, 192, 192));
157 pen.setStyle(Qt::DotLine);
161 p.drawLine(QPoint(hmargin, voffset),
162 QPoint(hmargin + hsize, voffset));
168 p.drawLine(QPoint(hmargin, voffset),
169 QPoint(hmargin + hsize, voffset));
void setGuide(const QString &guide)
void addBox(int percent, const QString &text=QString(), Style style=Normal, Qt::Alignment halign=Qt::AlignLeft)
PrintOut(QPrinter *printer)
void flushLine(bool mayBreak=false)
Combined button and popup list for selecting options.