Updated the eraser on the lines as objects

preferencesAboutTextFull
shibakaneki 13 years ago
parent 775c9b9e65
commit 1a43936d45
  1. 4
      src/board/UBDrawingController.cpp
  2. 116
      src/domain/UBGraphicsScene.cpp

@ -45,7 +45,7 @@ UBDrawingController::UBDrawingController(QObject * parent)
, mActiveRuler(NULL)
, mStylusTool((UBStylusTool::Enum)-1)
, mLatestDrawingTool((UBStylusTool::Enum)-1)
, mDrawingMode(/*DRAWING_MODE*/eDrawingMode_Vector)
, mDrawingMode(DRAWING_MODE)
{
connect(UBSettings::settings(), SIGNAL(colorContextChanged()), this, SIGNAL(colorPaletteChanged()));
@ -114,7 +114,7 @@ void UBDrawingController::setStylusTool(int tool)
UBApplication::mainWindow->actionPen->setChecked(true);
else if (mStylusTool == UBStylusTool::Eraser){
UBApplication::mainWindow->actionEraser->setChecked(true);
//mDrawingMode = eDrawingMode_Artistic;
mDrawingMode = eDrawingMode_Artistic;
}
else if (mStylusTool == UBStylusTool::Marker)
UBApplication::mainWindow->actionMarker->setChecked(true);

@ -314,6 +314,7 @@ void UBGraphicsScene::selectionChangedProcessing()
+ QString::number(selectedItems().first()->data(UBGraphicsItemData::ItemOwnZValue).toReal(), 'f'));
}
}
void UBGraphicsScene::enableGroupingButton()
{
QAction *groupAction = UBApplication::mainWindow->actionGroupItems;
@ -324,6 +325,7 @@ void UBGraphicsScene::enableGroupingButton()
groupAction->setEnabled(false);
}
}
void UBGraphicsScene::processGroupItems()
{
qDebug() << "processing grouping items";
@ -345,9 +347,6 @@ void UBGraphicsScene::processGroupItems()
qDebug() << groupItem->boundingRect();
}
// MARK: -
// MARK: Mouse/Tablet events handling
bool UBGraphicsScene::inputDevicePress(const QPointF& scenePos, const qreal& pressure)
{
//mMesure1Ms = 0;
@ -434,7 +433,6 @@ bool UBGraphicsScene::inputDevicePress(const QPointF& scenePos, const qreal& pre
return accepted;
}
bool UBGraphicsScene::inputDeviceMove(const QPointF& scenePos, const qreal& pressure)
{
bool accepted = false;
@ -518,7 +516,6 @@ bool UBGraphicsScene::inputDeviceMove(const QPointF& scenePos, const qreal& pres
return accepted;
}
bool UBGraphicsScene::inputDeviceRelease()
{
/*
@ -617,8 +614,6 @@ bool UBGraphicsScene::inputDeviceRelease()
return accepted;
}
// MARK: -
void UBGraphicsScene::drawEraser(const QPointF &pPoint, bool isFirstDraw)
{
qreal eraserWidth = UBSettings::settings()->currentEraserWidth();
@ -694,7 +689,6 @@ void UBGraphicsScene::moveTo(const QPointF &pPoint)
mDrawWithCompass = false;
}
void UBGraphicsScene::drawLineTo(const QPointF &pEndPoint, const qreal &pWidth, bool bLineStyle)
{
if (mPreviousWidth == -1.0)
@ -746,11 +740,8 @@ void UBGraphicsScene::drawLineTo(const QPointF &pEndPoint, const qreal &pWidth,
}
}
void UBGraphicsScene::eraseLineTo(const QPointF &pEndPoint, const qreal &pWidth)
{
// QList<QGraphicsItem*> itemList;
const QLineF line(mPreviousPoint, pEndPoint);
const QPolygonF eraserPolygon = UBGeometryUtils::lineToPolygon(line, pWidth);
@ -787,7 +778,6 @@ void UBGraphicsScene::eraseLineTo(const QPointF &pEndPoint, const qreal &pWidth)
}
}
}
}else{
QSet<QGraphicsItem*> toBeAddedItems;
QSet<QGraphicsItem*> toBeRemovedItems;
@ -797,23 +787,19 @@ void UBGraphicsScene::eraseLineTo(const QPointF &pEndPoint, const qreal &pWidth)
if (mShouldUseOMP)
{
// #pragma omp parallel for
#pragma omp parallel for
for (int i = 0; i < collidItemsSize; i++)
{
UBGraphicsPolygonItem *collidingPolygonItem = qgraphicsitem_cast<UBGraphicsPolygonItem*>(collidItems.at(i));
if (NULL != collidingPolygonItem)
{
collidingPolygonItem->setColor(QColor(Qt::green));
UBGraphicsStrokesGroup* pGroup = collidingPolygonItem->strokesGroup();
if(eraserInnerRect.contains(collidingPolygonItem->boundingRect()))
{
// #pragma omp critical
qDebug() << "case 1";
#pragma omp critical
// Put the entire polygon into the remove list
collidingPolygonItem->setColor(QColor(Qt::blue));
toBeRemovedItems << collidingPolygonItem;
}
else
@ -825,43 +811,55 @@ void UBGraphicsScene::eraseLineTo(const QPointF &pEndPoint, const qreal &pWidth)
collidingPath.addPolygon(collidingPolygon);
// Then we substract the eraser path to the polygon and we simplify it
QPainterPath croppedPath = collidingPath.subtracted(eraserPath);
/**/
QTransform polyTransform = collidingPolygonItem->sceneTransform();
QPointF mTrPrevPoint;
QPointF mTrEndPoint;
// TODO: Handle the scale & rotation transform here
mTrPrevPoint.setX(mPreviousPoint.x() - polyTransform.dx());
mTrPrevPoint.setY(mPreviousPoint.y() - polyTransform.dy());
mTrEndPoint.setX(pEndPoint.x() - polyTransform.dx());
mTrEndPoint.setY(pEndPoint.y() - polyTransform.dy());
const QLineF trLine(mTrPrevPoint, mTrEndPoint);
const QPolygonF trEraserPolygon = UBGeometryUtils::lineToPolygon(trLine, pWidth);
QPainterPath trEraser;
trEraser.addPolygon(trEraserPolygon);
QPainterPath croppedPath = collidingPath.subtracted(trEraser);
/**/
// Original
//QPainterPath croppedPath = collidingPath.subtracted(eraserPath);
QPainterPath croppedPathSimplified = croppedPath.simplified();
/*if (croppedPath == collidingPath)
{
// NOOP
qDebug() << "case 2";
toBeRemovedItems << collidingPolygonItem;
}
else */if (croppedPathSimplified.isEmpty())
{
// #pragma omp critical
qDebug() << "case 3";
#pragma omp critical
// 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
#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
#pragma omp critical
// Remove the original polygonitem because it has been replaced by many smaller polygons
collidingPolygonItem->setColor(QColor(Qt::blue));
toBeRemovedItems << collidingPolygonItem;
}
}
@ -934,30 +932,14 @@ void UBGraphicsScene::eraseLineTo(const QPointF &pEndPoint, const qreal &pWidth)
mRemovedItems += toBeRemovedItems;
}
// bool hack = false;
// 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);
poly->setTransform(poly->strokesGroup()->transform());
poly->strokesGroup()->addToGroup(poly);
}
}
//addItem(pG);
}else{
addItems(toBeAddedItems);
mAddedItems += toBeAddedItems;
@ -967,7 +949,6 @@ void UBGraphicsScene::eraseLineTo(const QPointF &pEndPoint, const qreal &pWidth)
mPreviousPoint = pEndPoint;
}
void UBGraphicsScene::drawArcTo(const QPointF& pCenterPoint, qreal pSpanAngle)
{
mDrawWithCompass = true;
@ -1079,7 +1060,6 @@ void UBGraphicsScene::recolorAllItems()
}
}
UBGraphicsPolygonItem* UBGraphicsScene::lineToPolygonItem(const QLineF &pLine, const qreal &pWidth)
{
UBGraphicsPolygonItem *polygonItem = new UBGraphicsPolygonItem(pLine, pWidth);
@ -1089,7 +1069,6 @@ UBGraphicsPolygonItem* UBGraphicsScene::lineToPolygonItem(const QLineF &pLine, c
return polygonItem;
}
void UBGraphicsScene::initPolygonItem(UBGraphicsPolygonItem* polygonItem)
{
QColor colorOnDarkBG;
@ -1121,7 +1100,6 @@ void UBGraphicsScene::initPolygonItem(UBGraphicsPolygonItem* polygonItem)
polygonItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Graphic));
}
UBGraphicsPolygonItem* UBGraphicsScene::arcToPolygonItem(const QLineF& pStartRadius, qreal pSpanAngle, qreal pWidth)
{
QPolygonF polygon = UBGeometryUtils::arcToPolygon(pStartRadius, pSpanAngle, pWidth);
@ -1129,7 +1107,6 @@ UBGraphicsPolygonItem* UBGraphicsScene::arcToPolygonItem(const QLineF& pStartRad
return polygonToPolygonItem(polygon);
}
UBGraphicsPolygonItem* UBGraphicsScene::polygonToPolygonItem(const QPolygonF pPolygon)
{
UBGraphicsPolygonItem *polygonItem = new UBGraphicsPolygonItem(pPolygon);
@ -1139,14 +1116,12 @@ UBGraphicsPolygonItem* UBGraphicsScene::polygonToPolygonItem(const QPolygonF pPo
return polygonItem;
}
void UBGraphicsScene::hideEraser()
{
if (mEraser)
mEraser->hide();
}
void UBGraphicsScene::leaveEvent(QEvent * event)
{
Q_UNUSED(event);
@ -1221,13 +1196,11 @@ UBGraphicsScene* UBGraphicsScene::sceneDeepCopy() const
return copy;
}
UBItem* UBGraphicsScene::deepCopy() const
{
return sceneDeepCopy();
}
void UBGraphicsScene::clearItemsAndAnnotations()
{
deselectAllItems();
@ -1259,7 +1232,6 @@ void UBGraphicsScene::clearItemsAndAnnotations()
setDocumentUpdated();
}
void UBGraphicsScene::clearItems()
{
deselectAllItems();
@ -1297,7 +1269,6 @@ void UBGraphicsScene::clearItems()
setDocumentUpdated();
}
void UBGraphicsScene::clearAnnotations()
{
QSet<QGraphicsItem*> emptyList;
@ -1328,7 +1299,6 @@ void UBGraphicsScene::clearAnnotations()
setDocumentUpdated();
}
UBGraphicsPixmapItem* UBGraphicsScene::addPixmap(const QPixmap& pPixmap, const QPointF& pPos, qreal pScaleFactor, bool pUseAnimation)
{
UBGraphicsPixmapItem* pixmapItem = new UBGraphicsPixmapItem();
@ -1368,7 +1338,6 @@ UBGraphicsPixmapItem* UBGraphicsScene::addPixmap(const QPixmap& pPixmap, const Q
return pixmapItem;
}
void UBGraphicsScene::textUndoCommandAdded(UBGraphicsTextItem *textItem)
{
if (enableUndoRedoStack) { //should be deleted after scene own undo stack implemented
@ -1377,7 +1346,6 @@ void UBGraphicsScene::textUndoCommandAdded(UBGraphicsTextItem *textItem)
}
}
UBGraphicsVideoItem* UBGraphicsScene::addVideo(const QUrl& pVideoFileUrl, bool shouldPlayAsap, const QPointF& pPos)
{
UBGraphicsVideoItem* videoItem = new UBGraphicsVideoItem(pVideoFileUrl);
@ -1440,7 +1408,6 @@ UBGraphicsAudioItem* UBGraphicsScene::addAudio(const QUrl& pAudioFileUrl, bool s
return audioItem;
}
UBGraphicsWidgetItem* UBGraphicsScene::addWidget(const QUrl& pWidgetUrl, const QPointF& pPos)
{
int widgetType = UBAbstractWidget::widgetType(pWidgetUrl);
@ -1460,7 +1427,6 @@ UBGraphicsWidgetItem* UBGraphicsScene::addWidget(const QUrl& pWidgetUrl, const Q
}
}
UBGraphicsAppleWidgetItem* UBGraphicsScene::addAppleWidget(const QUrl& pWidgetUrl, const QPointF& pPos)
{
UBGraphicsAppleWidgetItem *appleWidget = new UBGraphicsAppleWidgetItem(pWidgetUrl);
@ -1470,7 +1436,6 @@ UBGraphicsAppleWidgetItem* UBGraphicsScene::addAppleWidget(const QUrl& pWidgetUr
return appleWidget;
}
UBGraphicsW3CWidgetItem* UBGraphicsScene::addW3CWidget(const QUrl& pWidgetUrl, const QPointF& pPos, int widgetType)
{
UBGraphicsW3CWidgetItem *w3CWidget = new UBGraphicsW3CWidgetItem(pWidgetUrl, 0, widgetType);
@ -1511,7 +1476,6 @@ void UBGraphicsScene::addGraphicsWidget(UBGraphicsWidgetItem* graphicsWidget, co
}
}
UBGraphicsW3CWidgetItem* UBGraphicsScene::addOEmbed(const QUrl& pContentUrl, const QPointF& pPos)
{
QStringList widgetPaths = UBPersistenceManager::persistenceManager()->allWidgets(UBSettings::settings()->applicationApplicationsLibraryDirectory());
@ -1564,7 +1528,6 @@ UBGraphicsSvgItem* UBGraphicsScene::addSvg(const QUrl& pSvgFileUrl, const QPoint
return svgItem;
}
UBGraphicsTextItem* UBGraphicsScene::addText(const QString& pString, const QPointF& pTopLeft)
{
return addTextWithFont(pString, pTopLeft, UBSettings::settings()->fontPixelSize()
@ -1572,7 +1535,6 @@ UBGraphicsTextItem* UBGraphicsScene::addText(const QString& pString, const QPoin
, UBSettings::settings()->isItalicFont());
}
UBGraphicsTextItem* UBGraphicsScene::addTextWithFont(const QString& pString, const QPointF& pTopLeft
, int pointSize, const QString& fontFamily, bool bold, bool italic)
{
@ -1629,6 +1591,7 @@ UBGraphicsTextItem* UBGraphicsScene::addTextWithFont(const QString& pString, con
return textItem;
}
UBGraphicsTextItem *UBGraphicsScene::addTextHtml(const QString &pString, const QPointF& pTopLeft)
{
UBGraphicsTextItem *textItem = new UBGraphicsTextItem();
@ -1692,7 +1655,6 @@ void UBGraphicsScene::removeItem(QGraphicsItem* item)
mFastAccessItems.removeAll(item);
}
void UBGraphicsScene::removeItems(const QSet<QGraphicsItem*>& items)
{
setModified(true);
@ -1706,7 +1668,6 @@ void UBGraphicsScene::removeItems(const QSet<QGraphicsItem*>& items)
mFastAccessItems.removeAll(item);
}
void UBGraphicsScene::deselectAllItems()
{
foreach(QGraphicsItem *gi, selectedItems ())
@ -1752,7 +1713,6 @@ QGraphicsItem* UBGraphicsScene::setAsBackgroundObject(QGraphicsItem* item, bool
return item;
}
QRectF UBGraphicsScene::normalizedSceneRect(qreal ratio)
{
@ -1792,7 +1752,6 @@ QRectF UBGraphicsScene::normalizedSceneRect(qreal ratio)
return normalizedRect;
}
void UBGraphicsScene::setDocument(UBDocumentProxy* pDocument)
{
if (pDocument != mDocument)
@ -1807,7 +1766,6 @@ void UBGraphicsScene::setDocument(UBDocumentProxy* pDocument)
}
}
QGraphicsItem* UBGraphicsScene::scaleToFitDocumentSize(QGraphicsItem* item, bool center, int margin, bool expand)
{
int maxWidth = mNominalSize.width() - (margin * 2);
@ -1831,7 +1789,6 @@ QGraphicsItem* UBGraphicsScene::scaleToFitDocumentSize(QGraphicsItem* item, bool
return item;
}
void UBGraphicsScene::addRuler(QPointF center)
{
UBGraphicsRuler* ruler = new UBGraphicsRuler(); // mem : owned and destroyed by the scene
@ -1847,7 +1804,6 @@ void UBGraphicsScene::addRuler(QPointF center)
setModified(true);
}
void UBGraphicsScene::addProtractor(QPointF center)
{
// Protractor
@ -2039,7 +1995,6 @@ void UBGraphicsScene::addMask(const QPointF &center)
setModified(true);
}
void UBGraphicsScene::setRenderingQuality(UBItem::RenderingQuality pRenderingQuality)
{
QListIterator<QGraphicsItem*> itItems(mFastAccessItems);
@ -2057,7 +2012,6 @@ void UBGraphicsScene::setRenderingQuality(UBItem::RenderingQuality pRenderingQua
}
}
QList<QUrl> UBGraphicsScene::relativeDependencies() const
{
QList<QUrl> relativePathes;
@ -2077,7 +2031,6 @@ QList<QUrl> UBGraphicsScene::relativeDependencies() const
return relativePathes;
}
QSize UBGraphicsScene::nominalSize()
{
if (mDocument && !mNominalSize.isValid())
@ -2088,7 +2041,6 @@ QSize UBGraphicsScene::nominalSize()
return mNominalSize;
}
void UBGraphicsScene::setNominalSize(const QSize& pSize)
{
if (nominalSize() != pSize)
@ -2102,7 +2054,6 @@ void UBGraphicsScene::setNominalSize(const QSize& pSize)
}
}
void UBGraphicsScene::setNominalSize(int pWidth, int pHeight)
{
setNominalSize(QSize(pWidth, pHeight));
@ -2112,10 +2063,12 @@ void UBGraphicsScene::setSelectedZLevel(QGraphicsItem * item)
{
item->setZValue(mZLayerController->generateZLevel(itemLayerType::SelectedItem));
}
void UBGraphicsScene::setOwnZlevel(QGraphicsItem *item)
{
item->setZValue(item->data(UBGraphicsItemData::ItemOwnZValue).toReal());
}
void UBGraphicsScene::groupItems(QList<QGraphicsItem *> &itemList)
{
foreach (QGraphicsItem *item, itemList) {
@ -2124,7 +2077,6 @@ void UBGraphicsScene::groupItems(QList<QGraphicsItem *> &itemList)
}
}
qreal UBGraphicsScene::changeZLevelTo(QGraphicsItem *item, UBZLayerController::moveDestination dest)
{
return mZLayerController->changeZLevelTo(item, dest);
@ -2142,7 +2094,6 @@ QGraphicsItem* UBGraphicsScene::rootItem(QGraphicsItem* item) const
return root;
}
void UBGraphicsScene::drawItems (QPainter * painter, int numItems,
QGraphicsItem * items[], const QStyleOptionGraphicsItem options[], QWidget * widget)
{
@ -2317,13 +2268,13 @@ void UBGraphicsScene::keyReleaseEvent(QKeyEvent * keyEvent)
QGraphicsScene::keyReleaseEvent(keyEvent);
}
void UBGraphicsScene::setDocumentUpdated()
{
if (document())
document()->setMetaData(UBSettings::documentUpdatedAt
, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()));
}
void UBGraphicsScene::createEraiser()
{
mEraser = new QGraphicsEllipseItem(); // mem : owned and destroyed by the scene
@ -2337,6 +2288,7 @@ void UBGraphicsScene::createEraiser()
addItem(mEraser);
}
void UBGraphicsScene::createPointer()
{
mPointer = new QGraphicsEllipseItem(); // mem : owned and destroyed by the scene

Loading…
Cancel
Save