void InspectorVolta::setElement() { TextLineBaseSegment* ts = static_cast<TextLineBaseSegment*>(inspector->element()); TextLineBase* t = ts->textLineBase(); bool bt = !t->beginText().isEmpty(); bool ct = !t->continueText().isEmpty(); bool et = !t->endText().isEmpty(); tl.hasBeginText->setChecked(bt); tl.hasContinueText->setChecked(ct); tl.hasEndText->setChecked(et); tl.beginWidget->setVisible(bt); tl.continueWidget->setVisible(ct); tl.endWidget->setVisible(et); InspectorElementBase::setElement(); }
TextLineBase::TextLineBase(const TextLineBase& e) : SLine(e) { for (P_ID pid : pids) setProperty(pid, e.getProperty(pid)); }
void TextLineBaseSegment::draw(QPainter* painter) const { TextLineBase* tl = textLineBase(); qreal _spatium = spatium(); // color for line (text color comes from the text properties) QColor color; if (selected() && !(score() && score()->printing())) color = (track() > -1) ? MScore::selectColor[voice()] : MScore::selectColor[0]; else if (!tl->visible() || !tl->lineVisible()) color = Qt::gray; else color = tl->lineColor(); if (!_text->empty()) { painter->translate(_text->pos()); _text->setVisible(tl->visible()); _text->draw(painter); painter->translate(-_text->pos()); } if (!_endText->empty()) { painter->translate(_endText->pos()); _endText->setVisible(tl->visible()); _endText->draw(painter); painter->translate(-_endText->pos()); } if (npoints == 0) return; qreal textlineLineWidth = tl->lineWidth().val() * _spatium; QPen pen(color, textlineLineWidth, tl->lineStyle()); if (tl->lineStyle() == Qt::CustomDashLine) { QVector<qreal> dashes { tl->dashLineLen(), tl->dashGapLen() }; pen.setDashPattern(dashes); } painter->setPen(pen); if (twoLines) { // hairpins painter->drawLines(&points[0], 1); painter->drawLines(&points[2], 1); } else { for (int i = 0; i < npoints; ++i) painter->drawLines(&points[i], 1); } }
void TextLineBaseSegment::layout() { npoints = 0; TextLineBase* tl = textLineBase(); qreal _spatium = spatium(); if (!tl->diagonal()) _userOff2.setY(0); switch (spannerSegmentType()) { case SpannerSegmentType::SINGLE: case SpannerSegmentType::BEGIN: _text->setXmlText(tl->beginText()); _text->setFamily(tl->beginFontFamily()); _text->setSize(tl->beginFontSize()); _text->setOffset(tl->beginTextOffset()); _text->setAlign(tl->beginTextAlign()); break; case SpannerSegmentType::MIDDLE: case SpannerSegmentType::END: _text->setXmlText(tl->continueText()); _text->setFamily(tl->continueFontFamily()); _text->setSize(tl->continueFontSize()); _text->setOffset(tl->continueTextOffset()); _text->setAlign(tl->continueTextAlign()); break; } _text->setTrack(track()); _text->layout(); if ((isSingleType() || isEndType())) { _endText->setXmlText(tl->endText()); _endText->setFamily(tl->endFontFamily()); _endText->setSize(tl->endFontSize()); _endText->setOffset(tl->endTextOffset()); _endText->setAlign(tl->endTextAlign()); _endText->setTrack(track()); _endText->layout(); } else { _endText->setXmlText(""); } QPointF pp1; QPointF pp2(pos2()); // diagonal line with no text - just use the basic rectangle for line (ignore hooks) if (_text->empty() && _endText->empty() && pp2.y() != 0) { npoints = 2; points[0] = pp1; points[1] = pp2; setbbox(QRectF(pp1, pp2).normalized()); return; } // line has text or is not diagonal - calculate reasonable bbox qreal x1 = qMin(0.0, pp2.x()); qreal x2 = qMax(0.0, pp2.x()); qreal y0 = point(-textLineBase()->lineWidth()); qreal y1 = qMin(0.0, pp2.y()) + y0; qreal y2 = qMax(0.0, pp2.y()) - y0; qreal l = 0.0; if (!_text->empty()) { qreal textlineTextDistance = _spatium * .5; if (((isSingleType() || isBeginType()) && (tl->beginTextPlace() == PlaceText::LEFT)) || ((isMiddleType() || isEndType()) && (tl->continueTextPlace() == PlaceText::LEFT))) l = _text->pos().x() + _text->bbox().width() + textlineTextDistance; qreal h = _text->height(); if (textLineBase()->beginTextPlace() == PlaceText::ABOVE) y1 = qMin(y1, -h); else if (textLineBase()->beginTextPlace() == PlaceText::BELOW) y2 = qMax(y2, h); else { y1 = qMin(y1, -h * .5); y2 = qMax(y2, h * .5); } x2 = qMax(x2, _text->width()); } if (textLineBase()->endHookType() != HookType::NONE) { qreal h = pp2.y() + point(textLineBase()->endHookHeight()); if (h > y2) y2 = h; else if (h < y1) y1 = h; } if (textLineBase()->beginHookType() != HookType::NONE) { qreal h = point(textLineBase()->beginHookHeight()); if (h > y2) y2 = h; else if (h < y1) y1 = h; } bbox().setRect(x1, y1, x2 - x1, y2 - y1); if (!_text->empty()) bbox() |= _text->bbox().translated(_text->pos()); // DEBUG // set end text position and extend bbox if (!_endText->empty()) { _endText->setPos(bbox().right(), 0); bbox() |= _endText->bbox().translated(_endText->pos()); } if (!(tl->lineVisible() || score()->showInvisible())) return; if (tl->lineVisible() || !score()->printing()) { QPointF pp1(l, 0.0); qreal beginHookWidth; qreal endHookWidth; if (tl->beginHookType() == HookType::HOOK_45) { beginHookWidth = fabs(tl->beginHookHeight().val() * _spatium * .4); pp1.rx() += beginHookWidth; } else beginHookWidth = 0; if (tl->endHookType() == HookType::HOOK_45) { endHookWidth = fabs(tl->endHookHeight().val() * _spatium * .4); pp2.rx() -= endHookWidth; } else endHookWidth = 0; // don't draw backwards lines (or hooks) if text is longer than nominal line length bool backwards = !_text->empty() && pp1.x() > pp2.x() && !tl->diagonal(); if ((tl->beginHookType() != HookType::NONE) && (isSingleType() || isBeginType())) { qreal hh = tl->beginHookHeight().val() * _spatium; points[npoints] = QPointF(pp1.x() - beginHookWidth, pp1.y() + hh); ++npoints; points[npoints] = pp1; } if (!backwards) { points[npoints] = pp1; ++npoints; points[npoints] = pp2; // painter->drawLine(QLineF(pp1.x(), pp1.y(), pp2.x(), pp2.y())); if ((tl->endHookType() != HookType::NONE) && (isSingleType() || isEndType())) { ++npoints; qreal hh = tl->endHookHeight().val() * _spatium; // painter->drawLine(QLineF(pp2.x(), pp2.y(), pp2.x() + endHookWidth, pp2.y() + hh)); points[npoints] = QPointF(pp2.x() + endHookWidth, pp2.y() + hh); } } } }