|
|
|
@ -70,6 +70,7 @@ |
|
|
|
|
#include "UBGraphicsPixmapItem.h" |
|
|
|
|
#include "UBGraphicsSvgItem.h" |
|
|
|
|
#include "UBGraphicsPolygonItem.h" |
|
|
|
|
#include "UBGraphicsVectorItem.h" |
|
|
|
|
#include "UBGraphicsMediaItem.h" |
|
|
|
|
#include "UBGraphicsWidgetItem.h" |
|
|
|
|
#include "UBGraphicsPDFItem.h" |
|
|
|
@ -539,8 +540,9 @@ bool UBGraphicsScene::inputDeviceMove(const QPointF& scenePos, const qreal& pres |
|
|
|
|
width /= UBApplication::boardController->systemScaleFactor(); |
|
|
|
|
width /= UBApplication::boardController->currentZoom(); |
|
|
|
|
|
|
|
|
|
if (currentTool == UBStylusTool::Line || dc->mActiveRuler) |
|
|
|
|
if (currentTool == UBStylusTool::Line || dc->mActiveRuler || currentTool == UBStylusTool::Vector) |
|
|
|
|
{ |
|
|
|
|
if (UBDrawingController::drawingController()->stylusTool() != UBStylusTool::Vector) |
|
|
|
|
if (UBDrawingController::drawingController()->stylusTool() != UBStylusTool::Marker) |
|
|
|
|
if(NULL != mpLastPolygon && NULL != mCurrentStroke && mAddedItems.size() > 0){ |
|
|
|
|
UBCoreGraphicsScene::removeItemFromDeletion(mpLastPolygon); |
|
|
|
@ -580,7 +582,9 @@ bool UBGraphicsScene::inputDeviceMove(const QPointF& scenePos, const qreal& pres |
|
|
|
|
else if (currentTool == UBStylusTool::Line) { |
|
|
|
|
drawLineTo(position, width, true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
else if (currentTool == UBStylusTool::Vector) { |
|
|
|
|
drawLineTo(position, width, true); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
bool interpolate = false; |
|
|
|
|
|
|
|
|
@ -667,7 +671,16 @@ bool UBGraphicsScene::inputDeviceRelease(int tool) |
|
|
|
|
|
|
|
|
|
if (currentTool == UBStylusTool::Eraser) |
|
|
|
|
hideEraser(); |
|
|
|
|
if(currentTool == UBStylusTool::Vector) |
|
|
|
|
{ |
|
|
|
|
if (mUndoRedoStackEnabled) |
|
|
|
|
{ //should be deleted after scene own undo stack implemented
|
|
|
|
|
UBGraphicsItemUndoCommand* uc = new UBGraphicsItemUndoCommand(this, NULL, mpLastVector); |
|
|
|
|
UBApplication::undoStack->push(uc); |
|
|
|
|
|
|
|
|
|
mAddedItems.clear(); |
|
|
|
|
} |
|
|
|
|
} else{ |
|
|
|
|
|
|
|
|
|
UBDrawingController *dc = UBDrawingController::drawingController(); |
|
|
|
|
|
|
|
|
@ -741,6 +754,7 @@ bool UBGraphicsScene::inputDeviceRelease(int tool) |
|
|
|
|
mCurrentPolygon = 0; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (mRemovedItems.size() > 0 || mAddedItems.size() > 0) |
|
|
|
|
{ |
|
|
|
@ -920,6 +934,7 @@ void UBGraphicsScene::moveTo(const QPointF &pPoint) |
|
|
|
|
} |
|
|
|
|
void UBGraphicsScene::drawLineTo(const QPointF &pEndPoint, const qreal &pWidth, bool bLineStyle) |
|
|
|
|
{ |
|
|
|
|
if(UBDrawingController::drawingController()->stylusTool() == UBStylusTool::Vector) bLineStyle = true; |
|
|
|
|
drawLineTo(pEndPoint, pWidth, pWidth, bLineStyle); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
@ -943,8 +958,16 @@ void UBGraphicsScene::drawLineTo(const QPointF &pEndPoint, const qreal &startWid |
|
|
|
|
mAddedItems.clear(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (UBDrawingController::drawingController()->stylusTool() != UBStylusTool::Vector) |
|
|
|
|
{ |
|
|
|
|
UBGraphicsPolygonItem *polygonItem = lineToPolygonItem(QLineF(mPreviousPoint, pEndPoint), initialWidth, endWidth); |
|
|
|
|
addPolygonItemToCurrentStroke(polygonItem); |
|
|
|
|
} else |
|
|
|
|
{ |
|
|
|
|
UBGraphicsVectorItem *vectorItem = new UBGraphicsVectorItem(QLineF(mPreviousPoint, pEndPoint), initialWidth, endWidth); |
|
|
|
|
initVectorItem(vectorItem); |
|
|
|
|
addVectorItemToCurrentStroke(vectorItem); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!bLineStyle) { |
|
|
|
|
mPreviousPoint = pEndPoint; |
|
|
|
@ -998,6 +1021,19 @@ void UBGraphicsScene::addPolygonItemToCurrentStroke(UBGraphicsPolygonItem* polyg |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void UBGraphicsScene::addVectorItemToCurrentStroke(UBGraphicsVectorItem* vectorItem) |
|
|
|
|
{ |
|
|
|
|
vectorItem->setFlag(QGraphicsItem::ItemIsMovable, true); |
|
|
|
|
vectorItem->setFlag(QGraphicsItem::ItemIsSelectable, true); |
|
|
|
|
vectorItem->SetDelegate(); |
|
|
|
|
|
|
|
|
|
mpLastVector = vectorItem; |
|
|
|
|
mAddedItems.insert(vectorItem); |
|
|
|
|
|
|
|
|
|
// Here we add the item to the scene
|
|
|
|
|
addItem(vectorItem); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
void UBGraphicsScene::eraseLineTo(const QPointF &pEndPoint, const qreal &pWidth) |
|
|
|
|
{ |
|
|
|
|
const QLineF line(mPreviousPoint, pEndPoint); |
|
|
|
@ -1017,13 +1053,15 @@ void UBGraphicsScene::eraseLineTo(const QPointF &pEndPoint, const qreal &pWidth) |
|
|
|
|
typedef QList<QPolygonF> POLYGONSLIST; |
|
|
|
|
QList<POLYGONSLIST> intersectedPolygons; |
|
|
|
|
|
|
|
|
|
QList<UBGraphicsVectorItem*> intersectedVectorItems; |
|
|
|
|
|
|
|
|
|
#pragma omp parallel for |
|
|
|
|
for(int i=0; i<collidItems.size(); i++) |
|
|
|
|
{ |
|
|
|
|
UBGraphicsPolygonItem *pi = qgraphicsitem_cast<UBGraphicsPolygonItem*>(collidItems[i]); |
|
|
|
|
if(pi == NULL) |
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
UBGraphicsVectorItem *vi = qgraphicsitem_cast<UBGraphicsVectorItem*>(collidItems[i]); |
|
|
|
|
if(pi != NULL) |
|
|
|
|
{ |
|
|
|
|
QPainterPath itemPainterPath; |
|
|
|
|
itemPainterPath.addPolygon(pi->sceneTransform().map(pi->polygon())); |
|
|
|
|
|
|
|
|
@ -1046,6 +1084,23 @@ void UBGraphicsScene::eraseLineTo(const QPointF &pEndPoint, const qreal &pWidth) |
|
|
|
|
intersectedPolygons << newPath.simplified().toFillPolygons(pi->sceneTransform().inverted()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else if (vi != NULL) |
|
|
|
|
{ |
|
|
|
|
QPainterPath itemPainterPath; |
|
|
|
|
QList<QPointF> linePoints = vi->linePoints(); |
|
|
|
|
for (int i=0; i < linePoints.count(); ++i) |
|
|
|
|
{ |
|
|
|
|
itemPainterPath.addEllipse(linePoints[i], 1, 1); |
|
|
|
|
} |
|
|
|
|
if (eraserPath.contains(itemPainterPath) || eraserPath.intersects(itemPainterPath)) |
|
|
|
|
{ |
|
|
|
|
#pragma omp critical |
|
|
|
|
{ |
|
|
|
|
// Compete remove item
|
|
|
|
|
intersectedVectorItems << vi; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for(int i=0; i<intersectedItems.size(); i++) |
|
|
|
@ -1093,7 +1148,21 @@ void UBGraphicsScene::eraseLineTo(const QPointF &pEndPoint, const qreal &pWidth) |
|
|
|
|
intersectedPolygonItem->setTransform(t); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!intersectedItems.empty()) |
|
|
|
|
for (int i=0; i<intersectedVectorItems.size(); i++) |
|
|
|
|
{ |
|
|
|
|
UBGraphicsVectorItem *intersectedVectorItem = intersectedVectorItems[i]; |
|
|
|
|
|
|
|
|
|
mRemovedItems << intersectedVectorItem; |
|
|
|
|
QTransform t; |
|
|
|
|
bool bApplyTransform = false; |
|
|
|
|
removeItem(intersectedVectorItem); |
|
|
|
|
if (bApplyTransform) |
|
|
|
|
{ |
|
|
|
|
intersectedVectorItem ->setTransform(t); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!intersectedItems.empty() || !intersectedVectorItems.empty()) |
|
|
|
|
setModified(true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1271,6 +1340,28 @@ void UBGraphicsScene::initPolygonItem(UBGraphicsPolygonItem* polygonItem) |
|
|
|
|
polygonItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Graphic)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void UBGraphicsScene::initVectorItem(UBGraphicsVectorItem* vectorItem) |
|
|
|
|
{ |
|
|
|
|
QColor colorOnDarkBG; |
|
|
|
|
QColor colorOnLightBG; |
|
|
|
|
|
|
|
|
|
colorOnDarkBG = UBApplication::boardController->penColorOnDarkBackground(); |
|
|
|
|
colorOnLightBG = UBApplication::boardController->penColorOnLightBackground(); |
|
|
|
|
|
|
|
|
|
if (mDarkBackground) |
|
|
|
|
{ |
|
|
|
|
vectorItem->setColor(colorOnDarkBG); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
vectorItem->setColor(colorOnLightBG); |
|
|
|
|
} |
|
|
|
|
vectorItem->setColorOnDarkBackground(colorOnDarkBG); |
|
|
|
|
vectorItem->setColorOnLightBackground(colorOnLightBG); |
|
|
|
|
|
|
|
|
|
vectorItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Graphic)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
UBGraphicsPolygonItem* UBGraphicsScene::arcToPolygonItem(const QLineF& pStartRadius, qreal pSpanAngle, qreal pWidth) |
|
|
|
|
{ |
|
|
|
|
QPolygonF polygon = UBGeometryUtils::arcToPolygon(pStartRadius, pSpanAngle, pWidth); |
|
|
|
@ -1491,7 +1582,7 @@ void UBGraphicsScene::clearContent(clearCase pCase) |
|
|
|
|
? qgraphicsitem_cast<UBGraphicsGroupContainerItem*>(item->parentItem()) |
|
|
|
|
: 0; |
|
|
|
|
UBGraphicsItemDelegate *curDelegate = UBGraphicsItem::Delegate(item); |
|
|
|
|
if (!curDelegate) { |
|
|
|
|
if (!curDelegate && item->type() != UBGraphicsVectorItem::Type) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1499,6 +1590,12 @@ void UBGraphicsScene::clearContent(clearCase pCase) |
|
|
|
|
bool isStrokesGroup = item->type() == UBGraphicsStrokesGroup::Type; |
|
|
|
|
|
|
|
|
|
bool shouldDelete = false; |
|
|
|
|
if(item->type()==UBGraphicsVectorItem::Type) |
|
|
|
|
{ |
|
|
|
|
removedItems << item; |
|
|
|
|
this->removeItem(item); |
|
|
|
|
} else |
|
|
|
|
{ |
|
|
|
|
switch (static_cast<int>(pCase)) { |
|
|
|
|
case clearAnnotations : |
|
|
|
|
shouldDelete = isStrokesGroup; |
|
|
|
@ -1510,6 +1607,7 @@ void UBGraphicsScene::clearContent(clearCase pCase) |
|
|
|
|
shouldDelete = !isGroup && !isBackgroundObject(item); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(shouldDelete) { |
|
|
|
|
if (itemGroup) { |
|
|
|
|