new Line erase

lineStyle
thomas_lucky13 2 years ago
parent 67a6ce6c6c
commit 9a02d1a654
  1. 16
      src/domain/UBGraphicsLineItem.cpp
  2. 18
      src/domain/UBGraphicsLineItem.h
  3. 50
      src/domain/UBGraphicsScene.cpp

@ -6,7 +6,6 @@
#include "core/memcheck.h" #include "core/memcheck.h"
#include <iostream>
UBGraphicsLineItem::UBGraphicsLineItem (QGraphicsItem * parent) UBGraphicsLineItem::UBGraphicsLineItem (QGraphicsItem * parent)
: QGraphicsLineItem(parent) : QGraphicsLineItem(parent)
@ -20,7 +19,6 @@ UBGraphicsLineItem::UBGraphicsLineItem (QGraphicsItem * parent)
initialize(); initialize();
} }
UBGraphicsLineItem::UBGraphicsLineItem (const QLineF & line, QGraphicsItem * parent) UBGraphicsLineItem::UBGraphicsLineItem (const QLineF & line, QGraphicsItem * parent)
: QGraphicsLineItem(line, parent) : QGraphicsLineItem(line, parent)
, mOriginalWidth(-1) , mOriginalWidth(-1)
@ -144,6 +142,20 @@ Qt::PenStyle UBGraphicsLineItem::style() const
return QGraphicsLineItem::pen().style(); return QGraphicsLineItem::pen().style();
} }
QList<QPointF> UBGraphicsLineItem::linePoints()
{
QList<QPointF> points = QList<QPointF>();
qreal incr = 1/line().length();
if (incr<0) incr*=-1;
if (incr>0)
{
for (qreal t = 0; t <= 1; t+=incr)
{
points.push_back(line().pointAt(t));
}
}
return points;
}
UBItem* UBGraphicsLineItem::deepCopy() const UBItem* UBGraphicsLineItem::deepCopy() const
{ {

@ -37,23 +37,23 @@ class UBGraphicsLineItem : public QGraphicsLineItem, public UBItem
virtual UBGraphicsScene* scene(); virtual UBGraphicsScene* scene();
inline void subtract(UBGraphicsLineItem *pi) inline void subtract(UBGraphicsLineItem *li)
{ {
//if (boundingRect().intersects(pi->boundingRect())) /*if (boundingRect().intersects(li->boundingRect()))
//{ {
//QLineF subtractedLine = line().substracted(pi->line()); QLineF subtractedLine = line().substracted(li->line());
/*if (line() != subtractedLine) if (line() != subtractedLine)
{ {
mIsNominalLine = false; mIsNominalLine = false;
QGraphicsLineItem::setLine(subtractedLine); QGraphicsLineItem::setLine(subtractedLine);
}
}*/ }*/
//}
} }
inline void subtractIntersecting(UBGraphicsLineItem *pi) inline void subtractIntersecting(UBGraphicsLineItem *li)
{ {
/*QLineF subtractedLine = line();.substracted(pi->line()) /*QLineF subtractedLine = line().substracted(li->line());
if (line() != subtractedLine) if (line() != subtractedLine)
{ {
mIsNominalLine = false; mIsNominalLine = false;
@ -84,6 +84,8 @@ class UBGraphicsLineItem : public QGraphicsLineItem, public UBItem
void setNominalLine(bool isNominalLine) { mIsNominalLine = isNominalLine; } void setNominalLine(bool isNominalLine) { mIsNominalLine = isNominalLine; }
QList<QPointF> linePoints();
QColor colorOnDarkBackground() const QColor colorOnDarkBackground() const
{ {
return mColorOnDarkBackground; return mColorOnDarkBackground;

@ -1047,13 +1047,15 @@ void UBGraphicsScene::eraseLineTo(const QPointF &pEndPoint, const qreal &pWidth)
typedef QList<QPolygonF> POLYGONSLIST; typedef QList<QPolygonF> POLYGONSLIST;
QList<POLYGONSLIST> intersectedPolygons; QList<POLYGONSLIST> intersectedPolygons;
QList<UBGraphicsLineItem*> intersectedLineItems;
#pragma omp parallel for #pragma omp parallel for
for(int i=0; i<collidItems.size(); i++) for(int i=0; i<collidItems.size(); i++)
{ {
UBGraphicsPolygonItem *pi = qgraphicsitem_cast<UBGraphicsPolygonItem*>(collidItems[i]); UBGraphicsPolygonItem *pi = qgraphicsitem_cast<UBGraphicsPolygonItem*>(collidItems[i]);
if(pi == NULL) UBGraphicsLineItem *li = qgraphicsitem_cast<UBGraphicsLineItem*>(collidItems[i]);
continue; if(pi != NULL)
{
QPainterPath itemPainterPath; QPainterPath itemPainterPath;
itemPainterPath.addPolygon(pi->sceneTransform().map(pi->polygon())); itemPainterPath.addPolygon(pi->sceneTransform().map(pi->polygon()));
@ -1076,6 +1078,23 @@ void UBGraphicsScene::eraseLineTo(const QPointF &pEndPoint, const qreal &pWidth)
intersectedPolygons << newPath.simplified().toFillPolygons(pi->sceneTransform().inverted()); intersectedPolygons << newPath.simplified().toFillPolygons(pi->sceneTransform().inverted());
} }
} }
} else if (li != NULL)
{
QPainterPath itemPainterPath;
QList<QPointF> linePoints = li->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
intersectedLineItems << li;
}
}
}
} }
for(int i=0; i<intersectedItems.size(); i++) for(int i=0; i<intersectedItems.size(); i++)
@ -1123,7 +1142,21 @@ void UBGraphicsScene::eraseLineTo(const QPointF &pEndPoint, const qreal &pWidth)
intersectedPolygonItem->setTransform(t); intersectedPolygonItem->setTransform(t);
} }
if (!intersectedItems.empty()) for (int i=0; i<intersectedLineItems.size(); i++)
{
UBGraphicsLineItem *intersectedLineItem = intersectedLineItems[i];
mRemovedItems << intersectedLineItem;
QTransform t;
bool bApplyTransform = false;
removeItem(intersectedLineItem);
if (bApplyTransform)
{
intersectedLineItem ->setTransform(t);
}
}
if (!intersectedItems.empty() || !intersectedLineItems.empty())
setModified(true); setModified(true);
} }
@ -1552,7 +1585,7 @@ void UBGraphicsScene::clearContent(clearCase pCase)
? qgraphicsitem_cast<UBGraphicsGroupContainerItem*>(item->parentItem()) ? qgraphicsitem_cast<UBGraphicsGroupContainerItem*>(item->parentItem())
: 0; : 0;
UBGraphicsItemDelegate *curDelegate = UBGraphicsItem::Delegate(item); UBGraphicsItemDelegate *curDelegate = UBGraphicsItem::Delegate(item);
if (!curDelegate) { if (!curDelegate && item->type() != UBGraphicsLineItem::Type) {
continue; continue;
} }
@ -1560,6 +1593,12 @@ void UBGraphicsScene::clearContent(clearCase pCase)
bool isStrokesGroup = item->type() == UBGraphicsStrokesGroup::Type; bool isStrokesGroup = item->type() == UBGraphicsStrokesGroup::Type;
bool shouldDelete = false; bool shouldDelete = false;
if(item->type()==UBGraphicsLineItem::Type)
{
removedItems << item;
this->removeItem(item);
} else
{
switch (static_cast<int>(pCase)) { switch (static_cast<int>(pCase)) {
case clearAnnotations : case clearAnnotations :
shouldDelete = isStrokesGroup; shouldDelete = isStrokesGroup;
@ -1571,6 +1610,7 @@ void UBGraphicsScene::clearContent(clearCase pCase)
shouldDelete = !isGroup && !isBackgroundObject(item); shouldDelete = !isGroup && !isBackgroundObject(item);
break; break;
} }
}
if(shouldDelete) { if(shouldDelete) {
if (itemGroup) { if (itemGroup) {

Loading…
Cancel
Save