bool HoverPoints::eventFilter(QObject *object, QEvent *event) { if (object == m_widget && m_enabled) { switch (event->type()) { case QEvent::MouseButtonPress: { if (!m_fingerPointMapping.isEmpty()) return true; QMouseEvent *me = (QMouseEvent *) event; QPointF clickPos = me->pos(); int index = -1; for (int i=0; i<m_points.size(); ++i) { QPainterPath path; if (m_shape == CircleShape) path.addEllipse(pointBoundingRect(i)); else path.addRect(pointBoundingRect(i)); if (path.contains(clickPos)) { index = i; break; } } if (me->button() == Qt::LeftButton) { if (index == -1) { if (!m_editable) return false; int pos = 0; // Insert sort for x or y if (m_sortType == XSort) { for (int i=0; i<m_points.size(); ++i) if (m_points.at(i).x() > clickPos.x()) { pos = i; break; } } else if (m_sortType == YSort) { for (int i=0; i<m_points.size(); ++i) if (m_points.at(i).y() > clickPos.y()) { pos = i; break; } } m_points.insert(pos, clickPos); m_locks.insert(pos, 0); m_currentIndex = pos; firePointChange(); } else { m_currentIndex = index; } return true; } else if (me->button() == Qt::RightButton) { if (index >= 0 && m_editable) { if (m_locks[index] == 0) { m_locks.remove(index); m_points.remove(index); } firePointChange(); return true; } } } break; case QEvent::MouseButtonRelease: if (!m_fingerPointMapping.isEmpty()) return true; m_currentIndex = -1; break; case QEvent::MouseMove: if (!m_fingerPointMapping.isEmpty()) return true; if (m_currentIndex >= 0) movePoint(m_currentIndex, ((QMouseEvent *)event)->pos()); break; case QEvent::TouchBegin: case QEvent::TouchUpdate: { const QTouchEvent *const touchEvent = static_cast<const QTouchEvent*>(event); const QList<QTouchEvent::TouchPoint> points = touchEvent->touchPoints(); const qreal pointSize = qMax(m_pointSize.width(), m_pointSize.height()); foreach (const QTouchEvent::TouchPoint &touchPoint, points) { const int id = touchPoint.id(); switch (touchPoint.state()) { case Qt::TouchPointPressed: { // find the point, move it QSet<int> activePoints = QSet<int>::fromList(m_fingerPointMapping.values()); int activePoint = -1; qreal distance = -1; const int pointsCount = m_points.size(); const int activePointCount = activePoints.size(); if (pointsCount == 2 && activePointCount == 1) { // only two points activePoint = activePoints.contains(0) ? 1 : 0; } else { for (int i=0; i<pointsCount; ++i) { if (activePoints.contains(i)) continue; qreal d = QLineF(touchPoint.pos(), m_points.at(i)).length(); if ((distance < 0 && d < 12 * pointSize) || d < distance) { distance = d; activePoint = i; } } } if (activePoint != -1) { m_fingerPointMapping.insert(touchPoint.id(), activePoint); movePoint(activePoint, touchPoint.pos()); } } break; case Qt::TouchPointReleased: { // move the point and release QHash<int,int>::iterator it = m_fingerPointMapping.find(id); movePoint(it.value(), touchPoint.pos()); m_fingerPointMapping.erase(it); } break; case Qt::TouchPointMoved: { // move the point const int pointIdx = m_fingerPointMapping.value(id, -1); if (pointIdx >= 0) // do we track this point? movePoint(pointIdx, touchPoint.pos()); } break; default: break; } } if (m_fingerPointMapping.isEmpty()) { event->ignore(); return false; } else { return true; } } break; case QEvent::TouchEnd: if (m_fingerPointMapping.isEmpty()) { event->ignore(); return false; } return true; break; case QEvent::Resize: { QResizeEvent *e = (QResizeEvent *) event; if (e->oldSize().width() == 0 || e->oldSize().height() == 0) break; qreal stretch_x = e->size().width() / qreal(e->oldSize().width()); qreal stretch_y = e->size().height() / qreal(e->oldSize().height()); for (int i=0; i<m_points.size(); ++i) { QPointF p = m_points[i]; movePoint(i, QPointF(p.x() * stretch_x, p.y() * stretch_y), false); } firePointChange(); break; } case QEvent::Paint: { QWidget *that_widget = m_widget; m_widget = 0; QApplication::sendEvent(object, event); m_widget = that_widget; paintPoints(); #ifdef QT_OPENGL_SUPPORT ArthurFrame *af = qobject_cast<ArthurFrame *>(that_widget); if (af && af->usesOpenGL()) af->glWidget()->swapBuffers(); #endif return true; } default: break; } } return false; }
void QgsComposerShape::drawShapeUsingSymbol( QPainter* p ) { p->save(); p->setRenderHint( QPainter::Antialiasing ); //setup painter scaling to dots so that raster symbology is drawn to scale double dotsPerMM = p->device()->logicalDpiX() / 25.4; //setup render context QgsMapSettings ms = mComposition->mapSettings(); //context units should be in dots ms.setOutputDpi( p->device()->logicalDpiX() ); QgsRenderContext context = QgsRenderContext::fromMapSettings( ms ); context.setPainter( p ); context.setForceVectorOutput( true ); QgsExpressionContext expressionContext = createExpressionContext(); context.setExpressionContext( expressionContext ); p->scale( 1 / dotsPerMM, 1 / dotsPerMM ); // scale painter from mm to dots //generate polygon to draw QList<QPolygonF> rings; //empty list QPolygonF shapePolygon; //shapes with curves must be enlarged before conversion to QPolygonF, or //the curves are approximated too much and appear jaggy QTransform t = QTransform::fromScale( 100, 100 ); //inverse transform used to scale created polygons back to expected size QTransform ti = t.inverted(); switch ( mShape ) { case Ellipse: { //create an ellipse QPainterPath ellipsePath; ellipsePath.addEllipse( QRectF( 0, 0, rect().width() * dotsPerMM, rect().height() * dotsPerMM ) ); QPolygonF ellipsePoly = ellipsePath.toFillPolygon( t ); shapePolygon = ti.map( ellipsePoly ); break; } case Rectangle: { //if corner radius set, then draw a rounded rectangle if ( mCornerRadius > 0 ) { QPainterPath roundedRectPath; roundedRectPath.addRoundedRect( QRectF( 0, 0, rect().width() * dotsPerMM, rect().height() * dotsPerMM ), mCornerRadius * dotsPerMM, mCornerRadius * dotsPerMM ); QPolygonF roundedPoly = roundedRectPath.toFillPolygon( t ); shapePolygon = ti.map( roundedPoly ); } else { shapePolygon = QPolygonF( QRectF( 0, 0, rect().width() * dotsPerMM, rect().height() * dotsPerMM ) ); } break; } case Triangle: { shapePolygon << QPointF( 0, rect().height() * dotsPerMM ); shapePolygon << QPointF( rect().width() * dotsPerMM, rect().height() * dotsPerMM ); shapePolygon << QPointF( rect().width() / 2.0 * dotsPerMM, 0 ); shapePolygon << QPointF( 0, rect().height() * dotsPerMM ); break; } } mShapeStyleSymbol->startRender( context ); mShapeStyleSymbol->renderPolygon( shapePolygon, &rings, nullptr, context ); mShapeStyleSymbol->stopRender( context ); p->restore(); }
void CMindMapUiShapeList::setupMenus() { QAction *action = NULL; QList<QIcon> icons; QList<int> filtered; QStringList labels; QPainterPath path; CDiagramIconProvider *provider = NULL; labels << tr("Rect") << tr("Rounded Rect") << tr("Ellipse") << tr("Diamond") << tr("Underline") << tr("Left Fish Head") << tr("Right Fish Head") << tr("None"); provider = CDiagramIconProvider::instance(); // rect path = QPainterPath(); path.addRect( -6, -4, 12, 8 ); icons << provider->genIconForPath(path); // rounded rect path = QPainterPath(); path.addRoundedRect(-6, -4, 12, 8, 3, 3); icons << provider->genIconForPath(path); // ellipse path = QPainterPath(); path.addEllipse( -6, -4, 12, 8 ); icons << provider->genIconForPath(path); // diamond path = QPainterPath(); path.moveTo( 0, -6 ); path.lineTo( 6, 0 ); path.lineTo( 0, 6 ); path.lineTo( -6, 0 ); path.lineTo( 0, -6 ); icons << provider->genIconForPath(path); // underline path = QPainterPath(); path.moveTo( -6, 6 ); path.lineTo( 6, 6 ); icons << provider->genIconForPath(path); // fish head left path = QPainterPath(); path.moveTo(-6, 0); path.lineTo(6, -6); path.lineTo(6, 6); path.lineTo(-6, 0); icons << provider->genIconForPath(path); // fish head right path = QPainterPath(); path.moveTo(6, 0); path.lineTo(-6, 6); path.lineTo(-6, -6); path.lineTo(6, 0); icons << provider->genIconForPath(path); // borderless icons << QIcon(); // only some of the shape types are added to the // menu filtered << 0 << 1 << 2 << 3 << 4 << 7; for (int i = 0; i < filtered.length(); ++i) { int index = filtered.at(i); action = addAction(icons.at(index), labels.at(index)); action->setData( QVariant(index) ); m_actions.push_back(action); } }
QPolygonF UBGeometryUtils::arcToPolygon(const QLineF& startRadius, qreal spanAngleInDegrees, qreal width) { qreal startAngleInDegrees = - startRadius.angle(); if (startAngleInDegrees > 180) startAngleInDegrees -= 360; else if (startAngleInDegrees < -180) startAngleInDegrees += 360; qreal radiusLength = startRadius.length(); qreal angle = 2 * asin(width / (2 * radiusLength)) * 180 / PI; bool overlap = abs(spanAngleInDegrees) > 360 - angle; if (overlap) spanAngleInDegrees = spanAngleInDegrees < 0 ? -360 : 360; qreal endAngleInDegrees = startAngleInDegrees + spanAngleInDegrees; qreal innerRadius = radiusLength - width / 2; QRectF innerSquare( startRadius.p1().x() - innerRadius, startRadius.p1().y() - innerRadius, 2 * innerRadius, 2 * innerRadius); qreal outerRadius = radiusLength + width / 2; QRectF outerSquare( startRadius.p1().x() - outerRadius, startRadius.p1().y() - outerRadius, 2 * outerRadius, 2 * outerRadius); QRectF startSquare( startRadius.p2().x() - width / 2, startRadius.p2().y() - width / 2, width, width); QRectF endSquare( startRadius.p1().x() + radiusLength * cos(endAngleInDegrees * PI / 180.0) - width / 2, startRadius.p1().y() + radiusLength * sin(endAngleInDegrees * PI / 180.0) - width / 2, width, width); QPainterPath painterPath( QPointF( startRadius.p1().x() + innerRadius * cos(startAngleInDegrees * PI / 180.0), startRadius.p1().y() + innerRadius * sin(startAngleInDegrees * PI / 180.0))); startAngleInDegrees = - startAngleInDegrees; endAngleInDegrees = - endAngleInDegrees; spanAngleInDegrees = - spanAngleInDegrees; if (overlap) { painterPath.addEllipse(outerSquare); QPainterPath innerPainterPath; innerPainterPath.addEllipse(innerSquare); painterPath = painterPath.subtracted(innerPainterPath); } else { painterPath.arcTo(innerSquare, startAngleInDegrees, spanAngleInDegrees); painterPath.arcTo(endSquare, 180.0 + endAngleInDegrees, spanAngleInDegrees > 0 ? -180.0 : 180.0); painterPath.arcTo(outerSquare, endAngleInDegrees, - spanAngleInDegrees); painterPath.arcTo(startSquare, startAngleInDegrees, spanAngleInDegrees > 0 ? -180.0 : 180.0); painterPath.closeSubpath(); } return painterPath.toFillPolygon(); }
static void draw(Painter *painter, Operation op, bool opengl, bool antialias, bool filled) { int N = 30000; struct timeval before, after; painter->setLimits(QRectF(0, 0, 100, 100)); painter->setAntialias(antialias); painter->setHasFill(filled); QFile file(OUTFILE); file.open(QIODevice::Append); QTextStream stream(&file); switch(op) { case Qanviz::Glyph: { QPainterPath path; path.addEllipse(45, 45, 10, 10); //uint circle = painter->registerPath(path); double *x = new double[N]; double *y = new double[N]; for (int i = 0; i < N; i++) { x[i] = 50;//rand()*100.0/RAND_MAX; y[i] = 50;//rand()*100.0/RAND_MAX; } BEGIN_TIMING; painter->drawGlyphs(path, x, y, NULL, NULL, NULL, N); END_TIMING; /* BEGIN_TIMING for (int i = 0; i < 10; i++) painter->drawGlyphs(path, x+i, y+i, 1); END_TIMING */ } break; case Qanviz::Polygon: { double x[3], y[3]; x[0] = 45; y[0] = 55; x[1] = 55; y[1] = 55; x[2] = 50; y[2] = 45; BEGIN_TIMING; for (int i = 0; i < N; i++) painter->drawPolygon(x, y, 3); END_TIMING; } break; case Qanviz::Rectangle: { double *x = new double[N]; double *y = new double[N]; double *w = new double[N]; double *h = new double[N]; for (int i = 0; i < N; i++) { x[i] = 45; y[i] = 45; w[i] = 10; h[i] = 10; } BEGIN_TIMING; painter->drawRectangles(x, y, w, h, N); END_TIMING; } break; case Qanviz::Point: { double *x = new double[N]; double *y = new double[N]; for (int i = 0; i < N; i++) { x[i] = 50; y[i] = 50; } BEGIN_TIMING; painter->drawPoints(x, y, N); END_TIMING; } break; case Qanviz::Line: { int L = 10000; double *x = new double[N/L]; double *y = new double[N/L]; for (int i = 0; i < N/L; i++) { x[i] = i*3; y[i] = 100 * (i % 2); //Rprintf("%f %f\n", x[i], y[i]); } BEGIN_TIMING; for (int i = 0; i < L; i++) painter->drawPolyline(x, y, N / L); END_TIMING; } break; case Qanviz::Segment: { double *x0 = new double[N]; double *y0 = new double[N]; double *x1 = new double[N]; double *y1 = new double[N]; for (int i = 0; i < N; i++) { x0[i] = 0; y0[i] = 0; x1[i] = 100; y1[i] = 100; } BEGIN_TIMING; painter->drawSegments(x0, y0, x1, y1, N); END_TIMING; } break; case Qanviz::Circle: BEGIN_TIMING; for (int i = 0; i < N; i++) painter->drawCircle(50, 50, 5); stream << "R5"; END_TIMING; BEGIN_TIMING; for (int i = 0; i < N; i++) painter->drawCircle(50, 50, 30); stream << "R30"; END_TIMING; BEGIN_TIMING; for (int i = 0; i < N; i++) painter->drawCircle(50, 50, 35); stream << "R35"; END_TIMING; break; default: error("Unknown drawing operation"); } }
/*! Sets the points of the array to those describing an ellipse with size, width \a w by height \a h, and position (\a x, \a y). The returned array has sufficient resolution for use as pixels. */ void Q3PointArray::makeEllipse(int x, int y, int w, int h) { QPainterPath path; path.addEllipse(x, y, w, h); *this = path.toSubpathPolygons().at(0).toPolygon(); }
void LightMaps::paintEvent(QPaintEvent *event) { QPainter p; p.begin(this); m_normalMap->render(&p, event->rect()); p.setPen(Qt::black); #if defined(Q_OS_SYMBIAN) QFont font = p.font(); font.setPixelSize(13); p.setFont(font); #endif p.drawText(rect(), Qt::AlignBottom | Qt::TextWordWrap, "Map data CCBYSA 2009 OpenStreetMap.org contributors"); p.end(); if (zoomed) { int dim = qMin(width(), height()); int magnifierSize = qMin(MAX_MAGNIFIER, dim * 2 / 3); int radius = magnifierSize / 2; int ring = radius - 15; QSize box = QSize(magnifierSize, magnifierSize); // reupdate our mask if (maskPixmap.size() != box) { maskPixmap = QPixmap(box); maskPixmap.fill(Qt::transparent); QRadialGradient g; g.setCenter(radius, radius); g.setFocalPoint(radius, radius); g.setRadius(radius); g.setColorAt(1.0, QColor(255, 255, 255, 0)); g.setColorAt(0.5, QColor(128, 128, 128, 255)); QPainter mask(&maskPixmap); mask.setRenderHint(QPainter::Antialiasing); mask.setCompositionMode(QPainter::CompositionMode_Source); mask.setBrush(g); mask.setPen(Qt::NoPen); mask.drawRect(maskPixmap.rect()); mask.setBrush(QColor(Qt::transparent)); mask.drawEllipse(g.center(), ring, ring); mask.end(); } QPoint center = dragPos - QPoint(0, radius); center = center + QPoint(0, radius / 2); QPoint corner = center - QPoint(radius, radius); QPoint xy = center * 2 - QPoint(radius, radius); // only set the dimension to the magnified portion if (zoomPixmap.size() != box) { zoomPixmap = QPixmap(box); zoomPixmap.fill(Qt::lightGray); } if (true) { QPainter p(&zoomPixmap); p.translate(-xy); m_largeMap->render(&p, QRect(xy, box)); p.end(); } QPainterPath clipPath; clipPath.addEllipse(center, ring, ring); QPainter p(this); p.setRenderHint(QPainter::Antialiasing); p.setClipPath(clipPath); p.drawPixmap(corner, zoomPixmap); p.setClipping(false); p.drawPixmap(corner, maskPixmap); p.setPen(Qt::gray); p.drawPath(clipPath); } if (invert) { QPainter p(this); p.setCompositionMode(QPainter::CompositionMode_Difference); p.fillRect(event->rect(), Qt::white); p.end(); } }
QPainterPath SPoint::shape() const { QPainterPath path; path.addEllipse(brect()); return path; }
QPainterPath Puck::shape() const { QPainterPath path; path.addEllipse(QRectF(-0.5*dimension, -0.5*dimension, dimension, dimension)); return path; }
void Lib_dialog::draw (){ QPainter painter; painter.begin(ui->widget); if (fx.getCount()==0 && fx.getinicialize()) {painter.end(); return;} painter.setRenderHint(QPainter::Antialiasing); QPen pen; pen.setStyle(Qt::SolidLine); //��� ����� �� ����������� pen.setWidth(1);//������� ����� pen.setBrush(Qt::green); //���� pen.setCapStyle(Qt::RoundCap); //������������ � ����� pen.setJoinStyle(Qt::RoundJoin); //������ ���� painter.setPen(pen); //QColor currentColor (); QRect geom; geom=ui->widget->geometry(); int hght=geom.height(); int wdth=geom.width(); float minx=fx.getMinX(); float miny=fx.getMinY(); float maxx=fx.getMaxX(); float maxy=fx.getMaxY(); float wd=maxx-minx; float hd=maxy-miny; StructXY grid; if (fx.getGrid(&grid)) { float dfs=round(minx/grid.x)*grid.x; do { float n=(dfs-minx)/wd; int x1=n*wdth; QLine ln (x1,0,x1,hght); dfs+=grid.x; painter.drawLine (ln);} while (dfs<maxx+grid.x); dfs=round(miny/grid.y)*grid.y; do { float n=(dfs-miny)/hd; int y1=n*hght; QLine ln (0,y1,wdth,y1); dfs+=grid.y; painter.drawLine (ln);} while (dfs<maxy+grid.y); } pen.setBrush(Qt::black); painter.setPen(pen); float n=(fx[0].x-minx)/wd; int x1=n*wdth; n=(fx[0].y-miny)/hd; int y1=hght-n*hght; int i; { QPainterPath path; path.addEllipse(x1-4,y1-4,8,8); painter.fillPath(path, Qt::red); int x2,y2; int i; for (i=1; i<fx.getCount(); i++){ n=(fx[i].x-minx)/wd; x1=n*wdth; n=(fx[i-1].x-minx)/wd; x2=n*wdth; n=(fx[i].y-miny)/hd; y1=hght-n*hght; n=(fx[i-1].y-miny)/hd; y2=hght-n*hght; path.addEllipse(x1-4,y1-4,8,8); painter.fillPath(path, Qt::red); QLine ln ( x1,y1,x2,y2); painter.drawLine (ln); }} QPainterPath path; if (fx.getCurPoint(&i)) { n=(fx[i].x-minx)/wd; int x=n*wdth; n=(fx[i].y-miny)/hd; int y=hght-n*hght; path.addEllipse(x-5,y-5,10,10); painter.fillPath(path, Qt::blue); } painter.end(); }
QPainterPath State::shape() { QPainterPath path; path.addEllipse(this->boundingRect()); return path; }
QPainterPath Node::shape() const{ QPainterPath path; path.addEllipse((-1)*ellipseSide/2, (-1)*ellipseSide/2, ellipseSide, ellipseSide); return path; }
void Ckeyb::drawPressed(QImage *_img) { if (keyPressedList.isEmpty()) { return; } keyPressing.lock(); QMapIterator<int, quint64> i(keyPressedList); keyPressing.unlock(); while (i.hasNext()) { i.next(); QRect _rect = getKey(i.key()).Rect; _rect.setCoords(_rect.x()*pPC->internalImageRatio, _rect.y()*pPC->internalImageRatio, (_rect.x()+_rect.width())*pPC->internalImageRatio, (_rect.y()+_rect.height())*pPC->internalImageRatio); int _m = qMin(_rect.width(), _rect.height())*.25; _rect+= QMargins(_m,_m,_m,_m); int dim = qMax(_rect.width(), _rect.height()); int magnifierSize = dim * 2; int radius = magnifierSize / 2; int ring = radius - 15; QSize box = QSize(magnifierSize, magnifierSize); QPixmap maskPixmap; maskPixmap = QPixmap(box); maskPixmap.fill(Qt::transparent); QRadialGradient g; g.setCenter(radius, radius); g.setFocalPoint(radius, radius); g.setRadius(radius); g.setColorAt(1.0, QColor(64, 64, 64, 0)); g.setColorAt(0.5, QColor(0, 0, 0, 255)); QPainter mask(&maskPixmap); mask.setRenderHint(QPainter::Antialiasing); mask.setCompositionMode(QPainter::CompositionMode_Source); mask.setBrush(g); mask.setPen(Qt::NoPen); mask.drawRect(maskPixmap.rect()); mask.setBrush(QColor(Qt::transparent)); mask.drawEllipse(g.center(), ring, ring); mask.end(); QPoint center = _rect.center() - QPoint(0, radius); center = center + QPoint(0, radius / 2); QPoint corner = center - QPoint(radius, radius); QPoint xy = center * 2 - QPoint(radius, radius); // only set the dimension to the magnified portion QPixmap zoomPixmap = QPixmap(box); zoomPixmap.fill(Qt::lightGray); QPainter pz(&zoomPixmap); // pz.translate(-xy); QRect target=QRect(QPoint(0,0),box); pz.drawImage(target, *_img,_rect); pz.end(); QPainterPath clipPath; clipPath.addEllipse(center, ring, ring); QPainter p(_img); p.setRenderHint(QPainter::Antialiasing); p.setClipPath(clipPath); p.drawPixmap(corner, zoomPixmap); p.setClipping(false); p.drawPixmap(corner, maskPixmap); p.setPen(Qt::gray); p.drawPath(clipPath); p.end(); } }
void SessionGapsChart::drawChart(QPainter *p) { int firstLap = first, lastLap = last; double x = paintRect.left(); double y; double yFactor = (((double)paintRect.height()-40) / (double)(tMax-tMin)); int size; findFirstAndLastLap(firstLap, lastLap, size); firstLap = first; lastLap = last; if (/*lastLap - firstLap == 0 ||*/ lapDataArray.isEmpty()) return; drawAxes(p, firstLap, lastLap); double xFactor = ((double)paintRect.width()) / (double)(lastLap - firstLap); p->setRenderHint(QPainter::Antialiasing); int lastPaintedSC = -1; int lapsInWindow = 0; for (int i = 0; i < lapDataArray.size(); ++i) { if (lapDataArray[i].getLapNumber() >= firstLap && lapDataArray[i].getLapNumber() <= lastLap)// && lapDataArray[i].getTime().isValid()) { // if (lapDataArray[i].getRaceLapExtraData().isSCLap() && lapDataArray[i].getLapNumber() > lastPaintedSC) // { // double sc_x1 = (double)(lapDataArray[i].getLapNumber()-1 - firstLap) * xFactor + (double)paintRect.left(); // double sc_x2 = (double)(lapDataArray[i].getLapNumber() - firstLap) * xFactor + (double)paintRect.left(); // if (sc_x1 < paintRect.left()) // sc_x1 = paintRect.left(); // if (lastPaintedSCPixel == -1) // lastPaintedSCPixel = round(sc_x2); // else if (abs(round(sc_x1) - lastPaintedSCPixel) <= 5) // { // sc_x1 = (double)lastPaintedSCPixel; // lastPaintedSCPixel = round(sc_x2); // } // p->setPen(QColor(255, 255, 0, 0)); // p->setBrush(QBrush(QColor(255, 255, 0, 35))); // p->drawRect(round(sc_x1), paintRect.top(), round(sc_x2-sc_x1), paintRect.height()); // lastPaintedSC = lapDataArray[i].getLapNumber(); //// lastSCLap = lapDataArray[i].getLapNumber(); // } if (lapDataArray[i].getRaceLapExtraData().isSCLap() && !lapDataArray[i].getGap().contains("L") && lapDataArray[i].getLapNumber() > lastPaintedSC) { drawSCLap(p, lapDataArray[i], xFactor); lastPaintedSC = lapDataArray[i].getLapNumber(); } double gap = lapDataArray[i].getGap().toDouble(); if (lapDataArray[i].getGap().size() > 0 && lapDataArray[i].getGap()[lapDataArray[i].getGap().size()-1] == 'L') { if (tMax >= max) gap = -1.0; else gap = max; } if (lapDataArray[i].getPosition() == 1) gap = 0.0; if (tMax >= max && lapDataArray[i].getGap() == "") gap = -1.0; y = (double)(paintRect.bottom() - (double)(gap-tMin) * yFactor); if (gap == -1.0 && tMax >= max) y = 10; else if (gap > tMax && tMax >= max) y = 30; x = (double)(lapDataArray[i].getLapNumber() - firstLap) * xFactor + (double)paintRect.left(); //int no = EventData::getInstance()lapDataArray[i].getCarID() QColor color = getCarColor(lapDataArray[i]); QPen pen; pen.setWidth(3); pen.setColor(color); p->setPen(pen); if (y <= paintRect.bottom()) { QPainterPath path; p->setBrush(QBrush(color)); if (lapDataArray[i].getTime().toString() == "IN PIT") { path.addEllipse(QPoint(x, y), 7, 7); } else { path.addEllipse(QPoint(x, y), 2, 2); } p->drawPath(path); if (!scaling) { if (lapsInWindow >= lapDataCoordinates.size()) lapDataCoordinates.append(LapDataCoordinates(i, (int)x, (int)y)); else lapDataCoordinates[lapsInWindow] = LapDataCoordinates(i, (int)x, (int)y); } ++lapsInWindow; } if (lapDataArray[i].getLapNumber()-1 >= firstLap && i > 0) { if (lapDataArray[i].getCarID() == lapDataArray[i-1].getCarID()) { gap = lapDataArray[i-1].getGap().toDouble(); if (lapDataArray[i-1].getGap().size() > 0 && lapDataArray[i-1].getGap()[lapDataArray[i-1].getGap().size()-1] == 'L') { if (tMax >= max) gap = -1.0; else gap = max; } if (lapDataArray[i-1].getPosition() == 1) gap = 0.0; if (tMax >= max && lapDataArray[i-1].getGap() == "") gap = -1.0; double y1 = (double)(paintRect.bottom() - (double)(gap-tMin) * yFactor); if (gap == -1.0 && tMax >= max) y1 = 10; else if (gap > tMax && tMax >= max) y1 = 30; double x1 = (double)(lapDataArray[i].getLapNumber() - 1 - firstLap) * xFactor + (double)paintRect.left(); if ((y > paintRect.bottom() && y1 > paintRect.bottom()) || (y < paintRect.top() && y1 < paintRect.top())) continue; ChartWidget::checkX1(x1, y1, x, y); ChartWidget::checkX2(x1, y1, x, y); if (y1 >= paintRect.top() || y >= paintRect.top()) p->drawLine(x1, y1, x, y); drawRetire(p, x, y, 7, lapDataArray[i]); } } } } if (!scaling) clearLapDataCoordinates(lapsInWindow); }
void SessionPositionsChart::drawChart(QPainter *p) { int firstLap = 99, lastLap = 0; int chartMin = tMin == 1 ? 0 : tMin; double left = paintRect.left(); double x = left; double y; double yFactor = (((double)paintRect.height()) / (double)(tMax-chartMin)); int size; findFirstAndLastLap(firstLap, lastLap, size); firstLap = first; lastLap = last; double xFactor = ((double)paintRect.width()) / (double)(lastLap - firstLap); if (firstLap == 1) { firstLap = 0; xFactor = ((double)paintRect.width()) / (double)(lastLap); } if (/*lastLap - firstLap == 0 ||*/ lapDataArray.isEmpty()) return; drawAxes(p, firstLap, lastLap); p->setRenderHint(QPainter::Antialiasing); int lastPaintedSC = -1; for (int i = 0; i < lapDataArray.size(); ++i) { if (lapDataArray[i].getLapNumber() >= firstLap && lapDataArray[i].getLapNumber() <= lastLap)// && lapDataArray[i].getTime().isValid()) { // if (lapDataArray[i].getRaceLapExtraData().isSCLap() && lapDataArray[i].getLapNumber() > lastPaintedSC) // { // double sc_x1 = (double)(lapDataArray[i].getLapNumber() - firstLap) * xFactor + left; // double sc_x2 = (double)(lapDataArray[i].getLapNumber()+1 - firstLap) * xFactor + left; // if (sc_x1 < paintRect.left()) // sc_x1 = paintRect.left(); // if (lastPaintedSCPixel == -1) // lastPaintedSCPixel = round(sc_x2); // else if (abs(round(sc_x1) - lastPaintedSCPixel) <= 5) // { // sc_x1 = (double)lastPaintedSCPixel; // lastPaintedSCPixel = round(sc_x2); // } // p->setPen(QColor(255, 255, 0, 0)); // p->setBrush(QBrush(QColor(255, 255, 0, 35))); // p->drawRect(round(sc_x1), paintRect.top(), round(sc_x2-sc_x1), paintRect.height()-10); // lastPaintedSC = lapDataArray[i].getLapNumber(); //// lastSCLap = lapDataArray[i].getLapNumber(); // } if (lapDataArray[i].getRaceLapExtraData().isSCLap() && !lapDataArray[i].getGap().contains("L") && lapDataArray[i].getLapNumber() > lastPaintedSC) { int tmp = first; if (firstLap == 0) first -= 1; drawSCLap(p, lapDataArray[i], xFactor); lastPaintedSC = lapDataArray[i].getLapNumber(); first = tmp; } y = (double)(paintRect.top() + (double)(lapDataArray[i].getPosition()-tMin) * yFactor); x = (double)(lapDataArray[i].getLapNumber() - firstLap) * xFactor + left; //int no = EventData::getInstance()lapDataArray[i].getCarID() QColor color = getCarColor(lapDataArray[i]); QPen pen; pen.setWidth(3); pen.setColor(color); p->setPen(pen); if (y <= paintRect.bottom()) { if (lapDataArray[i].getTime().toString() == "IN PIT") { QPainterPath path; p->setBrush(QBrush(color)); path.addEllipse(QPoint(x, y), 7, 7); p->drawPath(path); } } if (lapDataArray[i].getLapNumber()-1 >= firstLap)//&& i > 0) { double x1 = x; double y1 = y; if (firstLap == 0 && lapDataArray[i].getLapNumber() == 1) { x1 = (double)(lapDataArray[i].getLapNumber() - 1) * xFactor + left; y1 = (double)(paintRect.top() + (double)(getDriverStartingPosition(lapDataArray[i])-tMin) * yFactor); } else if (i > 0) { x1 = (double)(lapDataArray[i].getLapNumber() - 1 - firstLap) * xFactor + left; y1 = (double)(paintRect.top() + (double)(lapDataArray[i-1].getPosition()-tMin) * yFactor); } if ((y > paintRect.bottom() && y1 > paintRect.bottom()) || (y < paintRect.top() && y1 < paintRect.top())) continue; ChartWidget::checkX1(x1, y1, x, y); ChartWidget::checkX2(x1, y1, x, y); p->drawLine(x1, y1, x, y); drawRetire(p, x, y, 7, lapDataArray[i]); if (i > 0 && x1 == left && firstLap != 0) drawDriversLegend(p, lapDataArray[i-1], y1); } // drawRetire(p, x, y, lapDataArray[i], color); } } }
QPainterPath PointGraphicsItem::shape() const { QPainterPath path; path.addEllipse(boundingRect().adjusted(-4,-4, 4, 4)); return path; }
QPainterPath MeshGraphItemVelocityHandle::shape() const { QPainterPath path; path.addEllipse(-5, -5, 10, 10); return path; }
QPainterPath shape() const { QPainterPath path; path.addEllipse(boundingRect()); return path; }
void UIGraphicsButton::paint(QPainter *pPainter, const QStyleOptionGraphicsItem* /* pOption */, QWidget* /* pWidget = 0 */) { /* Prepare variables: */ int iMargin = data(GraphicsButton_Margin).toInt(); QIcon icon = data(GraphicsButton_Icon).value<QIcon>(); QSize iconSize = data(GraphicsButton_IconSize).toSize(); /* Which type button has: */ switch (m_buttonType) { case UIGraphicsButtonType_Iconified: { /* Just draw the pixmap: */ pPainter->drawPixmap(QRect(QPoint(iMargin, iMargin), iconSize), icon.pixmap(iconSize)); break; } case UIGraphicsButtonType_DirectArrow: { /* Prepare variables: */ QPalette pal = palette(); QColor buttonColor = pal.color(m_fParentSelected ? QPalette::HighlightedText : QPalette::Mid); #ifdef Q_WS_MAC /* Mac is using only light standard highlight colors, keeping highlight-text color always black. * User can choose a darker (non-standard) highlight color but it will be his visibility problem. * I think using highlight-text color (black) for arrow-buttons is too ugly, * so the corresponding color will be received from the highlight color: */ if (m_fParentSelected) buttonColor = pal.color(QPalette::Highlight).darker(150); #endif /* Q_WS_MAC */ /* Setup: */ pPainter->setRenderHint(QPainter::Antialiasing); QPen pen = pPainter->pen(); pen.setColor(buttonColor); pen.setWidth(2); pen.setCapStyle(Qt::RoundCap); /* Draw path: */ QPainterPath circlePath; circlePath.moveTo(iMargin, iMargin); circlePath.lineTo(iMargin + iconSize.width() / 2, iMargin); circlePath.arcTo(QRectF(circlePath.currentPosition(), iconSize).translated(-iconSize.width() / 2, 0), 90, -180); circlePath.lineTo(iMargin, iMargin + iconSize.height()); circlePath.closeSubpath(); pPainter->strokePath(circlePath, pen); /* Draw triangle: */ QPainterPath linePath; linePath.moveTo(iMargin + 5, iMargin + 5); linePath.lineTo(iMargin + iconSize.height() - 5, iMargin + iconSize.width() / 2); linePath.lineTo(iMargin + 5, iMargin + iconSize.width() - 5); pPainter->strokePath(linePath, pen); break; } case UIGraphicsButtonType_RoundArrow: { /* Prepare variables: */ QPalette pal = palette(); QColor buttonColor = pal.color(m_fParentSelected ? QPalette::HighlightedText : QPalette::Mid); #ifdef Q_WS_MAC /* Mac is using only light standard highlight colors, keeping highlight-text color always black. * User can choose a darker (non-standard) highlight color but it will be his visibility problem. * I think using highlight-text color (black) for arrow-buttons is too ugly, * so the corresponding color will be received from the highlight color: */ if (m_fParentSelected) buttonColor = pal.color(QPalette::Highlight).darker(150); #endif /* Q_WS_MAC */ /* Setup: */ pPainter->setRenderHint(QPainter::Antialiasing); QPen pen = pPainter->pen(); pen.setColor(buttonColor); pen.setWidth(2); pen.setCapStyle(Qt::RoundCap); /* Draw circle: */ QPainterPath circlePath; circlePath.moveTo(iMargin, iMargin); circlePath.addEllipse(QRectF(circlePath.currentPosition(), iconSize)); pPainter->strokePath(circlePath, pen); /* Draw triangle: */ QPainterPath linePath; linePath.moveTo(iMargin + 5, iMargin + 5); linePath.lineTo(iMargin + iconSize.height() - 5, iMargin + iconSize.width() / 2); linePath.lineTo(iMargin + 5, iMargin + iconSize.width() - 5); pPainter->strokePath(linePath, pen); break; } } }
QPainterPath Place::shape () const { QPainterPath shape; shape.addEllipse(0, 0, place_diameter , place_diameter); return shape; }
QPainterPath ControlSlider::handlePath() { QPainterPath path; path.addEllipse(handleRect()); return path; }
QPainterPath QGIViewPart::drawPainterPath(TechDrawGeometry::BaseGeom *baseGeom) const { QPainterPath path; switch(baseGeom->geomType) { case TechDrawGeometry::CIRCLE: { TechDrawGeometry::Circle *geom = static_cast<TechDrawGeometry::Circle *>(baseGeom); double x = geom->center.fX - geom->radius; double y = geom->center.fY - geom->radius; path.addEllipse(x, y, geom->radius * 2, geom->radius * 2); //topleft@(x,y) radx,rady //Base::Console().Message("TRACE -drawPainterPath - making an CIRCLE @(%.3f,%.3f) R:%.3f\n",x, y, geom->radius); } break; case TechDrawGeometry::ARCOFCIRCLE: { TechDrawGeometry::AOC *geom = static_cast<TechDrawGeometry::AOC *>(baseGeom); //double x = geom->center.fX - geom->radius; //double y = geom->center.fY - geom->radius; pathArc(path, geom->radius, geom->radius, 0., geom->largeArc, geom->cw, geom->endPnt.fX, geom->endPnt.fY, geom->startPnt.fX, geom->startPnt.fY); //Base::Console().Message("TRACE -drawPainterPath - making an ARCOFCIRCLE @(%.3f,%.3f) R:%.3f\n",x, y, geom->radius); } break; case TechDrawGeometry::ELLIPSE: { TechDrawGeometry::Ellipse *geom = static_cast<TechDrawGeometry::Ellipse *>(baseGeom); // Calculate start and end points as ellipse with theta = 0 and pi double startX = geom->center.fX + geom->major * cos(geom->angle), startY = geom->center.fY + geom->major * sin(geom->angle), endX = geom->center.fX - geom->major * cos(geom->angle), endY = geom->center.fY - geom->major * sin(geom->angle); pathArc(path, geom->major, geom->minor, geom->angle, false, false, endX, endY, startX, startY); pathArc(path, geom->major, geom->minor, geom->angle, false, false, startX, startY, endX, endY); //Base::Console().Message("TRACE -drawPainterPath - making an ELLIPSE @(%.3f,%.3f) R1:%.3f R2:%.3f\n",x, y, geom->major, geom->minor); } break; case TechDrawGeometry::ARCOFELLIPSE: { TechDrawGeometry::AOE *geom = static_cast<TechDrawGeometry::AOE *>(baseGeom); pathArc(path, geom->major, geom->minor, geom->angle, geom->largeArc, geom->cw, geom->endPnt.fX, geom->endPnt.fY, geom->startPnt.fX, geom->startPnt.fY); //Base::Console().Message("TRACE -drawPainterPath - making an ARCOFELLIPSE R1:%.3f R2:%.3f From: (%.3f,%.3f) To: (%.3f,%.3f)\n",geom->major, geom->minor,geom->startPnt.fX, geom->startPnt.fY,geom->endPnt.fX, geom->endPnt.fY); } break; case TechDrawGeometry::BSPLINE: { TechDrawGeometry::BSpline *geom = static_cast<TechDrawGeometry::BSpline *>(baseGeom); std::vector<TechDrawGeometry::BezierSegment>::const_iterator it = geom->segments.begin(); // Move painter to the beginning of our first segment path.moveTo(it->pnts[0].fX, it->pnts[0].fY); //Base::Console().Message("TRACE -drawPainterPath - making an BSPLINE From: (%.3f,%.3f)\n",it->pnts[0].fX,it->pnts[0].fY); for ( ; it != geom->segments.end(); ++it) { // At this point, the painter is either at the beginning // of the first segment, or end of the last if ( it->poles == 2 ) { // Degree 1 bezier = straight line... path.lineTo(it->pnts[1].fX, it->pnts[1].fY); } else if ( it->poles == 3 ) { path.quadTo(it->pnts[1].fX, it->pnts[1].fY, it->pnts[2].fX, it->pnts[2].fY); } else if ( it->poles == 4 ) { path.cubicTo(it->pnts[1].fX, it->pnts[1].fY, it->pnts[2].fX, it->pnts[2].fY, it->pnts[3].fX, it->pnts[3].fY); } else { //can only handle lines,quads,cubes Base::Console().Error("Bad pole count (%d) for BezierSegment of BSpline geometry\n",it->poles); path.lineTo(it->pnts[1].fX, it->pnts[1].fY); //show something for debugging } } } break; case TechDrawGeometry::GENERIC: { TechDrawGeometry::Generic *geom = static_cast<TechDrawGeometry::Generic *>(baseGeom); path.moveTo(geom->points[0].fX, geom->points[0].fY); std::vector<Base::Vector2D>::const_iterator it = geom->points.begin(); //Base::Console().Message("TRACE -drawPainterPath - making an GENERIC From: (%.3f,%.3f)\n",geom->points[0].fX, geom->points[0].fY); for(++it; it != geom->points.end(); ++it) { path.lineTo((*it).fX, (*it).fY); //Base::Console().Message(">>>> To: (%.3f,%.3f)\n",(*it).fX, (*it).fY); } } break; default: Base::Console().Error("Error - drawPainterPath - UNKNOWN geomType: %d\n",baseGeom->geomType); break; } double rot = getViewObject()->Rotation.getValue(); if (rot) { QTransform t; t.rotate(-rot); path = t.map(path); } return path; }
//! [3] void Window::setupShapes() { QPainterPath truck; //! [3] truck.setFillRule(Qt::WindingFill); truck.moveTo(0.0, 87.0); truck.lineTo(0.0, 60.0); truck.lineTo(10.0, 60.0); truck.lineTo(35.0, 35.0); truck.lineTo(100.0, 35.0); truck.lineTo(100.0, 87.0); truck.lineTo(0.0, 87.0); truck.moveTo(17.0, 60.0); truck.lineTo(55.0, 60.0); truck.lineTo(55.0, 40.0); truck.lineTo(37.0, 40.0); truck.lineTo(17.0, 60.0); truck.addEllipse(17.0, 75.0, 25.0, 25.0); truck.addEllipse(63.0, 75.0, 25.0, 25.0); //! [4] QPainterPath clock; //! [4] clock.addEllipse(-50.0, -50.0, 100.0, 100.0); clock.addEllipse(-48.0, -48.0, 96.0, 96.0); clock.moveTo(0.0, 0.0); clock.lineTo(-2.0, -2.0); clock.lineTo(0.0, -42.0); clock.lineTo(2.0, -2.0); clock.lineTo(0.0, 0.0); clock.moveTo(0.0, 0.0); clock.lineTo(2.732, -0.732); clock.lineTo(24.495, 14.142); clock.lineTo(0.732, 2.732); clock.lineTo(0.0, 0.0); //! [5] QPainterPath house; //! [5] house.moveTo(-45.0, -20.0); house.lineTo(0.0, -45.0); house.lineTo(45.0, -20.0); house.lineTo(45.0, 45.0); house.lineTo(-45.0, 45.0); house.lineTo(-45.0, -20.0); house.addRect(15.0, 5.0, 20.0, 35.0); house.addRect(-35.0, -15.0, 25.0, 25.0); //! [6] QPainterPath text; //! [6] QFont font; font.setPixelSize(50); QRect fontBoundingRect = QFontMetrics(font).boundingRect(tr("Qt")); text.addText(-QPointF(fontBoundingRect.center()), font, tr("Qt")); //! [7] shapes.append(clock); shapes.append(house); shapes.append(text); shapes.append(truck); connect(shapeComboBox, SIGNAL(activated(int)), this, SLOT(shapeSelected(int))); }
void QBadgeLabel::fillEllipse(QPainter *painter, qreal x, qreal y, qreal size, const QColor &c) { QPainterPath path = QPainterPath(); path.addEllipse(x, y, size, size); painter->fillPath(path, QBrush(c)); }
void SessionLapTimesChart::drawChart(QPainter *p) { int firstLap = first, lastLap = last; double x = paintRect.left(); double y; double yFactor = (((double)paintRect.height()) / (double)(tMax-tMin)); double secs; int size; findFirstAndLastLap(firstLap, lastLap, size); firstLap = first; lastLap = last; if (/*lastLap - firstLap == 0 ||*/ lapDataArray.isEmpty()) return; drawAxes(p, firstLap, lastLap); double xFactor = ((double)paintRect.width()) / (double)(lastLap - firstLap); p->setRenderHint(QPainter::Antialiasing); int lastPaintedSC = -1; // lapDataXYArray.clear(); int lapsInWindow = 0; for (int i = 0; i < lapDataArray.size(); ++i) { if (lapDataArray[i].getLapNumber() >= firstLap && lapDataArray[i].getLapNumber() <= lastLap)// && lapDataArray[i].getTime().isValid()) { secs = lapDataArray[i].getTime().toDouble(); if (!lapDataArray[i].getTime().isValid() && lapDataArray[i].getLapNumber()-1 >= firstLap && i > 0)// && i < lapDataArray.size()-1) { secs = lapDataArray[i-1].getTime().toDouble(); if (!lapDataArray[i-1].getTime().isValid() && lapDataArray[i].getLapNumber()+1 <= lastLap && i < lapDataArray.size()-1) { QString pl = EventData::getInstance().getDriversData()[lapDataArray[i].getCarID()-1].getPitTime(lapDataArray[i].getLapNumber()); secs = LapTime(lapDataArray[i+1].getTime() + LapTime(pl) + LapTime(5000)).toDouble(); } } if (lapDataArray[i].getRaceLapExtraData().isSCLap() && !lapDataArray[i].getGap().contains("L") && lapDataArray[i].getLapNumber() > lastPaintedSC) { drawSCLap(p, lapDataArray[i], xFactor); lastPaintedSC = lapDataArray[i].getLapNumber(); } // if (lapDataArray[i].getRaceLapExtraData().isSCLap() && lapDataArray[i].getLapNumber() > lastPaintedSC) // { // double sc_x1 = (double)(lapDataArray[i].getLapNumber() - firstLap) * xFactor + (double)paintRect.left(); // double sc_x2 = (double)(lapDataArray[i].getLapNumber()+1 - firstLap) * xFactor + (double)paintRect.left(); // if (sc_x1 < paintRect.left()) // sc_x1 = paintRect.left(); // if (lastPaintedSCPixel == -1) // lastPaintedSCPixel = round(sc_x2); // else if (abs(round(sc_x1) - lastPaintedSCPixel) <= 5) // { // sc_x1 = (double)lastPaintedSCPixel; // lastPaintedSCPixel = round(sc_x2); // } // p->setPen(QColor(255, 255, 0, 0)); // p->setBrush(QBrush(QColor(255, 255, 0, 35))); // p->drawRect(round(sc_x1), paintRect.top(), round(sc_x2-sc_x1), paintRect.height()); // lastPaintedSC = lapDataArray[i].getLapNumber(); // } if (secs > tMax && tMax == max) secs = tMax; // if (secs < tMin) // secs = tMin; y = (double)(paintRect.bottom() - (double)(secs-tMin) * yFactor); x = (double)(lapDataArray[i].getLapNumber() - firstLap) * xFactor + (double)paintRect.left(); //int no = EventData::getInstance()lapDataArray[i].getCarID() QColor color = getCarColor(lapDataArray[i]); QPen pen; pen.setWidth(3); pen.setColor(color); p->setPen(pen); QPainterPath path; if (!scaling) { if (lapsInWindow >= lapDataCoordinates.size()) lapDataCoordinates.append(LapDataCoordinates(i, (int)x, (int)y)); else lapDataCoordinates[lapsInWindow] = LapDataCoordinates(i, (int)x, (int)y); } // p->setBrush(QBrush(ColorsManager::getInstance().getDefaultColor(LTPackets::BACKGROUND])); p->setBrush(QBrush(color)); if (y < paintRect.bottom()) { if (lapDataArray[i].getTime().toString() == "IN PIT") { // p->setBrush(QBrush(QColor())); path.addEllipse(QPoint(x, y), 7, 7); } else { path.addEllipse(QPoint(x, y), 2, 2); } p->drawPath(path); } if (lapDataArray[i].getLapNumber()-1 >= firstLap && i > 0) { double x1 = (double)(lapDataArray[i].getLapNumber() - 1 - firstLap) * xFactor + (double)paintRect.left(); secs = lapDataArray[i-1].getTime().toDouble(); if (!lapDataArray[i-1].getTime().isValid() && i-2 >= firstLap) { secs = lapDataArray[i-2].getTime().toDouble(); if (!lapDataArray[i-2].getTime().isValid())// && i < lapDataArray.size()-1) { QString pl = EventData::getInstance().getDriversData()[lapDataArray[i-1].getCarID()-1].getPitTime(lapDataArray[i-1].getLapNumber()); secs = LapTime(lapDataArray[i].getTime() + LapTime(pl) + LapTime(5000)).toDouble(); } } if (secs > tMax && tMax == max) secs = tMax; // if (secs < tMin) // secs = tMin; double y1 = (double)(paintRect.bottom() - (double)(secs-tMin) * yFactor); if ((y > paintRect.bottom() && y1 > paintRect.bottom()) || (y < paintRect.top() && y1 < paintRect.top())) continue; ChartWidget::checkX1(x1, y1, x, y); ChartWidget::checkX2(x1, y1, x, y); p->drawLine(x1, y1, x, y); drawRetire(p, x, y, 7, lapDataArray[i]); } ++lapsInWindow; } } if (!scaling) clearLapDataCoordinates(lapsInWindow); }
void GraphicsContext::addRoundedRectClip(const IntRect& rect, const IntSize& topLeft, const IntSize& topRight, const IntSize& bottomLeft, const IntSize& bottomRight) { if (paintingDisabled()) return; // Need sufficient width and height to contain these curves. Sanity check our top/bottom // values and our width/height values to make sure the curves can all fit. int requiredWidth = qMax(topLeft.width() + topRight.width(), bottomLeft.width() + bottomRight.width()); if (requiredWidth > rect.width()) return; int requiredHeight = qMax(topLeft.height() + bottomLeft.height(), topRight.height() + bottomRight.height()); if (requiredHeight > rect.height()) return; // Clip to our rect. clip(rect); // OK, the curves can fit. QPainterPath path; // Add the four ellipses to the path. Technically this really isn't good enough, since we could end up // not clipping the other 3/4 of the ellipse we don't care about. We're relying on the fact that for // normal use cases these ellipses won't overlap one another (or when they do the curvature of one will // be subsumed by the other). path.addEllipse(QRectF(rect.x(), rect.y(), topLeft.width() * 2, topLeft.height() * 2)); path.addEllipse(QRectF(rect.right() - topRight.width() * 2, rect.y(), topRight.width() * 2, topRight.height() * 2)); path.addEllipse(QRectF(rect.x(), rect.bottom() - bottomLeft.height() * 2, bottomLeft.width() * 2, bottomLeft.height() * 2)); path.addEllipse(QRectF(rect.right() - bottomRight.width() * 2, rect.bottom() - bottomRight.height() * 2, bottomRight.width() * 2, bottomRight.height() * 2)); int topLeftRightHeightMax = qMax(topLeft.height(), topRight.height()); int bottomLeftRightHeightMax = qMax(bottomLeft.height(), bottomRight.height()); int topBottomLeftWidthMax = qMax(topLeft.width(), bottomLeft.width()); int topBottomRightWidthMax = qMax(topRight.width(), bottomRight.width()); // Now add five rects (one for each edge rect in between the rounded corners and one for the interior). path.addRect(QRectF(rect.x() + topLeft.width(), rect.y(), rect.width() - topLeft.width() - topRight.width(), topLeftRightHeightMax)); path.addRect(QRectF(rect.x() + bottomLeft.width(), rect.bottom() - bottomLeftRightHeightMax, rect.width() - bottomLeft.width() - bottomRight.width(), bottomLeftRightHeightMax)); path.addRect(QRectF(rect.x(), rect.y() + topLeft.height(), topBottomLeftWidthMax, rect.height() - topLeft.height() - bottomLeft.height())); path.addRect(QRectF(rect.right() - topBottomRightWidthMax, rect.y() + topRight.height(), topBottomRightWidthMax, rect.height() - topRight.height() - bottomRight.height())); path.addRect(QRectF(rect.x() + topBottomLeftWidthMax, rect.y() + topLeftRightHeightMax, rect.width() - topBottomLeftWidthMax - topBottomRightWidthMax, rect.height() - topLeftRightHeightMax - bottomLeftRightHeightMax)); path.setFillRule(Qt::WindingFill); m_data->p().setClipPath(path, Qt::IntersectClip); }
QPainterPath Node::shape() const { QPainterPath path; path.addEllipse(-20, -20, 40, 40); return path; }
void tst_QPainterPath::closing() { // lineto's { QPainterPath triangle(QPoint(100, 100)); triangle.lineTo(200, 100); triangle.lineTo(200, 200); QCOMPARE(triangle.elementCount(), 3); triangle.closeSubpath(); QCOMPARE(triangle.elementCount(), 4); QCOMPARE(triangle.elementAt(3).type, QPainterPath::LineToElement); triangle.moveTo(300, 300); QCOMPARE(triangle.elementCount(), 5); QCOMPARE(triangle.elementAt(4).type, QPainterPath::MoveToElement); triangle.lineTo(400, 300); triangle.lineTo(400, 400); QCOMPARE(triangle.elementCount(), 7); triangle.closeSubpath(); QCOMPARE(triangle.elementCount(), 8); // this will should trigger implicit moveto... triangle.lineTo(600, 300); QCOMPARE(triangle.elementCount(), 10); QCOMPARE(triangle.elementAt(8).type, QPainterPath::MoveToElement); QCOMPARE(triangle.elementAt(9).type, QPainterPath::LineToElement); triangle.lineTo(600, 700); QCOMPARE(triangle.elementCount(), 11); } // curveto's { QPainterPath curves(QPoint(100, 100)); curves.cubicTo(200, 100, 100, 200, 200, 200); QCOMPARE(curves.elementCount(), 4); curves.closeSubpath(); QCOMPARE(curves.elementCount(), 5); QCOMPARE(curves.elementAt(4).type, QPainterPath::LineToElement); curves.moveTo(300, 300); QCOMPARE(curves.elementCount(), 6); QCOMPARE(curves.elementAt(5).type, QPainterPath::MoveToElement); curves.cubicTo(400, 300, 300, 400, 400, 400); QCOMPARE(curves.elementCount(), 9); curves.closeSubpath(); QCOMPARE(curves.elementCount(), 10); // should trigger implicit moveto.. curves.cubicTo(100, 800, 800, 100, 800, 800); QCOMPARE(curves.elementCount(), 14); QCOMPARE(curves.elementAt(10).type, QPainterPath::MoveToElement); QCOMPARE(curves.elementAt(11).type, QPainterPath::CurveToElement); } { QPainterPath rects; rects.addRect(100, 100, 100, 100); QCOMPARE(rects.elementCount(), 5); QCOMPARE(rects.elementAt(0).type, QPainterPath::MoveToElement); QCOMPARE(rects.elementAt(4).type, QPainterPath::LineToElement); rects.addRect(300, 100, 100,100); QCOMPARE(rects.elementCount(), 10); QCOMPARE(rects.elementAt(5).type, QPainterPath::MoveToElement); QCOMPARE(rects.elementAt(9).type, QPainterPath::LineToElement); rects.lineTo(0, 0); QCOMPARE(rects.elementCount(), 12); QCOMPARE(rects.elementAt(10).type, QPainterPath::MoveToElement); QCOMPARE(rects.elementAt(11).type, QPainterPath::LineToElement); } { QPainterPath ellipses; ellipses.addEllipse(100, 100, 100, 100); QCOMPARE(ellipses.elementCount(), 13); QCOMPARE(ellipses.elementAt(0).type, QPainterPath::MoveToElement); QCOMPARE(ellipses.elementAt(10).type, QPainterPath::CurveToElement); ellipses.addEllipse(300, 100, 100,100); QCOMPARE(ellipses.elementCount(), 26); QCOMPARE(ellipses.elementAt(13).type, QPainterPath::MoveToElement); QCOMPARE(ellipses.elementAt(23).type, QPainterPath::CurveToElement); ellipses.lineTo(0, 0); QCOMPARE(ellipses.elementCount(), 28); QCOMPARE(ellipses.elementAt(26).type, QPainterPath::MoveToElement); QCOMPARE(ellipses.elementAt(27).type, QPainterPath::LineToElement); } { QPainterPath path; path.moveTo(10, 10); path.lineTo(40, 10); path.lineTo(25, 20); path.lineTo(10 + 1e-13, 10 + 1e-13); QCOMPARE(path.elementCount(), 4); path.closeSubpath(); QCOMPARE(path.elementCount(), 4); } }
void tst_QPainterPath::testContainsAndIntersects_data() { QTest::addColumn<QPainterPath>("path"); QTest::addColumn<QPainterPath>("candidate"); QTest::addColumn<bool>("contained"); QTest::addColumn<bool>("intersects"); QTest::newRow("rect vs small ellipse (upper left)") << rectPath(0, 0, 100, 100) << ellipsePath(0, 0, 50, 50) << false << true; QTest::newRow("rect vs small ellipse (upper right)") << rectPath(0, 0, 100, 100) << ellipsePath(50, 0, 50, 50) << false << true; QTest::newRow("rect vs small ellipse (lower right)") << rectPath(0, 0, 100, 100) << ellipsePath(50, 50, 50, 50) << false << true; QTest::newRow("rect vs small ellipse (lower left)") << rectPath(0, 0, 100, 100) << ellipsePath(0, 50, 50, 50) << false << true; QTest::newRow("rect vs small ellipse (centered)") << rectPath(0, 0, 100, 100) << ellipsePath(25, 25, 50, 50) << true << true; QTest::newRow("rect vs equal ellipse") << rectPath(0, 0, 100, 100) << ellipsePath(0, 0, 100, 100) << false << true; QTest::newRow("rect vs big ellipse") << rectPath(0, 0, 100, 100) << ellipsePath(-10, -10, 120, 120) << false << true; QPainterPath twoEllipses = ellipsePath(0, 0, 100, 100).united(ellipsePath(200, 0, 100, 100)); QTest::newRow("rect vs two small ellipses") << rectPath(0, 0, 100, 100) << ellipsePath(25, 25, 50, 50).united(ellipsePath(225, 25, 50, 50)) << false << true; QTest::newRow("rect vs two equal ellipses") << rectPath(0, 0, 100, 100) << twoEllipses << false << true; QTest::newRow("rect vs self") << rectPath(0, 0, 100, 100) << rectPath(0, 0, 100, 100) << false << true; QTest::newRow("ellipse vs self") << ellipsePath(0, 0, 100, 100) << ellipsePath(0, 0, 100, 100) << false << true; QPainterPath twoRects = rectPath(0, 0, 100, 100).united(rectPath(200, 0, 100, 100)); QTest::newRow("two rects vs small ellipse (upper left)") << twoRects << ellipsePath(0, 0, 50, 50) << false << true; QTest::newRow("two rects vs small ellipse (upper right)") << twoRects << ellipsePath(50, 0, 50, 50) << false << true; QTest::newRow("two rects vs small ellipse (lower right)") << twoRects << ellipsePath(50, 50, 50, 50) << false << true; QTest::newRow("two rects vs small ellipse (lower left)") << twoRects << ellipsePath(0, 50, 50, 50) << false << true; QTest::newRow("two rects vs small ellipse (centered)") << twoRects << ellipsePath(25, 25, 50, 50) << true << true; QTest::newRow("two rects vs equal ellipse") << twoRects << ellipsePath(0, 0, 100, 100) << false << true; QTest::newRow("two rects vs big ellipse") << twoRects << ellipsePath(-10, -10, 120, 120) << false << true; QTest::newRow("two rects vs two small ellipses") << twoRects << ellipsePath(25, 25, 50, 50).united(ellipsePath(225, 25, 50, 50)) << true << true; QTest::newRow("two rects vs two equal ellipses") << twoRects << ellipsePath(0, 0, 100, 100).united(ellipsePath(200, 0, 100, 100)) << false << true; QTest::newRow("two rects vs self") << twoRects << twoRects << false << true; QTest::newRow("two ellipses vs self") << twoEllipses << twoEllipses << false << true; QPainterPath windingRect = rectPath(0, 0, 100, 100); windingRect.addRect(25, 25, 100, 50); windingRect.setFillRule(Qt::WindingFill); QTest::newRow("rect with winding rule vs tall rect") << windingRect << rectPath(40, 20, 20, 60) << true << true; QTest::newRow("rect with winding rule vs self") << windingRect << windingRect << false << true; QPainterPath thickFrame = rectPath(0, 0, 100, 100).subtracted(rectPath(25, 25, 50, 50)); QPainterPath thinFrame = rectPath(10, 10, 80, 80).subtracted(rectPath(15, 15, 70, 70)); QTest::newRow("thin frame in thick frame") << thickFrame << thinFrame << true << true; QTest::newRow("rect in thick frame") << thickFrame << rectPath(40, 40, 20, 20) << false << false; QTest::newRow("rect in thin frame") << thinFrame << rectPath(40, 40, 20, 20) << false << false; QPainterPath ellipses; ellipses.addEllipse(0, 0, 10, 10); ellipses.addEllipse(4, 4, 2, 2); ellipses.setFillRule(Qt::WindingFill); // the definition of QPainterPath::intersects() and contains() is fill-area based, QTest::newRow("line in rect") << rectPath(0, 0, 100, 100) << linePath(10, 10, 90, 90) << true << true; QTest::newRow("horizontal line in rect") << rectPath(0, 0, 100, 100) << linePath(10, 50, 90, 50) << true << true; QTest::newRow("vertical line in rect") << rectPath(0, 0, 100, 100) << linePath(50, 10, 50, 90) << true << true; QTest::newRow("line through rect") << rectPath(0, 0, 100, 100) << linePath(-10, -10, 110, 110) << false << true; QTest::newRow("line through rect 2") << rectPath(0, 0, 100, 100) << linePath(-10, 0, 110, 100) << false << true; QTest::newRow("line through rect 3") << rectPath(0, 0, 100, 100) << linePath(5, 10, 110, 100) << false << true; QTest::newRow("line through rect 4") << rectPath(0, 0, 100, 100) << linePath(-10, 0, 90, 90) << false << true; QTest::newRow("horizontal line through rect") << rectPath(0, 0, 100, 100) << linePath(-10, 50, 110, 50) << false << true; QTest::newRow("vertical line through rect") << rectPath(0, 0, 100, 100) << linePath(50, -10, 50, 110) << false << true; QTest::newRow("line vs line") << linePath(0, 0, 10, 10) << linePath(10, 0, 0, 10) << false << true; QTest::newRow("line in rect with hole") << rectPath(0, 0, 10, 10).subtracted(rectPath(2, 2, 6, 6)) << linePath(4, 4, 6, 6) << false << false; QTest::newRow("line in ellipse") << ellipses << linePath(3, 5, 7, 5) << false << true; QTest::newRow("line in ellipse 2") << ellipses << linePath(4.5, 5, 5.5, 5) << true << true; QTest::newRow("winding ellipse") << ellipses << ellipsePath(4, 4, 2, 2) << false << true; QTest::newRow("winding ellipse 2") << ellipses << ellipsePath(4.5, 4.5, 1, 1) << true << true; ellipses.setFillRule(Qt::OddEvenFill); QTest::newRow("odd even ellipse") << ellipses << ellipsePath(4, 4, 2, 2) << false << true; QTest::newRow("odd even ellipse 2") << ellipses << ellipsePath(4.5, 4.5, 1, 1) << false << false; }
void tst_QPainterPath::contains_QPointF_data() { QTest::addColumn<QPainterPath>("path"); QTest::addColumn<QPointF>("pt"); QTest::addColumn<bool>("contained"); QPainterPath path; path.addRect(0, 0, 100, 100); // ##### // # # // # # // # # // ##### QTest::newRow("[0,0] in [0,0,100,100]") << path << QPointF(0, 0) << true; QTest::newRow("[99,0] in [0,0,100,100]") << path << QPointF(99, 0) << true; QTest::newRow("[0,99] in [0,0,100,100]") << path << QPointF(0, 99) << true; QTest::newRow("[99,99] in [0,0,100,100]") << path << QPointF(99, 99) << true; QTest::newRow("[99.99,0] in [0,0,100,100]") << path << QPointF(99.99, 0) << true; QTest::newRow("[0,99.99] in [0,0,100,100]") << path << QPointF(0, 99.99) << true; QTest::newRow("[99.99,99.99] in [0,0,100,100]") << path << QPointF(99.99, 99.99) << true; QTest::newRow("[0.01,0.01] in [0,0,100,100]") << path << QPointF(0.01, 0.01) << true; QTest::newRow("[0,0.01] in [0,0,100,100]") << path << QPointF(0, 0.01) << true; QTest::newRow("[0.01,0] in [0,0,100,100]") << path << QPointF(0.01, 0) << true; QTest::newRow("[-0.01,-0.01] in [0,0,100,100]") << path << QPointF(-0.01, -0.01) << false; QTest::newRow("[-0,-0.01] in [0,0,100,100]") << path << QPointF(0, -0.01) << false; QTest::newRow("[-0.01,0] in [0,0,100,100]") << path << QPointF(-0.01, 0) << false; QTest::newRow("[-10,0] in [0,0,100,100]") << path << QPointF(-10, 0) << false; QTest::newRow("[100,0] in [0,0,100,100]") << path << QPointF(100, 0) << false; QTest::newRow("[0,-10] in [0,0,100,100]") << path << QPointF(0, -10) << false; QTest::newRow("[0,100] in [0,0,100,100]") << path << QPointF(0, 100) << false; QTest::newRow("[100.1,0] in [0,0,100,100]") << path << QPointF(100.1, 0) << false; QTest::newRow("[0,100.1] in [0,0,100,100]") << path << QPointF(0, 100.1) << false; path.addRect(50, 50, 100, 100); // ##### // # # // # ##### // # # # # // ##### # // # # // ##### QTest::newRow("[49,49] in 2 rects") << path << QPointF(49,49) << true; QTest::newRow("[50,50] in 2 rects") << path << QPointF(50,50) << false; QTest::newRow("[100,100] in 2 rects") << path << QPointF(100,100) << true; path.setFillRule(Qt::WindingFill); QTest::newRow("[50,50] in 2 rects (winding)") << path << QPointF(50,50) << true; path.addEllipse(0, 0, 150, 150); // ##### // ## ## // # ##### // # # # # // ##### # // ## ## // ##### QTest::newRow("[50,50] in complex (winding)") << path << QPointF(50, 50) << true; path.setFillRule(Qt::OddEvenFill); QTest::newRow("[50,50] in complex (windinf)") << path << QPointF(50, 50) << true; QTest::newRow("[49,49] in complex") << path << QPointF(49,49) << false; QTest::newRow("[100,100] in complex") << path << QPointF(49,49) << false; // unclosed triangle path = QPainterPath(); path.moveTo(100, 100); path.lineTo(130, 70); path.lineTo(150, 110); QTest::newRow("[100,100] in triangle") << path << QPointF(100, 100) << true; QTest::newRow("[140,100] in triangle") << path << QPointF(140, 100) << true; QTest::newRow("[130,80] in triangle") << path << QPointF(130, 80) << true; QTest::newRow("[110,80] in triangle") << path << QPointF(110, 80) << false; QTest::newRow("[150,100] in triangle") << path << QPointF(150, 100) << false; QTest::newRow("[120,110] in triangle") << path << QPointF(120, 110) << false; QRectF base_rect(0, 0, 20, 20); path = QPainterPath(); path.addEllipse(base_rect); // not strictly precise, but good enougth to verify fair precision. QPainterPath inside; inside.addEllipse(base_rect.adjusted(5, 5, -5, -5)); QPolygonF inside_poly = inside.toFillPolygon(); for (int i=0; i<inside_poly.size(); ++i) QTest::newRow("inside_ellipse") << path << inside_poly.at(i) << true; QPainterPath outside; outside.addEllipse(base_rect.adjusted(-5, -5, 5, 5)); QPolygonF outside_poly = outside.toFillPolygon(); for (int i=0; i<outside_poly.size(); ++i) QTest::newRow("outside_ellipse") << path << outside_poly.at(i) << false; path = QPainterPath(); base_rect = QRectF(50, 50, 200, 200); path.addEllipse(base_rect); path.setFillRule(Qt::WindingFill); QTest::newRow("topleft outside ellipse") << path << base_rect.topLeft() << false; QTest::newRow("topright outside ellipse") << path << base_rect.topRight() << false; QTest::newRow("bottomright outside ellipse") << path << base_rect.bottomRight() << false; QTest::newRow("bottomleft outside ellipse") << path << base_rect.bottomLeft() << false; // Test horizontal curve segment path = QPainterPath(); path.moveTo(100, 100); path.cubicTo(120, 100, 180, 100, 200, 100); path.lineTo(150, 200); path.closeSubpath(); QTest::newRow("horizontal cubic, out left") << path << QPointF(0, 100) << false; QTest::newRow("horizontal cubic, out right") << path << QPointF(300, 100) <<false; QTest::newRow("horizontal cubic, in mid") << path << QPointF(150, 100) << true; }