コード例 #1
0
SpriteScene::SpriteScene(QObject *parent) : QGraphicsScene(parent)
{
    QGraphicsItem * dragon;
    QGraphicsItem * Frame;
    QGraphicsItem * Square;
    QList<QString > tmp;
    QFileInfo ourFile(currentFile);
    QString imgFileM;
    QPixmap sprite, mask;
    croc = new QGraphicsPixmapItem;
    sizer = new QGraphicsRectItem;

    mCurrentFrameX = 0;
    mCurrentFrameY = 0;

    x=0; y=0, dir=1;
    mPos = QPoint(0,0);

    sprite = QPixmap(currentFile);

    tmp = ourFile.fileName().split(".", QString::SkipEmptyParts);
    if(tmp.size()==2)
        imgFileM = tmp[0] + "m." + tmp[1];
    else
        imgFileM = "";
    mask = QPixmap( ourFile.absoluteDir().path() + "/" + imgFileM );

    sprite.setMask(mask);
    mSpriteImage = QPixmap(sprite);

    draw();

    Frame = addRect(0,0,100,100, QPen(Qt::gray, 1), Qt::transparent);
    Frame->setZValue(-10);

    croc->setPixmap(QPixmap(currentImage));
    dragon = addPixmap(QPixmap(currentImage));
    croc->setParentItem(dragon);
    dragon->setZValue(0);

    Square = addRect(0,0,0,0, QPen(Qt::NoPen), Qt::transparent);
    sizer->setRect(0,0,100,100);
    sizer->setPen(QPen(Qt::green));
    sizer->setParentItem(Square);
    sizer->setZValue(3);

    //qDebug() << "Scene created";
}
コード例 #2
0
ファイル: ModulePortGI.cpp プロジェクト: mhaehnel/q2d
ModulePortGI::ModulePortGI(
    QPointF position,
    DocumentEntry* relatedEntry,
    model::enums::PortDirection direction)
    : ParentSchematicElement(position, relatedEntry) {

    m_moduleDirection = direction;

    QGraphicsItem* decal;
    switch (direction) {
    case model::enums::PortDirection::OUT :
        decal = factories::GIFactory::createModulePortDecalOut();
        break;
    case model::enums::PortDirection::IN :
        decal = factories::GIFactory::createModulePortDecalIn();
        break;
    default : // should not happen
        Q_ASSERT(false);
    }
    decal->setZValue(-1);
    this->addActual(decal);
    this->setFlag(QGraphicsItem::ItemIsMovable);
    this->setFlag(QGraphicsItem::ItemIsSelectable);
    this->setFlag(QGraphicsItem::ItemSendsScenePositionChanges); // needed to detect movement
}
コード例 #3
0
ファイル: MapView.cpp プロジェクト: BenjBoug/Map-Editor
/**
 * @brief MapView::blitTile
 * @param i
 * @param j
 * @param bl
 * @param layer
 * @param opacity
 */
void MapView::blitTile(int i, int j, int bl, int layer, float opacity)
{
    QPixmap tile = chipset.copy((bl%(chipset.width()/BLOCSIZE))*BLOCSIZE,(bl/(chipset.width()/BLOCSIZE))*BLOCSIZE,BLOCSIZE,BLOCSIZE);
    QGraphicsItem * item = this->addPixmap(tile);
    item->setZValue(layer);
    item->setOpacity(opacity);
    item->setPos(i*BLOCSIZE,j*BLOCSIZE);
}
コード例 #4
0
void TilesetEditor::drawGrid() {
    int vert = 7;
    if (tiles.size() < 6) vert = tiles.size()+1;
    if (tiles.size() != 0) {
        for (int i=0; i<vert; i++) {
            int h = (tiles.size()-i)/6 + 1;
            if (i==0 && tiles.size()%6 == 0) h--;
            QGraphicsItem *item = m_scene->addLine(i*oldTilesWidth, 0, i*oldTilesWidth, h*oldTilesHeight, QPen(QColor(0xFF888888)));
            item->setZValue(9);
        }
        int h = (tiles.size()-1)/6 + 1;
        for (int i=0; i<h+1; i++) {
            int w=6;
            if ((i == h || tiles.size() < 6) && tiles.size()%6 != 0) w = tiles.size()%6;
            QGraphicsItem *item = m_scene->addLine(0, i*oldTilesHeight, w*oldTilesWidth, i*oldTilesHeight, QPen(QColor(0xFF888888)));
            item->setZValue(9);
        }
    }
}
コード例 #5
0
ファイル: mainwindow.cpp プロジェクト: Nobu19800/RMC
void MainWindow::sendToBack()
{
    if (scene->selectedItems().isEmpty())
        return;

    QGraphicsItem *selectedItem = scene->selectedItems().first();
    QList<QGraphicsItem *> overlapItems = selectedItem->collidingItems();

    qreal zValue = 0;
    foreach (QGraphicsItem *item, overlapItems) {
        if (item->zValue() <= zValue &&
            item->type() == JointItem::Type)
            zValue = item->zValue() - 0.1;
    }
    selectedItem->setZValue(zValue);
}
コード例 #6
0
void GInstructionView::UpdateView()
{
	if(!m_pInstruction)
		return;
//	m_pInstruction->UpdateGraphicsItem();
	QGraphicsItem* pItemInstruction = &m_pInstruction->m_GraphicsItem;
	// is the item already displayed in a scene?
	m_pInsScene = pItemInstruction->scene();
	// if so, we display this scene, centered on the item. An item can only be in ONE scene at a time
	// else we make a scene and display the item.
	if(!m_pInsScene) {
		m_pInsScene = new QGraphicsScene(m_pInstruction);
		m_pInsScene->addItem(pItemInstruction);
	}
	setScene(m_pInsScene);
	pItemInstruction->setZValue(0.0);
	FitInstructionInView();
}
コード例 #7
0
ファイル: mapscene.cpp プロジェクト: naiello/tiled
void MapScene::refreshScene()
{
    mLayerItems.clear();
    mObjectItems.clear();

    removeItem(mDarkRectangle);
    clear();
    addItem(mDarkRectangle);

    if (!mMapDocument) {
        setSceneRect(QRectF());
        return;
    }

    updateSceneRect();

    const Map *map = mMapDocument->map();
    mLayerItems.resize(map->layerCount());

    if (map->backgroundColor().isValid())
        setBackgroundBrush(map->backgroundColor());
    else
        setBackgroundBrush(mDefaultBackgroundColor);

    int layerIndex = 0;
    for (Layer *layer : map->layers()) {
        QGraphicsItem *layerItem = createLayerItem(layer);
        layerItem->setZValue(layerIndex);
        addItem(layerItem);
        mLayerItems[layerIndex] = layerItem;
        ++layerIndex;
    }

    TileSelectionItem *tileSelectionItem = new TileSelectionItem(mMapDocument);
    tileSelectionItem->setZValue(10000 - 2);
    addItem(tileSelectionItem);

    mObjectSelectionItem = new ObjectSelectionItem(mMapDocument);
    mObjectSelectionItem->setZValue(10000 - 1);
    addItem(mObjectSelectionItem);

    updateCurrentLayerHighlight();
}
コード例 #8
0
ファイル: QGILine.cpp プロジェクト: Mr-Kumar-Abhishek/qboard
void QGILineNode::mousePressEvent(QGraphicsSceneMouseEvent *ev)
{
	this->m_active = true;
	if( (ev->buttons() & Qt::LeftButton) )
	{
		QGraphicsItem * p = this->parentItem();
		if( p )
		{
			ev->accept();
			qreal zV = qboard::nextZLevel(p);
			if( zV > this->zValue() )
			{
				p->setZValue(zV);
			}
		}
	}
	this->QGraphicsItem::mousePressEvent(ev);
	this->update();
}
コード例 #9
0
ファイル: desktopview.cpp プロジェクト: varuna/plexydesk
    void DesktopView::setTopMostWidget(const QPoint &pt)
    {
        int i = 0;
        QGraphicsItem *clickedItem = scene()->itemAt(pt);
        if (clickedItem == 0)
            return;

        QList<QGraphicsItem *> itemsList = scene()->items();
        qStableSort(itemsList.begin(), itemsList.end(), getLessThanWidget);

        clickedItem->setZValue(itemsList.size());

        foreach(QGraphicsItem* item, itemsList) {
            if (item == clickedItem)
                continue;

            item->setZValue(i);
            i++;
        }

        clickedItem->update();
    }
コード例 #10
0
ファイル: lvl_section.cpp プロジェクト: nexia29/PlatGEnWohl
//  ////////////////////////////Drawing the inactive intersection space////////////////////////////////////
void LvlScene::drawSpace()
{
    const long padding = 400000;

    WriteToLog(QtDebugMsg, QString("Draw intersection space-> Find and remove current"));
    foreach(QGraphicsItem * spaceItem, items())
    {
        if(spaceItem->data(0).toString()=="Space")
        {
            removeItem(spaceItem);
            delete spaceItem;
            continue;
        }
        if(spaceItem->data(0).toString()=="SectionBorder")
        {
            removeItem(spaceItem);
            delete spaceItem;
            continue;
        }
    }

    QPolygon bigSpace;
    QGraphicsItem * item;
    QGraphicsItem * item2;
    QVector<QPoint > drawing;

    int i, j;
    long l, r, t, b;
    //x, y, h, w;

    WriteToLog(QtDebugMsg, QString("Draw intersection space-> Find minimal"));
    j=-1;
    do
    {
        j++;
        l = LvlData->sections[j].size_left;
        r = LvlData->sections[j].size_right;
        t = LvlData->sections[j].size_top;
        b = LvlData->sections[j].size_bottom;
    }
    while(
        ((LvlData->sections[j].size_left==0) &&
         (LvlData->sections[j].size_right==0) &&
         (LvlData->sections[j].size_top==0) &&
         (LvlData->sections[j].size_bottom==0)) && (j<LvlData->sections.size())
    );

    for(i=0; i<LvlData->sections.size(); i++)
    {

        if(
            (LvlData->sections[i].size_left==0) &&
            (LvlData->sections[i].size_right==0) &&
            (LvlData->sections[i].size_top==0) &&
            (LvlData->sections[i].size_bottom==0))
            continue;

        if(LvlData->sections[i].size_left < l)
            l = LvlData->sections[i].size_left;
        if(LvlData->sections[i].size_right > r)
            r = LvlData->sections[i].size_right;
        if(LvlData->sections[i].size_top < t)
            t = LvlData->sections[i].size_top;
        if(LvlData->sections[i].size_bottom > b)
            b = LvlData->sections[i].size_bottom;
    }

    WriteToLog(QtDebugMsg, QString("Draw intersection space-> Draw polygon"));

    drawing.clear();
    drawing.push_back(QPoint(l-padding, t-padding));
    drawing.push_back(QPoint(r+padding, t-padding));
    drawing.push_back(QPoint(r+padding, b+padding));
    drawing.push_back(QPoint(l-padding, b+padding));
    drawing.push_back(QPoint(l-padding, t+padding));

    bigSpace = QPolygon(drawing);


    l = LvlData->sections[LvlData->CurSection].size_left;
    r = LvlData->sections[LvlData->CurSection].size_right;
    t = LvlData->sections[LvlData->CurSection].size_top;
    b = LvlData->sections[LvlData->CurSection].size_bottom;


    WriteToLog(QtDebugMsg, QString("Draw intersection space-> Draw editing hole"));
    drawing.clear();
    drawing.push_back(QPoint(l-1, t-1));
    drawing.push_back(QPoint(r+1, t-1));
    drawing.push_back(QPoint(r+1, b+1));
    drawing.push_back(QPoint(l-1, b+1));
    drawing.push_back(QPoint(l-1, t-1));

    bigSpace = bigSpace.subtracted(QPolygon(drawing));

    WriteToLog(QtDebugMsg, QString("Draw intersection space-> add polygon to Item"));
    item = addPolygon(bigSpace, QPen(Qt::NoPen), QBrush(Qt::black));//Add inactive space
    item2 = addPolygon(QPolygon(drawing), QPen(Qt::red, 2));
    item->setZValue(spaceZ1);
    item2->setZValue(spaceZ2);
    item->setOpacity(qreal(0.4));
    item->setData(0, "Space");
    item2->setData(0, "SectionBorder");

}
コード例 #11
0
ファイル: lvl_section.cpp プロジェクト: nexia29/PlatGEnWohl
// ////////////////////////////////////Draw BG image/////////////////////////////////////////////////
void LvlScene::DrawBG(int x, int y, int w, int h, int sctID,
                      QPixmap &srcimg, QPixmap &srcimg2, obj_BG &bgsetup)
{
    /* Old Algorith */
    //QPixmap BackImg;
    //QPainter * BGPaint;
    //QPixmap img;
    int si_attach, attach;

    /* New Algorith */
    QGraphicsItem * item;
    //QGraphicsRectItem * itemR=NULL;

    QColor FillColor; //Fill undrawed space with color

    long sctW,//Section Width
         sctH,//Section Height
         R1W, //Img Width  (Row1)
         R1H, //Img Height (Row1)
         R1Hc=0, //Crop height from bottom
         R1Ho=0, //Offset from top
         R2W, //Img Width  (Row2)
         R2H, //Img Height (Row2)
         R2Hc=0, //Crop height from bottom
         R2Ho=0, //Offset from top
         RectPlus=0,
         toY; //Placing position Y 0 - top

    sctW = (long)fabs(x-w);
    sctH = (long)fabs(y-h);

    WriteToLog(QtDebugMsg, "Draw BG -> Draw BG Image");

    attach = bgsetup.attached;

// ///////////////////SingleRow BG///////////////////////////
    if((bgsetup.type==0)&&(!bgsetup.editing_tiled))
    {
        WriteToLog(QtDebugMsg, "Draw BG -> Style: SingleRow BG");

        R1W = srcimg.width();
        R1H = srcimg.height();

        if(attach==0) // Get Pixel color (0 - bottom, 1 - top)
            FillColor = QColor( srcimg.toImage().pixel(0,0) ); // from top
        else
            FillColor = QColor( srcimg.toImage().pixel(0,(R1H-1)) ); //from bottom

        if(attach==0)
        {   // 0 - bottom
            toY = (sctH>R1H)? sctH-R1H : 0;
            R1Hc = ((R1H>sctH) ? R1H-sctH : 0); //Crop height from bottom
            R1Ho = R1Hc; //Offset from top
            RectPlus=0;
        }
        else
        {   // 1 - top
            toY = 0;
            R1Hc = ((R1H>sctH) ? R1H-sctH : 0); //Crop height from bottom
            R1Ho = 0; //Offset from top
            RectPlus=R1H;
        }

        // /////////////////////Draw row//////////////////

        item = addRect(0, 0, sctW, R1H-R1Hc, Qt::NoPen, QBrush(srcimg.copy(0, R1Ho, R1W, R1H-R1Hc)));
        item->setData(0, QString("BackGround%1").arg(sctID) );
        item->setPos(x, y+toY);
        item->setZValue(bgZ);

        if(R1H < sctH)
        {
            item = addRect(0, 0, sctW, sctH-R1H, Qt::NoPen, QBrush(FillColor));
            item->setData(0, QString("BackGround%1").arg(sctID) );
            item->setPos(x,y+RectPlus);
            item->setZValue(bgZ);
        }

    }
    else

// ///////////////////DoubleRow BG////////////////////////
        if((bgsetup.type==1)&&(!bgsetup.editing_tiled))
        {
            WriteToLog(QtDebugMsg, "Draw BG -> Style: DoubleRow BG");

            si_attach = bgsetup.second_attached; // Second image attach

            R1W = srcimg.width();
            R1H = srcimg.height();

            //Fill empty space
            if((!srcimg2.isNull()) && (si_attach==0))
                FillColor = QColor( srcimg2.toImage().pixel(0,0) );
            else
                FillColor = QColor( srcimg.toImage().pixel(0,0) );

            toY = (sctH>R1H)? sctH-R1H : 0;
            R1Hc = ((R1H>sctH) ? R1H-sctH : 0); //Crop height from bottom
            R1Ho = R1Hc; //Offset from top
            RectPlus=0;

            WriteToLog(QtDebugMsg, QString("Draw BG -> Draw first row, params: "));

            // /////////////////////Draw first row//////////////////
            item = addRect(0, 0, sctW, R1H-R1Hc, Qt::NoPen, QBrush(srcimg.copy(0, R1Ho, R1W, R1H-R1Hc)));
            item->setData(0, QString("BackGround%1").arg(sctID) );
            item->setPos(x, y+toY);
            item->setZValue(bgZ);
            // /////////////////////Draw first row//////////////////

            WriteToLog(QtDebugMsg, "Draw BG -> Draw second row");

            R2W = srcimg2.width();
            R2H = srcimg2.height();

            if(si_attach==0) // over first
            {
                toY = (sctH-R1H > R2H)? sctH-R2H-R1H : 0;
                R2Hc = ((R2H+R1H>sctH) ? R2H-(sctH-R1H) : 0); //Crop height from bottom
                R2Ho = R2Hc; //Offset from top
                RectPlus=R2H;
            }
            else if(si_attach==1) // bottom
            {
                toY = (sctH > R2H)? sctH-R2H : 0;
                R2Hc = ((R2H>sctH) ? R2H-sctH : 0); //Crop height from bottom
                R2Ho = R2Hc; //Offset from top
                RectPlus=0;
            }

            if((!srcimg2.isNull()) && ((sctH > R1H)||(si_attach==1)))
            {

                // /////////////////////Draw second row//////////////////
                item = addRect(0, 0, sctW, R2H-R2Hc, Qt::NoPen, QBrush( srcimg2.copy(0, R2Ho, R2W, R2H-R2Hc) ));
                item->setData(0, QString("BackGround%1").arg(sctID) );
                item->setPos(x, y+toY);
                item->setZValue(bgZ+0.0000000001);
                // /////////////////////Draw second row//////////////////

            } else if(srcimg2.isNull())
                WriteToLog(QtWarningMsg, "Draw BG -> second image is Null");


            if( R1H+RectPlus < sctH )
            {
                item = addRect(0, 0, sctW, sctH-R1H-RectPlus, Qt::NoPen, QBrush(FillColor));
                item->setData(0, QString("BackGround%1").arg(sctID) );
                item->setPos(x,y);
                item->setZValue(bgZ);
            }

        }
        else

// ///////////////////////////////Tiled BG///////////////////////////////
        {

            WriteToLog(QtDebugMsg, "Draw BG -> Style: Tiled");

            R1W = srcimg.width();
            R1H = srcimg.height();
            if(attach==0)
            {
                //Attached to Bottom
                RectPlus = sctH % R1H;

                toY = (sctH>R1H)? sctH-R1H : 0;

                //R1Hc = R1H-RectPlus; // Crop height from bottom/Offset from top

                item = addRect(0, 0, sctW, RectPlus, Qt::NoPen,
                               QBrush(srcimg.copy(0, R1H-RectPlus, R1W, RectPlus))
                              );
                item->setData(0, QString("BackGround%1").arg(sctID) );
                item->setPos(x,y);
                item->setZValue(bgZ);

                if(sctH >= R1H)
                {
                    item = addRect(0, 0, sctW, sctH-RectPlus, Qt::NoPen, QBrush(srcimg));
                    item->setData(0, "BackGround"+QString::number(sctID) );
                    item->setPos(x,y+RectPlus);
                    item->setZValue(bgZ);
                }

            }
            else
            {
                //Attached to Top
                item = addRect(0, 0, sctW, sctH, Qt::NoPen, QBrush(srcimg));
                item->setData(0, QString("BackGround%1").arg(sctID) );
                item->setPos(x,y);
                item->setZValue(bgZ);
            }
        }

    WriteToLog(QtDebugMsg, "acceptedID is "+QString::number(sctID)+" data is "+item->data(0).toString());

    WriteToLog(QtDebugMsg, "Draw BG -> Drawed");
}
コード例 #12
0
ファイル: board_file.cpp プロジェクト: kipr/ks2
void BoardFile::parse(const QString &contents, QGraphicsScene *scene)
{
#ifndef Q_OS_WIN
	const QStringList lines = contents.split("\n", QString::SkipEmptyParts);
#else
	const QStringList lines = contents.split("\r\n", QString::SkipEmptyParts);
#endif
	quint32 lineNum = 0;
	QPen pen;
	QBrush brush;
	qreal z = 0.0;
	double unitMult = 1.0;
	foreach(const QString &line, lines) {
		++lineNum;
		if(line.startsWith("#")) continue;
		QStringList parts = line.split(" ", QString::SkipEmptyParts);
		quint16 args = parts.size() - 1;
		if(parts[0] == "line") {
			if(args != 4) {
				error(lineNum, 4, args);
				continue;
			}
			QGraphicsItem *item = scene->addLine(parts[1].toDouble() * unitMult, parts[2].toDouble() * unitMult,
				parts[3].toDouble() * unitMult, parts[4].toDouble() * unitMult, pen);
			item->setData(0, BoardFile::Real);
			item->setZValue(z);
		} else if(parts[0] == "dec-line") {
			if(args != 4) {
				error(lineNum, 4, args);
				continue;
			}
			QGraphicsItem *item = scene->addLine(parts[1].toDouble() * unitMult, parts[2].toDouble() * unitMult,
				parts[3].toDouble() * unitMult, parts[4].toDouble() * unitMult, pen);
			item->setData(0, BoardFile::Fake);
			item->setZValue(z);
		} else if(parts[0] == "tape") {
			if(args != 4) {
				error(lineNum, 4, args);
				continue;
			}
			QGraphicsItem *item = scene->addLine(parts[1].toDouble() * unitMult, parts[2].toDouble() * unitMult,
				parts[3].toDouble() * unitMult, parts[4].toDouble() * unitMult, pen);
			item->setData(0, BoardFile::Tape);
			item->setZValue(z);
		} else if(parts[0] == "set-z") {
			if(args != 1) {
				error(lineNum, 1, args);
				continue;
			}
			z = parts[1].toDouble();
		} else if(parts[0] == "dec-rect") {
			if(args != 4) {
				error(lineNum, 4, args);
				continue;
			}
			QGraphicsItem *item = scene->addRect(parts[1].toDouble() * unitMult, parts[2].toDouble() * unitMult,
				parts[3].toDouble() * unitMult, parts[4].toDouble() * unitMult, pen, brush);
			item->setData(0, BoardFile::Fake);
			item->setZValue(z);
		} else if(parts[0] == "pen") {
			if(args != 2) {
				error(lineNum, 2, args);
				continue;
			}
			pen = QPen(QBrush(QColor(parts[1])), parts[2].toUInt());
		} else if(parts[0] == "brush") {
			if(args != 1) {
				error(lineNum, 1, args);
				continue;
			}
			brush = QBrush(QColor(parts[1]));
		} else if(parts[0] == "set-units") {
			if(args != 1) {
				error(lineNum, 1, args);
				continue;
			}
			if(parts[1] == "in") {
				unitMult = 2.54;
			} else if(parts[1] == "cm") {
				unitMult = 1.0;
			} else error(lineNum, parts[1]);
		} else error(lineNum, parts[0]);
	}
コード例 #13
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;
}
コード例 #14
0
ファイル: logscene.cpp プロジェクト: crossleyjuan/djon
void LogScene::getTaskItem(const QModelIndex &index) {
    Task* task = _model->task(index);

    Calendar* calendar = task->project()->projectDefaultCalendar();
    int hoursInDay = calendar->endHour().hour() - calendar->startHour().hour();
    std::vector<TaskLog*>* logs =task->logs();
    double startHour = 0;//calendar->startHour().hour();
    double endHour = 24;//calendar->endHour().hour() + 1;
    double minuteSize = (double)24*BLOCKSIZE / (double)((endHour - startHour) * 60);
    int red = 0;
    for (std::vector<TaskLog*>::iterator iter = logs->begin(); iter != logs->end(); iter++) {
        TaskLog* log = *iter;

        QSize size = sizeHint(index);

        int bordermargin = (size.height() * .4) / 2;

        int daysToStart = _startDate.daysTo(*log->start);
        double x1 = (double)daysToStart * (double)_dayWidth;
        DTime logStartTime = log->start->time();
        double y1 = (double)(logStartTime.totalMinutes() - (startHour*60)) * minuteSize;

        double x2 = (daysToStart + 1) * (double)_dayWidth;
        DTime logEndTime = log->end->time();
        if (log->end->getDay() != log->start->getDay()) {
            logEndTime = DTime(23, 59, 59);
        }
        double y2 = (double)(logEndTime.totalMinutes() - (startHour*60)) * minuteSize;

        QBrush b(task->taskColor());//QImage(":/img/task_bar.png"));//(QPixmap(":/img/task_bar.png"));
        red += 20;
        QColor penColor((task->taskColor().red() < 100) ? 0: (task->taskColor().red() - 100),
                        (task->taskColor().green() < 100) ? 0: (task->taskColor().green() - 100),
                        (task->taskColor().blue() < 100) ? 0: (task->taskColor().blue() - 100));
        QPen pen(penColor);
        if (log->activeLog) {
            pen.setWidth(3);
        }

        QGraphicsItem* item = this->addRect(x1, y1, (x2 - x1), (y2 - y1), pen, b);
        item->setZValue(1);
        if ((y2 - y1) > 20) {
            QFont f("Arial", 8);
            f.setWeight(QFont::Light);
            QBrush brush(penColor);

            std::string description = *task->shortDescription();
            int textY = y1 + 5;
            while (description.length() > 0) {
                std::string label;
                if (description.length() > 15) {
                    label = description.substr(0, 15);
                    description = description.substr(15);
                    if ((label.at(label.length() - 1) != ' ') &&
                        (description.at(0) != ' ')) {
                        int pos;
                        if ((pos = label.rfind(' ')) != std::string::npos) {
                            description = label.substr(pos) + description;
                            label = label.substr(0, pos);
                        }
                    }
                } else {
                    label = description;
                    description = "";
                }
                label = label.erase(label.find_last_not_of(" \n\r\t")+1);
                description = description.erase(description.find_last_not_of(" \n\r\t")+1);
                if ((textY + 20) < y2) {
                    QGraphicsSimpleTextItem* text = this->addSimpleText(tr(label.c_str()));
                    text->setPos(x1 + 10, textY);
                    //text->rotate(90);
                    text->setVisible(true);
                    text->setBrush(brush);
                    text->setFont(f);
                    text->setZValue(2);
                    textY += 15;
                } else {
                    break;
                }
            }
        }
        _currentY += sizeHint(index).height();
    }
    delete(logs);
}
コード例 #15
0
dmz::QtCanvasObjectGroup *
dmz::QtPluginCanvasObjectBasic::_create_item (
      ObjectStruct &os,
      QGraphicsItem *parent,
      const Config &ItemList,
      HashTableStringTemplate<String> &table) {

   QtCanvasObjectGroup *group (0);

   if (parent) {

      group = new QtCanvasObjectGroup (parent);

      QGraphicsItem *item (0);

      ConfigIterator it;
      Config cd;
      Float32 z (1.0);

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

         const String DataName (cd.get_name ().to_lower ());
         const String ItemName (config_to_string ("name", cd));
         const Boolean Isect (config_to_boolean ("isect", cd, True));

         if (DataName == "image") {

            item = _create_image_item (os, group, cd, table);

            if (Isect) {

               item->setData (QtCanvasObjectHandleIndex, (quint64)os.ObjHandle);
            }
         }
         else if (DataName == "text") {

            item =  _create_text_item (os, group, cd);

            if (Isect) {

               item->setData (QtCanvasObjectHandleIndex, (quint64)os.ObjHandle);
            }
         }
         else if (DataName == "group") {

            item = _create_item (os, group, cd, table);
         }

         if (item) {

            item->setFlag (QGraphicsItem::ItemIgnoresParentOpacity, true);
            item->setFlag (QGraphicsItem::ItemDoesntPropagateOpacityToChildren, true);

            item->setZValue (z++);

            if (ItemName) {

               String name (ItemName);
               name << "." << os.ObjHandle;

               item->setData (QtCanvasObjectNameIndex, name.get_buffer ());

               os.itemTable.store (ItemName, item);
            }
         }
      }
   }

   return group;
}