bool LensEffectsPlugin::run(ScribusDoc* doc, QString) { ScribusDoc* currDoc = doc; if (currDoc == 0) currDoc = ScCore->primaryMainWindow()->doc; if (currDoc->m_Selection->count() > 0) { LensDialog *dia = new LensDialog(currDoc->scMW(), currDoc); if (dia->exec()) { for (int a = 0; a < dia->origPathItem.count(); a++) { PageItem *currItem = currDoc->m_Selection->itemAt(a); if (currItem->itemType() == PageItem::Line) continue; QPainterPath path = dia->origPathItem[a]->path(); FPointArray points; points.fromQPainterPath(path); currItem->PoLine = points; currItem->Frame = false; currItem->ClipEdited = true; currItem->FrameType = 3; currDoc->AdjustItemSize(currItem); currItem->OldB2 = currItem->width(); currItem->OldH2 = currItem->height(); currItem->updateClip(); currItem->ContourLine = currItem->PoLine.copy(); } currDoc->changed(); } delete dia; } return true; }
bool SmoothPathPlugin::run(ScribusDoc* doc, QString) { ScribusDoc* currDoc = doc; if (currDoc == 0) currDoc = ScCore->primaryMainWindow()->doc; if (currDoc->m_Selection->count() > 0) { PageItem *currItem = currDoc->m_Selection->itemAt(0); QPainterPath pp; if (currItem->itemType() == PageItem::PolyLine) pp = currItem->PoLine.toQPainterPath(false); else pp = currItem->PoLine.toQPainterPath(true); QList<QPolygonF> polyList = pp.toSubpathPolygons(); QPainterPath result; for (int a = 0; a < polyList.count(); a++) { result.addPath(bezierFit(polyList[a], 5.0)); } currItem->PoLine.fromQPainterPath(result); currItem->ClipEdited = true; currItem->FrameType = 3; currDoc->AdjustItemSize(currItem); currItem->OldB2 = currItem->width(); currItem->OldH2 = currItem->height(); currItem->updateClip(); currDoc->regionsChanged()->update(QRectF()); currDoc->changed(); } return true; }
bool SubdividePlugin::run(ScribusDoc* doc, QString) { ScribusDoc* currDoc = doc; if (currDoc == 0) currDoc = ScCore->primaryMainWindow()->doc; double nearT = 0.5; uint docSelectionCount = currDoc->m_Selection->count(); if (docSelectionCount != 0) { for (uint aa = 0; aa < docSelectionCount; ++aa) { FPointArray points; PageItem *currItem = currDoc->m_Selection->itemAt(aa); if (currDoc->nodeEdit.isContourLine) { uint psize = currItem->ContourLine.size(); for (uint a = 0; a < psize-3; a += 4) { if (currItem->ContourLine.point(a).x() > 900000) { points.setMarker(); continue; } FPoint base = currItem->ContourLine.point(a); FPoint c1 = currItem->ContourLine.point(a+1); FPoint base2 = currItem->ContourLine.point(a+2); FPoint c2 = currItem->ContourLine.point(a+3); FPoint cn1 = (1.0 - nearT) * base + nearT * c1; FPoint cn2 = (1.0 - nearT) * cn1 + nearT * ((1.0 - nearT) * c1 + nearT * c2); FPoint cn3 = (1.0 - nearT) * ((1.0 - nearT) * c1 + nearT * c2) + nearT * ((1.0 - nearT) * c2 + nearT * base2); FPoint cn4 = (1.0 - nearT) * c2 + nearT * base2; FPoint bp1 = (1.0 - nearT) * cn2 + nearT * cn3; if ((base == c1) && (base2 == c2)) { points.addPoint(base); points.addPoint(c1); points.addPoint(bp1); points.addPoint(bp1); points.addPoint(bp1); points.addPoint(bp1); points.addPoint(base2); points.addPoint(c2); } else { points.addPoint(base); points.addPoint(cn1); points.addPoint(bp1); points.addPoint(cn2); points.addPoint(bp1); points.addPoint(cn3); points.addPoint(base2); points.addPoint(cn4); } } currItem->ContourLine = points; } else { uint psize = currItem->PoLine.size(); for (uint a = 0; a < psize-3; a += 4) { if (currItem->PoLine.point(a).x() > 900000) { points.setMarker(); continue; } FPoint base = currItem->PoLine.point(a); FPoint c1 = currItem->PoLine.point(a+1); FPoint base2 = currItem->PoLine.point(a+2); FPoint c2 = currItem->PoLine.point(a+3); FPoint cn1 = (1.0 - nearT) * base + nearT * c1; FPoint cn2 = (1.0 - nearT) * cn1 + nearT * ((1.0 - nearT) * c1 + nearT * c2); FPoint cn3 = (1.0 - nearT) * ((1.0 - nearT) * c1 + nearT * c2) + nearT * ((1.0 - nearT) * c2 + nearT * base2); FPoint cn4 = (1.0 - nearT) * c2 + nearT * base2; FPoint bp1 = (1.0 - nearT) * cn2 + nearT * cn3; if ((base == c1) && (base2 == c2)) { points.addPoint(base); points.addPoint(c1); points.addPoint(bp1); points.addPoint(bp1); points.addPoint(bp1); points.addPoint(bp1); points.addPoint(base2); points.addPoint(c2); } else { points.addPoint(base); points.addPoint(cn1); points.addPoint(bp1); points.addPoint(cn2); points.addPoint(bp1); points.addPoint(cn3); points.addPoint(base2); points.addPoint(cn4); } } currItem->PoLine = points; currItem->Frame = false; currItem->ClipEdited = true; currItem->FrameType = 3; currDoc->AdjustItemSize(currItem); currItem->OldB2 = currItem->width(); currItem->OldH2 = currItem->height(); currItem->updateClip(); } } currDoc->regionsChanged()->update(QRectF()); currDoc->changed(); } return true; }
bool PathFinderPlugin::run(ScribusDoc* doc, QString) { QString vers = QString(qVersion()).left(5); if (vers < "4.3.3") { QMessageBox::information(doc->scMW(), tr("Qt Version too old"), tr("This plugin requires at least version 4.3.3 of the Qt library")); return true; } ScribusDoc* currDoc = doc; if (currDoc == 0) currDoc = ScCore->primaryMainWindow()->doc; if (currDoc->m_Selection->count() > 1) { PageItem *Item1 = currDoc->m_Selection->itemAt(0); PageItem *Item2 = currDoc->m_Selection->itemAt(1); PathFinderDialog *dia = new PathFinderDialog(currDoc->scMW(), currDoc, Item1, Item2); if (dia->exec()) { if (dia->keepItem1) { PageItem *newItem; if (dia->swapped) { newItem = new PageItem_Polygon(*Item2); newItem->setSelected(false); currDoc->Items->insert(Item2->ItemNr, newItem); } else { newItem = new PageItem_Polygon(*Item1); newItem->setSelected(false); currDoc->Items->insert(Item1->ItemNr, newItem); } } if (dia->keepItem2) { PageItem *newItem; if (dia->swapped) { newItem = new PageItem_Polygon(*Item1); newItem->setSelected(false); currDoc->Items->insert(Item1->ItemNr, newItem); } else { newItem = new PageItem_Polygon(*Item2); newItem->setSelected(false); currDoc->Items->insert(Item2->ItemNr, newItem); } } if (dia->keepItem1 || dia->keepItem2) currDoc->renumberItemsInListOrder(); if (dia->opMode != 4) { PageItem *currItem; QPainterPath path; FPointArray points; if (dia->targetColor == 0) { currItem = Item1; if (dia->swapped) { currItem = Item2; currItem->setXYPos(Item1->xPos(), Item1->yPos()); currItem->setRotation(0.0); } } else { if (dia->swapped) currItem = Item1; else { currItem = Item2; currItem->setXYPos(Item1->xPos(), Item1->yPos()); currItem->setRotation(0.0); } } path = dia->result; points.fromQPainterPath(path); currItem->PoLine = points; currItem->Frame = false; currItem->ClipEdited = true; currItem->FrameType = 3; currDoc->AdjustItemSize(currItem); currItem->OldB2 = currItem->width(); currItem->OldH2 = currItem->height(); currItem->updateClip(); currItem->ContourLine = currItem->PoLine.copy(); currDoc->m_Selection->removeItem(currItem); currDoc->itemSelection_DeleteItem(); } else { QPainterPath path; FPointArray points; PageItem *newItem; double i1x = Item1->xPos(); double i1y = Item1->yPos(); path = dia->result; if (!path.isEmpty()) { points.fromQPainterPath(path); Item1->PoLine = points; Item1->Frame = false; Item1->ClipEdited = true; Item1->FrameType = 3; currDoc->AdjustItemSize(Item1); Item1->OldB2 = Item1->width(); Item1->OldH2 = Item1->height(); Item1->updateClip(); Item1->ContourLine = Item1->PoLine.copy(); } path = QPainterPath(); path = dia->result1; if (!path.isEmpty()) { points.fromQPainterPath(path); Item2->setXYPos(i1x, i1y); Item2->setRotation(0.0); Item2->PoLine = points; Item2->Frame = false; Item2->ClipEdited = true; Item2->FrameType = 3; currDoc->AdjustItemSize(Item2); Item2->OldB2 = Item2->width(); Item2->OldH2 = Item2->height(); Item2->updateClip(); Item2->ContourLine = Item2->PoLine.copy(); } path = QPainterPath(); path = dia->result2; if (!path.isEmpty()) { if (dia->targetColor == 0) { newItem = new PageItem_Polygon(*Item1); newItem->setXYPos(i1x, i1y); } else { newItem = new PageItem_Polygon(*Item2); newItem->setXYPos(i1x, i1y); newItem->setRotation(0.0); } currDoc->Items->append(newItem); newItem->ItemNr = currDoc->Items->count()-1; newItem->setSelected(false); points.fromQPainterPath(path); newItem->PoLine = points; newItem->Frame = false; newItem->ClipEdited = true; newItem->FrameType = 3; currDoc->AdjustItemSize(newItem); newItem->OldB2 = newItem->width(); newItem->OldH2 = newItem->height(); newItem->updateClip(); newItem->ContourLine = newItem->PoLine.copy(); if (dia->targetColor == 2) { QString fill = dia->getOtherFillColor(); if (fill == CommonStrings::tr_NoneColor) fill = CommonStrings::None; newItem->setFillColor(fill); QString stroke = dia->getOtherLineColor(); if (stroke == CommonStrings::tr_NoneColor) stroke = CommonStrings::None; newItem->setLineColor(stroke); } } currDoc->m_Selection->clear(); currDoc->view()->Deselect(true); } currDoc->changed(); currDoc->view()->DrawNew(); } delete dia; } return true; }
bool PathFinderPlugin::run(ScribusDoc* doc, QString) { ScribusDoc* currDoc = doc; if (currDoc == 0) currDoc = ScCore->primaryMainWindow()->doc; if (currDoc->m_Selection->count() <= 1) return true; //<<#9046 UndoTransaction* activeTransaction = NULL; UndoManager* undoManager = UndoManager::instance(); if (UndoManager::undoEnabled()) activeTransaction = new UndoTransaction(undoManager->beginTransaction(Um::SelectionGroup, Um::IDocument, Um::PathOperation, "", Um::IPolygon)); //>>#9046 PageItem *Item1 = currDoc->m_Selection->itemAt(0); PageItem *Item2 = currDoc->m_Selection->itemAt(1); PathFinderDialog *dia = new PathFinderDialog(currDoc->scMW(), currDoc, Item1, Item2); if (dia->exec()) { int opMode=dia->opMode; if (dia->keepItem1) { PageItem *newItem; if (dia->swapped) { newItem = new PageItem_Polygon(*Item2); newItem->setSelected(false); currDoc->Items->insert(currDoc->Items->indexOf(Item2), newItem); } else { newItem = new PageItem_Polygon(*Item1); newItem->setSelected(false); currDoc->Items->insert(currDoc->Items->indexOf(Item1), newItem); } if (UndoManager::undoEnabled()) { ScItemState<PageItem*> *is = new ScItemState<PageItem*>("Create PageItem"); is->set("CREATE_ITEM", "create_item"); is->setItem(newItem); UndoObject *target = currDoc->Pages->at(Item1->OwnPage); undoManager->action(target, is); } } if (dia->keepItem2) { PageItem *newItem; if (dia->swapped) { newItem = new PageItem_Polygon(*Item1); newItem->setSelected(false); currDoc->Items->insert(currDoc->Items->indexOf(Item1), newItem); } else { newItem = new PageItem_Polygon(*Item2); newItem->setSelected(false); currDoc->Items->insert(currDoc->Items->indexOf(Item2), newItem); } if (UndoManager::undoEnabled()) { ScItemState<PageItem*> *is = new ScItemState<PageItem*>("Create PageItem"); is->set("CREATE_ITEM", "create_item"); is->setItem(newItem); UndoObject *target = currDoc->Pages->at(Item1->OwnPage); undoManager->action(target, is); } } if (opMode != 4) { PageItem *currItem; QPainterPath path; FPointArray points; if (dia->targetColor == 0) { currItem = Item1; if (dia->swapped) { currItem = Item2; currItem->setXYPos(Item1->xPos(), Item1->yPos()); currItem->setRotation(0.0); } } else { if (dia->swapped) currItem = Item1; else { currItem = Item2; currItem->setXYPos(Item1->xPos(), Item1->yPos()); currItem->setRotation(0.0); } } path = dia->result; points.fromQPainterPath(path); //<<#9046 FPointArray oldPOLine=currItem->PoLine; FPointArray oldContourLine=currItem->ContourLine; ScItemState<QPair<QPair<FPointArray, FPointArray>, QPair<FPointArray, FPointArray> > >* state = NULL; if (UndoManager::undoEnabled()) { state = new ScItemState<QPair<QPair<FPointArray, FPointArray>, QPair<FPointArray, FPointArray> > >(Um::PathOperation); state->set("PATH_OPERATION", "path_operation"); state->set("PATH_OP_OLD_FRAME", currItem->Frame); state->set("PATH_OP_OLD_CLIPEDITED", currItem->ClipEdited); state->set("PATH_OP_OLD_FRAMETYPE", currItem->FrameType); state->set("PATH_OP_OLD_OLDB2", currItem->OldB2); state->set("PATH_OP_OLD_OLDH2", currItem->OldH2); state->set("PATH_OP_NEW_FRAME", false); state->set("PATH_OP_NEW_CLIPEDITED", true); state->set("PATH_OP_NEW_FRAMETYPE", 3); } //>>#9046 currItem->PoLine = points; currItem->Frame = false; currItem->ClipEdited = true; currItem->FrameType = 3; currDoc->AdjustItemSize(currItem); currItem->OldB2 = currItem->width(); currItem->OldH2 = currItem->height(); currItem->updateClip(); currItem->ContourLine = currItem->PoLine.copy(); //<<#9046 if (UndoManager::undoEnabled()) { state->set("PATH_OP_NEW_OLDB2", currItem->OldB2); state->set("PATH_OP_NEW_OLDH2", currItem->OldH2); state->setItem(QPair<QPair<FPointArray, FPointArray>, QPair<FPointArray, FPointArray> >(QPair<FPointArray, FPointArray>(oldPOLine, oldContourLine), QPair<FPointArray, FPointArray>(points, currItem->ContourLine))); undoManager->action(currItem, state); } //>>#9046 currDoc->m_Selection->removeItem(currItem); currDoc->itemSelection_DeleteItem(); } else { QPainterPath path; FPointArray points; PageItem *newItem; double i1x = Item1->xPos(); double i1y = Item1->yPos(); path = dia->result; if (!path.isEmpty()) { points.fromQPainterPath(path); //<<#9046 FPointArray oldPOLine=Item1->PoLine; FPointArray oldContourLine=Item1->ContourLine; ScItemState<QPair<QPair<FPointArray, FPointArray>, QPair<FPointArray, FPointArray> > >* state = NULL; if (UndoManager::undoEnabled()) { state = new ScItemState<QPair<QPair<FPointArray, FPointArray>, QPair<FPointArray, FPointArray> > >(Um::PathOperation); state->set("PATH_OPERATION", "path_operation"); state->set("PATH_OP_OLD_FRAME", Item1->Frame); state->set("PATH_OP_OLD_CLIPEDITED", Item1->ClipEdited); state->set("PATH_OP_OLD_FRAMETYPE", Item1->FrameType); state->set("PATH_OP_OLD_OLDB2", Item1->OldB2); state->set("PATH_OP_OLD_OLDH2", Item1->OldH2); state->set("PATH_OP_NEW_FRAME", false); state->set("PATH_OP_NEW_CLIPEDITED", true); state->set("PATH_OP_NEW_FRAMETYPE", 3); } //>>#9046 Item1->PoLine = points; Item1->Frame = false; Item1->ClipEdited = true; Item1->FrameType = 3; currDoc->AdjustItemSize(Item1); Item1->OldB2 = Item1->width(); Item1->OldH2 = Item1->height(); Item1->updateClip(); Item1->ContourLine = Item1->PoLine.copy(); //<<#9046 if (UndoManager::undoEnabled()) { state->set("PATH_OP_NEW_OLDB2", Item1->OldB2); state->set("PATH_OP_NEW_OLDH2", Item1->OldH2); state->setItem(QPair<QPair<FPointArray, FPointArray>, QPair<FPointArray, FPointArray> >(QPair<FPointArray, FPointArray>(oldPOLine, oldContourLine), QPair<FPointArray, FPointArray>(Item1->PoLine, Item1->ContourLine))); undoManager->action(Item1, state); } //>>#9046 } path = QPainterPath(); path = dia->result1; if (!path.isEmpty()) { points.fromQPainterPath(path); //<<#9046 FPointArray oldPOLine=Item2->PoLine; FPointArray oldContourLine=Item2->ContourLine; ScItemState<QPair<QPair<FPointArray, FPointArray>, QPair<FPointArray, FPointArray> > >* state = NULL; if (UndoManager::undoEnabled()) { state = new ScItemState<QPair<QPair<FPointArray, FPointArray>, QPair<FPointArray, FPointArray> > >(Um::PathOperation); state->set("PATH_OPERATION", "path_operation"); state->set("PATH_OP_OLD_FRAME", Item2->Frame); state->set("PATH_OP_OLD_CLIPEDITED", Item2->ClipEdited); state->set("PATH_OP_OLD_FRAMETYPE", Item2->FrameType); state->set("PATH_OP_OLD_OLDB2", Item2->OldB2); state->set("PATH_OP_OLD_OLDH2", Item2->OldH2); state->set("PATH_OP_NEW_FRAME", false); state->set("PATH_OP_NEW_CLIPEDITED", true); state->set("PATH_OP_NEW_FRAMETYPE", 3); } //>>#9046 Item2->setXYPos(i1x, i1y); Item2->setRotation(0.0); Item2->PoLine = points; Item2->Frame = false; Item2->ClipEdited = true; Item2->FrameType = 3; currDoc->AdjustItemSize(Item2); Item2->OldB2 = Item2->width(); Item2->OldH2 = Item2->height(); Item2->updateClip(); Item2->ContourLine = Item2->PoLine.copy(); //<<#9046 if (UndoManager::undoEnabled()) { state->set("PATH_OP_NEW_OLDB2", Item2->OldB2); state->set("PATH_OP_NEW_OLDH2", Item2->OldH2); state->setItem(QPair<QPair<FPointArray, FPointArray>, QPair<FPointArray, FPointArray> >(QPair<FPointArray, FPointArray>(oldPOLine, oldContourLine), QPair<FPointArray, FPointArray>(Item2->PoLine, Item2->ContourLine))); undoManager->action(Item2, state); } //>>#9046 } path = QPainterPath(); path = dia->result2; if (!path.isEmpty()) { if (dia->targetColor == 0) { newItem = new PageItem_Polygon(*Item1); newItem->setXYPos(i1x, i1y); } else { newItem = new PageItem_Polygon(*Item2); newItem->setXYPos(i1x, i1y); newItem->setRotation(0.0); } currDoc->Items->append(newItem); newItem->setSelected(false); points.fromQPainterPath(path); newItem->PoLine = points; newItem->Frame = false; newItem->ClipEdited = true; newItem->FrameType = 3; currDoc->AdjustItemSize(newItem); newItem->OldB2 = newItem->width(); newItem->OldH2 = newItem->height(); newItem->updateClip(); newItem->ContourLine = newItem->PoLine.copy(); if (dia->targetColor == 2) { QString fill = dia->getOtherFillColor(); if (fill == CommonStrings::tr_NoneColor) fill = CommonStrings::None; newItem->setFillColor(fill); QString stroke = dia->getOtherLineColor(); if (stroke == CommonStrings::tr_NoneColor) stroke = CommonStrings::None; newItem->setLineColor(stroke); } } currDoc->m_Selection->clear(); currDoc->view()->Deselect(true); } currDoc->changed(); currDoc->view()->DrawNew(); } delete dia; //<<#9046 if (activeTransaction) { activeTransaction->commit(); delete activeTransaction; activeTransaction = NULL; } //>>#9046 return true; }
bool PathStrokerPlugin::run(ScribusDoc* doc, QString) { ScribusDoc* currDoc = doc; if (currDoc == 0) currDoc = ScCore->primaryMainWindow()->doc; if (currDoc->m_Selection->count() > 0) { QVector<double> m_array; PageItem *currItem = currDoc->m_Selection->itemAt(0); FPointArray path = currItem->PoLine; QPainterPath pp; if (currItem->itemType() == PageItem::PolyLine) pp = path.toQPainterPath(false); else pp = path.toQPainterPath(true); if (currItem->NamedLStyle.isEmpty()) { QPainterPathStroker stroke; stroke.setCapStyle(currItem->lineEnd()); stroke.setJoinStyle(currItem->lineJoin()); if (currItem->lineStyle() == Qt::SolidLine) stroke.setDashPattern(currItem->lineStyle()); else { getDashArray(currItem->lineStyle(), 1, m_array); stroke.setDashPattern(m_array); } stroke.setWidth(currItem->lineWidth()); QPainterPath result = stroke.createStroke(pp).simplified(); if (currItem->startArrowIndex() != 0) { FPoint Start = currItem->PoLine.point(0); for (uint xx = 1; xx < currItem->PoLine.size(); xx += 2) { FPoint Vector = currItem->PoLine.point(xx); if ((Start.x() != Vector.x()) || (Start.y() != Vector.y())) { double r = atan2(Start.y()-Vector.y(),Start.x()-Vector.x())*(180.0/M_PI); QMatrix arrowTrans; FPointArray arrow = currDoc->arrowStyles.at(currItem->startArrowIndex()-1).points.copy(); arrowTrans.translate(Start.x(), Start.y()); arrowTrans.rotate(r); arrowTrans.scale(currItem->lineWidth(), currItem->lineWidth()); arrow.map(arrowTrans); result.addPath(arrow.toQPainterPath(true)); break; } } } if (currItem->endArrowIndex() != 0) { FPoint End = currItem->PoLine.point(currItem->PoLine.size()-2); for (uint xx = currItem->PoLine.size()-1; xx > 0; xx -= 2) { FPoint Vector = currItem->PoLine.point(xx); if ((End.x() != Vector.x()) || (End.y() != Vector.y())) { double r = atan2(End.y()-Vector.y(),End.x()-Vector.x())*(180.0/M_PI); QMatrix arrowTrans; FPointArray arrow = currDoc->arrowStyles.at(currItem->endArrowIndex()-1).points.copy(); arrowTrans.translate(End.x(), End.y()); arrowTrans.rotate(r); arrowTrans.scale(currItem->lineWidth(), currItem->lineWidth()); arrow.map(arrowTrans); result.addPath(arrow.toQPainterPath(true)); break; } } } currDoc->m_Selection->clear(); PageItem* newItem = currDoc->convertItemTo(currItem, PageItem::Polygon); newItem->setLineWidth(0); newItem->setLineStyle(Qt::SolidLine); newItem->setFillColor(newItem->lineColor()); newItem->setFillShade(newItem->lineShade()); newItem->setFillTransparency(newItem->lineTransparency()); newItem->setFillBlendmode(newItem->lineBlendmode()); FPointArray points; points.fromQPainterPath(result); newItem->PoLine = points; newItem->Frame = false; newItem->ClipEdited = true; newItem->FrameType = 3; currDoc->AdjustItemSize(newItem); newItem->OldB2 = newItem->width(); newItem->OldH2 = newItem->height(); newItem->updateClip(); newItem->ContourLine = newItem->PoLine.copy(); newItem->setFillEvenOdd(true); currDoc->m_Selection->addItem(newItem); } else { currDoc->m_Selection->clear(); multiLine ml = currDoc->MLineStyles[currItem->NamedLStyle]; bool first = true; for (int it = ml.size()-1; it > -1; it--) { if ((ml[it].Color != CommonStrings::None) && (ml[it].Width != 0)) { QPainterPathStroker stroke; stroke.setCapStyle(static_cast<Qt::PenCapStyle>(ml[it].LineEnd)); stroke.setJoinStyle(static_cast<Qt::PenJoinStyle>(ml[it].LineJoin)); if (static_cast<Qt::PenStyle>(ml[it].Dash) == Qt::SolidLine) stroke.setDashPattern(static_cast<Qt::PenStyle>(ml[it].Dash)); else { getDashArray(static_cast<Qt::PenStyle>(ml[it].Dash), 1, m_array); stroke.setDashPattern(m_array); } stroke.setWidth(ml[it].Width); QPainterPath result = stroke.createStroke(pp).simplified(); PageItem* newItem; if (first) { newItem = currDoc->convertItemTo(currItem, PageItem::Polygon); } else { newItem = new PageItem_Polygon(*currItem); newItem->convertTo(PageItem::Polygon); currDoc->Items->append(newItem); } first = false; newItem->ItemNr = currDoc->Items->count()-1; newItem->setLineStyle(Qt::SolidLine); newItem->setFillColor(ml[it].Color); newItem->setFillShade(ml[it].Shade); newItem->setFillTransparency(newItem->lineTransparency()); newItem->setFillBlendmode(newItem->lineBlendmode()); newItem->setLineColor(CommonStrings::None); newItem->setCustomLineStyle(""); FPointArray points; points.fromQPainterPath(result); newItem->PoLine = points; newItem->Frame = false; newItem->ClipEdited = true; newItem->FrameType = 3; currDoc->AdjustItemSize(newItem); newItem->OldB2 = newItem->width(); newItem->OldH2 = newItem->height(); newItem->updateClip(); newItem->ContourLine = newItem->PoLine.copy(); newItem->setFillEvenOdd(true); currDoc->m_Selection->addItem(newItem); } } if (currItem->startArrowIndex() != 0) { FPoint Start = currItem->PoLine.point(0); for (uint xx = 1; xx < currItem->PoLine.size(); xx += 2) { FPoint Vector = currItem->PoLine.point(xx); if ((Start.x() != Vector.x()) || (Start.y() != Vector.y())) { double r = atan2(Start.y()-Vector.y(),Start.x()-Vector.x())*(180.0/M_PI); QMatrix arrowTrans; FPointArray arrow = currDoc->arrowStyles.at(currItem->startArrowIndex()-1).points.copy(); arrowTrans.translate(Start.x(), Start.y()); arrowTrans.rotate(r); arrowTrans.scale(currItem->lineWidth(), currItem->lineWidth()); arrow.map(arrowTrans); PageItem* newItem = new PageItem_Polygon(*currItem); currDoc->Items->append(newItem); newItem->ItemNr = currDoc->Items->count()-1; newItem->setLineWidth(0); newItem->setLineStyle(Qt::SolidLine); newItem->setCustomLineStyle(""); newItem->setFillColor(newItem->lineColor()); newItem->setFillShade(newItem->lineShade()); newItem->setFillTransparency(newItem->lineTransparency()); newItem->setFillBlendmode(newItem->lineBlendmode()); newItem->PoLine = arrow; newItem->Frame = false; newItem->ClipEdited = true; newItem->FrameType = 3; currDoc->AdjustItemSize(newItem); newItem->OldB2 = newItem->width(); newItem->OldH2 = newItem->height(); newItem->updateClip(); newItem->ContourLine = newItem->PoLine.copy(); newItem->setFillEvenOdd(true); currDoc->m_Selection->addItem(newItem); break; } } } if (currItem->endArrowIndex() != 0) { FPoint End = currItem->PoLine.point(currItem->PoLine.size()-2); for (uint xx = currItem->PoLine.size()-1; xx > 0; xx -= 2) { FPoint Vector = currItem->PoLine.point(xx); if ((End.x() != Vector.x()) || (End.y() != Vector.y())) { double r = atan2(End.y()-Vector.y(),End.x()-Vector.x())*(180.0/M_PI); QMatrix arrowTrans; FPointArray arrow = currDoc->arrowStyles.at(currItem->endArrowIndex()-1).points.copy(); arrowTrans.translate(End.x(), End.y()); arrowTrans.rotate(r); arrowTrans.scale(currItem->lineWidth(), currItem->lineWidth()); arrow.map(arrowTrans); PageItem* newItem = new PageItem_Polygon(*currItem); currDoc->Items->append(newItem); newItem->ItemNr = currDoc->Items->count()-1; newItem->setLineWidth(0); newItem->setLineStyle(Qt::SolidLine); newItem->setCustomLineStyle(""); newItem->setFillColor(newItem->lineColor()); newItem->setFillShade(newItem->lineShade()); newItem->setFillTransparency(newItem->lineTransparency()); newItem->setFillBlendmode(newItem->lineBlendmode()); newItem->PoLine = arrow; newItem->Frame = false; newItem->ClipEdited = true; newItem->FrameType = 3; currDoc->AdjustItemSize(newItem); newItem->OldB2 = newItem->width(); newItem->OldH2 = newItem->height(); newItem->updateClip(); newItem->ContourLine = newItem->PoLine.copy(); newItem->setFillEvenOdd(true); currDoc->m_Selection->addItem(newItem); break; } } } if (currDoc->m_Selection->count() > 1) currDoc->itemSelection_GroupObjects(false, false); currDoc->m_Selection->itemAt(0)->emitAllToGUI(); } currDoc->changed(); } return true; }
bool PathCutPlugin::run(ScribusDoc* doc, QString) { QString vers = QString(qVersion()).left(5); if (vers < "4.3.3") { QMessageBox::information(doc->scMW(), tr("Qt Version too old"), tr("This plugin requires at least version 4.3.3 of the Qt library")); return true; } ScribusDoc* currDoc = doc; if (currDoc == 0) currDoc = ScCore->primaryMainWindow()->doc; if (currDoc->m_Selection->count() > 1) { PageItem *Item1 = currDoc->m_Selection->itemAt(0); PageItem *Item2 = currDoc->m_Selection->itemAt(1); if (Item1->itemType() != PageItem::PolyLine) { Item1 = currDoc->m_Selection->itemAt(1); Item2 = currDoc->m_Selection->itemAt(0); } FPointArray path = Item1->PoLine; QPainterPathStroker stroke; stroke.setWidth(Item1->lineWidth()); QPainterPath cutter = stroke.createStroke(path.toQPainterPath(false)); QMatrix ms; ms.translate(Item1->xPos() - Item2->xPos(), Item1->yPos() - Item2->yPos()); ms.rotate(Item1->rotation()); cutter = ms.map(cutter); path.map(ms); FPoint start = path.point(0); FPoint end = path.point(path.size()-2); QMatrix mm; mm.rotate(Item2->rotation()); QPainterPath objekt = mm.map(Item2->PoLine.toQPainterPath(true)); if ((objekt.contains(QPointF(start.x(), start.y()))) || (objekt.contains(QPointF(end.x(), end.y())))) { QMessageBox::information(doc->scMW(), tr("Error"), tr("The cutting line must cross the polygon and\nboth end points must lie outside of the polygon")); return true; } QPainterPath result = objekt.subtracted(cutter); FPointArray points; points.fromQPainterPath(result); Item2->PoLine = points; Item2->Frame = false; Item2->ClipEdited = true; Item2->FrameType = 3; currDoc->AdjustItemSize(Item2); Item2->OldB2 = Item2->width(); Item2->OldH2 = Item2->height(); Item2->updateClip(); Item2->ContourLine = Item2->PoLine.copy(); currDoc->m_Selection->clear(); currDoc->m_Selection->addItem(Item1); currDoc->itemSelection_DeleteItem(); currDoc->m_Selection->clear(); currDoc->m_Selection->addItem(Item2); currDoc->itemSelection_SplitItems(); currDoc->changed(); } return true; }