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; }