Ejemplo n.º 1
0
/**
 * \brief Draw the palette
 * @param event as the paint event
 */
void UBDockPalette::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event);
    QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing);
    painter.setPen(Qt::NoPen);
    painter.setBrush(mBackgroundBrush);

    if(mOrientation == eUBDockOrientation_Left)
    {
	QPainterPath path;
	path.setFillRule(Qt::WindingFill);
	path.addRect(0.0, 0.0, width()-border(), height());
        path.addRoundedRect(width()-2*border(), border(), 2*border(), TABSIZE, radius(), radius());
	painter.drawPath(path);
        painter.drawPixmap(width() - border() + 1, border() + 1 , border() - 4, TABSIZE - 2, mIcon);
    }
    else if(mOrientation == eUBDockOrientation_Right)
    {
	QPainterPath path;
	path.setFillRule(Qt::WindingFill);
	path.addRect(border(), 0.0, width()-border(), height());
	path.addRoundedRect(0.0, border(), 2*border(), TABSIZE, radius(), radius());
	painter.drawPath(path);
        painter.drawPixmap(2, border() + 1, border() - 3, TABSIZE - 2, mIcon);
    }
    else
    {
	painter.drawRoundedRect(border(), border(), width() - 2 * border(), height() - 2 * border(), radius(), radius());
    }
}
Ejemplo n.º 2
0
void DropShadowWidget::paintEvent(QPaintEvent *event)
{    
    int margins = 10;
    if(this->isMaximized()){
       margins = 0;
    }
    QPainterPath path;
    path.setFillRule(Qt::WindingFill);
    path.addRect(margins, margins, this->width()-2*margins, this->height()-2*margins);

    QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing, true);
    painter.fillPath(path, QBrush(Qt::white));

    QColor color(0, 0, 0, 50);
    for(int i=0; i<margins; i++)
    {
        QPainterPath path;
        path.setFillRule(Qt::WindingFill);
        path.addRect(margins-i, margins-i, this->width()-(margins-i)*2, this->height()-(margins-i)*2);
        color.setAlpha(150 - qSqrt(i)*50);
        painter.setPen(color);
        painter.drawPath(path);
    }
}
Ejemplo n.º 3
0
void tst_QPainterPath::arcWinding_data()
{
    QTest::addColumn<QPainterPath>("path");
    QTest::addColumn<QPointF>("point");
    QTest::addColumn<bool>("inside");

    QPainterPath a;
    a.addEllipse(0, 0, 100, 100);
    a.addRect(50, 50, 100, 100);

    QTest::newRow("Case A (oddeven)") << a << QPointF(55, 55) << false;
    a.setFillRule(Qt::WindingFill);
    QTest::newRow("Case A (winding)") << a << QPointF(55, 55) << true;

    QPainterPath b;
    b.arcMoveTo(0, 0, 100, 100, 10);
    b.arcTo(0, 0, 100, 100, 10, 360);
    b.addRect(50, 50, 100, 100);

    QTest::newRow("Case B (oddeven)") << b << QPointF(55, 55) << false;
    b.setFillRule(Qt::WindingFill);
    QTest::newRow("Case B (winding)") << b << QPointF(55, 55) << false;

    QPainterPath c;
    c.arcMoveTo(0, 0, 100, 100, 0);
    c.arcTo(0, 0, 100, 100, 0, 360);
    c.addRect(50, 50, 100, 100);

    QTest::newRow("Case C (oddeven)") << c << QPointF(55, 55) << false;
    c.setFillRule(Qt::WindingFill);
    QTest::newRow("Case C (winding)") << c << QPointF(55, 55) << false;

    QPainterPath d;
    d.arcMoveTo(0, 0, 100, 100, 10);
    d.arcTo(0, 0, 100, 100, 10, -360);
    d.addRect(50, 50, 100, 100);

    QTest::newRow("Case D (oddeven)") << d << QPointF(55, 55) << false;
    d.setFillRule(Qt::WindingFill);
    QTest::newRow("Case D (winding)") << d << QPointF(55, 55) << true;

    QPainterPath e;
    e.arcMoveTo(0, 0, 100, 100, 0);
    e.arcTo(0, 0, 100, 100, 0, -360);
    e.addRect(50, 50, 100, 100);

    QTest::newRow("Case E (oddeven)") << e << QPointF(55, 55) << false;
    e.setFillRule(Qt::WindingFill);
    QTest::newRow("Case E (winding)") << e << QPointF(55, 55) << true;
}
Ejemplo n.º 4
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;
}
Ejemplo n.º 5
0
void UBGraphicsCache::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    Q_UNUSED(option);
    Q_UNUSED(widget);

    painter->setBrush(mMaskColor);
    painter->setPen(mMaskColor);

    // Draw the hole
    QPainterPath path;
    path.addRect(rect());

    if(mDrawMask)
    {
        if(eMaskShape_Circle == mMaskShape)
        {
            path.addEllipse(mShapePos, mShapeWidth, mShapeWidth);
        }
        else if(eMaskShap_Rectangle == mMaskShape)
        {
            path.addRect(mShapePos.x() - mShapeWidth, mShapePos.y() - mShapeWidth, 2*mShapeWidth, 2*mShapeWidth);
        }
        path.setFillRule(Qt::OddEvenFill);
    }

    painter->drawPath(path);
}
Ejemplo n.º 6
0
void QRoundProgressBar::drawValue(QPainter &p, const QRectF &baseRect, double value, double arcLength)
{
    // nothing to draw
    if (value == m_min)
        return;

    // for Line style
    if (m_barStyle == StyleLine)
    {
        p.setPen(QPen(palette().highlight().color(), m_dataPenWidth));
        p.setBrush(Qt::NoBrush);
        p.drawArc(baseRect.adjusted(m_outlinePenWidth/2, m_outlinePenWidth/2, -m_outlinePenWidth/2, -m_outlinePenWidth/2),
                  m_nullPosition * 16,
                  -arcLength * 16);
        return;
    }

    // for Pie and Donut styles
    QPainterPath dataPath;
    dataPath.setFillRule(Qt::WindingFill);

    // pie segment outer
    dataPath.moveTo(baseRect.center());
    dataPath.arcTo(baseRect, m_nullPosition, -arcLength);
    dataPath.lineTo(baseRect.center());

    p.setBrush(palette().highlight());
    p.setPen(QPen(palette().shadow().color(), m_dataPenWidth));
    p.drawPath(dataPath);
}
Ejemplo n.º 7
0
QPainterPath BI_Via::toQPainterPathPx(const Length& expansion) const noexcept {
  QPainterPath p = getOutline(expansion).toQPainterPathPx();
  p.setFillRule(Qt::OddEvenFill);  // important to subtract the hole!
  p.addEllipse(QPointF(0, 0), mDrillDiameter->toPx() / 2,
               mDrillDiameter->toPx() / 2);
  return p;
}
Ejemplo n.º 8
0
void tst_QPainterPath::intersects_QRectF_data()
{
    QTest::addColumn<QPainterPath>("path");
    QTest::addColumn<QRectF>("rect");
    QTest::addColumn<bool>("intersects");

    QPainterPath path;
    path.addRect(0, 0, 100, 100);

    QTest::newRow("same rect") << path << QRectF(0.1, 0.1, 99, 99) << true; // ###
    QTest::newRow("outside") << path << QRectF(-1, -1, 100, 100) << true;
    QTest::newRow("covers") << path << QRectF(-1, -1, 102, 102) << true;
    QTest::newRow("left") << path << QRectF(-10, 50, 5, 5) << false;
    QTest::newRow("top") << path << QRectF(50, -10, 5, 5) << false;
    QTest::newRow("right") << path << QRectF(110, 50, 5, 5) << false;
    QTest::newRow("bottom") << path << QRectF(50, 110, 5, 5) << false;

    path.addRect(50, 50, 100, 100);

    QTest::newRow("r1 top") << path << QRectF(0.1, 0.1, 99, 49) << true;
    QTest::newRow("r1 left") << path << QRectF(0.1, 0.1, 49, 99) << true;
    QTest::newRow("r2 right") << path << QRectF(100.01, 50.1, 49, 99) << true;
    QTest::newRow("r2 bottom") << path << QRectF(50.1, 100.1, 99, 49) << true;
    QTest::newRow("inside 2 rects") << path << QRectF(51, 51, 48, 48) << false;

    path.setFillRule(Qt::WindingFill);
    QTest::newRow("inside 2 rects (winding)") << path << QRectF(51, 51, 48, 48) << true;

    path.addEllipse(0, 0, 150, 150);
    QTest::newRow("topRight 2 rects") << path << QRectF(100, 25, 24, 24) << true;
    QTest::newRow("bottomLeft 2 rects") << path << QRectF(25, 100, 24, 24) << true;

    QTest::newRow("horizontal line") << linePath(0, 0, 10, 0) << QRectF(1, -1, 2, 2) << true;
    QTest::newRow("vertical line") << linePath(0, 0, 0, 10) << QRectF(-1, 1, 2, 2) << true;
}
Ejemplo n.º 9
0
/**
 * @brief RefreshGeometry  refresh item on scene.
 */
void VToolSpline::RefreshGeometry()
{
    this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor));
    const VSpline *spl = VAbstractTool::data.GeometricObject<const VSpline *>(id);
    QPainterPath path;
    path.addPath(spl->GetPath());
    path.setFillRule( Qt::WindingFill );
    this->setPath(path);
    QPointF splinePoint = VAbstractTool::data.GeometricObject<const VPointF *>(spl->GetP1().id())->toQPointF();
    QPointF controlPoint = spl->GetP2();
    emit RefreshLine(1, SplinePointPosition::FirstPoint, controlPoint, splinePoint);
    splinePoint = VAbstractTool::data.GeometricObject<const VPointF *>(spl->GetP4().id())->toQPointF();
    controlPoint = spl->GetP3();
    emit RefreshLine(1, SplinePointPosition::LastPoint, controlPoint, splinePoint);

    disconnect(controlPoints[0], &VControlPointSpline::ControlPointChangePosition, this,
            &VToolSpline::ControlPointChangePosition);
    disconnect(controlPoints[1], &VControlPointSpline::ControlPointChangePosition, this,
            &VToolSpline::ControlPointChangePosition);
    controlPoints[0]->setPos(spl->GetP2());
    controlPoints[1]->setPos(spl->GetP3());
    connect(controlPoints[0], &VControlPointSpline::ControlPointChangePosition, this,
            &VToolSpline::ControlPointChangePosition);
    connect(controlPoints[1], &VControlPointSpline::ControlPointChangePosition, this,
            &VToolSpline::ControlPointChangePosition);
}
Ejemplo n.º 10
0
void TClickableLabel::paintEvent(QPaintEvent *e)
{
    QPainter painter(this);

    if (m_isEnter) {
        painter.save();
        
        QRect r = rect();
    
        double h = r.height();
        double h2 = r.height() / 2.0;
        QPainterPath path;
        path.addRect(r.x() + h2, r.y() + 0, r.width() - h2 * 2, r.height());
        path.addEllipse(r.x(), r.y(), h, h);
        path.addEllipse(r.x() + r.width() - h, r.y(), h, h);
        path.setFillRule(Qt::WindingFill);
        painter.setPen(Qt::NoPen);
        painter.setBrush( palette().brush(QPalette::Highlight) );
        painter.setRenderHint(QPainter::Antialiasing);
        painter.drawPath(path);
        
        painter.restore();
    }
    
    QRect r = rect();
    r.setX((int) (r.x() + m_text->textWidth())/2);
    
    m_text->drawContents(&painter, r);
    
    painter.end();
    QWidget::paintEvent(e);
}
Ejemplo n.º 11
0
/**
 * \brief Draw the palette
 * @param event as the paint event
 */
void UBDockPalette::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event);
    QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing);
    painter.setPen(Qt::NoPen);
    painter.setBrush(mBackgroundBrush);
    QPainterPath path;
    path.setFillRule(Qt::WindingFill);

    int nbTabs = mTabWidgets.size();
    if(0 < nbTabs)
    {
        // First draw the BIG RECTANGLE (I write it big because the rectangle is big...)
        if(mOrientation == eUBDockOrientation_Left)
        {
            path.addRect(0.0, 0.0, width(), height());
        }
        else if(mOrientation == eUBDockOrientation_Right)
        {
            path.addRect(0.0, 0.0, width(), height());
        }

        painter.drawPath(path);
    }
}
Ejemplo n.º 12
0
QPainterPath IsometricRenderer::shape(const MapObject *object) const
{
    QPainterPath path;
    if (!object->cell().isEmpty()) {
        path.addRect(boundingRect(object));
    } else {
        switch (object->shape()) {
        case MapObject::Ellipse:
        case MapObject::Rectangle:
            path.addPolygon(pixelRectToScreenPolygon(object->bounds()));
            break;
        case MapObject::Polygon:
        case MapObject::Polyline: {
            const QPointF &pos = object->position();
            const QPolygonF polygon = object->polygon().translated(pos);
            const QPolygonF screenPolygon = pixelToScreenCoords(polygon);
            if (object->shape() == MapObject::Polygon) {
                path.addPolygon(screenPolygon);
            } else {
                for (int i = 1; i < screenPolygon.size(); ++i) {
                    path.addPolygon(lineToPolygon(screenPolygon[i - 1],
                                                  screenPolygon[i]));
                }
                path.setFillRule(Qt::WindingFill);
            }
            break;
        }
        }
    }
    return path;
}
Ejemplo n.º 13
0
void ZLabel::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
	QPainterPath path;
	path.setFillRule(Qt::WindingFill);

	path.moveTo(m_BRect.x(), m_BRect.y());
	path.lineTo(m_BRect.x()+m_BRect.width()/2, m_BRect.y());

	QRectF rect = m_BRect;
	rect.setX(rect.x()+rect.width()/2);

	path.arcTo(rect, 90, -180);
	path.lineTo(m_BRect.x(), m_BRect.y()+m_BRect.height());

	painter->setPen(QPen(Qt::black, 0) );
	painter->drawPath(path);

    if(option->state & QStyle::State_Selected) {
        painter->setPen(Qt::NoPen);
        QColor lightGray(192, 192, 192, 128);
        painter->setBrush(lightGray);
        painter->drawPath(path);
    }
    else {
    	painter->setPen(Qt::NoPen);
        QColor lightGray(128, 128, 128, 128);
        painter->setBrush(lightGray);
        painter->drawPath(path);
    }
    QFont font; font.setPixelSize(18);
    painter->setPen(QPen(Qt::black, 0));
    painter->setFont(font);

    painter->drawText(m_BRect, Qt::AlignCenter, QString::number(m_iZLayer) );
}
QPainterPath
rce::gui::RGraphicsFlagItem::
generateFlagPath(const QRectF &flagArea)
{
    QPainterPath path;
    path.setFillRule(Qt::WindingFill);
    path.moveTo(0,0);
    if((flagArea.width() > 0) &&
       (flagArea.height() > 0))
    {
        QRectF adjustedArea = flagArea.adjusted(-RCE_EMPHASED_LINE_WIDTH,
                                                -RCE_EMPHASED_LINE_WIDTH,
                                                RCE_EMPHASED_LINE_WIDTH,
                                                RCE_EMPHASED_LINE_WIDTH); // TODO: Make this automaticly scale with font size

        path.lineTo(adjustedArea.bottomLeft());
        path.addRect(adjustedArea);
    }

    path.moveTo(0,0);
    path.addEllipse(QPointF(0,0),
                    1.0, 1.0);

    return path;
}
Ejemplo n.º 15
0
QPainterPath TextSymbol::painterPath(void)
{
  QPainterPath path;

  path.setFillRule(Qt::WindingFill);

  QString filename = ctx.loader->absPath("fonts/" + m_font);
  FontDataStore* ds = CachedFontParser::parse(filename);

  QMatrix mat(m_xsize / ds->xsize(), 0, 0, m_ysize / ds->ysize(), 0, 0);

  for (int i = 0; i < m_text.length(); ++i) {
    CharRecord* rec = ds->charRecord(m_text[i].toAscii());
    if (rec) {
      QPainterPath p = mat.map(rec->painterPath(m_width_factor));
      path.addPath(p);
    }
    mat.translate(ds->xsize() + ds->offset(), 0);
  }

  QRectF b = path.boundingRect();
  QMatrix mat2;
  mat2.translate(-b.x(), -(b.y() + b.height()));
  path = mat2.map(path);

  return path;
}
Ejemplo n.º 16
0
void QPaintEngineEx::drawStaticTextItem(QStaticTextItem *staticTextItem)
{
    QPainterPath path;
#ifndef Q_WS_MAC
    path.setFillRule(Qt::WindingFill);
#endif

    if (staticTextItem->numGlyphs == 0)
        return;

    QFontEngine *fontEngine = staticTextItem->fontEngine();
    fontEngine->addGlyphsToPath(staticTextItem->glyphs, staticTextItem->glyphPositions,
                                staticTextItem->numGlyphs, &path, 0);
    if (!path.isEmpty()) {
        QPainterState *s = state();
        QPainter::RenderHints oldHints = s->renderHints;
        bool changedHints = false;
        if (bool(oldHints & QPainter::TextAntialiasing)
            && !bool(fontEngine->fontDef.styleStrategy & QFont::NoAntialias)
            && !bool(oldHints & QPainter::Antialiasing)) {
            s->renderHints |= QPainter::Antialiasing;
            renderHintsChanged();
            changedHints = true;
        }

        fill(qtVectorPathForPath(path), s->pen.color());

        if (changedHints) {
            s->renderHints = oldHints;
            renderHintsChanged();
        }
    }
}
Ejemplo n.º 17
0
void tst_QPainterPath::testOperatorDatastream()
{
    QPainterPath path;
    path.addEllipse(0, 0, 100, 100);
    path.addRect(0, 0, 100, 100);
    path.setFillRule(Qt::WindingFill);

    // Write out
    {
        QFile data("data");
        bool ok = data.open(QFile::WriteOnly);
        QVERIFY(ok);
        QDataStream stream(&data);
        stream << path;
    }

    QPainterPath other;
    // Read in
    {
        QFile data("data");
        bool ok = data.open(QFile::ReadOnly);
        QVERIFY(ok);
        QDataStream stream(&data);
        stream >> other;
    }

    QVERIFY(other == path);
}
Ejemplo n.º 18
0
/**
 * \brief Draw the palette
 * @param event as the paint event
 */
void UBDockPalette::paintEvent(QPaintEvent *event)
{
	Q_UNUSED(event);
	QPainter painter(this);
	painter.setRenderHint(QPainter::Antialiasing);
	painter.setPen(Qt::NoPen);
	painter.setBrush(mBackgroundBrush);
	QPainterPath path;
	path.setFillRule(Qt::WindingFill);

	int nbTabs = mTabWidgets.size();
	if(0 < nbTabs)
	{
		// First draw the BIG RECTANGLE (I write it big because the rectangle is big...)
		if(mOrientation == eUBDockOrientation_Left)
		{
			path.addRect(0.0, 0.0, width(), height());
		}
		else if(mOrientation == eUBDockOrientation_Right)
		{
			path.addRect(0.0, 0.0, width(), height());
		}

		// THEN DRAW THE small tabs (yes, the tabs are small...)
		if(eUBDockTabOrientation_Up == mTabsOrientation)
		{
			mHTab = border();
		}
		else
		{
			mHTab = height() - border() - nbTabs*TABSIZE - (nbTabs-1)*tabSpacing();
		}
		painter.drawPath(path);
	}
}
void CustomFrame::paintEvent(QPaintEvent *e)
{
    int border = FRAME_BORDER;
    if (this->isMaximized()) {
        border = 0;
    }

    QPainter painter(this);
    QPainterPath painterPath;
    painterPath.setFillRule(Qt::WindingFill);
    painterPath.addRect(border, border, this->width()-2*border, this->height()-2*border);
    painter.setRenderHint(QPainter::Antialiasing, true);
    painter.fillPath(painterPath, QBrush(Qt::white));
    QColor color(200, 200, 200);
    for (int i=0; i<border; i++) {
        color.setAlpha((i+1)*30);
        painter.setPen(color);
        painter.drawRect(border-i, border-i, this->width()-(border-i)*2, this->height()-(border-i)*2);
    }

    painter.setPen(Qt::NoPen);
    painter.setBrush(Qt::white);
    // 这里可以在资源中指定一张标题背景图片
    //painter.drawPixmap(QRect(border, border, this->width()-2*border, this->height()-2*border), QPixmap(DEFAULT_SKIN));
    painter.drawRect(QRect(border, TITLE_HEIGHT, this->width()-2*border, this->height()-TITLE_HEIGHT-border));

    QFrame::paintEvent(e);
}
Ejemplo n.º 20
0
static QPainterPath qwtTransformPath( const QwtScaleMap &xMap,
        const QwtScaleMap &yMap, const QPainterPath &path, bool doAlign )
{
    QPainterPath shape;
    shape.setFillRule( path.fillRule() );

    for ( int i = 0; i < path.elementCount(); i++ )
    {
        const QPainterPath::Element &element = path.elementAt( i );

        double x = xMap.transform( element.x );
        double y = yMap.transform( element.y );

        switch( element.type )
        {
            case QPainterPath::MoveToElement:
            {
                if ( doAlign )
                {
                    x = qRound( x );
                    y = qRound( y );
                }

                shape.moveTo( x, y );
                break;
            }
            case QPainterPath::LineToElement:
            {
                if ( doAlign )
                {
                    x = qRound( x );
                    y = qRound( y );
                }

                shape.lineTo( x, y );
                break;
            }
            case QPainterPath::CurveToElement:
            {
                const QPainterPath::Element& element1 = path.elementAt( ++i );
                const double x1 = xMap.transform( element1.x );
                const double y1 = yMap.transform( element1.y );

                const QPainterPath::Element& element2 = path.elementAt( ++i );
                const double x2 = xMap.transform( element2.x );
                const double y2 = yMap.transform( element2.y );

                shape.cubicTo( x, y, x1, y1, x2, y2 );
                break;
            }
            case QPainterPath::CurveToDataElement:
            {
                break;
            }
        }
    }

    return shape;
}
Ejemplo n.º 21
0
QPainterPath Paths::windingFill()
{
    QPainterPath path;
    path.addRect(0, 0, 100, 100);
    path.addRect(50, 25, 100, 50);
    path.setFillRule(Qt::WindingFill);
    return path;
}
Ejemplo n.º 22
0
void Window::setupShapes()
{
    QPainterPath truck;
    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);

    QPainterPath clock;
    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);

    QPainterPath house;
    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);

    QPainterPath text;
    QFont font;
    font.setPixelSize(50);
    QRect fontBoundingRect = QFontMetrics(font).boundingRect(tr("Qt"));
    text.addText(-QPointF(fontBoundingRect.center()), font, tr("Qt"));

    shapes.append(clock);
    shapes.append(house);
    shapes.append(text);
    shapes.append(truck);

    connect(shapeComboBox, SIGNAL(activated(int)), this, SLOT(shapeSelected(int)));
}
Ejemplo n.º 23
0
 QPainterPath shape() const override
 {
     QPainterPath path;
     path.setFillRule(Qt::WindingFill);
     if (m_arrowItem)
         path.addRect(mapRectFromItem(m_arrowItem, m_arrowItem->boundingRect()));
     if (m_diamondItem)
         path.addRect(mapRectFromItem(m_diamondItem, m_diamondItem->boundingRect()));
     return path;
 }
void GraphicsContext::clipPath(WindRule clipRule)
{
    if (paintingDisabled())
        return;

    QPainter *p = m_data->p();
    QPainterPath newPath = m_data->currentPath;
    newPath.setFillRule(clipRule == RULE_EVENODD ? Qt::OddEvenFill : Qt::WindingFill);
    p->setClipPath(newPath);
}
Ejemplo n.º 25
0
//------------------------------------------------------------------------------
void
Canvas::DrawFilledRectangle(int left, int top, int right, int bottom,
                            const Color color)
  {
  QPainterPath path;
  path.setFillRule(Qt::WindingFill);
  path.addRect(left, top, right - left, bottom - top);
  Brush a_brush(color);
  this->pushObject(path, this->pen(), a_brush());
  }
void DropShadowWidget::paintEvent(QPaintEvent *event)
{
    QPainterPath path;
    path.setFillRule(Qt::WindingFill);
    path.addRect(10,10,this->width()-20,this->height()-20);

    QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing, true);
    painter.fillPath(path, QBrush(Qt::red));

    QColor color(0,0,0,50);
    for(int i=0; i<10; ++i){
        QPainterPath path;
        path.setFillRule(Qt::WindingFill);
        path.addRect(10-i, 10-i, this->width()-(10-i)*2, this->height()-(10-i)*2);
        color.setAlpha(150-qSqrt(i)*50);
        painter.setPen(color);
        painter.drawPath(path);
    }
}
QPainterPath CopyFilterGUIConnectionItem::shape() const
{
	QLineF l = line();

	QPainterPath path;
	path.setFillRule(Qt::WindingFill);
	double length = line().length();
	if (length > 0)
	{
		double offset = min(length, maxArrowSize);
		QLineF unit = l.unitVector();
		QLineF normal = l.normalVector().unitVector();
		QPointF v(unit.dx(), unit.dy());
		QPointF n(normal.dx(), normal.dy());
		QPointF p2 = l.p2();

		QPointF p3 = p2 - v * offset + 0.5 * n * offset;
		QPointF p4 = p2 - v * offset - 0.5 * n * offset;
		QPolygonF polygon;
		polygon.append(p4);
		polygon.append(p3);
		polygon.append(p2);
		path.addPolygon(polygon);

		QPolygonF polygon2;
		QPointF p1 = l.p1();
		polygon2.append(p2 + 3 * n);
		polygon2.append(p2 - 2 * n);
		polygon2.append(p1 - 2 * n);
		polygon2.append(p1 + 3 * n);
		path.addPolygon(polygon2);

		if (factor != 1.0 || isDecibel)
		{
			QFont font;
			font.setPixelSize(10);
			QPointF center = (l.p1() + l.p2()) / 2;
			QString text = QString("%1").arg(factor);
			if (isDecibel)
				text += " dB";

			QFontMetrics fontMetrics(font);
			QSizeF size = fontMetrics.size(0, text);
			size += QSizeF(2, 0);
			QRectF rect;
			rect.setSize(size);
			rect.moveCenter(center);
			path.addRoundedRect(rect.adjusted(-0.5, 0.5, 0.5, 0.5), 3, 3);
		}
	}

	return path;
}
QPainterPath OrthogonalRenderer::shape(const MapObject *object) const
{
    QPainterPath path;

    if (!object->cell().isEmpty()) {
        path.addRect(boundingRect(object));
    } else {
        switch (object->shape()) {
        case MapObject::Rectangle: {
            const QRectF bounds = object->bounds();
            const QRectF rect(tileToPixelCoords(bounds.topLeft()),
                              tileToPixelCoords(bounds.bottomRight()));

            if (rect.isNull()) {
                path.addEllipse(rect.topLeft(), 20, 20);
            } else {
                path.addRoundedRect(rect, 10, 10);
            }
            break;
        }
        case MapObject::Polygon:
        case MapObject::Polyline: {
            const QPointF &pos = object->position();
            const QPolygonF polygon = object->polygon().translated(pos);
            const QPolygonF screenPolygon = tileToPixelCoords(polygon);
            if (object->shape() == MapObject::Polygon) {
                path.addPolygon(screenPolygon);
            } else {
                for (int i = 1; i < screenPolygon.size(); ++i) {
                    path.addPolygon(lineToPolygon(screenPolygon[i - 1],
                                                  screenPolygon[i]));
                }
                path.setFillRule(Qt::WindingFill);
            }
            break;
        }
        case MapObject::Ellipse: {
            const QRectF bounds = object->bounds();
            const QRectF rect(tileToPixelCoords(bounds.topLeft()),
                              tileToPixelCoords(bounds.bottomRight()));

            if (rect.isNull()) {
                path.addEllipse(rect.topLeft(), 20, 20);
            } else {
                path.addEllipse(rect);
            }
            break;
        }
        }
    }

    return path;
}
Ejemplo n.º 29
0
QPainterPath ArrowItem::shape() const {
  QPainterPath selectPath;
  selectPath.setFillRule(Qt::WindingFill);
  selectPath.addPolygon(rect());
  selectPath.addPolygon(start);
  selectPath.addPolygon(end);
  if ((!isSelected() && !isHovering()) || (view()->mouseMode() == View::Create)) {
  } else {
    selectPath.addPath(grips());
  }
  return selectPath;
}
void MusicRemoteWidgetForCircle::paintEvent(QPaintEvent* event)
{
    MusicRemoteWidget::paintEvent(event);
    QPainter painter(this);
    painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
    QPainterPath path;
    path.addEllipse(15, 15, 135, 135);
    path.addEllipse(32, 32, 100, 100);
    path.setFillRule(Qt::OddEvenFill);
    painter.fillPath(path, QBrush(QColor(0, 0, 0, 50)));
    painter.end();
}