void TemporalConstraintView::paint(
        QPainter* painter,
        const QStyleOptionGraphicsItem* option,
        QWidget* widget)
{
    // Draw the rack bg
    if(auto rack = presenter().rack())
    {
        auto rackRect = rack->view().boundingRect();
        painter->fillRect(rackRect, QColor::fromRgba(qRgba(0, 127, 229, 76)));

        auto color = qApp->palette("ScenarioPalette").base().color();
        QPen pen{color, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin};
        painter->setPen(pen);
        painter->drawLine(rackRect.topLeft(), rackRect.bottomLeft());
        painter->drawLine(rackRect.topRight(), rackRect.bottomRight());
    }


    QPainterPath solidPath, dashedPath, leftBrace, rightBrace;

//    m_endState->setPos(defaultWidth(), 0);

    // Paths
    if(infinite())
    {
        if(minWidth() != 0)
        {
            solidPath.lineTo(minWidth(), 0);

            leftBrace.moveTo(minWidth(), -10);
            leftBrace.arcTo(minWidth() - 10, -10, 20, 20, 90, 180);
        }

        // TODO end state should be hidden
        dashedPath.moveTo(minWidth(), 0);
        dashedPath.lineTo(defaultWidth(), 0);
    }
    else if(minWidth() == maxWidth()) // TODO rigid()
    {
        solidPath.lineTo(defaultWidth(), 0);
    }
    else
    {
        if(minWidth() != 0)
            solidPath.lineTo(minWidth(), 0);

        dashedPath.moveTo(minWidth(), 0);
        dashedPath.lineTo(maxWidth(), 0);

        leftBrace.moveTo(minWidth(), -10);
        leftBrace.arcTo(minWidth() - 10, -10, 20, 20, 90, 180);

        rightBrace.moveTo(maxWidth(), 10);
        rightBrace.arcTo(maxWidth() - 10, -10, 20, 20, 270, 180);
    }

    QPainterPath playedPath;
    if(playWidth() != 0)
    {
        playedPath.lineTo(playWidth(), 0);
    }

    // Colors
    QColor constraintColor;
    if(isSelected())
    {
        constraintColor = QColor::fromRgbF(0.188235, 0.54902, 0.776471);
    }
    else
    {
        constraintColor = qApp->palette("ScenarioPalette").base().color();
    }
    if(warning())
    {
        constraintColor = QColor{200,150,0};
    }
    if(! isValid())
    {
        constraintColor = Qt::red;
    }

    m_solidPen.setColor(constraintColor);
    m_dashPen.setColor(constraintColor);

    // Drawing
    painter->setPen(m_solidPen);
    if(!solidPath.isEmpty())
        painter->drawPath(solidPath);
    if(!leftBrace.isEmpty())
        painter->drawPath(leftBrace);
    if(!rightBrace.isEmpty())
        painter->drawPath(rightBrace);

    painter->setPen(m_dashPen);
    if(!dashedPath.isEmpty())
        painter->drawPath(dashedPath);

    leftBrace.closeSubpath();
    rightBrace.closeSubpath();

    QPen anotherPen(Qt::transparent, 4);
    painter->setPen(anotherPen);
    QColor blueish = m_solidPen.color().lighter();
    blueish.setAlphaF(0.3);
    painter->setBrush(blueish);
    painter->drawPath(leftBrace);
    painter->drawPath(rightBrace);

    static const QPen playedPen{
        QBrush{Qt::green},
        4,
        Qt::SolidLine,
                Qt::RoundCap,
                Qt::RoundJoin
    };
    static const QPen dashedPlayedPen{
        QBrush{Qt::green},
        4,
        Qt::DashLine,
                Qt::RoundCap,
                Qt::RoundJoin
    };

    painter->setPen(playedPen);
    if(!playedPath.isEmpty())
        painter->drawPath(playedPath);


    int fontSize = 12;
    QRectF labelRect{0,0, defaultWidth(), (-fontSize - 2.)};
    QFont f("Ubuntu");
    f.setPixelSize(fontSize);
    painter->setFont(f);
    painter->setPen(m_labelColor);
    painter->drawText(labelRect, Qt::AlignCenter, m_label);
/*
    painter->setPen(Qt::darkRed);
    painter->setBrush(Qt::NoBrush);
    painter->drawRect(boundingRect());
*/
}
Пример #2
0
void TemporalConstraintView::paint(
        QPainter* painter,
        const QStyleOptionGraphicsItem*,
        QWidget*)
{
    qreal min_w = minWidth();
    qreal max_w = maxWidth();
    qreal def_w = defaultWidth();
    qreal play_w = playWidth();

    // Draw the stuff present if there is a rack *in the model* ?
    if(presenter().rack())
    {
        // Background
        auto rect = boundingRect();
        rect.adjust(0,15,0,-10);
        rect.setWidth(this->defaultWidth());
        painter->fillRect(rect, m_bgColor);

        // Fake timenode continuation
        auto color = ScenarioStyle::instance().RackSideBorder;
        QPen pen{color, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin};
        painter->setPen(pen);
        painter->drawLine(rect.topLeft(), rect.bottomLeft());
        painter->drawLine(rect.topRight(), rect.bottomRight());
    }


    QPainterPath solidPath, dashedPath, leftBrace, rightBrace;

    // Paths
    if(infinite())
    {
        if(min_w != 0.)
        {
            solidPath.lineTo(min_w, 0);

            leftBrace.moveTo(min_w, -10);
            leftBrace.arcTo(min_w - 10, -10, 20, 20, 90, 180);
        }

        // TODO end state should be hidden
        dashedPath.moveTo(min_w, 0);
        dashedPath.lineTo(def_w, 0);
    }
    else if(min_w == max_w) // TODO rigid()
    {
        solidPath.lineTo(def_w, 0);
    }
    else
    {
        if(min_w != 0.)
            solidPath.lineTo(min_w, 0);

        dashedPath.moveTo(min_w, 0);
        dashedPath.lineTo(max_w, 0);

        leftBrace.moveTo(min_w + 10, -10);
        leftBrace.arcTo(min_w, -10, 20, 20, 90, 180);
        leftBrace.closeSubpath();

        rightBrace.moveTo(max_w, 10);
        rightBrace.arcTo(max_w - 10, -10, 20, 20, 270, 180);
        rightBrace.closeSubpath();
        rightBrace.translate(-10, 0); // TODO bleh.
    }

    QPainterPath playedPath;
    if(play_w != 0.)
    {
        playedPath.lineTo(play_w, 0);
    }

    // Colors
    QColor constraintColor;
    // TODO make a switch instead
    if(isSelected())
    {
        constraintColor = ScenarioStyle::instance().ConstraintSelected;
    }
    else if(warning())
    {
        constraintColor = ScenarioStyle::instance().ConstraintWarning;
    }
    else
    {
        constraintColor = ScenarioStyle::instance().ConstraintBase;
    }
    if(! isValid())
    {
        constraintColor = ScenarioStyle::instance().ConstraintInvalid;
        this->setZValue(this->zValue()+ 1);
    }
    else
    {
        this->setZValue(parentObject()->zValue() + 3);
    }

    m_solidPen.setColor(constraintColor);
    m_dashPen.setColor(constraintColor);

    // Drawing
    painter->setPen(m_solidPen);
    if(!solidPath.isEmpty())
        painter->drawPath(solidPath);
    if(!leftBrace.isEmpty())
        painter->drawPath(leftBrace);
    if(!rightBrace.isEmpty())
        painter->drawPath(rightBrace);

    painter->setPen(m_dashPen);
    if(!dashedPath.isEmpty())
        painter->drawPath(dashedPath);

    leftBrace.closeSubpath();
    rightBrace.closeSubpath();

    QPen anotherPen(Qt::transparent, 4);
    painter->setPen(anotherPen);
    QColor blueish = m_solidPen.color().lighter();
    blueish.setAlphaF(0.3);
    painter->setBrush(blueish);
    painter->drawPath(leftBrace);
    painter->drawPath(rightBrace);

    static const QPen playedPen{
        QBrush{ScenarioStyle::instance().ConstraintPlayFill},
        4,
        Qt::SolidLine,
                Qt::RoundCap,
                Qt::RoundJoin
    };

    painter->setPen(playedPen);
    if(!playedPath.isEmpty())
        painter->drawPath(playedPath);


    static const int fontSize = 12;
    QRectF labelRect{0,0, defaultWidth(), (-fontSize - 2.)};
    auto f = ProcessFonts::Sans();
    f.setPointSize(fontSize);

    painter->setFont(f);
    painter->setPen(m_labelColor);
    painter->drawText(labelRect, Qt::AlignCenter, m_label);

#if defined(ISCORE_SCENARIO_DEBUG_RECTS)
    painter->setPen(Qt::darkRed);
    painter->setBrush(Qt::NoBrush);
    painter->drawRect(boundingRect());
#endif
}
Пример #3
0
void TemporalConstraintView::paint(
        QPainter* painter,
        const QStyleOptionGraphicsItem*,
        QWidget*)
{
    auto& skin = ScenarioStyle::instance();

    qreal min_w = minWidth();
    qreal max_w = maxWidth();
    qreal def_w = defaultWidth();
    qreal play_w = playWidth();

    m_labelItem->setPos(def_w / 2. - m_labelItem->boundingRect().width() / 2., -17);
    m_counterItem->setPos(def_w - m_counterItem->boundingRect().width() - 5, 5);
    m_leftBrace->setX(min_w);
    m_rightBrace->setX(max_w);

    // Draw the stuff present if there is a rack *in the model* ?
    if(presenter().rack())
    {
        // Background
        auto rect = boundingRect();
        rect.adjust(0,4,0,-10);
        rect.setWidth(this->defaultWidth());

        QColor bgColor = m_bgColor.getColor();
        bgColor.setAlpha(m_hasFocus ? 84 : 76);
        painter->fillRect(rect, bgColor);

        // Fake timenode continuation
        auto color = skin.RackSideBorder.getColor();
        QPen pen{color, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin};
        painter->setPen(pen);
        painter->drawLine(rect.topLeft(), rect.bottomLeft());
        painter->drawLine(rect.topRight(), rect.bottomRight());
    }


    QPainterPath solidPath, dashedPath, leftBrace, rightBrace;

    // Paths
    if(infinite())
    {
        if(min_w != 0.)
        {
            solidPath.lineTo(min_w, 0);

            m_leftBrace->show();
        }
        m_rightBrace->hide();

        // TODO end state should be hidden
        dashedPath.moveTo(min_w, 0);
        dashedPath.lineTo(def_w, 0);
    }
    else if(min_w == max_w) // TODO rigid()
    {
        solidPath.lineTo(def_w, 0);
        m_leftBrace->hide();
        m_rightBrace->hide();
    }
    else
    {
        if(min_w != 0.)
            solidPath.lineTo(min_w, 0);

        dashedPath.moveTo(min_w, 0);
        dashedPath.lineTo(max_w, 0);

        m_leftBrace->show();
        m_rightBrace->show();

    }

    QPainterPath playedPath;
    if(play_w != 0.)
    {
        playedPath.lineTo(std::min(play_w, std::max(def_w, max_w)), 0);
    }

    // Colors
    QColor constraintColor;
    // TODO make a switch instead
    if(isSelected())
    {
        constraintColor = skin.ConstraintSelected.getColor();
    }
    else if(warning())
    {
        constraintColor = skin.ConstraintWarning.getColor();
    }
    else
    {
        constraintColor = skin.ConstraintBase.getColor();
    }
    if(! isValid() || m_state == ConstraintExecutionState::Disabled)
    {
        constraintColor = skin.ConstraintInvalid.getColor();
    }


    m_solidPen.setColor(constraintColor);
    m_dashPen.setColor(constraintColor);

    // Drawing
    painter->setPen(m_solidPen);
    if(!solidPath.isEmpty())
        painter->drawPath(solidPath);

    painter->setPen(m_dashPen);
    if(!dashedPath.isEmpty())
        painter->drawPath(dashedPath);

    leftBrace.closeSubpath();
    rightBrace.closeSubpath();

    QPen anotherPen(Qt::transparent, 4);
    painter->setPen(anotherPen);
    QColor blueish = m_solidPen.color().lighter();
    blueish.setAlphaF(0.3);
    painter->setBrush(blueish);


    const QPen playedPen{
        skin.ConstraintPlayFill.getColor(),
        4,
        Qt::SolidLine,
                Qt::RoundCap,
                Qt::RoundJoin
    };

    painter->setPen(playedPen);
    if(!playedPath.isEmpty())
        painter->drawPath(playedPath);

    {
        auto& dur = presenter().model().duration;
        auto progress = dur.defaultDuration() * dur.playPercentage();
        if(!progress.isZero())
        {
            QString percent = progress.toString();
            m_counterItem->setText(percent);
        }
    }


#if defined(ISCORE_SCENARIO_DEBUG_RECTS)
    painter->setPen(Qt::darkRed);
    painter->setBrush(Qt::NoBrush);
    painter->drawRect(boundingRect());
#endif
}