MCPcopy Create free account
hub / github.com/OpenBoard-org/OpenBoard / addImage

Method addImage

src/domain/UBGraphicsScene.cpp:1582–1655  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1580}
1581
1582UBGraphicsPixmapItem* UBGraphicsScene::addImage(QByteArray pData, QGraphicsItem* replaceFor, const QPointF& pPos, qreal pScaleFactor, bool pUseAnimation, bool useProxyForDocumentPath)
1583{
1584 QBuffer buffer(&pData);
1585 QImageReader imageReader(&buffer);
1586 imageReader.setAutoTransform(true);
1587 QString format = imageReader.format();
1588 QImage img = imageReader.read();
1589 QPixmap pixmap = QPixmap::fromImage(img);
1590
1591 UBGraphicsPixmapItem* pixmapItem = new UBGraphicsPixmapItem();
1592
1593 pixmapItem->setFlag(QGraphicsItem::ItemIsMovable, true);
1594 pixmapItem->setFlag(QGraphicsItem::ItemIsSelectable, true);
1595
1596 pixmapItem->setPixmap(pixmap);
1597
1598 QPointF half(pixmap.width() * pScaleFactor / 2, pixmap.height() * pScaleFactor / 2);
1599 pixmapItem->setPos(pPos - half);
1600
1601 addItem(pixmapItem);
1602
1603 if (mUndoRedoStackEnabled) { //should be deleted after scene own undo stack implemented
1604 UBGraphicsItemUndoCommand* uc = new UBGraphicsItemUndoCommand(shared_from_this(), replaceFor, pixmapItem);
1605 UBApplication::undoStack->push(uc);
1606 }
1607
1608 pixmapItem->setTransform(QTransform::fromScale(pScaleFactor, pScaleFactor), true);
1609
1610 if (pUseAnimation)
1611 {
1612 pixmapItem->setOpacity(0);
1613
1614 QPropertyAnimation *animation = new QPropertyAnimation(pixmapItem, "opacity");
1615 animation->setDuration(1000);
1616 animation->setStartValue(0.0);
1617 animation->setEndValue(1.0);
1618
1619 animation->start();
1620 }
1621
1622 pixmapItem->show();
1623 setDocumentUpdated();
1624
1625 QString documentPath;
1626 if(useProxyForDocumentPath)
1627 documentPath = this->document()->persistencePath();
1628 else
1629 documentPath = UBApplication::boardController->selectedDocument()->persistencePath();
1630
1631 if (format != "png")
1632 {
1633 // provide compatibility with OpenBoard < 1.7.0 which uses 'contains("png")' as image indicator
1634 format = "png." + format;
1635 }
1636
1637 QString fileName = UBPersistenceManager::imageDirectory + "/" + pixmapItem->uuid().toString() + "." + format;
1638
1639 QString path = documentPath + "/" + fileName;

Callers 3

downloadFinishedMethod · 0.80
processMimeDataMethod · 0.80

Calls 12

documentMethod · 0.95
existsFunction · 0.85
setOpacityMethod · 0.80
persistencePathMethod · 0.80
selectedDocumentMethod · 0.80
setPixmapMethod · 0.45
widthMethod · 0.45
heightMethod · 0.45
startMethod · 0.45
showMethod · 0.45
uuidMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected