|
|
@ -567,7 +567,7 @@ bool UBGraphicsScene::inputDeviceRelease() |
|
|
|
} |
|
|
|
} |
|
|
|
}else if (mCurrentStroke) |
|
|
|
}else if (mCurrentStroke) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if(eDrawingMode_Vector == dc->drawingMode()){ |
|
|
|
if(eDrawingMode_Vector == DRAWING_MODE){ |
|
|
|
UBGraphicsStrokesGroup* pStrokes = new UBGraphicsStrokesGroup(); |
|
|
|
UBGraphicsStrokesGroup* pStrokes = new UBGraphicsStrokesGroup(); |
|
|
|
|
|
|
|
|
|
|
|
// Remove the strokes that were just drawn here and replace them by a stroke item
|
|
|
|
// Remove the strokes that were just drawn here and replace them by a stroke item
|
|
|
@ -575,6 +575,7 @@ bool UBGraphicsScene::inputDeviceRelease() |
|
|
|
mPreviousPolygonItems.removeAll(poly); |
|
|
|
mPreviousPolygonItems.removeAll(poly); |
|
|
|
removeItem(poly); |
|
|
|
removeItem(poly); |
|
|
|
UBCoreGraphicsScene::removeItemFromDeletion(poly); |
|
|
|
UBCoreGraphicsScene::removeItemFromDeletion(poly); |
|
|
|
|
|
|
|
poly->setStrokesGroup(pStrokes); |
|
|
|
pStrokes->addToGroup(poly); |
|
|
|
pStrokes->addToGroup(poly); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -756,13 +757,37 @@ void UBGraphicsScene::eraseLineTo(const QPointF &pEndPoint, const qreal &pWidth) |
|
|
|
eraserPathVar.addPolygon(eraserPolygon); |
|
|
|
eraserPathVar.addPolygon(eraserPolygon); |
|
|
|
const QPainterPath eraserPath = eraserPathVar; |
|
|
|
const QPainterPath eraserPath = eraserPathVar; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Get all the items that are intersecting with the eraser path
|
|
|
|
QList<QGraphicsItem*> collidItems = items(eraserBoundingRect, Qt::IntersectsItemBoundingRect); |
|
|
|
QList<QGraphicsItem*> collidItems = items(eraserBoundingRect, Qt::IntersectsItemBoundingRect); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(eDrawingMode_Vector == UBDrawingController::drawingController()->drawingMode()){ |
|
|
|
|
|
|
|
// NOTE: I decided to reuse the 'artistic' eraser all the time in order to have a better eraser
|
|
|
|
|
|
|
|
// For this reason, the following code is not used but we will keep it for now, in case of
|
|
|
|
|
|
|
|
// futur requirements.
|
|
|
|
|
|
|
|
foreach(QGraphicsItem* poly, collidItems){ |
|
|
|
|
|
|
|
UBGraphicsStrokesGroup* pGroup = dynamic_cast<UBGraphicsStrokesGroup*>(poly); |
|
|
|
|
|
|
|
if(NULL != pGroup){ |
|
|
|
|
|
|
|
// TODO: Ungroup the item, put back the polygons on the scene, deal with the
|
|
|
|
|
|
|
|
// eraser's bounding rect, remove the polygons that must be removed
|
|
|
|
|
|
|
|
// then create new groups.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Get all substrokes and verify if they are part of the eraserpath then deal with it
|
|
|
|
|
|
|
|
foreach(QGraphicsItem* item, poly->childItems()){ |
|
|
|
|
|
|
|
UBGraphicsPolygonItem* polygon = dynamic_cast<UBGraphicsPolygonItem*>(item); |
|
|
|
|
|
|
|
if(NULL != polygon){ |
|
|
|
|
|
|
|
if(eraserBoundingRect.intersects(polygon->boundingRect())){ |
|
|
|
|
|
|
|
pGroup->removeFromGroup(polygon); |
|
|
|
|
|
|
|
removeItem(polygon); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}else{ |
|
|
|
QSet<QGraphicsItem*> toBeAddedItems; |
|
|
|
QSet<QGraphicsItem*> toBeAddedItems; |
|
|
|
QSet<QGraphicsItem*> toBeRemovedItems; |
|
|
|
QSet<QGraphicsItem*> toBeRemovedItems; |
|
|
|
|
|
|
|
|
|
|
|
int collidItemsSize = collidItems.size(); |
|
|
|
int collidItemsSize = collidItems.size(); |
|
|
|
|
|
|
|
|
|
|
|
toBeAddedItems.reserve(collidItemsSize); |
|
|
|
toBeAddedItems.reserve(collidItemsSize); |
|
|
|
toBeRemovedItems.reserve(collidItemsSize); |
|
|
|
toBeRemovedItems.reserve(collidItemsSize); |
|
|
|
|
|
|
|
|
|
|
@ -771,22 +796,26 @@ void UBGraphicsScene::eraseLineTo(const QPointF &pEndPoint, const qreal &pWidth) |
|
|
|
#pragma omp parallel for |
|
|
|
#pragma omp parallel for |
|
|
|
for (int i = 0; i < collidItemsSize; i++) |
|
|
|
for (int i = 0; i < collidItemsSize; i++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
UBGraphicsPolygonItem *collidingPolygonItem |
|
|
|
UBGraphicsPolygonItem *collidingPolygonItem = dynamic_cast<UBGraphicsPolygonItem*>(collidItems.at(i)); |
|
|
|
= qgraphicsitem_cast<UBGraphicsPolygonItem*> (collidItems.at(i)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (collidingPolygonItem) |
|
|
|
if (NULL != collidingPolygonItem) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
UBGraphicsStrokesGroup* pGroup = collidingPolygonItem->strokesGroup(); |
|
|
|
|
|
|
|
|
|
|
|
if(eraserInnerRect.contains(collidingPolygonItem->boundingRect())) |
|
|
|
if(eraserInnerRect.contains(collidingPolygonItem->boundingRect())) |
|
|
|
{ |
|
|
|
{ |
|
|
|
#pragma omp critical |
|
|
|
#pragma omp critical |
|
|
|
|
|
|
|
// Put the entire polygon into the remove list
|
|
|
|
toBeRemovedItems << collidingPolygonItem; |
|
|
|
toBeRemovedItems << collidingPolygonItem; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
// Here we get the polygon of the colliding item
|
|
|
|
QPolygonF collidingPolygon = collidingPolygonItem->polygon(); |
|
|
|
QPolygonF collidingPolygon = collidingPolygonItem->polygon(); |
|
|
|
QPainterPath collidingPath; |
|
|
|
QPainterPath collidingPath; |
|
|
|
collidingPath.addPolygon(collidingPolygon); |
|
|
|
collidingPath.addPolygon(collidingPolygon); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Then we substract the eraser path to the polygon and we simplify it
|
|
|
|
QPainterPath croppedPath = collidingPath.subtracted(eraserPath); |
|
|
|
QPainterPath croppedPath = collidingPath.subtracted(eraserPath); |
|
|
|
QPainterPath croppedPathSimplified = croppedPath.simplified(); |
|
|
|
QPainterPath croppedPathSimplified = croppedPath.simplified(); |
|
|
|
|
|
|
|
|
|
|
@ -797,17 +826,25 @@ void UBGraphicsScene::eraseLineTo(const QPointF &pEndPoint, const qreal &pWidth) |
|
|
|
else if (croppedPathSimplified.isEmpty()) |
|
|
|
else if (croppedPathSimplified.isEmpty()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
#pragma omp critical |
|
|
|
#pragma omp critical |
|
|
|
|
|
|
|
// Put the entire polygon into the remove list if the eraser removes all its visible content
|
|
|
|
toBeRemovedItems << collidingPolygonItem; |
|
|
|
toBeRemovedItems << collidingPolygonItem; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
// Then we convert the remaining path to a list of polygons that will be converted in
|
|
|
|
|
|
|
|
// UBGraphicsPolygonItems and added to the scene
|
|
|
|
foreach(const QPolygonF &pol, croppedPathSimplified.toFillPolygons()) |
|
|
|
foreach(const QPolygonF &pol, croppedPathSimplified.toFillPolygons()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
UBGraphicsPolygonItem* croppedPolygonItem = collidingPolygonItem->deepCopy(pol); |
|
|
|
UBGraphicsPolygonItem* croppedPolygonItem = collidingPolygonItem->deepCopy(pol); |
|
|
|
#pragma omp critical |
|
|
|
#pragma omp critical |
|
|
|
|
|
|
|
// Add this new polygon to the 'added' list
|
|
|
|
toBeAddedItems << croppedPolygonItem; |
|
|
|
toBeAddedItems << croppedPolygonItem; |
|
|
|
|
|
|
|
if(NULL != pGroup){ |
|
|
|
|
|
|
|
croppedPolygonItem->setStrokesGroup(pGroup); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
#pragma omp critical |
|
|
|
#pragma omp critical |
|
|
|
|
|
|
|
// Remove the original polygonitem because it has been replaced by many smaller polygons
|
|
|
|
toBeRemovedItems << collidingPolygonItem; |
|
|
|
toBeRemovedItems << collidingPolygonItem; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -862,9 +899,28 @@ void UBGraphicsScene::eraseLineTo(const QPointF &pEndPoint, const qreal &pWidth) |
|
|
|
addItems(toBeAddedItems); |
|
|
|
addItems(toBeAddedItems); |
|
|
|
mAddedItems += toBeAddedItems; |
|
|
|
mAddedItems += toBeAddedItems; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(eDrawingMode_Vector == DRAWING_MODE){ |
|
|
|
|
|
|
|
foreach(QGraphicsItem* item, toBeAddedItems){ |
|
|
|
|
|
|
|
UBGraphicsPolygonItem* poly = dynamic_cast<UBGraphicsPolygonItem*>(item); |
|
|
|
|
|
|
|
if(NULL != poly && NULL != poly->strokesGroup()){ |
|
|
|
|
|
|
|
poly->strokesGroup()->addToGroup(poly); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
removeItems(toBeRemovedItems); |
|
|
|
removeItems(toBeRemovedItems); |
|
|
|
mRemovedItems += toBeRemovedItems; |
|
|
|
mRemovedItems += toBeRemovedItems; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(eDrawingMode_Vector == DRAWING_MODE){ |
|
|
|
|
|
|
|
foreach(QGraphicsItem* item, toBeRemovedItems){ |
|
|
|
|
|
|
|
UBGraphicsPolygonItem* poly = dynamic_cast<UBGraphicsPolygonItem*>(item); |
|
|
|
|
|
|
|
if(NULL != poly && NULL != poly->strokesGroup()){ |
|
|
|
|
|
|
|
poly->strokesGroup()->removeFromGroup(poly); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
mPreviousPoint = pEndPoint; |
|
|
|
mPreviousPoint = pEndPoint; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|