Esempio n. 1
0
/// Adds a caption for a graph beneath the actual diagram.
void DiagramScene::addCaption(const QString &name, QPen &pen)
{
	QGraphicsItemGroup* caption = new QGraphicsItemGroup(NULL);
	QGraphicsLineItem* l = addLine(0,0,100,0,pen);
	QGraphicsTextItem* t = addText(name);
	l->setPos(0,0);
	t->setPos(110, -(t->boundingRect()).height() / 2);
	caption->addToGroup(l);
	caption->addToGroup(t);
	caption->setFlag(QGraphicsItem::ItemIgnoresTransformations, true);

	_graphCaptions.push_back(caption);
	addItem(_graphCaptions[_graphCaptions.size() - 1]);
}
OutputComponent::OutputComponent()
    : Component(Component::OutputComponent), m_pin(0)
{
    setFlag(QGraphicsItem::ItemIsMovable);
    setFlag(QGraphicsItem::ItemSendsGeometryChanges);

    setMetaTypeId(qRegisterMetaType<OutputComponent>("OutputComponent"));

    m_pin = new Pin(Pin::Input, this);
    m_pin->setPos(-20,10);

    addPins(QList<Pin*>() << m_pin);

    QGraphicsLineItem* Lo = new QGraphicsLineItem(QLineF(0,0,10,0), m_pin);
    Lo->setPos(10,5);

    setToolTip("Output Component");
}
void PSV_CircularIndicatorItem::drawIndicator(int zValue)
{
    QPointF center(0, 0);
    QPointF topPot(center.x(), center.y() - m_colorCircleRadiusRatio * m_outerRadius/*m_coverBallRadius*/);
    QPointF bottomLeftPot(center.x() - m_outerRadius * m_indicatorWidthRatio, center.y());
    QPointF bottomRightPot(center.x() + m_outerRadius * m_indicatorWidthRatio, center.y());

    QLinearGradient indicatorGradient(topPot, bottomLeftPot);
    indicatorGradient.setColorAt(0.0, QColor(236, 187, 62));
    indicatorGradient.setColorAt(0.5, QColor(220, 147, 0));
    indicatorGradient.setColorAt(1.0, QColor(236, 187, 62));

    QPolygonF polygon;
    polygon.append(topPot);
    polygon.append(bottomLeftPot);
    polygon.append(bottomRightPot);
    //    if(m_polygonItem == NULL)
    {
        QGraphicsLineItem *item = new QGraphicsLineItem(this);
        item->setPos(m_rect.center().x(), m_rect.center().y());
        item->setZValue(zValue);
        m_polygonItem = new QGraphicsPolygonItem(item);
    }
    m_polygonItem->setPolygon(polygon);
    m_polygonItem->setPen(QPen(Qt::NoPen));
    m_polygonItem->setBrush(indicatorGradient);
    m_polygonItem->setZValue(zValue);
    qreal angle = (m_value - m_min) / (m_max - m_min) * 270 - 135;
    PSV_Public::printMes(angle,"angle");
#if QT_VERSION > QT_VERSION_CHECK(4, 6, 0)
    m_polygonItem->setRotation(angle);
#else
    m_polygonItem->rotate((m_value - m_min) / (m_max - m_min) * 270 - 135);
#endif

}