Commit fd92b8d5 authored by Ilia Ryabokon's avatar Ilia Ryabokon

Strokes group contain one object

parent f941091f
...@@ -1206,9 +1206,20 @@ bool UBSvgSubsetAdaptor::UBSvgSubsetWriter::persistScene(int pageIndex) ...@@ -1206,9 +1206,20 @@ bool UBSvgSubsetAdaptor::UBSvgSubsetWriter::persistScene(int pageIndex)
// Get the items from the scene // Get the items from the scene
QList<QGraphicsItem*> items = mScene->items(); QList<QGraphicsItem*> items = mScene->items();
int strokes = 0; int polygons = 0;
foreach(QGraphicsItem *item, items) {
if (item->type() == UBGraphicsPolygonItem::Type) {
polygons++;
} else if (item->type() == UBGraphicsStrokesGroup::Type) {
strokes++;
}
}
qDebug() << "---Strokes count" << strokes << "Polygons count" << polygons;
qSort(items.begin(), items.end(), itemZIndexComp); qSort(items.begin(), items.end(), itemZIndexComp);
UBGraphicsStroke *openStroke = 0; UBGraphicsStroke *openStroke = 0;
int nextStroke = 0;
bool groupHoldsInfo = false; bool groupHoldsInfo = false;
...@@ -1217,18 +1228,35 @@ bool UBSvgSubsetAdaptor::UBSvgSubsetWriter::persistScene(int pageIndex) ...@@ -1217,18 +1228,35 @@ bool UBSvgSubsetAdaptor::UBSvgSubsetWriter::persistScene(int pageIndex)
QGraphicsItem *item = items.takeFirst(); QGraphicsItem *item = items.takeFirst();
// Is the item a strokes group? // Is the item a strokes group?
UBGraphicsStrokesGroup* strokesGroupItem = qgraphicsitem_cast<UBGraphicsStrokesGroup*>(item); UBGraphicsStrokesGroup* strokesGroupItem = qgraphicsitem_cast<UBGraphicsStrokesGroup*>(item);
if(strokesGroupItem && strokesGroupItem->isVisible()){ if(strokesGroupItem && strokesGroupItem->isVisible()){
// Add the polygons // Add the polygons
foreach(QGraphicsItem* item, strokesGroupItem->childItems()){ //parsing number of polygons into one polygon
qDebug() << "parsing stroke number" << nextStroke++;
UBGraphicsPolygonItem *resultPoly = 0;
foreach(QGraphicsItem* item, strokesGroupItem->childItems()) {
UBGraphicsPolygonItem* poly = qgraphicsitem_cast<UBGraphicsPolygonItem*>(item); UBGraphicsPolygonItem* poly = qgraphicsitem_cast<UBGraphicsPolygonItem*>(item);
if(NULL != poly){ if (!poly) {
polygonItemToSvgPolygon(poly, true); continue;
items.removeOne(poly); } else if (!resultPoly) {
resultPoly = poly;
continue;
} }
QPolygonF newPolygon = poly->sceneTransform().map(poly->polygon());
QPainterPath strokePainterPath;
strokePainterPath.addPolygon(resultPoly->sceneTransform().map(resultPoly->polygon()));
QPolygonF oldPolygons = strokePainterPath.simplified().toFillPolygon(resultPoly->sceneTransform().inverted());
newPolygon = oldPolygons.united(newPolygon);
resultPoly->setPolygon(newPolygon);
//
items.removeOne(poly);
}
if (resultPoly) {
polygonItemToSvgPolygon(resultPoly, true);
items.removeOne(resultPoly);
} }
} }
......
...@@ -286,6 +286,7 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent, bool enableUndoRedoSta ...@@ -286,6 +286,7 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent, bool enableUndoRedoSta
, magniferDisplayViewWidget(0) , magniferDisplayViewWidget(0)
, mZLayerController(new UBZLayerController(this)) , mZLayerController(new UBZLayerController(this))
, mpLastPolygon(NULL) , mpLastPolygon(NULL)
, mCurrentPolygon(0)
{ {
UBCoreGraphicsScene::setObjectName("BoardScene"); UBCoreGraphicsScene::setObjectName("BoardScene");
#ifdef __ppc__ #ifdef __ppc__
...@@ -597,6 +598,7 @@ bool UBGraphicsScene::inputDeviceRelease() ...@@ -597,6 +598,7 @@ bool UBGraphicsScene::inputDeviceRelease()
delete mCurrentStroke; delete mCurrentStroke;
mCurrentStroke = 0; mCurrentStroke = 0;
} }
mCurrentPolygon = 0;
} }
} }
...@@ -705,21 +707,7 @@ void UBGraphicsScene::moveTo(const QPointF &pPoint) ...@@ -705,21 +707,7 @@ void UBGraphicsScene::moveTo(const QPointF &pPoint)
void UBGraphicsScene::drawLineTo(const QPointF &pEndPoint, const qreal &pWidth, bool bLineStyle) void UBGraphicsScene::drawLineTo(const QPointF &pEndPoint, const qreal &pWidth, bool bLineStyle)
{ {
if (mPreviousWidth == -1.0) if (mPreviousWidth == -1.0)
mPreviousWidth = pWidth; mPreviousWidth = pWidth;
UBGraphicsPolygonItem *polygonItem = lineToPolygonItem(QLineF(mPreviousPoint, pEndPoint), pWidth);
if (!polygonItem->brush().isOpaque())
{
// -------------------------------------------------------------------------------------
// Here we substract the polygons that are overlapping in order to keep the transparency
// -------------------------------------------------------------------------------------
for (int i = 0; i < mPreviousPolygonItems.size(); i++)
{
UBGraphicsPolygonItem* previous = mPreviousPolygonItems.value(i);
polygonItem->subtract(previous);
}
}
if (bLineStyle) if (bLineStyle)
{ {
...@@ -733,18 +721,45 @@ void UBGraphicsScene::drawLineTo(const QPointF &pEndPoint, const qreal &pWidth, ...@@ -733,18 +721,45 @@ void UBGraphicsScene::drawLineTo(const QPointF &pEndPoint, const qreal &pWidth,
mAddedItems.clear(); mAddedItems.clear();
} }
mpLastPolygon = polygonItem;
mAddedItems.insert(polygonItem);
// Here we add the item to the scene
addItem(polygonItem);
if (!mCurrentStroke) if (!mCurrentStroke)
mCurrentStroke = new UBGraphicsStroke(); mCurrentStroke = new UBGraphicsStroke();
polygonItem->setStroke(mCurrentStroke);
mPreviousPolygonItems.append(polygonItem); QPolygonF newPolygon = UBGeometryUtils::lineToPolygon(QLineF(mPreviousPoint, pEndPoint), pWidth);
if (!mCurrentPolygon)
{
mCurrentPolygon = new UBGraphicsPolygonItem();
mCurrentPolygon->setPolygon(newPolygon);
initPolygonItem(mCurrentPolygon);
addItem(mCurrentPolygon);
mAddedItems.insert(mCurrentPolygon);
mCurrentPolygon->setStroke(mCurrentStroke);
mpLastPolygon = mCurrentPolygon;
}
//newPolygon = newPolygon.united(mCurrentPolygon->polygon());
QPainterPath strokePainterPath;
strokePainterPath.addPolygon(mCurrentPolygon->sceneTransform().map(mCurrentPolygon->polygon()));
//QList<QPolygonF>
QPolygonF oldPolygons = strokePainterPath.simplified().toFillPolygon(mCurrentPolygon->sceneTransform().inverted());
newPolygon = oldPolygons.united(newPolygon);
/* foreach(QPolygonF polygon, oldPolygons)
{
newPolygon = polygon.united(newPolygon);
}
*/
mpLastPolygon = mCurrentPolygon;
mCurrentPolygon->setPolygon(newPolygon);
if (!bLineStyle) if (!bLineStyle)
{ {
......
...@@ -424,7 +424,7 @@ public slots: ...@@ -424,7 +424,7 @@ public slots:
UBGraphicsPolygonItem* mpLastPolygon; UBGraphicsPolygonItem* mpLastPolygon;
bool mDrawWithCompass; bool mDrawWithCompass;
UBGraphicsPolygonItem *mCurrentPolygon;
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment