Exemple #1
0
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;
}
Exemple #2
0
void SearchButton::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event);
    QPainterPath myPath;

    int radius = (height() / 5) * 2;
    QRect circle(height() / 3 - 1, height() / 4, radius, radius);
    myPath.addEllipse(circle);

    myPath.arcMoveTo(circle, 300);
    QPointF c = myPath.currentPosition();
    int diff = height() / 7;
    myPath.lineTo(qMin(width() - 2, (int)c.x() + diff), c.y() + diff);

    QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing, true);
    painter.setPen(QPen(Qt::darkGray, 2));
    painter.drawPath(myPath);

    if (m_menu) {
        QPainterPath dropPath;
        dropPath.arcMoveTo(circle, 320);
        QPointF c = dropPath.currentPosition();
        c = QPointF(c.x() + 3.5, c.y() + 0.5);
        dropPath.moveTo(c);
        dropPath.lineTo(c.x() + 4, c.y());
        dropPath.lineTo(c.x() + 2, c.y() + 2);
        dropPath.closeSubpath();
        painter.setPen(Qt::darkGray);
        painter.setBrush(Qt::darkGray);
        painter.setRenderHint(QPainter::Antialiasing, false);
        painter.drawPath(dropPath);
    }
    painter.end();
}
Exemple #3
0
//------------------------------------------------------------------------------
void
Canvas::DrawAnnulus(int x, int y,
                    unsigned inner_r, unsigned outer_r,
                    Angle start, Angle end)
  {
  QPainterPath p;
  QRectF ri(x - inner_r, y - inner_r, 2 * inner_r, 2 * inner_r);
  QRectF ro(x - outer_r, y - outer_r, 2 * outer_r, 2 * outer_r);
  // Draw the inner radius of the annulus.
  p.arcMoveTo(ri, start.Degrees());
  p.arcTo(ri, start.Degrees(), end.Degrees() - start.Degrees());
  if (start != end)
    { // Only draw the end caps when needed.
    // The currentPosition() will be at the end of the inner circle. Draw
    // one side of the annulus.
    // \todo This doesn't work because Angle(360) != Angle(0)!
    double xx = (outer_r - inner_r) * cos(end.Radians()) +
                p.currentPosition().rx();
    double yy = (outer_r - inner_r) * -sin(end.Radians()) +
                p.currentPosition().ry();
    p.lineTo(xx, yy);
    }
  else
    p.arcMoveTo(ro, end.Degrees());  // Set up for the outer circle.
  // The currentPosition() will be at the 'end' of the outer circle. Draw the
  // outer to the start.
  p.arcTo(ro, end.Degrees(), start.Degrees() - end.Degrees());
  if (start != end)
    {// And close it off to finish up.
    p.closeSubpath();
    }
  this->pushObject(p, this->pen(), this->brush());
  }
void AttitudeIndicator::drawScale(QPainter *painter, const QPointF &center,
    double radius, double origin, double minArc, double maxArc) const
{
    // counter clockwise, radian

    const double dir = (360.0 - origin) * M_PI / 180.0;
    const double offset = 4.0;

    const QPointF p0 = qwtPolar2Pos( center, offset, dir + M_PI );

    const double w = innerRect().width();

    QPainterPath path;
    path.moveTo( qwtPolar2Pos( p0, w, dir - M_PI_2 ) );
    path.lineTo( qwtPolar2Pos( path.currentPosition(), 2 * w, dir + M_PI_2 ) );
    path.lineTo( qwtPolar2Pos( path.currentPosition(), w, dir ) );
    path.lineTo( qwtPolar2Pos( path.currentPosition(), w, dir - M_PI_2 ) );

    painter->save();
    painter->setClipPath( path ); // swallow 180 - 360 degrees

    QwtDial::drawScale(painter,
        center, radius, origin, minArc, maxArc);

    painter->restore();
}
QRectF GlyphElement::renderToPath( const QString& raw, QPainterPath& path ) const
{
    Q_UNUSED( raw )
    Q_UNUSED( path )
    // try to lookup the char in the font database
    AttributeManager am;
    QString fontFamily = am.stringOf( "fontfamily", this );
    QFontDatabase db;
    QFont tmpFont;

    // determine if the specified font and glyph can be found
    if( db.families().contains( fontFamily ) )
    {
        tmpFont.setFamily( fontFamily );
        path.addText( path.currentPosition(), tmpFont,
                      QChar( am.stringOf( "index", this ).toInt() ) ); 
        QFontMetricsF fm(tmpFont);
        return fm.boundingRect(QChar( am.stringOf( "index", this ).toInt() ) );
    }
    else { // if not found use alt text
        path.addText( path.currentPosition(), font(), am.stringOf( "alt", this ) );
        QFontMetricsF fm(font());
        return fm.boundingRect(am.stringOf( "alt", this ));
    }
}
void RealTimeMultiSampleArrayDelegate::createPlotPath(const QModelIndex &index, QPainterPath& path, QList< QVector<float> >& data) const
{
    //get maximum range of respective channel type (range value in FiffChInfo does not seem to contain a reasonable value)
    qint32 kind = (static_cast<const RealTimeMultiSampleArrayModel*>(index.model()))->m_qListChInfo[index.row()].getKind();
    float fMaxValue = 1e-9;

//    switch(kind) {
//        case FIFFV_MEG_CH: {
//            qint32 unit = (static_cast<const RealTimeMultiSampleArrayModel*>(index.model()))->m_pfiffIO->m_qlistRaw[0]->info.chs[index.row()].unit;
//            if(unit == FIFF_UNIT_T_M) {
//                dMaxValue = m_qSettings.value("RawDelegate/max_meg_grad").toDouble();
//            }
//            else if(unit == FIFF_UNIT_T)
//                dMaxValue = m_qSettings.value("RawDelegate/max_meg_mag").toDouble();
//            break;
//        }
//        case FIFFV_EEG_CH: {
//            dMaxValue = m_qSettings.value("RawDelegate/max_eeg").toDouble();
//            break;
//        }
//        case FIFFV_EOG_CH: {
//            dMaxValue = m_qSettings.value("RawDelegate/max_eog").toDouble();
//            break;
//        }
//        case FIFFV_STIM_CH: {
//            dMaxValue = m_qSettings.value("RawDelegate/max_stim").toDouble();
//            break;
//        }
//    }

    float fValue;
    float fScaleY = m_fPlotHeight/(2*fMaxValue);

    float y_base = path.currentPosition().y();
    QPointF qSamplePosition;

    //plot all rows from list of pairs
    for(qint8 i=0; i < data.size(); ++i) {
        //create lines from one to the next sample
        for(qint32 j=0; j < data[i].size(); ++j)
        {
            float val = data[i][j];
            fValue = val*fScaleY;

            float newY = y_base+fValue;

            qSamplePosition.setY(newY);
            qSamplePosition.setX(path.currentPosition().x()+m_fDx);

            path.lineTo(qSamplePosition);
        }
    }

//    qDebug("Plot-PainterPath created!");
}
Exemple #7
0
void RawDelegate::createPlotPath(const QModelIndex &index, QPainterPath& path, QList<RowVectorPair>& listPairs) const
{
    //get maximum range of respective channel type (range value in FiffChInfo does not seem to contain a reasonable value)
    qint32 kind = (static_cast<const RawModel*>(index.model()))->m_chInfolist[index.row()].kind;
    double dMaxValue = 1e-9;

    switch(kind) {
    case FIFFV_MEG_CH: {
        qint32 unit = (static_cast<const RawModel*>(index.model()))->m_pfiffIO->m_qlistRaw[0]->info.chs[index.row()].unit;
        if(unit == FIFF_UNIT_T_M) {
            dMaxValue = m_qSettings.value("RawDelegate/max_meg_grad").toDouble();
        }
        else if(unit == FIFF_UNIT_T)
            dMaxValue = m_qSettings.value("RawDelegate/max_meg_mag").toDouble();
        break;
    }
    case FIFFV_EEG_CH: {
        dMaxValue = m_qSettings.value("RawDelegate/max_eeg").toDouble();
        break;
    }
    case FIFFV_EOG_CH: {
        dMaxValue = m_qSettings.value("RawDelegate/max_eog").toDouble();
        break;
    }
    case FIFFV_STIM_CH: {
        dMaxValue = m_qSettings.value("RawDelegate/max_stim").toDouble();
        break;
    }
    }

    double dValue;
    double dScaleY = m_dPlotHeight/(2*dMaxValue);

    double y_base = path.currentPosition().y();
    QPointF qSamplePosition;

    //plot all rows from list of pairs
    for(qint8 i=0; i < listPairs.size(); ++i) {
        //create lines from one to the next sample
        for(qint32 j=0; j < listPairs[i].second; ++j)
        {
            double val = *(listPairs[i].first+j);
            dValue = val*dScaleY;

            double newY = y_base+dValue;

            qSamplePosition.setY(newY);
            qSamplePosition.setX(path.currentPosition().x()+m_dDx);

            path.lineTo(qSamplePosition);
        }
    }

//    qDebug("Plot-PainterPath created!");
}
void tst_QPainterPath::currentPosition()
{
    QPainterPath p;

    QCOMPARE(p.currentPosition(), QPointF());

    p.moveTo(100, 100);
    QCOMPARE(p.currentPosition(), QPointF(100, 100));

    p.lineTo(200, 200);
    QCOMPARE(p.currentPosition(), QPointF(200, 200));

    p.cubicTo(300, 200, 200, 300, 500, 500);
    QCOMPARE(p.currentPosition(), QPointF(500, 500));
}
void RealTimeMultiSampleArrayDelegate::createGridPath(QPainterPath& path, QList< QVector<float> >& data) const
{
    //horizontal lines
    float distance = m_fPlotHeight/m_nhlines;

    QPointF startpos = path.currentPosition();
    QPointF endpoint(path.currentPosition().x()+data[0].size()*data.size()*m_fDx,path.currentPosition().y());

    for(qint8 i=0; i < m_nhlines-1; ++i) {
        endpoint.setY(endpoint.y()+distance);
        path.moveTo(startpos.x(),endpoint.y());
        path.lineTo(endpoint);
    }

//    qDebug("Grid-PainterPath created!");
}
Exemple #10
0
void RawDelegate::createGridPath(QPainterPath& path, QList<RowVectorPair>& listPairs) const
{
    //horizontal lines
    double distance = m_dPlotHeight/m_nhlines;

    QPointF startpos = path.currentPosition();
    QPointF endpoint(path.currentPosition().x()+listPairs[0].second*listPairs.size()*m_dDx,path.currentPosition().y());

    for(qint8 i=0; i < m_nhlines-1; ++i) {
        endpoint.setY(endpoint.y()+distance);
        path.moveTo(startpos.x(),endpoint.y());
        path.lineTo(endpoint);
    }

//    qDebug("Grid-PainterPath created!");
}
Exemple #11
0
void QgsCircularString::addToPainterPath( QPainterPath &path ) const
{
  int nPoints = numPoints();
  if ( nPoints < 1 )
  {
    return;
  }

  if ( path.isEmpty() || path.currentPosition() != QPointF( mX[0], mY[0] ) )
  {
    path.moveTo( QPointF( mX[0], mY[0] ) );
  }

  for ( int i = 0; i < ( nPoints - 2 ) ; i += 2 )
  {
    QgsPointSequence pt;
    segmentize( QgsPointV2( mX[i], mY[i] ), QgsPointV2( mX[i + 1], mY[i + 1] ), QgsPointV2( mX[i + 2], mY[i + 2] ), pt );
    for ( int j = 1; j < pt.size(); ++j )
    {
      path.lineTo( pt.at( j ).x(), pt.at( j ).y() );
    }
    //arcTo( path, QPointF( mX[i], mY[i] ), QPointF( mX[i + 1], mY[i + 1] ), QPointF( mX[i + 2], mY[i + 2] ) );
  }

  //if number of points is even, connect to last point with straight line (even though the circular string is not valid)
  if ( nPoints % 2 == 0 )
  {
    path.lineTo( mX[ nPoints - 1 ], mY[ nPoints - 1 ] );
  }
}
//=============================================================================
int sstQt01PathStoreViewCls::createDefaultItems(int iKey)
{
  //-----------------------------------------------------------------------------
  if ( iKey != 0) return -1;

  QPainterPath circlePath;
  QPainterPath squarePath;
  QPainterPath trianglePath;

  circlePath.addEllipse(QRect(0, 0, 100, 100));
  squarePath.addRect(QRect(0, 0, 100, 100));

  qreal x = trianglePath.currentPosition().x();
  qreal y = trianglePath.currentPosition().y();
  trianglePath.moveTo(x + 120 / 2, y);
  trianglePath.lineTo(0, 100);
  trianglePath.lineTo(120, 100);
  trianglePath.lineTo(x + 120 / 2, y);

  sstQt01ShapeItem oItem;

  oItem.createShapeItem(circlePath, "Circle", initialItemPosition(circlePath),
                  initialItemColor(),eSstQt01PathCircle);
  this->appendShapeItem(oItem);

  oItem.createShapeItem(squarePath, "Square", initialItemPosition(squarePath),
                  initialItemColor(),eSstQt01PathArea);
  this->appendShapeItem(oItem);

  oItem.createShapeItem(trianglePath, "Triangle",
                  initialItemPosition(trianglePath), initialItemColor(),eSstQt01PathArea);
  this->appendShapeItem(oItem);

  return 0;
}
void PlotSignalWidget::createGridPath(QPainterPath& path)
{
    //horizontal lines
    qint8 m_nhlines = 6;
    double distance = m_dPlotHeight/m_nhlines;

    path.moveTo(0,-m_dPlotHeight/2+distance);

    for(qint8 i=0; i < m_nhlines-1; ++i) {
        QPointF endpoint(this->width(),path.currentPosition().y());
        path.lineTo(endpoint);
        path.moveTo(0,path.currentPosition().y()+distance);
    }

    qDebug("Grid-PainterPath created!");
}
//-------------------------------------------------------------------------
void QGuidoItemContainer::updateTitleBar()
{
	int barHeight = QFontMetrics( mHeadBar->textItem()->font() ).height();

	QPainterPath path;
	path.moveTo( 0 , barHeight );
	path.arcTo( QRect(0,0,ROUNDED_RECT_RADIUS * 2 , ROUNDED_RECT_RADIUS * 2) , 180 , -90 );
	path.lineTo( rect().width() - ROUNDED_RECT_RADIUS * 2 , 0 );
	path.arcTo( QRect( path.currentPosition().x() , path.currentPosition().y() ,ROUNDED_RECT_RADIUS * 2 , ROUNDED_RECT_RADIUS * 2) , 90 , -90 );
	path.lineTo( rect().width() , barHeight );
	path.closeSubpath();

	mHeadBar->setPath( path );

	updateTitleText();
	updateTitleBarVisibility();
}
bool RenderThemeQt::paintMediaToggleClosedCaptionsButton(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r)
{
    HTMLMediaElement* mediaElement = toParentMediaElement(o);
    if (!mediaElement)
        return false;

    QSharedPointer<StylePainter> p = getStylePainter(paintInfo);
    if (p.isNull() || !p->isValid())
        return true;

    p->painter->setRenderHint(QPainter::Antialiasing, true);

    paintMediaBackground(p->painter, r);

    WorldMatrixTransformer transformer(p->painter, o, r);
    p->painter->setBrush(getMediaControlForegroundColor(o));

    QPainterPath captionBubble;
    captionBubble.moveTo(98.766, 43.244);
    captionBubble.cubicTo(captionBubble.currentPosition() + QPointF(0, -23.163), captionBubble.currentPosition() + QPointF(-21.775, -41.94), captionBubble.currentPosition() + QPointF(-48.637, -41.94));
    captionBubble.cubicTo(captionBubble.currentPosition() + QPointF(-26.859, 0), captionBubble.currentPosition() + QPointF(-48.635, 18.777), captionBubble.currentPosition() + QPointF(-48.635, 41.94));
    captionBubble.cubicTo(captionBubble.currentPosition() + QPointF(0, 18.266), captionBubble.currentPosition() + QPointF(13.546, 33.796), captionBubble.currentPosition() + QPointF(32.444, 39.549));
    captionBubble.cubicTo(captionBubble.currentPosition() + QPointF(1.131, 8.356), captionBubble.currentPosition() + QPointF(26.037, 24.255), captionBubble.currentPosition() + QPointF(22.864, 19.921));
    captionBubble.cubicTo(captionBubble.currentPosition() + QPointF(-4.462, -6.096), captionBubble.currentPosition() + QPointF(-5.159, -13.183), captionBubble.currentPosition() + QPointF(-5.07, -17.566));
    captionBubble.cubicTo(QPointF(77.85, 84.397), QPointF(98.766, 65.923), QPointF(98.766, 43.224));
    captionBubble.closeSubpath();

    p->painter->drawPath(captionBubble);
    return false;
}
Exemple #16
0
QRectF IdentifierElement::renderToPath( const QString& raw, QPainterPath& path ) const
{
    AttributeManager manager;
    QFont font = manager.font(this);
    path.addText( path.currentPosition(), font, raw );
    QFontMetricsF fm(font);
    return fm.boundingRect(raw);

}
Exemple #17
0
void TestSnapStrategy::testLineGuideDecoration()
{
    //tests the decoration by making sure there are horizontal and vertical lines in the guidesData
    LineGuideSnapStrategy toTest;

    const QPointF paramMousePosTwo;
    MockShapeController fakeShapeControllerBaseTwo;
    MockCanvas fakeKoCanvasBaseTwo(&fakeShapeControllerBaseTwo);

    KoGuidesData guidesData;
    //firstSnapPointList.push_back(
    QList<qreal> horzLines;
    horzLines.push_back(2);
    horzLines.push_back(3);
    horzLines.push_back(4);
    horzLines.push_back(5);

    QList<qreal> vertLines;
    vertLines.push_back(1);
    vertLines.push_back(2);
    vertLines.push_back(3);
    vertLines.push_back(4);

    guidesData.setHorizontalGuideLines(horzLines);
    guidesData.setVerticalGuideLines(vertLines);
    fakeKoCanvasBaseTwo.setGuidesData(&guidesData);
    qreal paramSnapDistanceTwo = 8;
    KoSnapGuide aKoSnapGuideTwo(&fakeKoCanvasBaseTwo);
    KoSnapProxy paramProxyTwo(&aKoSnapGuideTwo);
    toTest.snap(paramMousePosTwo, &paramProxyTwo, paramSnapDistanceTwo);

    KoViewConverter parameterConverter;
    QSizeF unzoomedSize = parameterConverter.viewToDocument(QSizeF(5, 5));
    QPointF snappedPos(1,2);
    QPointF originalEndPointOne(snappedPos + QPointF(unzoomedSize.width(), 0));
    QPointF originalEndPointTwo(snappedPos + QPointF(0, unzoomedSize.height()));
    QPainterPath resultingDecoration = toTest.decoration(parameterConverter);

    QVERIFY( (resultingDecoration.currentPosition() == originalEndPointOne) || (resultingDecoration.currentPosition() == originalEndPointTwo ) );
}
void UIGDetailsElement::paintBackground(QPainter *pPainter, const QStyleOptionGraphicsItem *pOption)
{
    /* Save painter: */
    pPainter->save();

    /* Prepare variables: */
    int iMargin = data(ElementData_Margin).toInt();
    int iHeaderHeight = 2 * iMargin + m_iMinimumHeaderHeight;
    QRect optionRect = pOption->rect;
    QRect fullRect = !m_fAnimationRunning ? optionRect :
                     QRect(optionRect.topLeft(), QSize(optionRect.width(), iHeaderHeight + m_iAdditionalHeight));
    int iFullHeight = fullRect.height();

    /* Prepare color: */
    QPalette pal = palette();
    QColor headerColor = pal.color(QPalette::Active, QPalette::Button);
    QColor strokeColor = pal.color(QPalette::Active, QPalette::Mid);
    QColor bodyColor = pal.color(QPalette::Active, QPalette::Base);

    /* Add clipping: */
    QPainterPath path;
    path.moveTo(m_iCornerRadius, 0);
    path.arcTo(QRectF(path.currentPosition(), QSizeF(2 * m_iCornerRadius, 2 * m_iCornerRadius)).translated(-m_iCornerRadius, 0), 90, 90);
    path.lineTo(path.currentPosition().x(), iFullHeight - m_iCornerRadius);
    path.arcTo(QRectF(path.currentPosition(), QSizeF(2 * m_iCornerRadius, 2 * m_iCornerRadius)).translated(0, -m_iCornerRadius), 180, 90);
    path.lineTo(fullRect.width() - m_iCornerRadius, path.currentPosition().y());
    path.arcTo(QRectF(path.currentPosition(), QSizeF(2 * m_iCornerRadius, 2 * m_iCornerRadius)).translated(-m_iCornerRadius, -2 * m_iCornerRadius), 270, 90);
    path.lineTo(path.currentPosition().x(), m_iCornerRadius);
    path.arcTo(QRectF(path.currentPosition(), QSizeF(2 * m_iCornerRadius, 2 * m_iCornerRadius)).translated(-2 * m_iCornerRadius, -m_iCornerRadius), 0, 90);
    path.closeSubpath();
    pPainter->setClipPath(path);

    /* Calculate top rectangle: */
    QRect tRect = fullRect;
    tRect.setBottom(tRect.top() + iHeaderHeight);
    /* Calculate bottom rectangle: */
    QRect bRect = fullRect;
    bRect.setTop(tRect.bottom());

    /* Prepare top gradient: */
    QLinearGradient tGradient(tRect.bottomLeft(), tRect.topLeft());
    tGradient.setColorAt(0, headerColor.darker(110));
    tGradient.setColorAt(1, headerColor.darker(animationDarkness()));

    /* Paint all the stuff: */
    pPainter->fillRect(tRect, tGradient);
    pPainter->fillRect(bRect, bodyColor);

    /* Stroke path: */
    pPainter->setClipping(false);
    pPainter->strokePath(path, strokeColor);

    /* Restore painter: */
    pPainter->restore();
}
Exemple #19
0
void TestSnapStrategy::testBoundingBoxDecoration()
{
    //tests the decoration by making sure the returned path has the pre-calculated end point
    BoundingBoxSnapStrategy toTest;

    KoViewConverter viewConverter;
    QSizeF unzoomedSize = viewConverter.viewToDocument(QSizeF(5, 5));
    QPointF snappedPos(0,0);
    QPointF originalEndPoint(snappedPos + QPointF(unzoomedSize.width(), -unzoomedSize.height()));
    QPainterPath resultingDecoration = toTest.decoration(viewConverter);

    QVERIFY( resultingDecoration.currentPosition() == originalEndPoint );
}
QPainterPath KTBrushEditor::currentPainterPath()
{
	if ( m_editor->editing )
	{
		QPainterPath path = m_editor->createPath();
		QPointF position = path.currentPosition();
	
		QMatrix matrix;
		matrix.translate(-position.x(),-position.y());	
		return matrix.map(path);
	}
	return DDisplayPath::currentPainterPath();
}
Exemple #21
0
//------------------------------------------------------------------------------
void
Canvas::DrawKeyhole(int x, int y,
                    unsigned inner_r, unsigned outer_r,
                    Angle start, Angle end)
  {
  // Make sure that the 'left' angle is first.
  QPainterPath path;
  path.setFillRule(Qt::WindingFill);
  Angle startN = this->normalize(start);
  Angle endN   = this->normalize(end);
  Angle a[4];
  a[2] = (startN > endN) ? startN : endN;
  a[3] = (startN > endN) ? endN : startN;
  a[0] = this->geo2Screen(a[3]);
  a[1] = this->geo2Screen(a[2]);
#ifndef NDEBUG
  std::cerr << __LINE__ << ": "
            << a[0].Degrees() << ", " << a[1].Degrees() << ", "
            << a[2].Degrees() << ", " << a[3].Degrees() << std::endl;
#endif
  // Draw the inner with a segment left out for the cone.
  path.arcMoveTo(this->boundingBox(x, y, inner_r), a[0].Degrees());
  path.arcTo(this->boundingBox(x, y, inner_r),
             a[0].Degrees(), 360.0 - fabs(a[1].Degrees() - a[0].Degrees()));
  // The currentPosition() will be at the end of the inner circle. Draw
  // one side of the cone.
  double xx = (outer_r - inner_r) * cos(a[1].Radians()) +
              path.currentPosition().rx();
  double yy = (outer_r - inner_r) * -sin(a[1].Radians()) +
              path.currentPosition().ry();
  path.lineTo(xx, yy);
  // Draw the outer arc of the cone.
  path.arcTo(this->boundingBox(x, y, outer_r),
             a[1].Degrees(), fabs(a[1].Degrees() - a[0].Degrees()));
  // This will draw the other side of the cone to finish the keyhole.
  path.closeSubpath();
  this->pushObject(path, this->pen(), this->brush());
  }
Exemple #22
0
void UIMiniToolBar::rebuildShape()
{
#ifdef VBOX_RUNTIME_UI_WITH_SHAPED_MINI_TOOLBAR
    /* Rebuild shape: */
    QPainterPath shape;
    switch (m_alignment)
    {
        case Qt::AlignTop:
        {
            shape.moveTo(0, 0);
            shape.lineTo(shape.currentPosition().x(), height() - 10);
            shape.arcTo(QRectF(shape.currentPosition(), QSizeF(20, 20)).translated(0, -10), 180, 90);
            shape.lineTo(width() - 10, shape.currentPosition().y());
            shape.arcTo(QRectF(shape.currentPosition(), QSizeF(20, 20)).translated(-10, -20), 270, 90);
            shape.lineTo(shape.currentPosition().x(), 0);
            shape.closeSubpath();
            break;
        }
        case Qt::AlignBottom:
        {
            shape.moveTo(0, height());
            shape.lineTo(shape.currentPosition().x(), 10);
            shape.arcTo(QRectF(shape.currentPosition(), QSizeF(20, 20)).translated(0, -10), 180, -90);
            shape.lineTo(width() - 10, shape.currentPosition().y());
            shape.arcTo(QRectF(shape.currentPosition(), QSizeF(20, 20)).translated(-10, 0), 90, -90);
            shape.lineTo(shape.currentPosition().x(), height());
            shape.closeSubpath();
            break;
        }
        default:
            break;
    }
    m_shape = shape;

    /* Update: */
    update();
#endif /* VBOX_RUNTIME_UI_WITH_SHAPED_MINI_TOOLBAR */
}
void tst_QPainterPath::translate()
{
    QPainterPath path;

    // Path with no elements.
    QCOMPARE(path.currentPosition(), QPointF());
    path.translate(50.5, 50.5);
    QCOMPARE(path.currentPosition(), QPointF());
    QCOMPARE(path.translated(50.5, 50.5).currentPosition(), QPointF());

    // path.isEmpty(), but we have one MoveTo element that should be translated.
    path.moveTo(50, 50);
    QCOMPARE(path.currentPosition(), QPointF(50, 50));
    path.translate(99.9, 99.9);
    QCOMPARE(path.currentPosition(), QPointF(149.9, 149.9));
    path.translate(-99.9, -99.9);
    QCOMPARE(path.currentPosition(), QPointF(50, 50));
    QCOMPARE(path.translated(-50, -50).currentPosition(), QPointF(0, 0));

    // Complex path.
    QRegion shape(100, 100, 300, 200, QRegion::Ellipse);
    shape -= QRect(225, 175, 50, 50);
    QPainterPath complexPath;
    complexPath.addRegion(shape);
    QVector<QPointF> untranslatedElements;
    for (int i = 0; i < complexPath.elementCount(); ++i)
        untranslatedElements.append(QPointF(complexPath.elementAt(i)));

    const QPainterPath untranslatedComplexPath(complexPath);
    const QPointF offset(100, 100);
    complexPath.translate(offset);

    for (int i = 0; i < complexPath.elementCount(); ++i)
        QCOMPARE(QPointF(complexPath.elementAt(i)) - offset, untranslatedElements.at(i));

    QCOMPARE(complexPath.translated(-offset), untranslatedComplexPath);
}
Exemple #24
0
void TestSnapStrategy::testExtensionDecoration()
{
    //Tests the decoration is exercised by providing it with path
    //fakeShapeOne needs at least one subpath that is open in order to change the values of minDistances
    //which in turn opens the path where it is possible to get a true bool value back from the snap function
    // KoPathPointIndex openSubpath(const KoPathPointIndex &pointIndex); in KoPathShape needs to be called

    ExtensionSnapStrategy toTestTwo;
    const QPointF paramMousePosTwo;
    MockShapeController fakeShapeControllerBaseTwo;
    MockCanvas fakeKoCanvasBaseTwo(&fakeShapeControllerBaseTwo);
    KoShapeManager *fakeShapeManager = fakeKoCanvasBaseTwo.shapeManager();
    KoPathShape fakeShapeOne;
    QList<QPointF> firstSnapPointList;
    firstSnapPointList.push_back(QPointF(1,2));
    firstSnapPointList.push_back(QPointF(2,2));
    firstSnapPointList.push_back(QPointF(3,2));
    firstSnapPointList.push_back(QPointF(4,2));

    qreal paramSnapDistanceTwo = 4;
    fakeShapeOne.snapData().setSnapPoints(firstSnapPointList);
    fakeShapeOne.isVisible(true);

    QPointF firstPoint(0,2);
    QPointF secondPoint(1,2);
    QPointF thirdPoint(2,3);
    QPointF fourthPoint(3,4);

    fakeShapeOne.moveTo(firstPoint);
    fakeShapeOne.lineTo(secondPoint);
    fakeShapeOne.lineTo(thirdPoint);
    fakeShapeOne.lineTo(fourthPoint);

    fakeShapeManager->addShape(&fakeShapeOne);
    KoSnapGuide aKoSnapGuideTwo(&fakeKoCanvasBaseTwo);
    KoSnapProxy paramProxyTwo(&aKoSnapGuideTwo);

    toTestTwo.snap(paramMousePosTwo, &paramProxyTwo, paramSnapDistanceTwo);

    const KoViewConverter aConverter;
    QPainterPath resultingDecoration = toTestTwo.decoration(aConverter);
    QPointF resultDecorationLastPoint = resultingDecoration.currentPosition();

    QVERIFY( resultDecorationLastPoint == QPointF(0,2) );
}
Exemple #25
0
void QgsLineStringV2::addToPainterPath( QPainterPath& path ) const
{
  int nPoints = numPoints();
  if ( nPoints < 1 )
  {
    return;
  }

  if ( path.isEmpty() || path.currentPosition() != QPointF( mX.at( 0 ), mY.at( 0 ) ) )
  {
    path.moveTo( mX.at( 0 ), mY.at( 0 ) );
  }

  for ( int i = 1; i < nPoints; ++i )
  {
    path.lineTo( mX.at( i ), mY.at( i ) );
  }
}
Exemple #26
0
void QgsLineStringV2::addToPainterPath( QPainterPath& path ) const
{
  int nPoints = numPoints();
  if ( nPoints < 1 )
  {
    return;
  }

  if ( path.isEmpty() || path.currentPosition() != mCoords[0] )
  {
    path.moveTo( mCoords[0] );
  }

  for ( int i = 1; i < nPoints; ++i )
  {
    path.lineTo( mCoords[i] );
  }
}
void FrequencySpectrumDelegate::createPlotPath(const QModelIndex &index, const QStyleOptionViewItem &option, QPainterPath& path, RowVectorXd& data) const
{
    const FrequencySpectrumModel* t_pModel = static_cast<const FrequencySpectrumModel*>(index.model());

    float fMaxValue = data.maxCoeff();

    float fValue;
    float fScaleY = option.rect.height()/(fMaxValue*0.5);

    float y_base = path.currentPosition().y();
    QPointF qSamplePosition;

    qint32 lowerIdx = t_pModel->getLowerFrqBound();
    qint32 upperIdx = t_pModel->getUpperFrqBound();

    //Move to initial starting point
    if(data.size() > 0)
    {
        float val = 0;
        fValue = val*fScaleY;

        float newY = y_base+fValue;

        qSamplePosition.setY(newY);
        qSamplePosition.setX((double)option.rect.width()*t_pModel->getFreqScaleBound()[lowerIdx]);

        path.moveTo(qSamplePosition);
    }


    //create lines from one to the next sample
    qint32 i;
    for(i = lowerIdx+1; i <= upperIdx; ++i) {
        float val = data[i]-data[0]; //remove first sample data[0] as offset
        fValue = val*fScaleY;

        float newY = y_base+fValue;

        qSamplePosition.setY(newY);
        qSamplePosition.setX((double)option.rect.width()*t_pModel->getFreqScaleBound()[i]);

        path.lineTo(qSamplePosition);
    }
}
void UIPopupPane::configureClipping(const QRect &rect, QPainter &painter)
{
    /* Configure clipping: */
    QPainterPath path;
    int iDiameter = 6;
    QSizeF arcSize(2 * iDiameter, 2 * iDiameter);
    path.moveTo(rect.x() + iDiameter, rect.y());
    path.arcTo(QRectF(path.currentPosition(), arcSize).translated(-iDiameter, 0), 90, 90);
    path.lineTo(path.currentPosition().x(), rect.y() + rect.height() - iDiameter);
    path.arcTo(QRectF(path.currentPosition(), arcSize).translated(0, -iDiameter), 180, 90);
    path.lineTo(rect.x() + rect.width() - iDiameter, path.currentPosition().y());
    path.arcTo(QRectF(path.currentPosition(), arcSize).translated(-iDiameter, -2 * iDiameter), 270, 90);
    path.lineTo(path.currentPosition().x(), rect.y() + iDiameter);
    path.arcTo(QRectF(path.currentPosition(), arcSize).translated(-2 * iDiameter, -iDiameter), 0, 90);
    path.closeSubpath();
    painter.setClipPath(path);
}
Exemple #29
0
void FilterPlotScene::plotFilterFrequencyResponse()
{
    //Get row vector with filter coefficients and norm to 1
    RowVectorXcd coefficientsAFreq = m_pCurrentFilter->m_dFFTCoeffA;

    int numberCoeff = coefficientsAFreq.cols();
    int dsFactor = 0;
    if(numberCoeff>2000)
        dsFactor = numberCoeff/2000;

    double max = 0;
    for(int i = 0; i<numberCoeff-dsFactor; i++)
        if(std::abs(coefficientsAFreq(i)) > max)
            max = std::abs(coefficientsAFreq(i));

    coefficientsAFreq = coefficientsAFreq / max;

    //Create painter path
    QPainterPath path;
    double y = -20 * log10(std::abs(coefficientsAFreq(0))) * m_iScalingFactor; //-1 because we want to plot upwards
    if(y > m_dMaxMagnitude)
        y = m_dMaxMagnitude;
    y -= m_iDiagramMarginsVert;

    path.moveTo(-m_iDiagramMarginsVert, y); //convert to db

    for(int i = 0; i<numberCoeff; i+=dsFactor) {
        y = -20 * log10(std::abs(coefficientsAFreq(i))) * m_iScalingFactor; //-1 because we want to plot upwards
        if(y > m_dMaxMagnitude)
            y = m_dMaxMagnitude;

        y -= m_iDiagramMarginsVert;
        path.lineTo(path.currentPosition().x()+1,y);
    }

    QPen pen;
    pen.setColor(Qt::black);
    pen.setWidth(2);

    //Clear old and plot new filter path
    m_pGraphicsItemPath = addPath(path, pen);
}
void PlotSignalWidget::createPlotPath(QPainterPath& path)
{
    double dValue;
    QPointF qSamplePosition;

    //create lines from one to the next sample
    for(qint32 i=0; i < m_data.cols(); ++i)
    {
        dValue = m_data(0,i)*m_dScaleY;

        qSamplePosition.setY(dValue);
        qSamplePosition.setX(path.currentPosition().x()+m_dDx);

        path.lineTo(qSamplePosition);

        path.moveTo(qSamplePosition);
    }

    qDebug("Plot-PainterPath created!");
}