|
|
@ -65,6 +65,9 @@ |
|
|
|
|
|
|
|
|
|
|
|
#include "core/memcheck.h" |
|
|
|
#include "core/memcheck.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const QString groupText = "Group items"; |
|
|
|
|
|
|
|
const QString ungroupText = "Ungroup items"; |
|
|
|
|
|
|
|
|
|
|
|
qreal UBZLayerController::errorNumber = -20000001.0; |
|
|
|
qreal UBZLayerController::errorNumber = -20000001.0; |
|
|
|
|
|
|
|
|
|
|
|
UBZLayerController::UBZLayerController(QGraphicsScene *scene) : |
|
|
|
UBZLayerController::UBZLayerController(QGraphicsScene *scene) : |
|
|
@ -291,9 +294,15 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
connect(this, SIGNAL(selectionChanged()), this, SLOT(selectionChangedProcessing())); |
|
|
|
connect(this, SIGNAL(selectionChanged()), this, SLOT(selectionChangedProcessing())); |
|
|
|
connect(this, SIGNAL(selectionChanged()), this, SLOT(enableGroupingButton())); |
|
|
|
connect(this, SIGNAL(selectionChanged()), this, SLOT(updateGroupButtonState())); |
|
|
|
|
|
|
|
|
|
|
|
connect(UBApplication::mainWindow->actionGroupItems, SIGNAL(triggered()), this, SLOT(processGroupItems())); |
|
|
|
// just a stub don't treat as a result code
|
|
|
|
|
|
|
|
// static int i = 0;
|
|
|
|
|
|
|
|
// i++;
|
|
|
|
|
|
|
|
// if (i == 1) {
|
|
|
|
|
|
|
|
connect(UBApplication::mainWindow->actionGroupItems, SIGNAL(triggered()), this, SLOT(groupButtonClicked())); |
|
|
|
|
|
|
|
// qDebug() << "the connect is accepted";
|
|
|
|
|
|
|
|
// }
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
UBGraphicsScene::~UBGraphicsScene() |
|
|
|
UBGraphicsScene::~UBGraphicsScene() |
|
|
@ -308,39 +317,78 @@ 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::updateGroupButtonState() |
|
|
|
{ |
|
|
|
{ |
|
|
|
QAction *groupAction = UBApplication::mainWindow->actionGroupItems; |
|
|
|
QAction *groupAction = UBApplication::mainWindow->actionGroupItems; |
|
|
|
|
|
|
|
QList<QGraphicsItem*> selItems = selectedItems(); |
|
|
|
|
|
|
|
int selCount = selItems.count(); |
|
|
|
|
|
|
|
|
|
|
|
if (selectedItems().count() > 1) { |
|
|
|
if (selCount < 1) { |
|
|
|
groupAction->setEnabled(true); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
groupAction->setEnabled(false); |
|
|
|
groupAction->setEnabled(false); |
|
|
|
|
|
|
|
groupAction->setText(groupText); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else if (selCount == 1) { |
|
|
|
|
|
|
|
if (selItems.first()->type() == UBGraphicsGroupContainerItem::Type) { |
|
|
|
|
|
|
|
groupAction->setEnabled(true); |
|
|
|
|
|
|
|
groupAction->setText(ungroupText); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
groupAction->setEnabled(false); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else if (selCount > 1) { |
|
|
|
|
|
|
|
groupAction->setEnabled(true); |
|
|
|
|
|
|
|
groupAction->setText(groupText); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
void UBGraphicsScene::processGroupItems() |
|
|
|
void UBGraphicsScene::groupButtonClicked() |
|
|
|
{ |
|
|
|
{ |
|
|
|
qDebug() << "processing grouping items"; |
|
|
|
QAction *groupAction = UBApplication::mainWindow->actionGroupItems; |
|
|
|
|
|
|
|
QList<QGraphicsItem*> selItems = selectedItems(); |
|
|
|
|
|
|
|
if (!selItems.count()) { |
|
|
|
|
|
|
|
qDebug() << "Got grouping request when there is no any selected item on the scene"; |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
UBGraphicsGroupContainerItem *groupItem = new UBGraphicsGroupContainerItem(); |
|
|
|
if (groupAction->text() == groupText) { //The only way to get information from item, considering using smth else
|
|
|
|
|
|
|
|
UBGraphicsGroupContainerItem *groupItem = new UBGraphicsGroupContainerItem(); |
|
|
|
|
|
|
|
|
|
|
|
foreach (QGraphicsItem *item, selectedItems()) { |
|
|
|
foreach (QGraphicsItem *item, selItems) { |
|
|
|
item->setSelected(false); |
|
|
|
if (item->type() == UBGraphicsGroupContainerItem::Type) { |
|
|
|
item->setFlag(QGraphicsItem::ItemIsSelectable, false); |
|
|
|
QList<QGraphicsItem*> childItems = item->childItems(); |
|
|
|
item->setFlag( QGraphicsItem::ItemIsMovable, false); |
|
|
|
UBGraphicsGroupContainerItem *currentGroup = dynamic_cast<UBGraphicsGroupContainerItem*>(item); |
|
|
|
item->setFlag(QGraphicsItem::ItemIsFocusable); |
|
|
|
if (currentGroup) { |
|
|
|
groupItem->addToGroup(item); |
|
|
|
currentGroup->destroy(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
foreach (QGraphicsItem *chItem, childItems) { |
|
|
|
|
|
|
|
groupItem->addToGroup(chItem); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
groupItem->addToGroup(item); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
addItem(groupItem); |
|
|
|
|
|
|
|
groupItem->setVisible(true); |
|
|
|
|
|
|
|
groupItem->setFocus(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else if (groupAction->text() == ungroupText) { |
|
|
|
|
|
|
|
//Considering one selected item and it's a group
|
|
|
|
|
|
|
|
if (selItems.count() > 1) { |
|
|
|
|
|
|
|
qDebug() << "can't make sense of ungrouping more then one item. Grouping action should be performed for that purpose"; |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
UBGraphicsGroupContainerItem *currentGroup = dynamic_cast<UBGraphicsGroupContainerItem*>(selItems.first()); |
|
|
|
|
|
|
|
if (currentGroup) { |
|
|
|
|
|
|
|
currentGroup->destroy(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
addItem(groupItem); |
|
|
|
|
|
|
|
// groupItem->setPos(50, 50);
|
|
|
|
|
|
|
|
groupItem->setVisible(true); |
|
|
|
|
|
|
|
groupItem->setFocus(); |
|
|
|
|
|
|
|
qDebug() << groupItem->boundingRect(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// MARK: -
|
|
|
|
// MARK: -
|
|
|
@ -432,7 +480,6 @@ bool UBGraphicsScene::inputDevicePress(const QPointF& scenePos, const qreal& pre |
|
|
|
return accepted; |
|
|
|
return accepted; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool UBGraphicsScene::inputDeviceMove(const QPointF& scenePos, const qreal& pressure) |
|
|
|
bool UBGraphicsScene::inputDeviceMove(const QPointF& scenePos, const qreal& pressure) |
|
|
|
{ |
|
|
|
{ |
|
|
|
bool accepted = false; |
|
|
|
bool accepted = false; |
|
|
@ -567,7 +614,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 +622,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); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -746,6 +794,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); |
|
|
@ -756,114 +806,208 @@ 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); |
|
|
|
|
|
|
|
|
|
|
|
QSet<QGraphicsItem*> toBeAddedItems; |
|
|
|
if(eDrawingMode_Vector == UBDrawingController::drawingController()->drawingMode()){ |
|
|
|
QSet<QGraphicsItem*> toBeRemovedItems; |
|
|
|
// 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
|
|
|
|
int collidItemsSize = collidItems.size(); |
|
|
|
// 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); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
toBeAddedItems.reserve(collidItemsSize); |
|
|
|
}else{ |
|
|
|
toBeRemovedItems.reserve(collidItemsSize); |
|
|
|
QSet<QGraphicsItem*> toBeAddedItems; |
|
|
|
|
|
|
|
QSet<QGraphicsItem*> toBeRemovedItems; |
|
|
|
|
|
|
|
int collidItemsSize = collidItems.size(); |
|
|
|
|
|
|
|
toBeAddedItems.reserve(collidItemsSize); |
|
|
|
|
|
|
|
toBeRemovedItems.reserve(collidItemsSize); |
|
|
|
|
|
|
|
|
|
|
|
if (mShouldUseOMP) |
|
|
|
if (mShouldUseOMP) |
|
|
|
{ |
|
|
|
|
|
|
|
#pragma omp parallel for |
|
|
|
|
|
|
|
for (int i = 0; i < collidItemsSize; i++) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
UBGraphicsPolygonItem *collidingPolygonItem |
|
|
|
// #pragma omp parallel for
|
|
|
|
= qgraphicsitem_cast<UBGraphicsPolygonItem*> (collidItems.at(i)); |
|
|
|
for (int i = 0; i < collidItemsSize; i++) |
|
|
|
|
|
|
|
|
|
|
|
if (collidingPolygonItem) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
if(eraserInnerRect.contains(collidingPolygonItem->boundingRect())) |
|
|
|
UBGraphicsPolygonItem *collidingPolygonItem = qgraphicsitem_cast<UBGraphicsPolygonItem*>(collidItems.at(i)); |
|
|
|
{ |
|
|
|
|
|
|
|
#pragma omp critical |
|
|
|
if (NULL != collidingPolygonItem) |
|
|
|
toBeRemovedItems << collidingPolygonItem; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
QPolygonF collidingPolygon = collidingPolygonItem->polygon(); |
|
|
|
collidingPolygonItem->setColor(QColor(Qt::green)); |
|
|
|
QPainterPath collidingPath; |
|
|
|
|
|
|
|
collidingPath.addPolygon(collidingPolygon); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QPainterPath croppedPath = collidingPath.subtracted(eraserPath); |
|
|
|
UBGraphicsStrokesGroup* pGroup = collidingPolygonItem->strokesGroup(); |
|
|
|
QPainterPath croppedPathSimplified = croppedPath.simplified(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (croppedPath == collidingPath) |
|
|
|
if(eraserInnerRect.contains(collidingPolygonItem->boundingRect())) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// NOOP
|
|
|
|
// #pragma omp critical
|
|
|
|
} |
|
|
|
qDebug() << "case 1"; |
|
|
|
else if (croppedPathSimplified.isEmpty()) |
|
|
|
// Put the entire polygon into the remove list
|
|
|
|
{ |
|
|
|
collidingPolygonItem->setColor(QColor(Qt::blue)); |
|
|
|
#pragma omp critical |
|
|
|
|
|
|
|
toBeRemovedItems << collidingPolygonItem; |
|
|
|
toBeRemovedItems << collidingPolygonItem; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
foreach(const QPolygonF &pol, croppedPathSimplified.toFillPolygons()) |
|
|
|
// Here we get the polygon of the colliding item
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QPolygonF collidingPolygon = collidingPolygonItem->polygon(); |
|
|
|
|
|
|
|
QPainterPath collidingPath; |
|
|
|
|
|
|
|
collidingPath.addPolygon(collidingPolygon); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Then we substract the eraser path to the polygon and we simplify it
|
|
|
|
|
|
|
|
QPainterPath croppedPath = collidingPath.subtracted(eraserPath); |
|
|
|
|
|
|
|
QPainterPath croppedPathSimplified = croppedPath.simplified(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*if (croppedPath == collidingPath)
|
|
|
|
{ |
|
|
|
{ |
|
|
|
UBGraphicsPolygonItem* croppedPolygonItem = collidingPolygonItem->deepCopy(pol); |
|
|
|
// NOOP
|
|
|
|
#pragma omp critical |
|
|
|
qDebug() << "case 2"; |
|
|
|
toBeAddedItems << croppedPolygonItem; |
|
|
|
toBeRemovedItems << collidingPolygonItem; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else */if (croppedPathSimplified.isEmpty()) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// #pragma omp critical
|
|
|
|
|
|
|
|
qDebug() << "case 3"; |
|
|
|
|
|
|
|
// Put the entire polygon into the remove list if the eraser removes all its visible content
|
|
|
|
|
|
|
|
collidingPolygonItem->setColor(QColor(Qt::blue)); |
|
|
|
|
|
|
|
toBeRemovedItems << collidingPolygonItem; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
//qDebug() << "case 4";
|
|
|
|
|
|
|
|
// 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()) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
UBGraphicsPolygonItem* croppedPolygonItem = collidingPolygonItem->deepCopy(pol); |
|
|
|
|
|
|
|
croppedPolygonItem->setColor(QColor(Qt::black)); |
|
|
|
|
|
|
|
// #pragma omp critical
|
|
|
|
|
|
|
|
if(NULL != pGroup){ |
|
|
|
|
|
|
|
croppedPolygonItem->setStrokesGroup(pGroup); |
|
|
|
|
|
|
|
// croppedPolygonItem->setTransform(pGroup->sceneTransform().inverted());
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Add this new polygon to the 'added' list
|
|
|
|
|
|
|
|
toBeAddedItems << croppedPolygonItem; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// #pragma omp critical
|
|
|
|
|
|
|
|
// Remove the original polygonitem because it has been replaced by many smaller polygons
|
|
|
|
|
|
|
|
collidingPolygonItem->setColor(QColor(Qt::blue)); |
|
|
|
|
|
|
|
toBeRemovedItems << collidingPolygonItem; |
|
|
|
} |
|
|
|
} |
|
|
|
#pragma omp critical |
|
|
|
|
|
|
|
toBeRemovedItems << collidingPolygonItem; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
for (int i = 0; i < collidItemsSize; i++) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
UBGraphicsPolygonItem *collidingPolygonItem |
|
|
|
for (int i = 0; i < collidItemsSize; i++) |
|
|
|
= qgraphicsitem_cast<UBGraphicsPolygonItem*> (collidItems.at(i)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (collidingPolygonItem) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
if(eraserInnerRect.contains(collidingPolygonItem->boundingRect())) |
|
|
|
UBGraphicsPolygonItem *collidingPolygonItem = dynamic_cast<UBGraphicsPolygonItem*> (collidItems.at(i)); |
|
|
|
{ |
|
|
|
|
|
|
|
toBeRemovedItems << collidingPolygonItem; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
QPolygonF collidingPolygon = collidingPolygonItem->polygon(); |
|
|
|
|
|
|
|
QPainterPath collidingPath; |
|
|
|
|
|
|
|
collidingPath.addPolygon(collidingPolygon); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QPainterPath croppedPath = collidingPath.subtracted(eraserPath); |
|
|
|
if (collidingPolygonItem) |
|
|
|
QPainterPath croppedPathSimplified = croppedPath.simplified(); |
|
|
|
{ |
|
|
|
|
|
|
|
UBGraphicsStrokesGroup* pGroup = collidingPolygonItem->strokesGroup(); |
|
|
|
|
|
|
|
|
|
|
|
if (croppedPath == collidingPath) |
|
|
|
if(eraserInnerRect.contains(collidingPolygonItem->boundingRect())) |
|
|
|
{ |
|
|
|
|
|
|
|
// NOOP
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (croppedPathSimplified.isEmpty()) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
toBeRemovedItems << collidingPolygonItem; |
|
|
|
toBeRemovedItems << collidingPolygonItem; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
foreach(const QPolygonF &pol, croppedPathSimplified.toFillPolygons()) |
|
|
|
QPolygonF collidingPolygon = collidingPolygonItem->polygon(); |
|
|
|
|
|
|
|
QPainterPath collidingPath; |
|
|
|
|
|
|
|
collidingPath.addPolygon(collidingPolygon); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QPainterPath croppedPath = collidingPath.subtracted(eraserPath); |
|
|
|
|
|
|
|
QPainterPath croppedPathSimplified = croppedPath.simplified(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (croppedPath == collidingPath) |
|
|
|
{ |
|
|
|
{ |
|
|
|
UBGraphicsPolygonItem* croppedPolygonItem = collidingPolygonItem->deepCopy(pol); |
|
|
|
// NOOP
|
|
|
|
toBeAddedItems << croppedPolygonItem; |
|
|
|
} |
|
|
|
|
|
|
|
else if (croppedPathSimplified.isEmpty()) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
toBeRemovedItems << collidingPolygonItem; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
foreach(const QPolygonF &pol, croppedPathSimplified.toFillPolygons()) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
UBGraphicsPolygonItem* croppedPolygonItem = collidingPolygonItem->deepCopy(pol); |
|
|
|
|
|
|
|
toBeAddedItems << croppedPolygonItem; |
|
|
|
|
|
|
|
if(NULL != pGroup){ |
|
|
|
|
|
|
|
croppedPolygonItem->setStrokesGroup(pGroup); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
toBeRemovedItems << collidingPolygonItem; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
toBeRemovedItems << collidingPolygonItem; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
addItems(toBeAddedItems); |
|
|
|
if(eDrawingMode_Vector == DRAWING_MODE){ |
|
|
|
mAddedItems += toBeAddedItems; |
|
|
|
foreach(QGraphicsItem* item, toBeRemovedItems){ |
|
|
|
|
|
|
|
UBGraphicsPolygonItem* poly = dynamic_cast<UBGraphicsPolygonItem*>(item); |
|
|
|
|
|
|
|
if(NULL != poly){ |
|
|
|
|
|
|
|
if(NULL != poly->strokesGroup()){ |
|
|
|
|
|
|
|
poly->strokesGroup()->removeFromGroup(poly); |
|
|
|
|
|
|
|
removeItem(poly); |
|
|
|
|
|
|
|
}else{ |
|
|
|
|
|
|
|
qDebug() << "No group present"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}else{ |
|
|
|
|
|
|
|
removeItems(toBeRemovedItems); |
|
|
|
|
|
|
|
mRemovedItems += toBeRemovedItems; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
removeItems(toBeRemovedItems); |
|
|
|
// bool hack = false;
|
|
|
|
mRemovedItems += toBeRemovedItems; |
|
|
|
// UBGraphicsStrokesGroup* pG = new UBGraphicsStrokesGroup();
|
|
|
|
|
|
|
|
if(eDrawingMode_Vector == DRAWING_MODE){ |
|
|
|
|
|
|
|
foreach(QGraphicsItem* item, toBeAddedItems){ |
|
|
|
|
|
|
|
UBGraphicsPolygonItem* poly = dynamic_cast<UBGraphicsPolygonItem*>(item); |
|
|
|
|
|
|
|
if(NULL != poly && NULL != poly->strokesGroup()){ |
|
|
|
|
|
|
|
// 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; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
mPreviousPoint = pEndPoint; |
|
|
|
mPreviousPoint = pEndPoint; |
|
|
|
} |
|
|
|
} |
|
|
@ -1759,7 +1903,6 @@ QGraphicsItem* UBGraphicsScene::scaleToFitDocumentSize(QGraphicsItem* item, bool |
|
|
|
return item; |
|
|
|
return item; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void UBGraphicsScene::addRuler(QPointF center) |
|
|
|
void UBGraphicsScene::addRuler(QPointF center) |
|
|
|
{ |
|
|
|
{ |
|
|
|
UBGraphicsRuler* ruler = new UBGraphicsRuler(); // mem : owned and destroyed by the scene
|
|
|
|
UBGraphicsRuler* ruler = new UBGraphicsRuler(); // mem : owned and destroyed by the scene
|
|
|
|