void Page::drawHeaderFooter(QPainter* p, int area, const QString& ss) const { QString s = replaceTextMacros(ss); if (s.isEmpty()) return; Text text(score()); text.setTextStyleType(area < 3 ? TextStyleType::HEADER : TextStyleType::FOOTER); text.setParent(const_cast<Page*>(this)); text.setLayoutToParentWidth(true); Align flags; switch (area) { case 0: flags = AlignmentFlags::LEFT | AlignmentFlags::TOP; break; case 1: flags = AlignmentFlags::HCENTER | AlignmentFlags::TOP; break; case 2: flags = AlignmentFlags::RIGHT | AlignmentFlags::TOP; break; case 3: flags = AlignmentFlags::LEFT | AlignmentFlags::BOTTOM; break; case 4: flags = AlignmentFlags::HCENTER | AlignmentFlags::BOTTOM; break; case 5: flags = AlignmentFlags::RIGHT | AlignmentFlags::BOTTOM; break; } text.textStyle().setAlign(flags); text.setXmlText(s); text.layout(); p->translate(text.pos()); text.draw(p); p->translate(-text.pos()); }
void Page::drawHeaderFooter(QPainter* p, int area, const QString& ss) const { QString s = replaceTextMacros(ss); if (s.isEmpty()) return; Text* text; if (area < 3) { text = score()->headerText(); if (!text) { text = new Text(score(), Tid::HEADER); text->setLayoutToParentWidth(true); score()->setHeaderText(text); } } else { text = score()->footerText(); if (!text) { text = new Text(score(), Tid::FOOTER); text->setLayoutToParentWidth(true); score()->setFooterText(text); } } text->setParent((Page*)this); Align flags = Align::LEFT; switch (area) { case 0: flags = Align::LEFT | Align::TOP; break; case 1: flags = Align::HCENTER | Align::TOP; break; case 2: flags = Align::RIGHT | Align::TOP; break; case 3: flags = Align::LEFT | Align::BOTTOM; break; case 4: flags = Align::HCENTER | Align::BOTTOM; break; case 5: flags = Align::RIGHT | Align::BOTTOM; break; } text->setAlign(flags); text->setXmlText(s); text->layout(); p->translate(text->pos()); text->draw(p); p->translate(-text->pos()); text->setParent(0); }
void Page::drawStyledHeaderFooter(QPainter* p, int area, const QPointF& pt, const QString& ss) const { QString s = replaceTextMacros(ss); if (s.isEmpty()) return; int textStyle = TEXT_STYLE_FOOTER; int flags = Qt::TextDontClip; switch(area) { case 0: flags |= Qt::AlignLeft | Qt::AlignTop; textStyle = TEXT_STYLE_HEADER; break; case 1: flags |= Qt::AlignHCenter | Qt::AlignTop; textStyle = TEXT_STYLE_HEADER; break; case 2: flags |= Qt::AlignRight | Qt::AlignTop; textStyle = TEXT_STYLE_HEADER; break; case 3: flags |= Qt::AlignLeft | Qt::AlignBottom; break; case 4: flags |= Qt::AlignHCenter | Qt::AlignBottom; break; case 5: flags |= Qt::AlignRight | Qt::AlignBottom; break; } TextStyle ts = score()->textStyle(textStyle); p->setFont(ts.fontPx(spatium())); QRectF r(pt.x(), pt.y(), width() - lm() - rm(), height() - tm() - bm()); p->drawText(r, flags, s); }
void Page::draw(QPainter* painter) const { if (score()->layoutMode() != LayoutPage) return; // // draw header/footer // QTextDocument d; d.setDocumentMargin(0.0); d.setUseDesignMetrics(true); int n = no() + 1 + _score->pageNumberOffset(); d.setTextWidth(score()->loWidth() - lm() - rm()); QPointF o1(lm(), tm()); painter->translate(o1); painter->setPen(curColor()); QString s1, s2, s3; if (_score->styleB(ST_showHeader) && (no() || _score->styleB(ST_headerFirstPage))) { TextStyle ts = score()->textStyle(TEXT_STYLE_HEADER); QPointF o(ts.offset(spatium())); bool odd = (n & 1) || !_score->styleB(ST_headerOddEven); if (odd) { o.setX(-o.x()); s1 = _score->styleSt(ST_oddHeaderL); s2 = _score->styleSt(ST_oddHeaderC); s3 = _score->styleSt(ST_oddHeaderR); } else { s1 = _score->styleSt(ST_evenHeaderL); s2 = _score->styleSt(ST_evenHeaderC); s3 = _score->styleSt(ST_evenHeaderR); } if (_score->styleB(ST_headerStyled)) { drawStyledHeaderFooter(painter, 0, o, s1); drawStyledHeaderFooter(painter, 1, o, s2); drawStyledHeaderFooter(painter, 2, o, s3); } else { d.setDefaultFont(ts.font(1.0)); d.setTextWidth(_score->loWidth() - lm() - rm() - (2.0 * o.x())); QAbstractTextDocumentLayout::PaintContext c; c.cursorPosition = -1; c.palette.setColor(QPalette::Text, ts.foregroundColor()); painter->translate(o); QString s = _score->styleSt(odd ? ST_oddHeaderL : ST_evenHeaderL); if (!s.isEmpty()) { d.setHtml(replaceTextMacros(s)); d.documentLayout()->draw(painter, c); } s = replaceTextMacros(_score->styleSt(odd ? ST_oddHeaderC : ST_evenHeaderC)); if (!s.isEmpty()) { d.setHtml(s); d.documentLayout()->draw(painter, c); } s = replaceTextMacros(_score->styleSt(odd ? ST_oddHeaderR : ST_evenHeaderR)); if (!s.isEmpty()) { d.setHtml(s); d.documentLayout()->draw(painter, c); } painter->translate(-o); } } if (_score->styleB(ST_showFooter) && (no() || _score->styleB(ST_footerFirstPage))) { TextStyle ts = score()->textStyle(TEXT_STYLE_FOOTER); QPointF o(ts.offset(spatium())); bool odd = (n & 1) || !_score->styleB(ST_footerOddEven); if (odd) { o.setX(-o.x()); s1 = _score->styleSt(ST_oddFooterL); s2 = _score->styleSt(ST_oddFooterC); s3 = _score->styleSt(ST_oddFooterR); } else { s1 = _score->styleSt(ST_evenFooterL); s2 = _score->styleSt(ST_evenFooterC); s3 = _score->styleSt(ST_evenFooterR); } if (_score->styleB(ST_footerStyled)) { drawStyledHeaderFooter(painter, 3, o, s1); drawStyledHeaderFooter(painter, 4, o, s2); drawStyledHeaderFooter(painter, 5, o, s3); } else { qreal w = _score->loWidth() - lm() - rm() - (2.0 * o.x()); o = QPointF(0.0, _score->loHeight() - (tm() + bm())); QAbstractTextDocumentLayout::PaintContext c; c.cursorPosition = -1; c.palette.setColor(QPalette::Text, ts.foregroundColor()); painter->translate(o); qreal h1, h2, h3; QTextDocument d1, d2, d3; QFont f; if (!s1.isEmpty()) { d1.setDocumentMargin(0.0); d1.setUseDesignMetrics(true); s1 = replaceTextMacros(s1); d1.setTextWidth(w); d1.setHtml(s1); h1 = d1.documentLayout()->documentSize().height(); } else h1 = 0.0; if (!s2.isEmpty()) { d2.setDocumentMargin(0.0); d2.setUseDesignMetrics(true); s2 = replaceTextMacros(s2); d2.setTextWidth(w); d2.setHtml(s2); h2 = d2.documentLayout()->documentSize().height(); } else h2 = 0.0; if (!s3.isEmpty()) { d3.setDocumentMargin(0.0); d3.setUseDesignMetrics(true); s3 = replaceTextMacros(s3); d3.setTextWidth(w); d3.setHtml(s3); h3 = d3.documentLayout()->documentSize().height(); } else h3 = 0.0; qreal h = qMax(h1, h2); h = qMax(h, h3); QPointF pos(0.0, -h); painter->translate(pos); if (!s1.isEmpty()) d1.documentLayout()->draw(painter, c); if (!s2.isEmpty()) d2.documentLayout()->draw(painter, c); if (!s3.isEmpty()) d3.documentLayout()->draw(painter, c); painter->translate(-(o + pos)); } } painter->translate(-o1); }