Example #1
0
QRectF Visualizer::putWord(QString word, float x, float y, bool isOnTop, int pos, QMap<int, QVector<int> > map) {
    QGraphicsTextItem *wordItem = new QGraphicsTextItem(QString(word));
    if(selWordRef.isActive()) {
        if(selWordRef.isOnTop() == isOnTop) {
            if(selWordRef.getPos() == pos) {
                wordItem->setDefaultTextColor(QColor("red"));
            }
        } else {
            QMapIterator<int, QVector<int> > i(map);
            while(i.hasNext()) {
                i.next();
                qDebug() << i.key() << " --- " << selWordRef.getPos() - 1;
            }
            QVector<int> targets = map[selWordRef.getPos() - 1];
            if(targets.contains(pos)) {
                wordItem->setDefaultTextColor(QColor("orange"));
            }
        }
    }
    wordItem->setFont(font);
    wordItem->setPos(x, y);
    wordItem->setData(IS_ON_TOP_KEY, QVariant(isOnTop));
    wordItem->setData(POS_KEY, QVariant(pos));
    QRectF rect = wordItem->boundingRect();
    scene->addItem(wordItem);
    return rect;
}
Example #2
0
void widgetLandmark::NewRegion()
{
    ui->add_button->setChecked(false);
    // show ellipse and text in graphics view
    QPen pen = QPen(Qt::darkGreen,2);
    pen.setCosmetic(true);
    QRectF rect = _gview->GetCurrentSelectRect()->rect();
    QGraphicsEllipseItem* ellipse = _gview->GetScene()->addEllipse(rect,pen);
    ellipse->setTransform(QTransform::fromTranslate(_gview->GetTranslationX(),_gview->GetTranslationY()), true);


    // create region
    jpsRegion* region = new jpsRegion(_dmanager->GetRegionCounter(),"Region"+QString::number(_dmanager->GetRegionCounter()),
                                      rect.center(),std::fabs(rect.width()/2.0),std::fabs(rect.height()/2.0));


    QGraphicsTextItem* text = _gview->GetScene()->addText(region->GetCaption());
    text->setPos(rect.center().x()+_gview->GetTranslationX(),rect.center().y()+_gview->GetTranslationY());
    //text->setScale(gl_scale_f);
    text->setData(0,_gview->GetScaleF());
    text->setTransform(QTransform::fromScale(_gview->GetScaleF(),-_gview->GetScaleF()),true);

    region->SetTextItem(text);
    region->SetEllipse(ellipse);
    _dmanager->NewRegion(region);

    //show Region in listwidget
    ShowRegions();
}
Example #3
0
void widgetLandmark::SetPosInCMap()
{
    jpsLandmark* landmark = GetCurrentLandmark();

    if (landmark!=nullptr)
    {
        landmark->SetRect(_gview->GetCurrentSelectRect()->rect());
        QString string = "Ellipse: x: "+QString::number(landmark->GetRect().center().x())
                + " y: "+QString::number(landmark->GetRect().center().y())+" rA: "+QString::number(landmark->GetA())
                                         + " rB: "+QString::number(landmark->GetB());
        ui->ellipse_label->setText(string);
        ui->add_button->setChecked(false);

        // show ellipse and text in graphics view
        QPen pen = QPen(Qt::blue,2);
        pen.setCosmetic(true);
        QGraphicsEllipseItem* ellipse = _gview->GetScene()->addEllipse(landmark->GetRect(),pen);
        ellipse->setTransform(QTransform::fromTranslate(_gview->GetTranslationX(),_gview->GetTranslationY()), true);
        QGraphicsTextItem* text = _gview->GetScene()->addText(landmark->GetCaption());
        text->setPos(landmark->GetPos().x()+_gview->GetTranslationX(),landmark->GetPos().y()+_gview->GetTranslationY());
        //text->setScale(gl_scale_f);
        text->setData(0,_gview->GetScaleF());
        text->setTransform(QTransform::fromScale(_gview->GetScaleF(),-_gview->GetScaleF()),true);
        landmark->SetEllipseItem(ellipse);
        landmark->SetTextItem(text);
    }

}
Example #4
0
void PSV_ChartItem::updateForDouble()
{
    QMapIterator<QString,PSV_CurveInfo> iter(m_curveDataMap);
    qreal posY = m_staStartPoint.y();
    qreal posX = m_staStartPoint.x();
    while(iter.hasNext())
    {
        iter.next();
        PSV_CurveInfo curveInfo = iter.value();
        updateAxisRange(curveInfo.m_axisType);
        addCurveItem(curveInfo);
        addEllipseItem(curveInfo);
        if(!isStaHidden())
        {
            QGraphicsTextItem *textItem = new QGraphicsTextItem(this);
            textItem->setData(E_ITEM_TYPE,PSV::staLabelItem);
            textItem->setData(E_CURVE_NAME,curveInfo.m_curveName);
            textItem->setFlags(QGraphicsItem::ItemIsSelectable);
            textItem->installSceneEventFilter(this);

            textItem->setDefaultTextColor(getDefaultColor());
            textItem->setFont(staFont());
            textItem->setHtml(curveInfo.m_staHtmText);
            double textHeight = textItem->boundingRect().height();
            int staMaxHeight = (int)textHeight* 6 / 10;
            textItem->setPos(posX + textItem->boundingRect().height(),posY);

            QPixmap pixmap(staMaxHeight,staMaxHeight);
            pixmap.fill();
            QPen pen(curveInfo.m_lineColor);
            pen.setWidth(3);
            QPainter painter(&pixmap);
            painter.setPen(pen);
            if(!curveInfo.m_isHidden)
            {
                QBrush brush(curveInfo.m_lineColor);
                painter.setBrush(brush);
            }
            painter.drawRect(0, 0, pixmap.height(), pixmap.height());
            QGraphicsPixmapItem* pixmapItem = new QGraphicsPixmapItem(pixmap,this);
            pixmapItem->setPixmap(pixmap);
            pixmapItem->setPos(posX,posY + textHeight * 2 / 10);
            pixmapItem->setData(E_ITEM_TYPE,PSV::staLabelItem);
            pixmapItem->setData(E_CURVE_NAME,curveInfo.m_curveName);
            pixmapItem->setFlags(QGraphicsItem::ItemIsSelectable);
            pixmapItem->installSceneEventFilter(this);
            if(posX + 2 * m_staMaxWidth > m_chartRect.right())
            {
                posX = m_staStartPoint.x();
                posY += textItem->boundingRect().height() + getData(PSV::margin,3).toInt();
            }
            else
            {
                posX += m_staMaxWidth;
            }
        }
    }
    //TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
    //    QGraphicsRectItem *item = new QGraphicsRectItem(m_rect,this);//TTTTTTTTTTTTTTT
    //    item->setPen(QPen(QColor(Qt::red)));//TTTTTTTTTTTTTTT
    //TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
}
Example #5
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;
}