|
|
@ -308,10 +308,12 @@ UBGraphicsScene::~UBGraphicsScene() |
|
|
|
|
|
|
|
|
|
|
|
void UBGraphicsScene::selectionChangedProcessing() |
|
|
|
void UBGraphicsScene::selectionChangedProcessing() |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (selectedItems().count()) |
|
|
|
if (selectedItems().count()){ |
|
|
|
|
|
|
|
qDebug() << "Selected item bounding rect: " << selectedItems().first()->boundingRect(); |
|
|
|
UBApplication::showMessage("ZValue is " + QString::number(selectedItems().first()->zValue(), 'f') + "own z value is " |
|
|
|
UBApplication::showMessage("ZValue is " + QString::number(selectedItems().first()->zValue(), 'f') + "own z value is " |
|
|
|
+ QString::number(selectedItems().first()->data(UBGraphicsItemData::ItemOwnZValue).toReal(), 'f')); |
|
|
|
+ QString::number(selectedItems().first()->data(UBGraphicsItemData::ItemOwnZValue).toReal(), 'f')); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
void UBGraphicsScene::enableGroupingButton() |
|
|
|
void UBGraphicsScene::enableGroupingButton() |
|
|
|
{ |
|
|
|
{ |
|
|
|
QAction *groupAction = UBApplication::mainWindow->actionGroupItems; |
|
|
|
QAction *groupAction = UBApplication::mainWindow->actionGroupItems; |
|
|
@ -747,6 +749,8 @@ void UBGraphicsScene::drawLineTo(const QPointF &pEndPoint, const qreal &pWidth, |
|
|
|
|
|
|
|
|
|
|
|
void UBGraphicsScene::eraseLineTo(const QPointF &pEndPoint, const qreal &pWidth) |
|
|
|
void UBGraphicsScene::eraseLineTo(const QPointF &pEndPoint, const qreal &pWidth) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
// QList<QGraphicsItem*> itemList;
|
|
|
|
|
|
|
|
|
|
|
|
const QLineF line(mPreviousPoint, pEndPoint); |
|
|
|
const QLineF line(mPreviousPoint, pEndPoint); |
|
|
|
|
|
|
|
|
|
|
|
const QPolygonF eraserPolygon = UBGeometryUtils::lineToPolygon(line, pWidth); |
|
|
|
const QPolygonF eraserPolygon = UBGeometryUtils::lineToPolygon(line, pWidth); |
|
|
@ -793,24 +797,29 @@ void UBGraphicsScene::eraseLineTo(const QPointF &pEndPoint, const qreal &pWidth) |
|
|
|
|
|
|
|
|
|
|
|
if (mShouldUseOMP) |
|
|
|
if (mShouldUseOMP) |
|
|
|
{ |
|
|
|
{ |
|
|
|
#pragma omp parallel for |
|
|
|
// #pragma omp parallel for
|
|
|
|
for (int i = 0; i < collidItemsSize; i++) |
|
|
|
for (int i = 0; i < collidItemsSize; i++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
UBGraphicsPolygonItem *collidingPolygonItem = dynamic_cast<UBGraphicsPolygonItem*>(collidItems.at(i)); |
|
|
|
UBGraphicsPolygonItem *collidingPolygonItem = qgraphicsitem_cast<UBGraphicsPolygonItem*>(collidItems.at(i)); |
|
|
|
|
|
|
|
|
|
|
|
if (NULL != collidingPolygonItem) |
|
|
|
if (NULL != collidingPolygonItem) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
collidingPolygonItem->setColor(QColor(Qt::green)); |
|
|
|
|
|
|
|
|
|
|
|
UBGraphicsStrokesGroup* pGroup = collidingPolygonItem->strokesGroup(); |
|
|
|
UBGraphicsStrokesGroup* pGroup = collidingPolygonItem->strokesGroup(); |
|
|
|
|
|
|
|
|
|
|
|
if(eraserInnerRect.contains(collidingPolygonItem->boundingRect())) |
|
|
|
if(eraserInnerRect.contains(collidingPolygonItem->boundingRect())) |
|
|
|
{ |
|
|
|
{ |
|
|
|
#pragma omp critical |
|
|
|
// #pragma omp critical
|
|
|
|
|
|
|
|
qDebug() << "case 1"; |
|
|
|
// Put the entire polygon into the remove list
|
|
|
|
// Put the entire polygon into the remove list
|
|
|
|
|
|
|
|
collidingPolygonItem->setColor(QColor(Qt::blue)); |
|
|
|
toBeRemovedItems << collidingPolygonItem; |
|
|
|
toBeRemovedItems << collidingPolygonItem; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Here we get the polygon of the colliding item
|
|
|
|
// 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); |
|
|
@ -819,32 +828,40 @@ void UBGraphicsScene::eraseLineTo(const QPointF &pEndPoint, const qreal &pWidth) |
|
|
|
QPainterPath croppedPath = collidingPath.subtracted(eraserPath); |
|
|
|
QPainterPath croppedPath = collidingPath.subtracted(eraserPath); |
|
|
|
QPainterPath croppedPathSimplified = croppedPath.simplified(); |
|
|
|
QPainterPath croppedPathSimplified = croppedPath.simplified(); |
|
|
|
|
|
|
|
|
|
|
|
if (croppedPath == collidingPath) |
|
|
|
/*if (croppedPath == collidingPath)
|
|
|
|
{ |
|
|
|
{ |
|
|
|
// NOOP
|
|
|
|
// NOOP
|
|
|
|
|
|
|
|
qDebug() << "case 2"; |
|
|
|
|
|
|
|
toBeRemovedItems << collidingPolygonItem; |
|
|
|
} |
|
|
|
} |
|
|
|
else if (croppedPathSimplified.isEmpty()) |
|
|
|
else */if (croppedPathSimplified.isEmpty()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
#pragma omp critical |
|
|
|
// #pragma omp critical
|
|
|
|
|
|
|
|
qDebug() << "case 3"; |
|
|
|
// Put the entire polygon into the remove list if the eraser removes all its visible content
|
|
|
|
// Put the entire polygon into the remove list if the eraser removes all its visible content
|
|
|
|
|
|
|
|
collidingPolygonItem->setColor(QColor(Qt::blue)); |
|
|
|
toBeRemovedItems << collidingPolygonItem; |
|
|
|
toBeRemovedItems << collidingPolygonItem; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
//qDebug() << "case 4";
|
|
|
|
// Then we convert the remaining path to a list of polygons that will be converted in
|
|
|
|
// Then we convert the remaining path to a list of polygons that will be converted in
|
|
|
|
// UBGraphicsPolygonItems and added to the scene
|
|
|
|
// 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 |
|
|
|
croppedPolygonItem->setColor(QColor(Qt::black)); |
|
|
|
// Add this new polygon to the 'added' list
|
|
|
|
// #pragma omp critical
|
|
|
|
toBeAddedItems << croppedPolygonItem; |
|
|
|
|
|
|
|
if(NULL != pGroup){ |
|
|
|
if(NULL != pGroup){ |
|
|
|
croppedPolygonItem->setStrokesGroup(pGroup); |
|
|
|
croppedPolygonItem->setStrokesGroup(pGroup); |
|
|
|
|
|
|
|
// croppedPolygonItem->setTransform(pGroup->sceneTransform().inverted());
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// Add this new polygon to the 'added' list
|
|
|
|
|
|
|
|
toBeAddedItems << croppedPolygonItem; |
|
|
|
} |
|
|
|
} |
|
|
|
#pragma omp critical |
|
|
|
// #pragma omp critical
|
|
|
|
// Remove the original polygonitem because it has been replaced by many smaller polygons
|
|
|
|
// Remove the original polygonitem because it has been replaced by many smaller polygons
|
|
|
|
|
|
|
|
collidingPolygonItem->setColor(QColor(Qt::blue)); |
|
|
|
toBeRemovedItems << collidingPolygonItem; |
|
|
|
toBeRemovedItems << collidingPolygonItem; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -855,11 +872,12 @@ void UBGraphicsScene::eraseLineTo(const QPointF &pEndPoint, const qreal &pWidth) |
|
|
|
{ |
|
|
|
{ |
|
|
|
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 (collidingPolygonItem) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
UBGraphicsStrokesGroup* pGroup = collidingPolygonItem->strokesGroup(); |
|
|
|
|
|
|
|
|
|
|
|
if(eraserInnerRect.contains(collidingPolygonItem->boundingRect())) |
|
|
|
if(eraserInnerRect.contains(collidingPolygonItem->boundingRect())) |
|
|
|
{ |
|
|
|
{ |
|
|
|
toBeRemovedItems << collidingPolygonItem; |
|
|
|
toBeRemovedItems << collidingPolygonItem; |
|
|
@ -887,6 +905,9 @@ void UBGraphicsScene::eraseLineTo(const QPointF &pEndPoint, const qreal &pWidth) |
|
|
|
{ |
|
|
|
{ |
|
|
|
UBGraphicsPolygonItem* croppedPolygonItem = collidingPolygonItem->deepCopy(pol); |
|
|
|
UBGraphicsPolygonItem* croppedPolygonItem = collidingPolygonItem->deepCopy(pol); |
|
|
|
toBeAddedItems << croppedPolygonItem; |
|
|
|
toBeAddedItems << croppedPolygonItem; |
|
|
|
|
|
|
|
if(NULL != pGroup){ |
|
|
|
|
|
|
|
croppedPolygonItem->setStrokesGroup(pGroup); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
toBeRemovedItems << collidingPolygonItem; |
|
|
|
toBeRemovedItems << collidingPolygonItem; |
|
|
@ -896,28 +917,50 @@ void UBGraphicsScene::eraseLineTo(const QPointF &pEndPoint, const qreal &pWidth) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
addItems(toBeAddedItems); |
|
|
|
|
|
|
|
mAddedItems += toBeAddedItems; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(eDrawingMode_Vector == DRAWING_MODE){ |
|
|
|
if(eDrawingMode_Vector == DRAWING_MODE){ |
|
|
|
foreach(QGraphicsItem* item, toBeAddedItems){ |
|
|
|
foreach(QGraphicsItem* item, toBeRemovedItems){ |
|
|
|
UBGraphicsPolygonItem* poly = dynamic_cast<UBGraphicsPolygonItem*>(item); |
|
|
|
UBGraphicsPolygonItem* poly = dynamic_cast<UBGraphicsPolygonItem*>(item); |
|
|
|
if(NULL != poly && NULL != poly->strokesGroup()){ |
|
|
|
if(NULL != poly){ |
|
|
|
poly->strokesGroup()->addToGroup(poly); |
|
|
|
if(NULL != poly->strokesGroup()){ |
|
|
|
|
|
|
|
poly->strokesGroup()->removeFromGroup(poly); |
|
|
|
|
|
|
|
removeItem(poly); |
|
|
|
|
|
|
|
}else{ |
|
|
|
|
|
|
|
qDebug() << "No group present"; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}else{ |
|
|
|
removeItems(toBeRemovedItems); |
|
|
|
removeItems(toBeRemovedItems); |
|
|
|
mRemovedItems += toBeRemovedItems; |
|
|
|
mRemovedItems += toBeRemovedItems; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// bool hack = false;
|
|
|
|
|
|
|
|
// UBGraphicsStrokesGroup* pG = new UBGraphicsStrokesGroup();
|
|
|
|
if(eDrawingMode_Vector == DRAWING_MODE){ |
|
|
|
if(eDrawingMode_Vector == DRAWING_MODE){ |
|
|
|
foreach(QGraphicsItem* item, toBeRemovedItems){ |
|
|
|
foreach(QGraphicsItem* item, toBeAddedItems){ |
|
|
|
UBGraphicsPolygonItem* poly = dynamic_cast<UBGraphicsPolygonItem*>(item); |
|
|
|
UBGraphicsPolygonItem* poly = dynamic_cast<UBGraphicsPolygonItem*>(item); |
|
|
|
if(NULL != poly && NULL != poly->strokesGroup()){ |
|
|
|
if(NULL != poly && NULL != poly->strokesGroup()){ |
|
|
|
poly->strokesGroup()->removeFromGroup(poly); |
|
|
|
// if(!hack){
|
|
|
|
|
|
|
|
// itemList = poly->strokesGroup()->childItems();
|
|
|
|
|
|
|
|
// removeItem(poly->strokesGroup());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// foreach(QGraphicsItem* it, itemList){
|
|
|
|
|
|
|
|
// pG->addToGroup(it);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// hack = true;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
qreal dx = -poly->strokesGroup()->sceneTransform().inverted().dx(); |
|
|
|
|
|
|
|
qreal dy = -poly->strokesGroup()->sceneTransform().inverted().dy(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//poly->setTransform(QTransform().translate(20, 0));
|
|
|
|
|
|
|
|
poly->setTransform(QTransform().translate(dx, dy)); |
|
|
|
|
|
|
|
poly->strokesGroup()/*pG*/->addToGroup(poly); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//addItem(pG);
|
|
|
|
|
|
|
|
}else{ |
|
|
|
|
|
|
|
addItems(toBeAddedItems); |
|
|
|
|
|
|
|
mAddedItems += toBeAddedItems; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|