Ejemplo n.º 1
1
void OutputCalibrationPage::setupVehicleItems()
{
    m_vehicleItems.clear();
    m_vehicleBoundsItem = new QGraphicsSvgItem();
    m_vehicleBoundsItem->setSharedRenderer(m_vehicleRenderer);
    m_vehicleBoundsItem->setElementId(m_vehicleElementIds[0]);
    m_vehicleBoundsItem->setZValue(-1);
    m_vehicleBoundsItem->setOpacity(0);
    m_vehicleScene->addItem(m_vehicleBoundsItem);

    QRectF parentBounds = m_vehicleRenderer->boundsOnElement(m_vehicleElementIds[0]);

    for (int i = 1; i < m_vehicleElementIds.size(); i++) {
        QGraphicsSvgItem *item = new QGraphicsSvgItem();
        item->setSharedRenderer(m_vehicleRenderer);
        item->setElementId(m_vehicleElementIds[i]);
        item->setZValue(i);
        item->setOpacity(1.0);

        QRectF itemBounds = m_vehicleRenderer->boundsOnElement(m_vehicleElementIds[i]);
        item->setPos(itemBounds.x() - parentBounds.x(), itemBounds.y() - parentBounds.y());

        m_vehicleScene->addItem(item);
        m_vehicleItems << item;
    }
}
Ejemplo n.º 2
0
void ConnectionDiagram::setupGraphicsSceneItems(QList<QString> elementsToShow)
{
    qreal z = 0;
    QRectF backgBounds = m_renderer->boundsOnElement("background");

    foreach(QString elementId, elementsToShow) {
        if (m_renderer->elementExists(elementId)) {
            QGraphicsSvgItem *element = new QGraphicsSvgItem();
            element->setSharedRenderer(m_renderer);
            element->setElementId(elementId);
            element->setZValue(z++);
            element->setOpacity(1.0);

            QMatrix matrix = m_renderer->matrixForElement(elementId);
            QRectF orig    = matrix.mapRect(m_renderer->boundsOnElement(elementId));
            element->setPos(orig.x(), orig.y());

            // QRectF orig = m_renderer->boundsOnElement(elementId);
            // element->setPos(orig.x() - backgBounds.x(), orig.y() - backgBounds.y());

            m_scene->addItem(element);
            qDebug() << "Adding " << elementId << " to scene at " << element->pos();
        } else {
            qDebug() << "Element with id: " << elementId << " not found.";
        }
    }
}
Ejemplo n.º 3
0
void ScriptWidget::loadSvgFile(const QString & file) 
{
  
  if (!file.isEmpty())
  {
      clearSvgItems();
      qDebug("Loading file %s",qPrintable(file)); 
      m_renderer = new QSvgRenderer(file);
      int zBuffer = 0; 
      foreach (QString itemName, m_items)
      {
        QGraphicsSvgItem * g = new QGraphicsSvgItem();
        Item * item = new Item(g,this);  
        item->setObjectName(itemName); 
        g->setElementId(itemName); 
        g->setSharedRenderer(m_renderer); 
        g->setZValue(zBuffer++); 
        m_scene->addItem(g); 
        qDebug("item %s",qPrintable(itemName));
      }
MonitorWidget::MonitorWidget(QWidget *parent) :
    QGraphicsView(parent), aspectRatioMode(Qt::KeepAspectRatio)
{
    setMinimumSize(180, 25);

    QGraphicsScene *scene = new QGraphicsScene();

    setScene(scene);

    setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);

    // no scroll bars
    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);

    setBackgroundBrush(QBrush(Utils::StyleHelper::baseColor()));

    setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);

    QSvgRenderer *renderer = new QSvgRenderer();

    if (renderer->load(QString(":/telemetry/images/tx-rx.svg"))) {
        // create graph
        graph = new QGraphicsSvgItem();
        graph->setSharedRenderer(renderer);
        graph->setElementId("background");

        graph->setFlags(QGraphicsItem::ItemClipsChildrenToShape | QGraphicsItem::ItemClipsToShape);

        scene->addItem(graph);

        int i;

        // create tx nodes
        i = 0;
        while (true) {
            QString id   = QString("tx%0").arg(i);
            QString bgId = QString("tx_bg%0").arg(i);
            if (!renderer->elementExists(id) || !renderer->elementExists(bgId)) {
                break;
            }
            QGraphicsSvgItem *item = createSvgItem(graph, bgId);
            item->setElementId(id);
            txNodes.append(item);
            i++;
        }

        // create rx nodes
        i = 0;
        while (true) {
            QString id   = QString("rx%0").arg(i);
            QString bgId = QString("rx_bg%0").arg(i);
            if (!renderer->elementExists(id) || !renderer->elementExists(bgId)) {
                break;
            }
            QGraphicsSvgItem *item = createSvgItem(graph, bgId);
            item->setElementId(id);
            rxNodes.append(item);
            i++;
        }

        if (renderer->elementExists("txSpeed")) {
            txSpeed = createTextItem(graph, "txSpeed", "Helvetica");
            txSpeed->setDefaultTextColor(Qt::white);
        } else {
            txSpeed = NULL;
        }

        if (renderer->elementExists("rxSpeed")) {
            rxSpeed = createTextItem(graph, "rxSpeed", "Helvetica");
            rxSpeed->setDefaultTextColor(Qt::white);
        } else {
            rxSpeed = NULL;
        }
        // scene->setSceneRect(graph->boundingRect());
    }

    connected = false;

    setMin(0.0);
    setMax(1200.0);

    telemetryUpdated(0.0, 0.0);
}
Ejemplo n.º 5
0
TelemetryMonitorWidget::TelemetryMonitorWidget(QWidget *parent) : QGraphicsView(parent)
{
    setMinimumSize(180,100);
    setMaximumSize(180,100);
    setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    setAlignment(Qt::AlignCenter);
    setFrameStyle(QFrame::NoFrame);
    setStyleSheet("background:transparent;");
    setAttribute(Qt::WA_TranslucentBackground);
    setWindowFlags(Qt::FramelessWindowHint);

    QGraphicsScene *scene = new QGraphicsScene(0,0,180,100, this);

    QSvgRenderer *renderer = new QSvgRenderer();
    if (renderer->load(QString(":/core/images/tx-rx.svg"))) {
        graph = new QGraphicsSvgItem();
        graph->setSharedRenderer(renderer);
        graph->setElementId("txrxBackground");

        QString name;
        QGraphicsSvgItem* pt;

        for (int i=0; i<NODE_NUMELEM; i++) {
            name = QString("tx%0").arg(i);
            if (renderer->elementExists(name)) {
                pt = new QGraphicsSvgItem();
                pt->setSharedRenderer(renderer);
                pt->setElementId(name);
                pt->setParentItem(graph);
                txNodes.append(pt);
            }

            name = QString("rx%0").arg(i);
            if (renderer->elementExists(name)) {
                pt = new QGraphicsSvgItem();
                pt->setSharedRenderer(renderer);
                pt->setElementId(name);
                pt->setParentItem(graph);
                rxNodes.append(pt);
            }
        }

        scene->addItem(graph);

        txSpeed = new QGraphicsTextItem();
        txSpeed->setDefaultTextColor(Qt::white);
        txSpeed->setFont(QFont("Helvetica",22,2));
        txSpeed->setParentItem(graph);
        scene->addItem(txSpeed);

        rxSpeed = new QGraphicsTextItem();
        rxSpeed->setDefaultTextColor(Qt::white);
        rxSpeed->setFont(QFont("Helvetica",22,2));
        rxSpeed->setParentItem(graph);
        scene->addItem(rxSpeed);

        scene->setSceneRect(graph->boundingRect());
        setScene(scene);
    }

    connected = false;
    txValue = 0.0;
    rxValue = 0.0;

    setMin(0.0);
    setMax(1200.0);

    showTelemetry();
}
void OutputCalibrationPage::setupVehicleItems()
{
    m_vehicleItems.clear();
    m_arrowsItems.clear();
    m_vehicleBoundsItem = new QGraphicsSvgItem();
    m_vehicleBoundsItem->setSharedRenderer(m_vehicleRenderer);
    m_vehicleBoundsItem->setElementId(m_vehicleElementIds[0]);
    m_vehicleBoundsItem->setZValue(-1);
    m_vehicleBoundsItem->setOpacity(0);
    m_vehicleScene->addItem(m_vehicleBoundsItem);

    QRectF parentBounds = m_vehicleRenderer->boundsOnElement(m_vehicleElementIds[0]);

    for (int i = 1; i < m_vehicleElementIds.size(); i++) {
        QGraphicsSvgItem *item = new QGraphicsSvgItem();
        item->setSharedRenderer(m_vehicleRenderer);
        item->setElementId(m_vehicleElementIds[i]);
        item->setZValue(i);
        item->setOpacity(1.0);

        QRectF itemBounds = m_vehicleRenderer->boundsOnElement(m_vehicleElementIds[i]);
        item->setPos(itemBounds.x() - parentBounds.x(), itemBounds.y() - parentBounds.y());

        m_vehicleScene->addItem(item);
        m_vehicleItems << item;

        bool addArrows = false;

        if ((m_vehicleElementIds[i].contains("left")) || (m_vehicleElementIds[i].contains("right"))
            || (m_vehicleElementIds[i].contains("elevator")) || (m_vehicleElementIds[i].contains("rudder"))
            || (m_vehicleElementIds[i].contains("steering")) || (m_vehicleElementIds[i] == "singleaileron-aileron")) {
            addArrows = true;
        }

        if (addArrows) {
            QString arrowUp   = "-up"; // right if rudder / steering
            QString arrowDown = "-down"; // left

            QGraphicsSvgItem *itemUp = new QGraphicsSvgItem();

            itemUp->setSharedRenderer(m_vehicleRenderer);
            QString elementUp = m_vehicleElementIds[i] + arrowUp;
            itemUp->setElementId(elementUp);
            itemUp->setZValue(i + 10);
            itemUp->setOpacity(0);

            QRectF itemBounds = m_vehicleRenderer->boundsOnElement(elementUp);
            itemUp->setPos(itemBounds.x() - parentBounds.x(), itemBounds.y() - parentBounds.y());
            m_vehicleScene->addItem(itemUp);

            m_arrowsItems << itemUp;

            QGraphicsSvgItem *itemDown = new QGraphicsSvgItem();
            itemDown->setSharedRenderer(m_vehicleRenderer);
            QString elementDown = m_vehicleElementIds[i] + arrowDown;
            itemDown->setElementId(elementDown);
            itemDown->setZValue(i + 10);
            itemDown->setOpacity(0);

            itemBounds = m_vehicleRenderer->boundsOnElement(elementDown);
            itemDown->setPos(itemBounds.x() - parentBounds.x(), itemBounds.y() - parentBounds.y());
            m_vehicleScene->addItem(itemDown);

            m_arrowsItems << itemDown;
        }
    }
}