Ejemplo n.º 1
0
void SnapshotCanvas::mousePressEvent(QMouseEvent *event)
{
    if (!m_toolkit) {
        QGraphicsView::mousePressEvent(event);
        return;
    }

    QGraphicsItem *item = itemAt(event->pos());
    if (item == m_pixmapItem) {
        bool itemDeselected = false;
        if (!m_scene->selectedItems().isEmpty()) {
            deselectItems();
            itemDeselected = true;
        }
        if (event->button() == Qt::LeftButton) {
            if (m_toolkit->itemCreationPolicy()
                    == GraphicsItemFactory::Static) {
                if (!itemDeselected) {
                    m_mouseDown = true;
                    m_currentDrawingItem = m_toolkit->createItem();
                    m_currentDrawingItem->createShape(mapToScene(event->pos()),
                                                      QPointF());
                    addItemToScene(m_currentDrawingItem);
                }
            } else {
                m_mouseDown = true;
                m_origin = mapToScene(event->pos());
            }
        }
    } else {
        QGraphicsView::mousePressEvent(event);
    }
}
Ejemplo n.º 2
0
void SnapshotCanvas::paste()
{
    QList<KaptionGraphicsItem*> tmp;
    while(!m_itemsClipboard.isEmpty()) {
        KaptionGraphicsItem *item = m_itemsClipboard.takeFirst();
        item->moveBy(-10, 10);
        addItemToScene(item);
        tmp << item->copy();
    }
    m_itemsClipboard = tmp; //Recursive pasting
}
Ejemplo n.º 3
0
void MainWindow::positionGameObjects()
{


    for(size_t i = 0; i< obj.size(); i++ )
    {

        if(obj.at(i)->getIsVisable()){
            //cout << "type: "  << obj.at(i)->getType() << endl;
            if(obj.at(i)->getType() == "STONE")
            {
                //cout << "add Stone" << endl;
                addItemToScene(obj.at(i),Qt::gray,Qt::gray);
            }
            if(obj.at(i)->getType() == "BIRD")
            {
                //cout << "add Bird" << endl;
                addItemToScene(obj.at(i),Qt::blue,Qt::blue);
            }
            if(obj.at(i)->getType() == "WOLF")
            {
               // cout << "add Wolf" << endl;
                addItemToScene(obj.at(i),Qt::red,Qt::red);
            }
            if(obj.at(i)->getType() == "CARROT")
            {
                //cout << "add Carrot" << endl;
                addItemToScene(obj.at(i),Qt::yellow,Qt::yellow);
            }
            if(obj.at(i)->getType() == "RABBIT")
            {
                //cout << "add Rabbit" << endl;
                addItemToScene(obj.at(i),Qt::darkGreen,Qt::green);
            }
        }
    }
}
Ejemplo n.º 4
0
void SnapshotCanvas::mouseMoveEvent(QMouseEvent *event)
{
    if (!m_toolkit) {
        QGraphicsView::mouseMoveEvent(event);
        return;
    }

    if (m_mouseDown) {
        QPointF pos = mapToScene(event->pos());
        if (!m_currentDrawingItem &&
                m_toolkit->itemCreationPolicy()
                    == GraphicsItemFactory::Dynamic) {
            m_currentDrawingItem = m_toolkit->createItem();
            m_currentDrawingItem->createShape(m_origin, pos);
            addItemToScene(m_currentDrawingItem);
        } else {
            m_currentDrawingItem->createShape(m_origin, pos);
        }
    } else {
        QGraphicsView::mouseMoveEvent(event);
    }
}
Ejemplo n.º 5
0
CustomGraphicsView::CustomGraphicsView(QWidget *parent)
	: QGraphicsView(parent)
{
	//Set scene.
	this->setScene(&m_graphicsScene);

	//Set width to default View width
	m_nWidth = this->geometry().width();

	//Set width to default View height
	m_nHeight = this->geometry().height();

	//View X-offset
	m_nOffsetX = 20;

	//View Y-offset
	m_nOffsetY = 20;

	//Gap between Items.
	m_nItemSpace = 10;

	m_nRow = 0;

	m_nColoumn = 0;

	m_nMaxColumn = 0;

	m_sceneRect.setWidth(m_nWidth);

	m_graphicsScene.setSceneRect(m_sceneRect);

	m_itemTransformation = Qt::SmoothTransformation;

	hXPSConvert = LoadLibrary(L"XpsConvertQt.dll");

	docConvertThread = new DocConverterThread(this);

	docConvertThread->start();

	connect(docConvertThread, SIGNAL(addItem(QString)), this, SLOT(addItemToScene(QString)));

	//Set Rendering hint flags of GraphicsView.
	this->setRenderHints (QPainter::TextAntialiasing);

	this->setDragMode(QGraphicsView::RubberBandDrag);

	viewThread = new ViewWorkerThread(this);

	viewThread->start();

	connect(this, SIGNAL(loadImage(QList<QGraphicsItem*>)), viewThread, SLOT(prepareImage(QList<QGraphicsItem*>)));

	connect(viewThread, SIGNAL(updateItem(CustomItem* )), this, SLOT(updateItemImage(CustomItem*)));

	//Set Cache mode flag.
	//this->setCacheMode (QGraphicsView::NoCache);

	timer = new QTimer(this);

	connect(timer, SIGNAL(timeout()), this, SLOT(updateItem()));

	timer->setSingleShot(true);

	//Set Viewport Update mode of the view.
	this->setViewportUpdateMode (QGraphicsView::SmartViewportUpdate);

	connect(this->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(onScrollValueChanged(int)));
}