LensDialog::LensDialog(QWidget* parent, ScribusDoc *doc) : QDialog(parent) { setupUi(this); buttonRemove->setEnabled(false); setModal(true); buttonZoomOut->setIcon(QIcon(loadIcon("16/zoom-out.png"))); buttonZoomI->setIcon(QIcon(loadIcon("16/zoom-in.png"))); PageItem *currItem; double gx, gy, gh, gw; doc->m_Selection->setGroupRect(); doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh); uint selectedItemCount = doc->m_Selection->count(); QStack<PageItem*> groupStack; QStack<QGraphicsPathItem*> groupStack2; QStack<PageItem*> groupStack3; groupStack2.push(0); for (uint i = 0; i < selectedItemCount; ++i) { currItem = doc->m_Selection->itemAt(i); FPointArray path = currItem->PoLine; QPainterPath pp; if (currItem->itemType() == PageItem::PolyLine) pp = path.toQPainterPath(false); else pp = path.toQPainterPath(true); origPath.append(pp); QGraphicsPathItem* pItem = new QGraphicsPathItem(pp, groupStack2.top()); if (groupStack2.top() == 0) { scene.addItem(pItem); pItem->setPos(currItem->xPos() - gx, currItem->yPos() - gy); pItem->rotate(currItem->rotation()); } else { PageItem* parent = groupStack3.top(); QMatrix mm; mm.rotate(-parent->rotation()); mm.translate(-parent->xPos(), -parent->yPos()); pItem->setPos(mm.map(QPointF(currItem->xPos(), currItem->yPos()))); } pItem->setZValue(i); origPathItem.append(pItem); if (((currItem->fillColor() == CommonStrings::None) && (currItem->GrType == 0)) || (currItem->controlsGroup())) pItem->setBrush(Qt::NoBrush); else { if (currItem->GrType != 0) { if (currItem->GrType != 8) { QGradient pat; double x1 = currItem->GrStartX; double y1 = currItem->GrStartY; double x2 = currItem->GrEndX; double y2 = currItem->GrEndY; switch (currItem->GrType) { case 1: case 2: case 3: case 4: case 6: pat = QLinearGradient(x1, y1, x2, y2); break; case 5: case 7: pat = QRadialGradient(x1, y1, sqrt(pow(x2 - x1, 2) + pow(y2 - y1,2)), x1, y1); break; } QList<VColorStop*> colorStops = currItem->fill_gradient.colorStops(); QColor qStopColor; for( int offset = 0 ; offset < colorStops.count() ; offset++ ) { qStopColor = colorStops[ offset ]->color; int h, s, v, sneu, vneu; int shad = colorStops[offset]->shade; qStopColor.getHsv(&h, &s, &v); sneu = s * shad / 100; vneu = 255 - ((255 - v) * shad / 100); qStopColor.setHsv(h, sneu, vneu); qStopColor.setAlphaF(colorStops[offset]->opacity); pat.setColorAt(colorStops[ offset ]->rampPoint, qStopColor); } pItem->setBrush(pat); } else if ((currItem->GrType == 8) && (!currItem->pattern().isEmpty()) && (doc->docPatterns.contains(currItem->pattern()))) { double patternScaleX, patternScaleY, patternOffsetX, patternOffsetY, patternRotation; currItem->patternTransform(patternScaleX, patternScaleY, patternOffsetX, patternOffsetY, patternRotation); QMatrix qmatrix; qmatrix.translate(patternOffsetX, patternOffsetY); qmatrix.rotate(patternRotation); qmatrix.scale(patternScaleX / 100.0, patternScaleY / 100.0); QImage pat = *doc->docPatterns[currItem->pattern()].getPattern(); QBrush brush = QBrush(pat); brush.setMatrix(qmatrix); pItem->setBrush(brush); } } else { QColor paint = ScColorEngine::getShadeColorProof(doc->PageColors[currItem->fillColor()], doc, currItem->fillShade()); paint.setAlphaF(1.0 - currItem->fillTransparency()); pItem->setBrush(paint); } } if ((currItem->lineColor() == CommonStrings::None) || (currItem->controlsGroup())) pItem->setPen(Qt::NoPen); else { QColor paint = ScColorEngine::getShadeColorProof(doc->PageColors[currItem->lineColor()], doc, currItem->lineShade()); paint.setAlphaF(1.0 - currItem->lineTransparency()); pItem->setPen(QPen(paint, currItem->lineWidth(), currItem->lineStyle(), currItem->lineEnd(), currItem->lineJoin())); } if (currItem->controlsGroup()) { groupStack.push(currItem->groupsLastItem); groupStack2.push(pItem); groupStack3.push(currItem); pItem->setFlags(QGraphicsItem::ItemClipsChildrenToShape); } if (groupStack.count() != 0) { while (currItem == groupStack.top()) { groupStack3.pop(); groupStack2.pop(); groupStack.pop(); if (groupStack.count() == 0) break; } } } previewWidget->setRenderHint(QPainter::Antialiasing); previewWidget->setScene(&scene); isFirst = true; addLens(); connect(spinXPos, SIGNAL(valueChanged(double)), this, SLOT(setNewLensX(double))); connect(spinYPos, SIGNAL(valueChanged(double)), this, SLOT(setNewLensY(double))); connect(spinRadius, SIGNAL(valueChanged(double)), this, SLOT(setNewLensRadius(double))); connect(spinStrength, SIGNAL(valueChanged(double)), this, SLOT(setNewLensStrength(double))); connect(buttonAdd, SIGNAL(clicked()), this, SLOT(addLens())); connect(buttonRemove, SIGNAL(clicked()), this, SLOT(removeLens())); connect(buttonMagnify, SIGNAL(toggled(bool)), this, SLOT(changeLens())); connect(buttonZoomI, SIGNAL(clicked()), this, SLOT(doZoomIn())); connect(buttonZoomOut, SIGNAL(clicked()), this, SLOT(doZoomOut())); connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); connect(&scene, SIGNAL(selectionChanged()), this, SLOT(selectionHasChanged())); }
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; }
void CreateMode::drawControls(QPainter* p) { if (!inItemCreation) return; QPointF topLeft(createObjectPos.x(), createObjectPos.y()); QPointF btRight(canvasCurrCoord.x(), canvasCurrCoord.y()); QColor drawColor = qApp->palette().color(QPalette::Active, QPalette::Highlight); if (createObjectMode != modeDrawLine) { QRectF bounds = QRectF(topLeft, btRight).normalized(); //Lock Height to Width for Control Modifier for region drawing if (modifiers==Qt::ControlModifier) { bounds.setHeight(bounds.width()); if (btRight.y()<topLeft.y()) bounds.moveBottom(topLeft.y()); if (btRight.x()<topLeft.x() && btRight.y()>topLeft.y()) bounds.moveTop(topLeft.y()); } QRect localRect = m_canvas->canvasToLocal(bounds); if (localRect.width() <= 0 || localRect.height() <= 0) return; p->setRenderHint(QPainter::Antialiasing); p->save(); p->setPen(QPen(drawColor, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin)); drawColor.setAlpha(64); p->setBrush(drawColor); p->drawRect(localRect); drawColor.setAlpha(255); p->setBrush(Qt::NoBrush); p->setPen(QPen(drawColor, 1, Qt::DashLine, Qt::FlatCap, Qt::MiterJoin)); int frameType = 0, itemType = 0; getFrameItemTypes(itemType, frameType); if (frameType == PageItem::Ellipse) { p->drawEllipse(localRect); } else if (createObjectMode == modeDrawArc) { QPainterPath path; path.moveTo(localRect.width() / 2.0, localRect.height() / 2.0); path.arcTo(0.0, 0.0, localRect.width(), localRect.height(), m_doc->itemToolPrefs().arcStartAngle, m_doc->itemToolPrefs().arcSweepAngle); path.closeSubpath(); p->translate(localRect.left(), localRect.top()); p->drawPath(path); } else if (createObjectMode == modeDrawRegularPolygon) { QPainterPath path = RegularPolygonPath(localRect.width(), localRect.height(), m_doc->itemToolPrefs().polyCorners, m_doc->itemToolPrefs().polyUseFactor, m_doc->itemToolPrefs().polyFactor, m_doc->itemToolPrefs().polyRotation, m_doc->itemToolPrefs().polyCurvature, m_doc->itemToolPrefs().polyInnerRot, m_doc->itemToolPrefs().polyOuterCurvature); p->translate(localRect.left(), localRect.top()); p->drawPath(path); } else if (createObjectMode == modeDrawSpiral) { QPainterPath path = SpiralPath(localRect.width(), localRect.height(), m_doc->itemToolPrefs().spiralStartAngle, m_doc->itemToolPrefs().spiralEndAngle, m_doc->itemToolPrefs().spiralFactor); p->translate(localRect.left(), localRect.top()); p->drawPath(path); } else if ((createObjectMode == modeDrawShapes) && (createObjectSubMode > 1)) { FPointArray poly; int valCount = m_doc->ValCount; double *vals = m_doc->ShapeValues; for (int a = 0; a < valCount-3; a += 4) { if (vals[a] < 0) { poly.setMarker(); continue; } double x1 = localRect.width() * vals[a] / 100.0; double y1 = localRect.height() * vals[a+1] / 100.0; double x2 = localRect.width() * vals[a+2] / 100.0; double y2 = localRect.height() * vals[a+3] / 100.0; poly.addPoint(x1, y1); poly.addPoint(x2, y2); } QPainterPath path = poly.toQPainterPath(false); p->translate(localRect.left(), localRect.top()); p->drawPath(path); } p->restore(); } else { QPoint p1 = m_canvas->canvasToLocal(topLeft); QPoint p2 = m_canvas->canvasToLocal(btRight); p->save(); p->setPen(QPen(drawColor, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin)); p->setBrush(drawColor); p->drawLine(p1, p2); p->restore(); } }
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; }