예제 #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;
    }
}
예제 #2
0
void PropertiesEditorDialog::valueChanged(QtProperty *property, const QVariant &value)
{
    if (!m_property_to_id.contains(property))
    {
        return;
    }

    if (!m_canvas)
    {
        return;
    }
    QList<QGraphicsSvgItem *> list = m_canvas->selectedGeneralItems();

    m_canvas->beginUndoMacro(tr("Change Property"));
    if (list.empty())
    {
        // Set the property directly on the canvas:
        m_canvas->setProperty(m_property_to_id[property].toLatin1().constData(), value);
    }
    else
    {
        // Otherwise, set it on the first item in the selection:
        QGraphicsSvgItem *item = list.front();
        item->setProperty(m_property_to_id[property].toLatin1().constData(), value);
    }
}
예제 #3
0
void OutputCalibrationPage::setupVehicleHighlightedPart()
{
    qreal dimOpaque = m_currentWizardIndex == 0 ? 1.0 : 0.3;
    qreal highlightOpaque = 1.0;
    int highlightedIndex  = m_vehicleHighlightElementIndexes[m_currentWizardIndex];

    for (int i = 0; i < m_vehicleItems.size(); i++) {
        QGraphicsSvgItem *item = m_vehicleItems[i];
        item->setOpacity((highlightedIndex == i) ? highlightOpaque : dimOpaque);
    }
}
예제 #4
0
QImage ImageView::renderSvg(const QSize &imageSize) const
{
    QImage image(imageSize, QImage::Format_ARGB32);
    image.fill(Qt::transparent);
    QPainter painter;
    painter.begin(&image);
#ifndef QT_NO_SVG
    QGraphicsSvgItem *svgItem = qgraphicsitem_cast<QGraphicsSvgItem *>(m_imageItem);
    QTC_ASSERT(svgItem, return image);
    svgItem->renderer()->render(&painter, QRectF(QPointF(), QSizeF(imageSize)));
#endif
    painter.end();
    return image;
}
void OutputCalibrationPage::setupVehicleHighlightedPart()
{
    qreal dimOpaque = m_currentWizardIndex == 0 ? 1.0 : 0.3;
    qreal highlightOpaque = 1.0;
    int highlightedIndex  = m_vehicleHighlightElementIndexes[m_currentWizardIndex];

    for (int i = 0; i < m_vehicleItems.size(); i++) {
        QGraphicsSvgItem *item = m_vehicleItems[i];
        if (highlightedIndex == i || (ui->calibrateAllMotors->isChecked() && m_vehicleElementTypes[i + 1] == MOTOR)) {
            item->setOpacity(highlightOpaque);
        } else {
            item->setOpacity(dimOpaque);
        }
    }
}
void OutputCalibrationPage::showElementMovement(bool isUp, qreal value)
{
    QString highlightedItemName = m_vehicleItems[m_currentWizardIndex]->elementId();

    for (int i = 0; i < m_arrowsItems.size(); i++) {
        QString upItemName   = highlightedItemName + "-up";
        QString downItemName = highlightedItemName + "-down";
        if (m_arrowsItems[i]->elementId() == upItemName) {
            QGraphicsSvgItem *itemUp = m_arrowsItems[i];
            itemUp->setOpacity(isUp ? value : 0);
        }
        if (m_arrowsItems[i]->elementId() == downItemName) {
            QGraphicsSvgItem *itemDown = m_arrowsItems[i];
            itemDown->setOpacity(isUp ? 0 : value);
        }
    }
}
예제 #7
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.";
        }
    }
}
예제 #8
0
MainWindow::MainWindow(QWidget *parent)
    : QWidget(parent)
{
    // create a scene with items,
    // use the view to show the scene
    QGraphicsScene *scene = new QGraphicsScene();
    QGraphicsView *gv = new QGraphicsView(this);
    gv->setScene(scene);
    if (gv->scene())
    {
        printf("renc: scene is not null.\n");

        // these two lines are at scene origin pos.
        scene->addLine(0, 0, 100, 0, QPen(Qt::red));
        scene->addLine(0, 0, 0, 100, QPen(Qt::green));

        /*QGraphicsRectItem *rect = */
        scene->addRect(QRectF(0,0,50,50), QPen(Qt::red), QBrush(Qt::green));

        // svg image
        QGraphicsSvgItem *svgItem = new QGraphicsSvgItem(svgFile2);
        scene->addItem((svgItem));
        svgItem->setPos(400, 0);
        bool rValid1 = svgItem->renderer()->isValid();
        printf("--%d--\n", rValid1);

        // QWidget to scene
        QPushButton *btn = new QPushButton("button 1");// at (0,0) by default.
        QGraphicsProxyWidget *btnWidget = scene->addWidget(btn);
        btnWidget->setPos(0, 400);

        //
        {
            SvgPushButton *btn2 = new SvgPushButton(svgFile1);
            QGraphicsProxyWidget *btnWidget2 = scene->addWidget(btn2);
            btnWidget2->setPos(400, 400);
        }
    }
    else
        printf("renc: scene is null.\n");

    //setCentralWidget(gv); setWindowTitle("Demo: graphics view");//QMainWindow
    setStyleSheet("background-color: rgb(100,120,50);");
}
예제 #9
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));
      }
예제 #10
0
void SymbolDataEditor::load(const QString & fileName)
{
    loadSettings();

    doc = QDomDocument("SVG");
    QFile file(fileName);

    if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
        return;

    if (!doc.setContent(&file))
    {
        file.close();
        return;
    }

    file.close();

    //scale viewbox because it is necessary in SvgView::insertSymbol()
    QDomElement svgElement = doc.elementsByTagName("svg").item(0).toElement();
    SvgView::scaleViewBox(svgElement);
    QByteArray scaledFile = doc.toString(0).replace(">\n<tspan", "><tspan").toUtf8();

    QGraphicsSvgItem *symbolItem = new QGraphicsSvgItem();
    symbolItem->setSharedRenderer(new QSvgRenderer(scaledFile));

    QSizeF itemSize = symbolItem->renderer()->defaultSize();
    clear();

    //add changed item to the scene
    scene->setSceneRect(0, 0, itemSize.width() * sceneScale, itemSize.height() * sceneScale);
    symbolItem->setPos(scene->width() / 2 - itemSize.width() / 2.0,
                       scene->height() / 2 - itemSize.height() / 2.0);
    scene->addItem(symbolItem);

    //autoscale graphicsview depending on items and views size
    limitScale(qMax(qreal(width()) / itemSize.width(),
                    qreal(height()) / itemSize.height()) / currentScaleFactor);
    centerOn(symbolItem);
    setDragMode(QGraphicsView::ScrollHandDrag);
}
예제 #11
0
void ImageView::setSVG(QString fileName) {
  image_ = QImage(fileName); // for tracking position and dimensions
  if(image_.isNull()) {
    if(imageItem_) {
      imageItem_->hide();
      imageItem_->setBrush(QBrush());
    }
    scene_->setSceneRect(0, 0, 0, 0);
  }
  else {
    scene_->clear();
    imageItem_ = nullptr;
    isSVG = true;
    QGraphicsSvgItem *svgItem = new QGraphicsSvgItem(fileName);
    scene_->addItem(svgItem);
    scene_->setSceneRect(svgItem->boundingRect());
  }

  if(autoZoomFit_)
    zoomFit();
  queueGenerateCache(); // deletes the cache timer in this case
}
예제 #12
0
QGraphicsSvgItem* GraphicsWorkflow::addAllSvgItems( const QString& name,  const QMap<int,QString>& cmds) {


     QGraphicsSvgItem *myitem = NULL;

     if ( myitem == NULL  ) {

         QByteArray myxml = SafetYAWL::readStringFromFile(name);
          QMap<QString,QPair<QPointF,QString> > ids = getXmlIds(myxml);

          QString curtitle = SafetYAWL::getConf()["GeneralOptions/currentflowtitle"];
         // qDebug(".......curtitle: |%s|", qPrintable(curtitle));
          QGraphicsTextItem* titleitem = NULL;
          QString includetitle = SafetYAWL::getConf()["GeneralOptions/currentflowtitle.include"];
          qDebug("includetitle: %s", qPrintable(includetitle));

          if ( includetitle.compare("on") == 0 ) {
            titleitem = NULL;
            addInfoGraphText(ids,curtitle,titleitem);
            if ( titleitem ) {
                _items.append(titleitem);
            }

          }
          QString includedate = SafetYAWL::getConf()["Graphs/infotext.include"];

          if ( includedate.compare("on") == 0 ) {
              SYD << tr("QGraphicsTextItem* myitem = addInfoGraphDateText(ids);");
              QGraphicsTextItem* myitem = addInfoGraphDateText(ids);
              if ( myitem) {
                  _items.append(myitem);
              }

          }


          QMap<QString,QString>  svgs = extractSvgElements(myxml);
            for(int i =0; i < svgs.keys().count(); i++) {
                QString key = svgs.keys().at(i);
                QString svg = svgs[ key];
                GraphicsSvgItemLive localitem(svg);
                myitem = localitem.loadSvgItem();
                if ( MainWindow::configurator->getWorkflow() != NULL ) {
                    QString info = MainWindow::configurator->getWorkflow()->infoModeMap()[ids[key].second];
                    if (key.startsWith("node")) {
                        myitem->setToolTip(tr("%1").arg(info));
                    }
                }
                myitem->setFlags(QGraphicsItem::ItemClipsToShape| QGraphicsItem::ItemIsMovable);
                myitem->setCacheMode(QGraphicsItem::NoCache);
                myitem->setZValue(0);                

                scene()->addItem(myitem);

                myitem->setPos(ids[key].first);
                _items.append(myitem);
            }

      }
     else {
          //QSvgRenderer *renderer = new QSvgRenderer(name);
     }
     qDebug("...addAllSvgItems..........(6)...");
     SafetYAWL::streamlog << SafetLog::Action
             << tr("Gráfico de \"Flujo de Trabajo\" generado correctamente...ok!");
     doGroup();
     SafetYAWL::streamlog << SafetLog::Action
             << tr("Agrupando Nodos...ok!");

     return myitem;
}
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);
}
예제 #14
0
int SvgView::renderText(const QStringRef &text)
{
    scene->clear();

    QRectF currentMarginsRect;

    if (changeMargins)
        currentMarginsRect = QRectF(QPointF(sheetRect.topRight().x() - marginsRect.topRight().x(),
                                            marginsRect.topLeft().y()),
                                    QPointF(sheetRect.bottomRight().x() - marginsRect.bottomLeft().x(),
                                            marginsRect.bottomRight().y()));
    else
        currentMarginsRect = marginsRect;

    scene->addRect(sheetRect);
    scene->addRect(currentMarginsRect, QPen(Qt::darkGray));

    QPointF cursor(currentMarginsRect.x(), currentMarginsRect.y());
    int endOfSheet = 0;

    for (QChar symbol : text)
    {
        qreal letterWidth = fontSize * dpmm / 4, letterHeight = fontSize * dpmm;

        //don't try to go beyond the right margin
        if (cursor.x() > (currentMarginsRect.x() + currentMarginsRect.width() - letterWidth))
        {
            if (symbol.isSpace())   //ignore whitespace-symbols at the end of the current line
                continue;
            cursor += QPointF(currentMarginsRect.x() - cursor.x(), letterHeight + lineSpacing * dpmm);
        }

        //stop rendering when you reach the end of sheet
        if (cursor.y() > currentMarginsRect.bottomRight().y() - letterHeight)
            return endOfSheet;

        if (symbol.isSpace())
        {
            switch (symbol.toLatin1())
            {
            case '\t':
                cursor += QPointF(letterWidth * spacesInTab, 0.0);
                endOfSheet++;
                continue;

            case '\n':
                cursor += QPointF(currentMarginsRect.x() - cursor.x(), letterHeight + lineSpacing * dpmm);
                endOfSheet++;
                continue;

            default:
                cursor += QPointF(letterWidth, 0.0);
                endOfSheet++;
                continue;
            }
        }

        if (!font.contains(symbol))
        {
            cursor += QPointF(letterWidth, 0.0);
            endOfSheet++;
            continue;
        }


        QGraphicsSvgItem *letter = new QGraphicsSvgItem(font.values(symbol).at(qrand() % font.values(symbol).size()));
        if (useCustomFontColor)
        {
            QGraphicsColorizeEffect *colorEffect = new QGraphicsColorizeEffect();
            colorEffect->setColor(fontColor);
            letter->setGraphicsEffect(colorEffect);
        }

        letter->setScale(letterHeight / letter->boundingRect().height());
        letterWidth = letter->boundingRect().width() * letter->scale() + letterSpacing * dpmm;
        letter->setPos(cursor);
        cursor += QPointF(letterWidth, 0.0);

        scene->addItem(letter);
        endOfSheet++;
    }

    return endOfSheet;
}
예제 #15
0
void loadFromXml( mlt_producer producer, QGraphicsScene *scene, const char *templateXml, const char *templateText )
{
	scene->clear();
	mlt_properties producer_props = MLT_PRODUCER_PROPERTIES( producer );
	QDomDocument doc;
	QString data = QString::fromUtf8(templateXml);
	QString replacementText = QString::fromUtf8(templateText);
	doc.setContent(data);
	QDomElement title = doc.documentElement();

	// Check for invalid title
	if ( title.isNull() || title.tagName() != "kdenlivetitle" ) return;
	
	// Check title locale
	if ( title.hasAttribute( "LC_NUMERIC" ) ) {
	    QString locale = title.attribute( "LC_NUMERIC" );
	    QLocale::setDefault( locale );
	}
	
        int originalWidth;
        int originalHeight;
	if ( title.hasAttribute("width") ) {
            originalWidth = title.attribute("width").toInt();
            originalHeight = title.attribute("height").toInt();
            scene->setSceneRect(0, 0, originalWidth, originalHeight);
        }
        else {
            originalWidth = scene->sceneRect().width();
            originalHeight = scene->sceneRect().height();
        }
        if ( title.hasAttribute( "out" ) ) {
            mlt_properties_set_position( producer_props, "_animation_out", title.attribute( "out" ).toDouble() );
        }
        else {
            mlt_properties_set_position( producer_props, "_animation_out", mlt_producer_get_out( producer ) );
        }
        
	mlt_properties_set_int( producer_props, "_original_width", originalWidth );
	mlt_properties_set_int( producer_props, "_original_height", originalHeight );

	QDomNode node;
	QDomNodeList items = title.elementsByTagName("item");
        for ( int i = 0; i < items.count(); i++ )
	{
		QGraphicsItem *gitem = NULL;
		node = items.item( i );
		QDomNamedNodeMap nodeAttributes = node.attributes();
		int zValue = nodeAttributes.namedItem( "z-index" ).nodeValue().toInt();
		if ( zValue > -1000 )
		{
			if ( nodeAttributes.namedItem( "type" ).nodeValue() == "QGraphicsTextItem" )
			{
				QDomNamedNodeMap txtProperties = node.namedItem( "content" ).attributes();
				QFont font( txtProperties.namedItem( "font" ).nodeValue() );
				QDomNode propsNode = txtProperties.namedItem( "font-bold" );
				if ( !propsNode.isNull() )
				{
					// Old: Bold/Not bold.
					font.setBold( propsNode.nodeValue().toInt() );
				}
				else
				{
					// New: Font weight (QFont::)
					font.setWeight( txtProperties.namedItem( "font-weight" ).nodeValue().toInt() );
				}
				font.setItalic( txtProperties.namedItem( "font-italic" ).nodeValue().toInt() );
				font.setUnderline( txtProperties.namedItem( "font-underline" ).nodeValue().toInt() );
				// Older Kdenlive version did not store pixel size but point size
				if ( txtProperties.namedItem( "font-pixel-size" ).isNull() )
				{
					QFont f2;
					f2.setPointSize( txtProperties.namedItem( "font-size" ).nodeValue().toInt() );
					font.setPixelSize( QFontInfo( f2 ).pixelSize() );
				}
				else
					font.setPixelSize( txtProperties.namedItem( "font-pixel-size" ).nodeValue().toInt() );
				QColor col( stringToColor( txtProperties.namedItem( "font-color" ).nodeValue() ) );
				QString text = node.namedItem( "content" ).firstChild().nodeValue();
				if ( !replacementText.isEmpty() )
				{
					text = text.replace( "%s", replacementText );
				}
				QGraphicsTextItem *txt = scene->addText(text, font);
				if (txtProperties.namedItem("font-outline").nodeValue().toDouble()>0.0){
					QTextDocument *doc = txt->document();
					// Make sure some that the text item does not request refresh by itself
					doc->blockSignals(true);
					QTextCursor cursor(doc);
					cursor.select(QTextCursor::Document);
					QTextCharFormat format;
					format.setTextOutline(
							QPen(QColor( stringToColor( txtProperties.namedItem( "font-outline-color" ).nodeValue() ) ),
							txtProperties.namedItem("font-outline").nodeValue().toDouble(),
							Qt::SolidLine,Qt::RoundCap,Qt::RoundJoin)
					);
					format.setForeground(QBrush(col));

					cursor.mergeCharFormat(format);
				} else {
					txt->setDefaultTextColor( col );
				}
				
				// Effects
				if (!txtProperties.namedItem( "typewriter" ).isNull()) {
					// typewriter effect
					mlt_properties_set_int( producer_props, "_animated", 1 );
					QStringList effetData = QStringList() << "typewriter" << text << txtProperties.namedItem( "typewriter" ).nodeValue();
					txt->setData(0, effetData);
					if ( !txtProperties.namedItem( "textwidth" ).isNull() )
						txt->setData( 1, txtProperties.namedItem( "textwidth" ).nodeValue() );
				}
				
				if ( txtProperties.namedItem( "alignment" ).isNull() == false )
				{
					txt->setTextWidth( txt->boundingRect().width() );
					QTextOption opt = txt->document()->defaultTextOption ();
					opt.setAlignment(( Qt::Alignment ) txtProperties.namedItem( "alignment" ).nodeValue().toInt() );
					txt->document()->setDefaultTextOption (opt);
				}
					if ( !txtProperties.namedItem( "kdenlive-axis-x-inverted" ).isNull() )
				{
					//txt->setData(OriginXLeft, txtProperties.namedItem("kdenlive-axis-x-inverted").nodeValue().toInt());
				}
				if ( !txtProperties.namedItem( "kdenlive-axis-y-inverted" ).isNull() )
				{
					//txt->setData(OriginYTop, txtProperties.namedItem("kdenlive-axis-y-inverted").nodeValue().toInt());
				}
					gitem = txt;
			}
			else if ( nodeAttributes.namedItem( "type" ).nodeValue() == "QGraphicsRectItem" )
			{
				QString rect = node.namedItem( "content" ).attributes().namedItem( "rect" ).nodeValue();
				QString br_str = node.namedItem( "content" ).attributes().namedItem( "brushcolor" ).nodeValue();
				QString pen_str = node.namedItem( "content" ).attributes().namedItem( "pencolor" ).nodeValue();
				double penwidth = node.namedItem( "content" ).attributes().namedItem( "penwidth") .nodeValue().toDouble();
				QGraphicsRectItem *rec = scene->addRect( stringToRect( rect ), QPen( QBrush( stringToColor( pen_str ) ), penwidth, Qt::SolidLine, Qt::SquareCap, Qt::RoundJoin ), QBrush( stringToColor( br_str ) ) );
				gitem = rec;
			}
			else if ( nodeAttributes.namedItem( "type" ).nodeValue() == "QGraphicsPixmapItem" )
			{
				const QString url = node.namedItem( "content" ).attributes().namedItem( "url" ).nodeValue();
				const QString base64 = items.item(i).namedItem("content").attributes().namedItem("base64").nodeValue();
				QImage img;
				if (base64.isEmpty()){
					img.load(url);
				}else{
					img.loadFromData(QByteArray::fromBase64(base64.toAscii()));
				}
				ImageItem *rec = new ImageItem(img);
				scene->addItem( rec );
				gitem = rec;
			}
			else if ( nodeAttributes.namedItem( "type" ).nodeValue() == "QGraphicsSvgItem" )
			{
				QString url = items.item(i).namedItem("content").attributes().namedItem("url").nodeValue();
				QString base64 = items.item(i).namedItem("content").attributes().namedItem("base64").nodeValue();
				QGraphicsSvgItem *rec = NULL;
				if (base64.isEmpty()){
					rec = new QGraphicsSvgItem(url);
				}else{
					rec = new QGraphicsSvgItem();
					QSvgRenderer *renderer= new QSvgRenderer(QByteArray::fromBase64(base64.toAscii()), rec );
					rec->setSharedRenderer(renderer);
				}
				if (rec){
					scene->addItem(rec);
					gitem = rec;
				}
			}
		}
		//pos and transform
		if ( gitem )
		{
			QPointF p( node.namedItem( "position" ).attributes().namedItem( "x" ).nodeValue().toDouble(),
			           node.namedItem( "position" ).attributes().namedItem( "y" ).nodeValue().toDouble() );
			gitem->setPos( p );
			gitem->setTransform( stringToTransform( node.namedItem( "position" ).firstChild().firstChild().nodeValue() ) );
			int zValue = nodeAttributes.namedItem( "z-index" ).nodeValue().toInt();
			gitem->setZValue( zValue );

#if QT_VERSION >= 0x040600
			// effects
			QDomNode eff = items.item(i).namedItem("effect");
			if (!eff.isNull()) {
				QDomElement e = eff.toElement();
				if (e.attribute("type") == "blur") {
					QGraphicsBlurEffect *blur = new QGraphicsBlurEffect();
					blur->setBlurRadius(e.attribute("blurradius").toInt());
					gitem->setGraphicsEffect(blur);
				}
				else if (e.attribute("type") == "shadow") {
					QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect();
					shadow->setBlurRadius(e.attribute("blurradius").toInt());
					shadow->setOffset(e.attribute("xoffset").toInt(), e.attribute("yoffset").toInt());
					gitem->setGraphicsEffect(shadow);
				}
			}
#endif
		}
	}

	QDomNode n = title.firstChildElement("background");
	if (!n.isNull()) {
		QColor color = QColor( stringToColor( n.attributes().namedItem( "color" ).nodeValue() ) );
                if (color.alpha() > 0) {
                        QGraphicsRectItem *rec = scene->addRect(0, 0, scene->width(), scene->height() , QPen( Qt::NoPen ), QBrush( color ) );
                        rec->setZValue(-1100);
                }
	  
	}

	QString startRect;
	n = title.firstChildElement( "startviewport" );
        // Check if node exists, if it has an x attribute, it is an old version title, don't use viewport
	if (!n.isNull() && !n.toElement().hasAttribute("x"))
	{
		startRect = n.attributes().namedItem( "rect" ).nodeValue();
	}
	n = title.firstChildElement( "endviewport" );
        // Check if node exists, if it has an x attribute, it is an old version title, don't use viewport
	if (!n.isNull() && !n.toElement().hasAttribute("x"))
	{
		QString rect = n.attributes().namedItem( "rect" ).nodeValue();
		if (startRect != rect)
			mlt_properties_set( producer_props, "_endrect", rect.toUtf8().data() );
	}
	if (!startRect.isEmpty()) {
	  	mlt_properties_set( producer_props, "_startrect", startRect.toUtf8().data() );
	}
	return;
}
예제 #16
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();
}
QGraphicsSvgItem *
dmz::QtPluginCanvasObjectBasic::_create_svg_item (
      ObjectStruct &os,
      QGraphicsItem *parent,
      const Config &Data,
      HashTableStringTemplate<String> &table) {

   QGraphicsSvgItem *item (new QGraphicsSvgItem (parent));

   Boolean center (True);

   if (_file_request (item, Data, table)) {

      ConfigIterator it;
      Config cd;

      while (Data.get_next_config (it, cd)) {

         const String DataName (cd.get_name ().to_lower ());

         if (DataName == "translate") {

            Vector vec (config_to_vector (cd));
            String itemName = config_to_string ("name", cd);

            if (itemName) {

               QGraphicsItem *img = os.itemTable.lookup (itemName);
               if (img) {

                  QRectF rect = img->boundingRect ();
                  Vector rectVec;
                  if (vec.get_x () == 0) { rectVec.set_x (0); }
                  else if (vec.get_x() > 0) { rectVec.set_x (rect.center ().x ()); }
                  else { rectVec.set_x (-rect.center ().x ()); }

                  if (vec.get_y () == 0) { rectVec.set_y (0); }
                  else if (vec.get_y () > 0) { rectVec.set_y (rect.center ().y ()); }
                  else { rectVec.set_y (-rect.center ().y ()); }

                  QPointF center = item->boundingRect ().center ();
                  rectVec.set_x (rectVec.get_x () - center.x ());
                  rectVec.set_y (rectVec.get_y () - center.y ());
                  vec += rectVec;
                  item->setPos (vec.get_x (), vec.get_y ());
               }
            }
            else { item->translate (vec.get_x (), vec.get_y ()); }

            center = False;
         }
         else if (DataName == "scale") {

            Vector vec (config_to_vector (cd));

            if (vec.get_x () && vec.get_y ()) {

               item->scale (vec.get_x (), vec.get_y ());
            }
         }
      }
   }
   else { delete item; item = 0; }

   if (item && center) {

      QRectF bound = item->boundingRect ();

      item->translate (bound.width () * -0.5f, bound.height () * -0.5f);
   }

   return item;
}
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;
        }
    }
}
dmz::Boolean
dmz::QtPluginCanvasObjectBasic::_file_request (
   QGraphicsItem *item,
   const Config &Data,
   HashTableStringTemplate<String> &table) {

   Boolean result (False);
   String fileName = config_to_string ("resource", Data);
   String *repName = table.lookup (fileName);

   const String Resource (repName ? *repName : fileName);

   if (Resource && item) {

      const String File = _rc.find_file (Resource);

      if (File) {

         QGraphicsPixmapItem *pixmapItem (
            qgraphicsitem_cast<QGraphicsPixmapItem *> (item));

         if (pixmapItem) {

            QPixmap pixmap;

            //_log.info << "Loading pixmap file: " << LocalFilePath << endl;

            if (pixmap.load (File.get_buffer ())) {

               pixmapItem->setPixmap (pixmap);
               result = True;
            }
            else {

               _log.error << "Pixmap failed to load: " << File << endl;
            }
         }

         QGraphicsSvgItem *svgItem (qgraphicsitem_cast<QGraphicsSvgItem *> (item));

         if (svgItem) {

            QSvgRenderer *renderer (
               _svgRendererTable.lookup (File));

            if (!renderer) {

               renderer = new QSvgRenderer ();

               //_log.info << "Loading SVG file: " << LocalFilePath << endl;

               if (renderer->load (QString (File.get_buffer ()))) {

                  _svgRendererTable.store (File, renderer);
               }
               else {

                  _log.error << "SVG failed to load: " << File << endl;
                  delete renderer; renderer = 0;
               }
            }

            if (renderer) {

               svgItem->setSharedRenderer (renderer);
               result = True;
            }
         }
      }
      else {

         _log.error << "Resource not found: " << Resource << endl;
      }
   }
   else {

      _log.error << "Unable to process unknown resource." << endl;
   }

   return result;
}
예제 #20
-1
void QStarPawn::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
                      QWidget *widget)
{
    QGraphicsEllipseItem::paint(painter, option, widget);

    if (_isStarOn) {
        QSvgRenderer *renderer = new QSvgRenderer(QString(":/resources/star.svg"));
        QGraphicsSvgItem *star = new QGraphicsSvgItem();
        star->setSharedRenderer(renderer);
        renderer->render(painter, boundingRect());
    }
}