示例#1
1
文件: text.cpp 项目: aeliot/MuseScore
void Text::layout1()
      {
      if (styled() && !_editMode)
            SimpleText::layout();
      else {
            _doc->setDefaultFont(textStyle().font(spatium()));
            qreal w = -1.0;
            QPointF o(textStyle().offset(spatium()));

            if (parent() && layoutToParentWidth()) {
                  Element* e = parent();
                  w = e->width();
                  if (e->type() == HBOX || e->type() == VBOX || e->type() == TBOX) {
                        Box* b = static_cast<Box*>(e);
                        w -= ((b->leftMargin() + b->rightMargin()) * MScore::DPMM);
                        }
                  }

            QTextOption to = _doc->defaultTextOption();
            to.setUseDesignMetrics(true);
            to.setWrapMode(w <= 0.0 ? QTextOption::NoWrap : QTextOption::WrapAtWordBoundaryOrAnywhere);
            _doc->setDefaultTextOption(to);

            if (w <= 0.0)
                  w = _doc->idealWidth();
            _doc->setTextWidth(w);

            QSizeF size(_doc->size());

            if (align() & ALIGN_BOTTOM)
                  o.ry() -= size.height();
            else if (align() & ALIGN_VCENTER)
                  o.ry() -= (size.height() * .5);
            else if (align() & ALIGN_BASELINE)
                  o.ry() -= baseLine();

            if (align() & ALIGN_RIGHT)
                  o.rx() -= size.width();
            else if (align() & ALIGN_HCENTER)
                  o.rx() -= (size.width() * .5);

            setbbox(QRectF(QPointF(0.0, 0.0), size));
            _doc->setModified(false);
            setPos(o);
            }
      if (parent()) {
            Element* e = parent();
            qreal w, h, xo, yo;
            if (layoutToParentWidth()) {
                  if (e->type() == HBOX || e->type() == VBOX || e->type() == TBOX) {
                        // consider inner margins of frame
                        Box* b = static_cast<Box*>(e);
                        xo = b->leftMargin() * MScore::DPMM;
                        yo = b->topMargin()  * MScore::DPMM;
                        w  = b->width()  - xo - b->rightMargin() * MScore::DPMM;
                        h  = b->height() - yo - b->bottomMargin()   * MScore::DPMM;
                        }
                  else {
                        w  = e->width();
                        h  = e->height();
                        xo = 0.0;
                        yo = 0.0;
                        }
                  QPointF ro(_textStyle.reloff() * .01);
                  rxpos() += xo + ro.x() * w;
                  rypos() += yo + ro.y() * h;
                  }
            if (e->type() == SEGMENT) {
                  Segment* s = static_cast<Segment*>(e);
                  rypos() += s->measure()->system()->staff(staffIdx())->y();
                  }
            }

      if (hasFrame())
            layoutFrame();
      }
示例#2
0
void SimpleText::layout()
      {
      if (parent() == 0 || _text.isEmpty())
            return;

      const TextStyle& s(style());

      QPointF o(s.offset(spatium()));
      if (_layoutToParentWidth && parent()) {
            Element* e = parent();
            if ((type() == MARKER || type() == JUMP) && e->parent())
                  e = e->parent();
            qreal w = e->width();
            qreal h = e->height();
            drawingRect = QRectF(0.0, 0.0, w, h);
            QPointF ro = s.reloff() * .01;
            setPos(o + QPointF(ro.x() * w, ro.y() * h));
            }
      else {
            drawingRect = QRectF();
            setPos(o);
            }

      QFontMetricsF fm(s.fontPx(spatium()));
      setbbox(fm.boundingRect(drawingRect, alignFlags(), _text));

      if (hasFrame())
            layoutFrame();
      }
示例#3
0
void Text::layout()
      {
      if (styled() && !_editMode) {
            SimpleText::layout();
            }
      else {
            _doc->setDefaultFont(textStyle().font(spatium()));
            qreal w = -1.0;
            qreal x = 0.0;
            qreal y = 0.0;
            if (parent() && layoutToParentWidth()) {
                  w = parent()->width();
                  if (parent()->type() == HBOX || parent()->type() == VBOX || parent()->type() == TBOX) {
                        Box* box = static_cast<Box*>(parent());
                        x += box->leftMargin() * MScore::DPMM;
                        y += box->topMargin() * MScore::DPMM;
                        w = box->width()   - ((box->leftMargin() + box->rightMargin()) * MScore::DPMM);
                        }
                  }

            QTextOption to = _doc->defaultTextOption();
            to.setUseDesignMetrics(true);
            to.setWrapMode(w <= 0.0 ? QTextOption::NoWrap : QTextOption::WrapAtWordBoundaryOrAnywhere);
            _doc->setDefaultTextOption(to);

            if (w < 0.0)
                  w = _doc->idealWidth();
            _doc->setTextWidth(w);

            setbbox(QRectF(QPointF(0.0, 0.0), _doc->size()));
            if (hasFrame())
                  layoutFrame();
            _doc->setModified(false);
            textStyle().layout(this);      // process alignment

#if 0 // TODO  TEXT_STYLE_TEXTLINE
            if ((textStyle().align() & ALIGN_VCENTER) && (textStyle() == TEXT_STYLE_TEXTLINE)) {
                  // special case: vertically centered text with TextLine needs to
                  // take into account the line width
                  TextLineSegment* tls = static_cast<TextLineSegment*>(parent());
                  TextLine* tl = tls->textLine();
                  if (tl) {
                        qreal textlineLineWidth = point(tl->lineWidth());
                        rypos() -= textlineLineWidth * .5;
                        }
                  }
#endif
            rxpos() += x;
            rypos() += y;
            }
      if (parent() && parent()->type() == SEGMENT) {
            Segment* s = static_cast<Segment*>(parent());
            rypos() += s ? s->measure()->system()->staff(staffIdx())->y() : 0.0;
            }
      adjustReadPos();
      }