int ViewportConfiguration::layoutHeight() const
{
    ASSERT(!constraintsAreAllRelative(m_configuration));

    const FloatSize& minimumLayoutSize = m_minimumLayoutSize;
    if (m_configuration.heightIsSet) {
        // If we scale to fit, then accept the viewport height with sanity checking.
        if (!m_configuration.initialScaleIsSet) {
            double maximumScale = this->maximumScale();
            double maximumContentHeightInViewportCoordinate = maximumScale * m_configuration.height;
            if (maximumContentHeightInViewportCoordinate < minimumLayoutSize.height()) {
                // The content zoomed to maxScale does not fit the the view. Return the minimum height that
                // satisfy the constraint maximumScale.
                return std::round(minimumLayoutSize.height() / maximumScale);
            }
            return std::round(m_configuration.height);
        }

        // If not, make sure the viewport width and initial scale can co-exist.
        double initialContentHeightInViewportCoordinate = m_configuration.height * m_configuration.initialScale;
        if (initialContentHeightInViewportCoordinate < minimumLayoutSize.height()) {
            // The specified width does not fit in viewport. Return the minimum height that satisfy the initialScale constraint.
            return std::round(minimumLayoutSize.height() / m_configuration.initialScale);
        }
        return std::round(m_configuration.height);
    }

    // If the page has a real scale, then just return the minimum size over the initial scale.
    if (m_configuration.initialScaleIsSet && !m_configuration.widthIsSet)
        return std::round(minimumLayoutSize.height() / m_configuration.initialScale);

    if (minimumLayoutSize.width() > 0)
        return std::round(minimumLayoutSize.height() * layoutWidth() / minimumLayoutSize.width());
    return minimumLayoutSize.height();
}
//----------------------------------------------------------------------------//
void VerticalLayoutContainer::layout()
{
    // used to compare UDims
    const float absWidth = getChildContentArea().get().getWidth();

    // this is where we store the top offset
    // we continually increase this number as we go through the windows
    UDim topOffset(0, 0);
    UDim layoutWidth(0, 0);

    for (ChildList::iterator it = d_children.begin(); it != d_children.end(); ++it)
    {
        Window* window = static_cast<Window*>(*it);

        const UVector2 offset = getOffsetForWindow(window);
        const UVector2 boundingSize = getBoundingSizeForWindow(window);

        // full child window width, including margins
        const UDim& childWidth = boundingSize.d_x;

        if (CoordConverter::asAbsolute(layoutWidth, absWidth) <
                CoordConverter::asAbsolute(childWidth, absWidth))
        {
            layoutWidth = childWidth;
        }

        window->setPosition(offset + UVector2(UDim(0, 0), topOffset));
        topOffset += boundingSize.d_y;
    }

    setSize(USize(layoutWidth, topOffset));
}
Exemple #3
0
void BarLine::layout()
      {
      qreal y1, y2;
      getY(&y1, &y2);
      qreal _spatium = spatium();

      qreal dw = layoutWidth(score(), barLineType(), magS());
      QRectF r(0.0, y1, dw, y2-y1);

      if (score()->styleB(ST_repeatBarTips)) {
            qreal mags = magS();
            int si = score()->symIdx();
            switch (barLineType()) {
                  case START_REPEAT:
                        r |= symbols[si][brackettipsRightUp].bbox(mags).translated(0, y1);
                        r |= symbols[si][brackettipsRightDown].bbox(mags).translated(0, y2);
                        break;
                  case END_REPEAT:
                        r |= symbols[si][brackettipsLeftUp].bbox(mags).translated(0, y1);
                        r |= symbols[si][brackettipsLeftDown].bbox(mags).translated(0, y2);
                        break;

                  case END_START_REPEAT:
                        {
                        qreal lw   = point(score()->styleS(ST_barWidth));
                        qreal lw2  = point(score()->styleS(ST_endBarWidth));
                        qreal d1   = point(score()->styleS(ST_endBarDistance));
                        const Sym& dotsym = symbols[score()->symIdx()][dotSym];
                        qreal dotw = dotsym.width(mags);
                        qreal x   =  dotw + 2 * d1 + lw + lw2 * .5;                     // thick bar

                        r |= symbols[si][brackettipsRightUp].bbox(mags).translated(x, y1);
                        r |= symbols[si][brackettipsRightDown].bbox(mags).translated(x, y2);
                        r |= symbols[si][brackettipsLeftUp].bbox(mags).translated(x, y1);
                        r |= symbols[si][brackettipsLeftDown].bbox(mags).translated(x, y2);
                        }
                        break;

                  default:
                        break;
                  }
            }
      foreach(Element* e, _el) {
            e->layout();
            if (e->type() == ARTICULATION) {
                  Articulation* a       = static_cast<Articulation*>(e);
                  MScore::Direction dir = a->direction();
                  qreal distance        = 0.5 * _spatium;
                  qreal x               = width() * .5;
                  if (dir == MScore::DOWN) {
                        qreal botY = y2 + distance;
                        a->setPos(QPointF(x, botY));
                        }
                  else {
                        qreal topY = y1 - distance;
                        a->setPos(QPointF(x, topY));
                        }
                  }
            }
bool ViewportConfiguration::shouldIgnoreHorizontalScalingConstraints() const
{
    if (!m_canIgnoreScalingConstraints)
        return false;

    if (!m_configuration.allowsShrinkToFit)
        return false;

    bool laidOutWiderThanViewport = m_contentSize.width() > layoutWidth();
    if (m_viewportArguments.width == ViewportArguments::ValueDeviceWidth)
        return laidOutWiderThanViewport;

    if (m_configuration.initialScaleIsSet && m_configuration.initialScale == 1)
        return laidOutWiderThanViewport;

    return false;
}
IntSize ViewportConfiguration::layoutSize() const
{
    return IntSize(layoutWidth(), layoutHeight());
}
double ViewportConfiguration::initialScaleIgnoringContentSize() const
{
    return initialScaleFromSize(layoutWidth(), layoutHeight(), false);
}
double ViewportConfiguration::initialScale() const
{
    return initialScaleFromSize(m_contentSize.width() > 0 ? m_contentSize.width() : layoutWidth(), m_contentSize.height() > 0 ? m_contentSize.height() : layoutHeight(), shouldIgnoreScalingConstraints());
}
Exemple #8
0
void BarLine::layout()
      {
      qreal y1, y2;
      getY(&y1, &y2);

      // if bar line does not belong to a system, has a staff and staff is set to hide bar lines, set null bbox
      if (parent() && parent()->type() != Element::Type::SYSTEM && staff() && !staff()->staffType()->showBarlines())
            setbbox(QRectF());

      // bar lines not hidden
      else {
            qreal dw = layoutWidth(score(), barLineType(), magS());
            QRectF r(0.0, y1, dw, y2-y1);

            if (score()->styleB(StyleIdx::repeatBarTips)) {
                  switch (barLineType()) {
                        case BarLineType::START_REPEAT:
                              r |= symBbox(SymId::bracketTop).translated(0, y1);
                              r |= symBbox(SymId::bracketBottom).translated(0, y2);
                              break;
                        case BarLineType::END_REPEAT:
                              {
                              qreal w1 = symBbox(SymId::reversedBracketTop).width();
                              r |= symBbox(SymId::reversedBracketTop).translated(dw - w1, y1);
                              r |= symBbox(SymId::reversedBracketBottom).translated(dw - w1, y2);
                              break;
                              }

                        case BarLineType::END_START_REPEAT:
                              {
                              qreal lw   = point(score()->styleS(StyleIdx::barWidth));
                              qreal lw2  = point(score()->styleS(StyleIdx::endBarWidth));
                              qreal d1   = point(score()->styleS(StyleIdx::endBarDistance));
                              qreal dotw = symWidth(SymId::repeatDot);
                              qreal x   =  dotw + 2 * d1 + lw + lw2 * .5;                     // thick bar
                              qreal w1 = symBbox(SymId::reversedBracketTop).width();
                              r |= symBbox(SymId::bracketTop).translated(x, y1);
                              r |= symBbox(SymId::bracketBottom).translated(x, y2);
                              r |= symBbox(SymId::reversedBracketTop).translated(x - w1 , y1);
                              r |= symBbox(SymId::reversedBracketBottom).translated(x - w1, y2);
                              }
                              break;

                        default:
                              break;
                        }
                  }
            setbbox(r);
            }

      // in any case, lay out attached elements
      foreach(Element* e, _el) {
            e->layout();
            if (e->type() == Element::Type::ARTICULATION) {
                  Articulation* a       = static_cast<Articulation*>(e);
                  MScore::Direction dir = a->direction();
                  qreal distance        = 0.5 * spatium();
                  qreal x               = width() * .5;
                  if (dir == MScore::Direction::DOWN) {
                        qreal botY = y2 + distance;
                        a->setPos(QPointF(x, botY));
                        }
                  else {
                        qreal topY = y1 - distance;
                        a->setPos(QPointF(x, topY));
                        }
                  }
            }