Exemplo n.º 1
0
void TextProp::setTextStyle(const TextStyle& s)
      {
      fontBold->setChecked(s.bold());
      fontItalic->setChecked(s.italic());
      fontUnderline->setChecked(s.underline());
      fontSize->setValue(s.size());
      color->setColor(s.foregroundColor());

      systemFlag->setChecked(s.systemFlag());
      int a = s.align();
      if (a & ALIGN_HCENTER)
            alignHCenter->setChecked(true);
      else if (a & ALIGN_RIGHT)
            alignRight->setChecked(true);
      else
            alignLeft->setChecked(true);

      if (a & ALIGN_VCENTER)
            alignVCenter->setChecked(true);
      else if (a & ALIGN_BOTTOM)
            alignBottom->setChecked(true);
      else if (a & ALIGN_BASELINE)
            alignBaseline->setChecked(true);
      else
            alignTop->setChecked(true);

      QString str;
      if (s.offsetType() == OFFSET_ABS) {
            xOffset->setValue(s.offset().x() * INCH);
            yOffset->setValue(s.offset().y() * INCH);
            mmUnit->setChecked(true);
            curUnit = 0;
            }
      else if (s.offsetType() == OFFSET_SPATIUM) {
            xOffset->setValue(s.offset().x());
            yOffset->setValue(s.offset().y());
            spatiumUnit->setChecked(true);
            curUnit = 1;
            }
      rxOffset->setValue(s.reloff().x());
      ryOffset->setValue(s.reloff().y());

      QFont f(s.family());
      f.setPixelSize(lrint(s.size()));
      f.setItalic(s.italic());
      f.setUnderline(s.underline());
      f.setBold(s.bold());
      fontSelect->setCurrentFont(f);
      sizeIsSpatiumDependent->setChecked(s.sizeIsSpatiumDependent());

      frameColor->setColor(s.frameColor());
      bgColor->setColor(s.backgroundColor());
      frameWidth->setValue(s.frameWidth());
      frame->setChecked(s.hasFrame());
      paddingWidth->setValue(s.paddingWidth());
      frameRound->setValue(s.frameRound());
      circleButton->setChecked(s.circle());
      boxButton->setChecked(!s.circle());
      }
Exemplo n.º 2
0
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);
      }