QPainterPath QSysMLAction::shape() const { QPainterPath p; p.connectPath(shapeInternal()); p.connectPath(shapeConnectionLines()); return p; }
void MainWindow::draw_ellipse(QPainterPath &path, double p) { double width = boundingRect.right() - boundingRect.left(); width /= 100.0; double left = boundingRect.left(); bool first = true; for (int i = 0; i <= 100; ++i) { double currentX = left + static_cast<double>(i)*width; double currentY = calculate_y1(currentX, p); if (first) { if (!(isnan(currentY) || isinf(currentY))) { path.moveTo(plot_x(currentX), plot_y(currentY)); first = false; } } else if (!(isnan(currentY) || isinf(currentY))) path.lineTo(plot_x(currentX), plot_y(currentY)); } for (int i = 100; i >= 0; --i) { double currentX = left + static_cast<double>(i)*width; double currentY = calculate_y2(currentX, p); if (!(isnan(currentY) || isinf(currentY))) path.lineTo(plot_x(currentX), plot_y(currentY)); } path.connectPath(path); }
QGIFace* QGIViewPart::drawFace(TechDrawGeometry::Face* f, int idx) { std::vector<TechDrawGeometry::Wire *> fWires = f->wires; QPainterPath facePath; for(std::vector<TechDrawGeometry::Wire *>::iterator wire = fWires.begin(); wire != fWires.end(); ++wire) { QPainterPath wirePath; for(std::vector<TechDrawGeometry::BaseGeom *>::iterator edge = (*wire)->geoms.begin(); edge != (*wire)->geoms.end(); ++edge) { //Save the start Position QPainterPath edgePath = drawPainterPath(*edge); // If the current end point matches the shape end point the new edge path needs reversing QPointF shapePos = (wirePath.currentPosition()- edgePath.currentPosition()); if(sqrt(shapePos.x() * shapePos.x() + shapePos.y()*shapePos.y()) < 0.05) { //magic tolerance edgePath = edgePath.toReversed(); } wirePath.connectPath(edgePath); } //dumpPath("wirePath:",wirePath); facePath.addPath(wirePath); } facePath.setFillRule(Qt::OddEvenFill); QGIFace* gFace = new QGIFace(idx); addToGroup(gFace); gFace->setPos(0.0,0.0); gFace->setPath(facePath); //debug a path //std::stringstream faceId; //faceId << "facePath " << idx; //dumpPath(faceId.str().c_str(),facePath); return gFace; }
void PolygonObject::updatePath(const QPainterPath& p) { normalPath = p; QPainterPath closedPath = normalPath; closedPath.closeSubpath(); QPainterPath reversePath = closedPath.toReversed(); reversePath.connectPath(closedPath); setObjectPath(reversePath); }
void SectorItem::updatePath() { if (this->_pathBuilder == NULL) return; QPainterPath newPath; newPath.addPath(this->_pathBuilder->inBound()); QPainterPath exBound = this->_pathBuilder->exBound().toReversed(); newPath.connectPath(exBound); this->setPath(newPath); }
void tst_QPainterPath::connectPathDuplicatePoint() { QPainterPath a; a.moveTo(10, 10); a.lineTo(20, 20); QPainterPath b; b.moveTo(20, 20); b.lineTo(30, 10); a.connectPath(b); QPainterPath c; c.moveTo(10, 10); c.lineTo(20, 20); c.lineTo(30, 10); QCOMPARE(c, a); }
static void drawControlBackground(QPainter* painter, const QPen& pen, const QRect& rect, const QBrush& brush) { QPen oldPen = painter->pen(); QBrush oldBrush = painter->brush(); painter->setRenderHint(QPainter::Antialiasing, true); painter->setPen(pen); painter->setBrush(brush); static const qreal line = 1.5; const QRectF paddedRect = rect.adjusted(line, line, -line, -line); static const int n = 3; const qreal invPow = 1 / double(n); ASSERT(paddedRect.width() >= paddedRect.height()); const int radius = paddedRect.height() / 2; const int xDelta = paddedRect.width() / 2 - radius; const QPointF center = paddedRect.center(); qreal x = 0; qreal y; QVector<QPainterPath> octants(8); // Stay within reasonable distance from edge values, which can cause artifacts at certain zoom levels. static const float epsilon = 0.02; for (y = radius - epsilon; y - epsilon > x; y -= 0.5) { x = radius * pow(1 - pow(qAbs(y) / radius , n), invPow); addPointToOctants(octants, center, x, y, xDelta); } QPainterPath path = octants.first(); for (int i = 1; i < 8; ++i) { // Due to the orientation of the arcs, we need to reverse the paths with odd indices. QPainterPath subPath = (i % 2) ? octants.at(i).toReversed() : octants.at(i); path.connectPath(subPath); } path.closeSubpath(); painter->drawPath(path); painter->setPen(oldPen); painter->setBrush(oldBrush); }
void MainWindow::draw_ellipse(const int activeDistributionNumber, QPainterPath &path, double p) { const int STEP_OF_GRID = 300; QRectF boundingRect(distributions[activeDistribution[activeDistributionNumber]].calculate_bounding_box(activeComponent[0], activeComponent[1])); double width = boundingRect.width(); width /= static_cast<double>(STEP_OF_GRID); double left = boundingRect.left(); bool first = true; for (int i = 0; i <= STEP_OF_GRID; ++i) { double currentX = left + static_cast<double>(i)*width; double currentY = distributions[activeDistribution[activeDistributionNumber]].calculate_y1(activeComponent[0], activeComponent[1], r[activeDistributionNumber], currentX, p); if (unlikely(first)) { if (!(isnan(currentY) || isinf(currentY))) { path.moveTo(plot_x(currentX), plot_y(currentY)); first = false; } } else if (!(isnan(currentY) || isinf(currentY))) path.lineTo(plot_x(currentX), plot_y(currentY)); } for (int i = STEP_OF_GRID; --i; ) { double currentX = left + static_cast<double>(i)*width; double currentY = distributions[activeDistribution[activeDistributionNumber]].calculate_y2(activeComponent[0], activeComponent[1], r[activeDistributionNumber], currentX, p); if (!(isnan(currentY) || isinf(currentY))) path.lineTo(plot_x(currentX), plot_y(currentY)); } path.connectPath(path); }
static QPainterPath qwtCombinePathList( const QRectF &rect, const QList<QPainterPath> &pathList ) { if ( pathList.isEmpty() ) return QPainterPath(); QPainterPath ordered[8]; // starting top left for ( int i = 0; i < pathList.size(); i++ ) { int index = -1; QPainterPath subPath = pathList[i]; const QRectF br = pathList[i].controlPointRect(); if ( br.center().x() < rect.center().x() ) { if ( br.center().y() < rect.center().y() ) { if ( qAbs( br.top() - rect.top() ) < qAbs( br.left() - rect.left() ) ) { index = 1; } else { index = 0; } } else { if ( qAbs( br.bottom() - rect.bottom() ) < qAbs( br.left() - rect.left() ) ) { index = 6; } else { index = 7; } } if ( subPath.currentPosition().y() > br.center().y() ) qwtRevertPath( subPath ); } else { if ( br.center().y() < rect.center().y() ) { if ( qAbs( br.top() - rect.top() ) < qAbs( br.right() - rect.right() ) ) { index = 2; } else { index = 3; } } else { if ( qAbs( br.bottom() - rect.bottom() ) < qAbs( br.right() - rect.right() ) ) { index = 5; } else { index = 4; } } if ( subPath.currentPosition().y() < br.center().y() ) qwtRevertPath( subPath ); } ordered[index] = subPath; } for ( int i = 0; i < 4; i++ ) { if ( ordered[ 2 * i].isEmpty() != ordered[2 * i + 1].isEmpty() ) { // we don't accept incomplete rounded borders return QPainterPath(); } } const QPolygonF corners( rect ); QPainterPath path; //path.moveTo( rect.topLeft() ); for ( int i = 0; i < 4; i++ ) { if ( ordered[2 * i].isEmpty() ) { path.lineTo( corners[i] ); } else { path.connectPath( ordered[2 * i] ); path.connectPath( ordered[2 * i + 1] ); } } path.closeSubpath(); #if 0 return path.simplified(); #else return path; #endif }
void CalligraphicMode::mouseReleaseEvent(QMouseEvent *m) { undoManager->setUndoEnabled(true); PageItem *currItem; m_MouseButtonPressed = false; m_canvas->resetRenderMode(); m->accept(); if (m_doc->appMode == modeDrawCalligraphicLine) { if (RecordP.size() > 1) { UndoTransaction createTransaction; if (UndoManager::undoEnabled()) createTransaction = UndoManager::instance()->beginTransaction(); uint z = m_doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, Mxp, Myp, 1, 1, m_doc->itemToolPrefs().calligraphicPenLineWidth, m_doc->itemToolPrefs().calligraphicPenFillColor, m_doc->itemToolPrefs().calligraphicPenLineColor); currItem = m_doc->Items->at(z); currItem->PoLine.resize(0); QList<QPointF> clipU; QList<QPointF> clipL; double mx = sin(m_doc->itemToolPrefs().calligraphicPenAngle / 180.0 * M_PI) * (m_doc->itemToolPrefs().calligraphicPenWidth / 2.0); double my = cos(m_doc->itemToolPrefs().calligraphicPenAngle / 180.0 * M_PI) * (m_doc->itemToolPrefs().calligraphicPenWidth / 2.0); for (int px = 0; px < RecordP.size()-1; ++px) { FPoint clp = RecordP.point(px); clipU.append(QPointF(clp.x() - mx, clp.y() - my)); clipL.prepend(QPointF(clp.x() + mx, clp.y() + my)); } QPainterPath ppU = bezierFit(clipU, 5.0); QPainterPath ppL = bezierFit(clipL, 5.0); QPainterPath pp; pp.addPath(ppU); pp.connectPath(ppL); pp.closeSubpath(); currItem->PoLine.fromQPainterPath(pp); FPoint tp2(getMinClipF(&currItem->PoLine)); currItem->setXYPos(tp2.x(), tp2.y(), true); currItem->PoLine.translate(-tp2.x(), -tp2.y()); FPoint tp(getMaxClipF(&currItem->PoLine)); m_doc->sizeItem(tp.x(), tp.y(), currItem, false, false, false); m_doc->adjustItemSize(currItem); m_doc->m_Selection->clear(); m_doc->m_Selection->addItem(currItem); currItem->ClipEdited = true; currItem->FrameType = 3; currItem->OwnPage = m_doc->OnPage(currItem); currItem->PLineArt = Qt::PenStyle(m_doc->itemToolPrefs().calligraphicPenStyle); currItem->setFillShade(m_doc->itemToolPrefs().calligraphicPenFillColorShade); currItem->setLineShade(m_doc->itemToolPrefs().calligraphicPenLineColorShade); currItem->setFillEvenOdd(true); m_view->resetMousePressed(); currItem->checkChanges(); QString targetName = Um::ScratchSpace; if (currItem->OwnPage > -1) targetName = m_doc->Pages->at(currItem->OwnPage)->getUName(); if (createTransaction) createTransaction.commit(targetName, currItem->getUPixmap(), Um::Create + " " + currItem->getUName(), "", Um::ICreate); //FIXME m_canvas->m_viewMode.operItemResizing = false; m_doc->changed(); } if (!PrefsManager::instance()->appPrefs.uiPrefs.stickyTools) { m_view->requestMode(modeNormal); } else m_view->requestMode(m_doc->appMode); return; } m_canvas->setRenderModeUseBuffer(false); m_doc->DragP = false; m_doc->leaveDrag = false; m_view->MidButt = false; if (m_view->groupTransactionStarted()) { for (int i = 0; i < m_doc->m_Selection->count(); ++i) m_doc->m_Selection->itemAt(i)->checkChanges(true); m_view->endGroupTransaction(); } for (int i = 0; i < m_doc->m_Selection->count(); ++i) m_doc->m_Selection->itemAt(i)->checkChanges(true); //Commit drag created items to undo manager. if (m_doc->m_Selection->itemAt(0)!=NULL) { m_doc->itemAddCommit(m_doc->m_Selection->itemAt(0)); } //Make sure the Zoom spinbox and page selector don't have focus if we click on the canvas m_view->m_ScMW->zoomSpinBox->clearFocus(); m_view->m_ScMW->pageSelector->clearFocus(); if (m_doc->m_Selection->itemAt(0) != 0) // is there the old clip stored for the undo action { currItem = m_doc->m_Selection->itemAt(0); m_doc->nodeEdit.finishTransaction(currItem); } }
void NMGChartSeries::paintArea(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { int maxValuesInPartialPath = 1000; QColor hsv = baseColor.toHsv(); hsv.setHsv(hsv.hue(), (int)(hsv.saturation()*0.25), hsv.value()); if(isAveraged || isAccumulated) { painter->setBrush(hsv); paintLine(painter, option, widget); } else { // not average nor accumulated /* NOTE A specific implementation is needed in this case because Graphics View doesn't * support correctly huge amount of points (X11 crashes). The design has been based in * partial paths that are painted with brush (to paint the area), and later they are * added to the complete path (to paint the boundary line).*/ painter->setPen(Qt::NoPen); painter->setBrush(hsv); QPainterPath completedPath; double closingYpixel = ((minValues.y < 0.0 && 0.0 < maxValues.y) ? yWindowToViewport(0.0) : ((minValues.y >= 0.0) ? yWindowToViewport(minValues.y) : yWindowToViewport(maxValues.y))); QList<Vertex>::const_iterator it = vertexList.constBegin(); do { QPainterPath partialPath; QPainterPath partialPathModif; partialPath.moveTo(xWindowToViewport(it->x), -yWindowToViewport(it->y)); for(int i = 1; i <= maxValuesInPartialPath && it != vertexList.constEnd(); i++, it++) { partialPath.lineTo(xWindowToViewport(it->x),-yWindowToViewport(it->y)); } if(completedPath.isEmpty()) { partialPathModif = partialPath; partialPathModif.lineTo(partialPathModif.currentPosition().rx(), -closingYpixel); partialPathModif.lineTo(xWindowToViewport(vertexList.first().x), -closingYpixel); completedPath = partialPath; } else { partialPathModif = partialPath; partialPathModif.lineTo(partialPath.currentPosition().rx(), -closingYpixel); partialPathModif.lineTo(completedPath.currentPosition().rx(), -closingYpixel); partialPathModif.lineTo(completedPath.currentPosition().rx(), completedPath.currentPosition().ry()); completedPath.connectPath(partialPath); } partialPathModif.closeSubpath(); painter->drawPath(partialPathModif); } while(it != vertexList.constEnd()); painter->setPen(Qt::SolidLine); painter->setPen(baseColor); painter->setBrush(Qt::NoBrush); completedPath.lineTo(xWindowToViewport(vertexList.last().x), -closingYpixel); completedPath.lineTo(xWindowToViewport(vertexList.first().x), -closingYpixel); completedPath.closeSubpath(); painter->drawPath(completedPath); } }