KoChild::Gadget KoChild::gadgetHitTest( const QPoint &p ) { if ( !frameRegion().contains( p ) ) return NoGadget; if ( QRegion( pointArray( QRect( -5, -5, 5, 5 ) ) ).contains( p ) ) return TopLeft; if ( QRegion( pointArray( QRect( d->m_geometry.width() / 2 - 3, -5, 5, 5 ) ) ).contains( p ) ) return TopMid; if ( QRegion( pointArray( QRect( d->m_geometry.width(), -5, 5, 5 ) ) ).contains( p ) ) return TopRight; if ( QRegion( pointArray( QRect( -5, d->m_geometry.height() / 2 - 3, 5, 5 ) ) ).contains( p ) ) return MidLeft; if ( QRegion( pointArray( QRect( -5, d->m_geometry.height(), 5, 5 ) ) ).contains( p ) ) return BottomLeft; if ( QRegion( pointArray( QRect( d->m_geometry.width() / 2 - 3, d->m_geometry.height(), 5, 5 ) ) ).contains( p ) ) return BottomMid; if ( QRegion( pointArray( QRect( d->m_geometry.width(), d->m_geometry.height(), 5, 5 ) ) ).contains( p ) ) return BottomRight; if ( QRegion( pointArray( QRect( d->m_geometry.width(), d->m_geometry.height() / 2 - 3, 5, 5 ) ) ).contains( p ) ) return MidRight; return Move; }
CompactRealArray findZeroes(Function &f, const RealInterval &i) { CompactRealArray result; RealPoint2DArray pointArray(SEARCHCOUNT); Real step = i.getLength() / (SEARCHCOUNT-1); Real x = i.getFrom(); for(int t = 0; t < SEARCHCOUNT-1; t++, x += step) { try { pointArray.add(RealPoint2D(x,f(x))); } catch (...) { // ignore } } try { pointArray.add(RealPoint2D(i.getTo(), f(i.getTo()))); } catch (...) { // ignore } const size_t n = pointArray.size(); const RealPoint2D *lastp = &pointArray[0]; for(size_t t = 1; t < n; t++) { const RealPoint2D &p = pointArray[t]; if(sign(lastp->y) * sign(p.y) != 1) { if(lastp->y == 0) { result.add(lastp->x); } else if(p.y != 0) { // lastp->y != 0 && p.y != 0 => opposite sign result.add(converge(f,lastp->x, p.x)); } } lastp = &p; } if(lastp->y == 0) { result.add(lastp->x); } return result; }
void QgsGrassEdit::displayElement( int line, const QPen & pen, int size, QPainter *painter ) { QgsDebugMsg( QString( "line = %1" ).arg( line ) ); // is it a valid line? if ( line == 0 ) return; if ( !mSymbDisplay[mLineSymb[line]] ) return; int type = mProvider->readLine( mPoints, NULL, line ); if ( type < 0 ) return; QPainter *myPainter; if ( !painter ) { myPainter = new QPainter(); myPainter->begin( mPixmap ); } else { myPainter = painter; } if ( type & GV_POINTS ) { displayIcon( mPoints->x[0], mPoints->y[0], pen, QgsVertexMarker::ICON_CROSS, size, myPainter ); } else // line { QgsPoint point; QPolygon pointArray( mPoints->n_points ); for ( int i = 0; i < mPoints->n_points; i++ ) { point.setX( mPoints->x[i] ); point.setY( mPoints->y[i] ); point = transformLayerToCanvas( point ); pointArray.setPoint( i, qRound( point.x() ), qRound( point.y() ) ); } myPainter->setPen( pen ); myPainter->drawPolyline( pointArray ); } if ( !painter ) { myPainter->end(); // porting mCanvas->update(); mCanvasEdit->update(); delete myPainter; } }
void DrawWidget::drawArray(float *input, int n, int sampleStep, double theZoomY, double offset) { double dh2 = double(height()-1) / 2.0; double scaleY = dh2 * theZoomY; int w = width() / sampleStep; Q3PointArray pointArray(w); int intStep = int(n / w); int remainderStep = n - (intStep * w); int pos = 0; int remainder = 0; for(int j=0; j<w; j++, pos+=intStep, remainder+=remainderStep) { if(remainder >= w) { pos++; remainder -= w; } myassert(pos < n); pointArray.setPoint(j, j*sampleStep, toInt(dh2 - (input[pos] + offset)*scaleY)); } //p.setPen(QPen(active->color, 0)); p.drawPolyline(pointArray); }
void JSONSerializer::SerializeFloatSplineNode( rapidjson::Value& nodeValue, const shared_ptr<FloatSplineNode>& node) { for (UINT layer = UINT(SplineLayer::BASE); layer < UINT(SplineLayer::COUNT); layer++) { SplineFloatComponent* component = node->GetComponent(SplineLayer(layer)); auto& points = component->GetPoints(); rapidjson::Value pointArray(rapidjson::kArrayType); for (UINT i = 0; i < points.size(); i++) { const SplinePoint& point = points[i]; rapidjson::Value p(rapidjson::kObjectType); p.AddMember("time", point.mTime, *mAllocator); p.AddMember("value", point.mValue, *mAllocator); p.AddMember("autotangent", point.mIsAutoangent, *mAllocator); p.AddMember("breakpoint", point.mIsBreakpoint, *mAllocator); p.AddMember("linear", point.mIsLinear, *mAllocator); pointArray.PushBack(p, *mAllocator); } const char* fieldName = EnumMapperA::GetStringFromEnum(SplineLayerMapper, layer); nodeValue.AddMember(rapidjson::GenericStringRef<char>(fieldName), pointArray, *mAllocator); } }
QRegion KoChild::region( const QWMatrix &matrix ) const { return QRegion( pointArray( matrix ) ); }
QPointArray KoChild::framePointArray( const QWMatrix &matrix ) const { return pointArray( QRect( -6, -6, d->m_geometry.width() + 12, d->m_geometry.height() + 12 ), matrix ); }
QRect KoChild::boundingRect() const { return pointArray().boundingRect(); }
QPointArray KoChild::pointArray( const QWMatrix &matrix ) const { return pointArray( QRect( 0, 0, d->m_geometry.width(), d->m_geometry.height() ), matrix ); }
int Vector2::ConvexHullInPlace(Vector2* pointArray, size_t nPoints) { if(nPoints <= 3) return nPoints; // Lowest point of the set Vector2* lowest = &pointArray[0]; for(int i = 1; i < nPoints; ++i) { if(lowest->y > pointArray[i].y) lowest = &pointArray[i]; } lowest->swap(pointArray[0]); SortByPolarAngle pred; pred.perspective = pointArray[0]; quicksort(pointArray + 1, nPoints - 1, pred); int nPointsInHull = 2; for(int i = 2; i < nPoints; ++i) { Vector2 lineA = pointArray[nPointsInHull - 1] - pointArray[nPointsInHull - 2]; Vector2 lineB = pointArray[i] - pointArray(nPointsInHull - 2); Real lineAlen = lineA.lenght(); Real lineBlen = lineB.lenght(); bool dropLastPointFromHull = false; if(lineAlen >= 1e-5f) lineA /= Math::Sqrt(lineAlen); else dropLastPointFromHull = true; if(lineBlen >= 1e-5f) lineB /= Math::Sqrt(lineBlen); Vector2 normal(-lineA.y, lineA.x); if(dropLastPointFromHull || normal.dotProduct(lineB) > 0.f || (normal.dotProduct(lineB) > -1e-4f && lineBlen >= lineAlen)) { if(nPointsInHull > 2) { --nPointsInHull; --i; } else { pointArray[nPointsInHull - 1] = pointArray[i]; } } else { pointArray[nPointsInHull++] = pointArray[i]; } } for(int i = 0; i < nPointsInHull && nPointsInHull > 3; ++i) { if(pointArray[i].equals(pointArray[(i+1)%nPointsInHull])) { for(int j = i; j+1 < nPointsInHull; ++j) pointArray[j] = pointArray[j+1]; --nPointsInHull; --i; continue; } Vector2 dirA = pointArray[(i+1)%nPointsInHull] - pointArray[i]; dirA.normalize(); Vector2 dirB = pointArray[i] - pointArray[(i+nPointsInHull-1)%nPointsInHull]; dirB.normalize(); if(dirA.dotProduct(dirB) >= 1.f - 1e-3f) { for(int j = i; j+1 < nPointsInHull; ++j) pointArray[j] = pointArray[j+1]; --nPointsInHull; --i; continue; } } return nPointsInHull; }
/** * Overrides standard method. */ void NodeWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { Q_UNUSED(option); Q_UNUSED(widget); setPenFromSettings(painter); if (UMLWidget::useFillColor()) { painter->setBrush(UMLWidget::fillColor()); } else { painter->setBrush(m_scene->backgroundColor()); } const int w = width(); const int h = height(); const int wDepth = (w/3 > DEPTH ? DEPTH : w/3); const int hDepth = (h/3 > DEPTH ? DEPTH : h/3); const int bodyOffsetY = hDepth; const int bodyWidth = w - wDepth; const int bodyHeight = h - hDepth; QFont font = UMLWidget::font(); font.setBold(true); const QFontMetrics &fm = getFontMetrics(FT_BOLD); const int fontHeight = fm.lineSpacing(); QString nameStr = name(); QPolygon pointArray(5); pointArray.setPoint(0, 0, bodyOffsetY); pointArray.setPoint(1, wDepth, 0); pointArray.setPoint(2, w, 0); pointArray.setPoint(3, w, bodyHeight); pointArray.setPoint(4, bodyWidth, h); painter->drawPolygon(pointArray); painter->drawRect(0, bodyOffsetY, bodyWidth, bodyHeight); painter->drawLine(w, 0, bodyWidth, bodyOffsetY); painter->setPen(textColor()); painter->setFont(font); int lines = 1; if (m_umlObject) { QString stereotype = m_umlObject->stereotype(); if (!stereotype.isEmpty()) { painter->drawText(0, bodyOffsetY + (bodyHeight/2) - fontHeight, bodyWidth, fontHeight, Qt::AlignCenter, m_umlObject->stereotype(true)); lines = 2; } } if (UMLWidget::isInstance()) { font.setUnderline(true); painter->setFont(font); nameStr = UMLWidget::instanceName() + QLatin1String(" : ") + nameStr; } if (lines == 1) { painter->drawText(0, bodyOffsetY + (bodyHeight/2) - (fontHeight/2), bodyWidth, fontHeight, Qt::AlignCenter, nameStr); } else { painter->drawText(0, bodyOffsetY + (bodyHeight/2), bodyWidth, fontHeight, Qt::AlignCenter, nameStr); } UMLWidget::paint(painter, option, widget); }
void DrawWidget::drawChannel(QPaintDevice &pd, Channel *ch, QPainter &p, double leftTime, double currentTime, double zoomX, double viewBottom, double zoomY, int viewType) { ZoomLookup *z; if(viewType == DRAW_VIEW_SUMMARY) z = &ch->summaryZoomLookup; else z = &ch->normalZoomLookup; ChannelLocker channelLocker(ch); QColor current = ch->color; QColor invert(255 - current.red(), 255 - current.green(), 255 - current.blue()); p.setPen(current); int viewBottomOffset = toInt(viewBottom / zoomY); printf("viewBottomOffset=%d, %f, %f\n", viewBottomOffset, viewBottom, zoomY); viewBottom = double(viewBottomOffset) * zoomY; // baseX is the no. of chunks a pixel must represent. double baseX = zoomX / ch->timePerChunk(); z->setZoomLevel(baseX); double currentChunk = ch->chunkFractionAtTime(currentTime); double leftFrameTime = currentChunk - ((currentTime - leftTime) / ch->timePerChunk()); //double leftFrameTime = leftTime / ch->timePerChunk(); double frameTime = leftFrameTime; //if(frameTime < 0.0) frameTime = 0.0; int n = 0; int baseElement = int(floor(frameTime / baseX)); if(baseElement < 0) { n -= baseElement; baseElement = 0; } int lastBaseElement = int(floor(double(ch->totalChunks()) / baseX)); Q3PointArray pointArray(pd.width()*2); //QPointArray topPoints(width()*2); //QPointArray bottomPoints(width()*2); //int pointIndex = 0; //int pointIndex = 0; if (baseX > 1) { // More samples than pixels int theWidth = pd.width(); //if(baseElement + theWidth > z->size()) z->setSize(baseElement + theWidth); if(lastBaseElement > z->size()) z->setSize(lastBaseElement); for(; n < theWidth && baseElement < lastBaseElement; n++, baseElement++) { myassert(baseElement >= 0); ZoomElement &ze = z->at(baseElement); if(!ze.isValid()) { if(calcZoomElement(ch, ze, baseElement, baseX)) continue; } if(ze.high() != 0.0f && ze.high() - ze.low() < 1.0) { //if range is closer than one semi-tone then draw a line between them //if(ze.noteLow > 0) { p.setPen(ze.color()); //p.setPen(QPen(ze.color(), lineWidth)); //Note: lineTo doen't draw a pixel on the last point of the line p.drawLine(n, pd.height() - lineTopHalfWidth - toInt(ze.high() / zoomY) + viewBottomOffset, n, pd.height() + lineBottomHalfWidth - toInt(ze.low() / zoomY) + viewBottomOffset); //pointArray.setPoint(pointIndex++, n, height() - lineTopHalfWidth - toInt(ze.high / zoomY) + viewBottomOffset); //pointArray.setPoint(pointIndex++, n, height() + lineBottomHalfWidth - toInt(ze.low / zoomY) + viewBottomOffset); } } //myassert(pointIndex <= width()*2); //p.setPen(ch->color); //p.drawLineSegments(pointArray, 0, pointIndex/2); } else { // More pixels than samples float err = 0.0, pitch = 0.0, prevPitch = 0.0, vol; int intChunk = (int) floor(frameTime); // Integer version of frame time if(intChunk < 0) intChunk = 0; double stepSize = 1.0 / baseX; // So we skip some pixels int x = 0, y; //double start = 0 - stepSize; double start = (double(intChunk) - frameTime) * stepSize; double stop = pd.width() + (2 * stepSize); int squareSize = (int(sqrt(stepSize)) / 2) * 2 + 1; //make it an odd number int halfSquareSize = squareSize/2; int penX=0, penY=0; //topPoints.setPoint(pointIndex, toInt(start), 0); //bottomPoints.setPoint(pointIndex++, toInt(start), height()); for (double n = start; n < stop && intChunk < (int)ch->totalChunks(); n += stepSize, intChunk++) { myassert(intChunk >= 0); //if (intChunk < 0) continue; // So we don't go off the beginning of the array AnalysisData *data = ch->dataAtChunk(intChunk); err = data->getCorrelation(); //vol = dB2ViewVal(data->logrms(), ch->rmsCeiling, ch->rmsFloor); vol = dB2Normalised(data->getLogRms(), ch->rmsCeiling, ch->rmsFloor); //if (err >= CERTAIN_THRESHOLD) { //float val = MIN(ch->dataAtChunk(intChunk)->volumeValue, 1.0); if(gdata->pitchContourMode() == 0) //p.setPen(QPen(colorBetween(colorGroup().background(), ch->color, err*2.0-1.0), lineWidth)); //p.setPen(QPen(colorBetween(gdata->backgroundColor(), ch->color, err*sqrt(data->rms)*10.0), lineWidth)); if(viewType == DRAW_VIEW_PRINT) p.setPen(QPen(colorBetween(QColor(255, 255, 255), ch->color, err*vol), lineWidth)); else p.setPen(QPen(colorBetween(gdata->backgroundColor(), ch->color, err*vol), lineWidth)); else p.setPen(QPen(ch->color, lineWidth)); x = toInt(n); //note = (data->isValid()) ? data->note : 0.0f; //note = (ch->isVisibleNote(data->noteIndex)) ? data->note : 0.0f; pitch = (ch->isVisibleChunk(data)) ? data->getPitch() : 0.0f; myassert(pitch >= 0.0 && pitch <= gdata->topPitch()); //pitch = bound(pitch, 0, gdata->topPitch()); y = pd.height() - 1 - toInt(pitch / zoomY) + viewBottomOffset; //y = height() - 1 - int((note / zoomY) - (viewBottom / zoomY)); if(pitch > 0.0f) { if(fabs(prevPitch - pitch) < 1.0 && n != start) { //if closer than one semi-tone from previous then draw a line between them //p.lineTo(x, y); p.drawLine(penX, penY, x, y); penX = x; penY = y; } else { p.drawPoint(x, y); //p.moveTo(x, y); penX = x; penY = y; } if(stepSize > 10) { //draw squares on the data points //p.setPen(invert); p.setBrush(Qt::NoBrush); p.drawRect(x - halfSquareSize, y - halfSquareSize, squareSize, squareSize); //p.setPen(QPen(current, 2)); } //} else { // p.moveTo(x, height()-1-int(((note-viewBottom) / zoomY))); //} } prevPitch = pitch; } } }
void QgsGrassEdit::displayIcon( double x, double y, const QPen & pen, int type, int size, QPainter *painter ) { QgsPoint point; QPolygon pointArray( 2 ); point.setX( x ); point.setY( y ); point = transformLayerToCanvas( point ); int px = qRound( point.x() ); int py = qRound( point.y() ); int m = ( size - 1 ) / 2; QPainter *myPainter; if ( !painter ) { myPainter = new QPainter(); myPainter->begin( mPixmap ); } else { myPainter = painter; } myPainter->setPen( pen ); switch ( type ) { case QgsVertexMarker::ICON_CROSS : pointArray.setPoint( 0, px - m, py ); pointArray.setPoint( 1, px + m, py ); myPainter->drawPolyline( pointArray ); pointArray.setPoint( 0, px, py + m ); pointArray.setPoint( 1, px, py - m ); myPainter->drawPolyline( pointArray ); break; case QgsVertexMarker::ICON_X : pointArray.setPoint( 0, px - m, py + m ); pointArray.setPoint( 1, px + m, py - m ); myPainter->drawPolyline( pointArray ); pointArray.setPoint( 0, px - m, py - m ); pointArray.setPoint( 1, px + m, py + m ); myPainter->drawPolyline( pointArray ); break; case QgsVertexMarker::ICON_BOX : pointArray.resize( 5 ); pointArray.setPoint( 0, px - m, py - m ); pointArray.setPoint( 1, px + m, py - m ); pointArray.setPoint( 2, px + m, py + m ); pointArray.setPoint( 3, px - m, py + m ); pointArray.setPoint( 4, px - m, py - m ); myPainter->drawPolyline( pointArray ); break; } if ( !painter ) { myPainter->end(); //mCanvas->update(); mCanvasEdit->update(); delete myPainter; } }