Example #1
0
/*!
    Draws the first \a pointCount points in the buffer \a points
*/
void QPaintEngine::drawPoints(const QPointF *points, int pointCount)
{
    QPainter *p = painter();
    if (!p)
        return;

    qreal penWidth = p->pen().widthF();
    if (penWidth == 0)
        penWidth = 1;

    bool ellipses = p->pen().capStyle() == Qt::RoundCap;

    p->save();

    QTransform transform;
    if (qt_pen_is_cosmetic(p->pen(), p->renderHints())) {
        transform = p->transform();
        p->setTransform(QTransform());
    }

    p->setBrush(p->pen().brush());
    p->setPen(Qt::NoPen);

    for (int i=0; i<pointCount; ++i) {
        QPointF pos = transform.map(points[i]);
        QRectF rect(pos.x() - penWidth / 2, pos.y() - penWidth / 2, penWidth, penWidth);

        if (ellipses)
            p->drawEllipse(rect);
        else
            p->drawRect(rect);
    }

    p->restore();
}
Example #2
0
void plot2d::paintEvent(QPaintEvent *)
{
    //printf("paintEvent\n"); fflush(stdout);
    if (!backbuffer || !backbuffervalid) {
        if (!backbuffer) {
            backbuffer = new QPixmap (size ());
        }

        backbuffer->fill (isEnabled () ? Qt::white : Qt::lightGray);
        QPainter pixmappainter (backbuffer);
        {
            QReadLocker rd (&lock);
            setBoundaries();
            drawChannels(pixmappainter);
        }
        drawTicks(pixmappainter);
        backbuffervalid = true;
    }

    QPainter painter (this);
    painter.drawPixmap(0, 0, *backbuffer);

    if (scalemode == ScaleX) {
        double start = (scalestart - viewport.x ()) / viewport.width();
        double end = (scaleend - viewport.x()) / viewport.width();
        QLine line1 (start * width (), 0.005 * height (), end * width (), 0.005 * height ());
        QLine line2 (start * width (), 0.995 * height (), end * width (), 0.995 * height ());

        painter.save ();
        QPen mypen = painter.pen();
        mypen.setColor(QColor(0,0,0,150));
        mypen.setWidth(5);
        painter.setPen (mypen);
        painter.drawLine (line1);
        painter.drawLine (line2);

        painter.restore ();
    }

    if (scalemode == ScaleY) {
        double start = (scalestart - viewport.y ()) / viewport.height();
        double end = (scaleend - viewport.y()) / viewport.height();
        QLine line1 (0.005 * width (), start * height (), 0.005 * width (), end * height ());
        QLine line2 (0.995 * width (), start * height (), 0.995 * width (), end * height ());

        painter.save ();
        QPen mypen = painter.pen();
        mypen.setColor(QColor(0,0,0,150));
        mypen.setWidth(5);
        painter.setPen (mypen);
        painter.drawLine (line1);
        painter.drawLine (line2);
        painter.restore ();
    }
}
Example #3
0
void PanelRadar::paintEvent(QPaintEvent* event) {
    const qreal scale0 = 0.14644660940672623779957781894758;
    const qreal scale1 = (1.0 - scale0);
    
    PanelWidget::paintEvent(event);
    QPainter p;
    p.begin(this);
    setMargins(&p);
    p.setRenderHint(QPainter::Antialiasing, true);
    p.setRenderHint(QPainter::TextAntialiasing, true);
    
    QPen pen = p.pen();
    pen.setWidth(1);
    p.setPen(QColor("black"));
    
    QPainterPath path;
    qreal rx = p.device()->width();
    qreal ry = p.device()->height();
    
    QPointF point(0.5 * rx, 0.5 * ry);
    
    path.addEllipse(point, 0.50 * rx, 0.50 * ry);
    p.fillPath(path, QColor("white"));
    path.addEllipse(point, 0.25 * rx, 0.25 * ry);
    p.drawPath(path);

    p.drawLine(0, 0.5 * ry, rx, 0.5 * ry);
    p.drawLine(0.5 * rx, 0, 0.5 * rx, ry);
    p.drawLine(rx * scale0 + 1, ry * scale0 + 1, rx * scale1 - 1, ry * scale1 - 1);
    p.drawLine(rx * scale0 + 1, ry * scale1 - 1, rx * scale1 - 1, ry * scale0 + 1);
    
    drawItems(&p);
    
    p.end();
}
void ImageDisplayer::drawSavedContour(QPainter &painter) 
{
	//cout << "seeds size: " << seeds.size() << endl;
	//cout << "paths size: " << paths.size() << endl;
	if(seeds.size() ==  paths.size()) {
		for(int i=0; i<seeds.size(); i++) {
			// draw seed
			QBrush o = painter.brush();
			painter.setBrush(QColor(255, 0, 0, 255));
			int x = seeds[i].pos[0];
			int y = seeds[i].pos[1];
			int* tem = img2dis(x, y);
			painter.drawRect(tem[0]-3, tem[1]-3, 7, 7);
			painter.setBrush(o);

			// draw path
			QPainterPath path;
			vector<vec2i> p = paths[i];
			int* tem2 = img2dis(p[0].pos[0], p[0].pos[1]);
			path.moveTo(tem2[0], tem2[1]);
			for(int j=1; j<p.size(); j++) {
				tem2 = img2dis(p[j].pos[0], p[j].pos[1]);
				path.lineTo(tem2[0], tem2[1]);
			}
			QPen op = painter.pen();
			QPen pen(Qt::green, 3);
			painter.setPen(pen);
			painter.drawPath(path);
			painter.setPen(op);
		}
	}
}
void GraphicsContext::strokePath()
{
    if (paintingDisabled())
        return;

    QPainter *p = m_data->p();
    QPen pen = p->pen();
    QPainterPath path = m_data->currentPath;

    switch (m_common->state.strokeColorSpace) {
    case SolidColorSpace:
        if (strokeColor().alpha())
            p->strokePath(path, pen);
        break;
    case PatternColorSpace: {
        TransformationMatrix affine;
        pen.setBrush(QBrush(m_common->state.strokePattern->createPlatformPattern(affine)));
        p->setPen(pen);
        p->strokePath(path, pen);
        break;
    }
    case GradientColorSpace: {
        QGradient* gradient = m_common->state.strokeGradient->platformGradient();
        *gradient = applySpreadMethod(*gradient, spreadMethod()); 
        pen.setBrush(QBrush(*gradient));
        p->setPen(pen);
        p->strokePath(path, pen);
        break;
    }
    }
    m_data->currentPath = QPainterPath();
}
Example #6
0
void PolygonWidget::UpdatePreView()
{
	double roundness = CurvatureSpin->value() / 100.0;
	QPixmap pm = QPixmap(Preview->width() - 5, Preview->height() - 5);
	pm.fill(Qt::white);
	QPainter p;
	p.begin(&pm);
	p.setBrush(Qt::NoBrush);
	p.setPen(Qt::black);
	QPainterPath pp = RegularPolygon(Preview->width() - 6, Preview->height() - 6, Ecken->value(), Konvex->isChecked(), GetFaktor(), Slider2->value(), roundness);
	QRectF br = pp.boundingRect();
	if (br.x() < 0)
	{
		QMatrix m;
		m.translate(-br.x(), 0);
		pp = pp * m;
	}
	if (br.y() < 0)
	{
		QMatrix m;
		m.translate(0, -br.y());
		pp = pp * m;
	}
	br = pp.boundingRect();
	if ((br.height() > Preview->height() - 6) || (br.width() > Preview->width() - 6))
	{
		QMatrix ma;
		double sca = static_cast<double>(qMax(Preview->height() - 6, Preview->width() - 6)) / static_cast<double>(qMax(br.width(), br.height()));
		ma.scale(sca, sca);
		pp = pp * ma;
	}
	p.strokePath(pp, p.pen());
	p.end();
	Preview->setPixmap(pm);
}
void VariableCapacitor::drawShape(QPainter &p) {
	initPainter(p);

	// Get centre point of component.
	int _y = (int)y();
	int _x = (int)x();

	p.drawRect(_x - 8, _y - 8, 5, 16);
	p.drawRect(_x + 3, _y - 8, 5, 16);

// 	p.drawLine( _x-8, _y, _x-16, _y );
// 	p.drawLine( _x+8, _y, _x+16, _y );

	// Diagonally pointing arrow
	QPointArray pa(3);
	pa[0] = QPoint(-4, 0);
	pa[1] = QPoint(-2, 4);
	pa[2] = QPoint(0, 0);

	pa.translate(_x + 16, _y - 8);
	p.setBrush(p.pen().color());
	p.drawPolygon(pa);

	p.drawLine(_x - 16, _y + 8, _x + 16, _y - 8);

	deinitPainter(p);
}
Example #8
0
void MarkerMapObject::paint(QPainter &painter, QRect view, int scale) {

	// Save the painter state for this paint session
	// so that it can be restored after without influencing other objects
	painter.save(); {

		// Translate, scale, and rotate...
		QTransform t;
		t.scale(1.0/scale, 1.0/scale);
		t.translate(x - view.x()*scale, view.height()*scale - y + view.y()*scale);
		painter.setTransform(t);

		for(int index = 0; index < transformationCount; index++) {
			long arrowLength = 1000*scale;
			long ballSize = 20*scale;
			Vector2D a = transformation[index].trans();
			Vector2D b = (transformation[index] * Trafo2D::trans(0, arrowLength)).trans();
			painter.setPen(transformationColors[index]);
			QPen pen = painter.pen();
			pen.setWidth(2*scale);
			painter.setPen(pen);
			painter.drawLine(a.x(), -a.y(), b.x(), -b.y());
			painter.setBrush(QBrush(transformationColors[index]));
			painter.drawEllipse(a.x()-ballSize/2, -(a.y()+ballSize/2), ballSize, ballSize);
		}

	} painter.restore();
}
Example #9
0
void QPaintEnginePrivate::drawBoxTextItem(const QPointF &p, const QTextItemInt &ti)
{
    if (!ti.glyphs.numGlyphs)
        return;

    // any fixes here should probably also be done in QFontEngineBox::draw
    const int size = qRound(ti.fontEngine->ascent());
    QVarLengthArray<QFixedPoint> positions;
    QVarLengthArray<glyph_t> glyphs;
    QTransform matrix = QTransform::fromTranslate(p.x(), p.y() - size);
    ti.fontEngine->getGlyphPositions(ti.glyphs, matrix, ti.flags, glyphs, positions);
    if (glyphs.size() == 0)
        return;

    QSize s(size - 3, size - 3);

    QPainter *painter = q_func()->state->painter();
    painter->save();
    painter->setBrush(Qt::NoBrush);
    QPen pen = painter->pen();
    pen.setWidthF(ti.fontEngine->lineThickness().toReal());
    painter->setPen(pen);
    for (int k = 0; k < positions.size(); k++)
        painter->drawRect(QRectF(positions[k].toPointF(), s));
    painter->restore();
}
Example #10
0
ImageBufferData::ImageBufferData(const IntSize& size)
    : m_pixmap(size)
{
    if (m_pixmap.isNull())
        return;

    m_pixmap.fill(QColor(Qt::transparent));

    QPainter* painter = new QPainter;
    m_painter = adoptPtr(painter);

    if (!painter->begin(&m_pixmap))
        return;

    // Since ImageBuffer is used mainly for Canvas, explicitly initialize
    // its painter's pen and brush with the corresponding canvas defaults
    // NOTE: keep in sync with CanvasRenderingContext2D::State
    QPen pen = painter->pen();
    pen.setColor(Qt::black);
    pen.setWidth(1);
    pen.setCapStyle(Qt::FlatCap);
    pen.setJoinStyle(Qt::SvgMiterJoin);
    pen.setMiterLimit(10);
    painter->setPen(pen);
    QBrush brush = painter->brush();
    brush.setColor(Qt::black);
    painter->setBrush(brush);
    painter->setCompositionMode(QPainter::CompositionMode_SourceOver);
    
    m_image = StillImage::createForRendering(&m_pixmap);
}
Example #11
0
  void DrawMana( QPainter& painter, int x, int y, int width, int height, int mana ) const {
    // Draw mana
    QPen origPen = painter.pen();
    QPen pen( QColor( 0, 52, 113 ) );
    pen.setCosmetic( true );
    pen.setWidth( 1 );
    painter.setPen( pen );

    QBrush brush( QColor( 40, 119, 238 ) );
    painter.setBrush( brush );

    QTransform transform;
    painter.translate( x + width * 0.5, y + height * 0.5 );
    painter.scale( width * 0.8, height * 0.8 );

    static const QPointF points[5] = {
      QPointF( 0.0, -1.0 ),
      QPointF( 1.0, -0.2 ),
      QPointF( 0.6, 1.0 ),
      QPointF( -0.6, 1.0 ),
      QPointF( -1.0, -0.2 ),
    };
    painter.drawConvexPolygon( points, 5 );
    painter.resetTransform();
    painter.setPen( origPen );

    painter.drawText( x, y, width, height, Qt::AlignCenter | Qt::AlignVCenter, QString::number( mana ) );
  }
Example #12
0
//-----------------------------------------------------------------------------
//!
//-----------------------------------------------------------------------------
void tWindPlotGraph::DrawTimeLabelAndGridLine(QPainter& painter, QPen& gridPen, int timeIncrement)
{
    // Work out the Y position for the label and grid line
    int samplePosition;

    // Calculate the samplePosition
    samplePosition = timeIncrement * 60000;
    samplePosition /= tDigitalTimePlotDataManager::Instance()->GetSamplePeriod(m_TimePlotRange);

    qreal y = m_GraphConfig.originY + (samplePosition * m_GraphConfig.pixPerTime);

    QFontMetrics fm = QFontMetrics(painter.font());

    // Draw the label
    QString label = QString("%1").arg(timeIncrement);
    QRect boundingRect = fm.boundingRect( label );

    int w = contentsRect().width();

    QRectF textRect = QRectF((w - m_GraphConfig.centreMarginWidth) / 2, y - (boundingRect.height() / 2), m_GraphConfig.centreMarginWidth, boundingRect.height() );
    painter.drawText(textRect, Qt::AlignCenter, label );

    QPen savedPen = painter.pen();

    // draw grid lines
    if ( (samplePosition != 0) && (samplePosition != m_TimePlotData[0].GetMaxNumberOfSamples()) )
    {
        painter.setPen( gridPen );
        painter.drawLine( m_GraphConfig.originX[0], static_cast<int>(y), m_GraphConfig.originX[0] + m_GraphConfig.extentX[0], static_cast<int>(y) );
        painter.drawLine( m_GraphConfig.originX[1], static_cast<int>(y), m_GraphConfig.originX[1] + m_GraphConfig.extentX[1], static_cast<int>(y) );
    }

    painter.setPen(savedPen);
}
Example #13
0
void ECBJT::drawShape( QPainter &p )
{
	const int _x = int(x());
	const int _y = int(y());
	
	initPainter(p);
	
	p.drawLine( _x-8, _y-8, _x-8, _y+8 );
	p.drawLine( _x+8, _y-8, _x-8, _y );
	p.drawLine( _x+8, _y+8, _x-8, _y );
	
	QPolygon pa(3);
	if ( m_bIsNPN )
	{
		pa[0] = QPoint( _x+6, _y+7 );
		pa[1] = QPoint( _x+2, _y+8 );
		pa[2] = QPoint( _x+5, _y+3 );
	}
	else
	{
		pa[0] = QPoint( _x-7, _y+1 );
		pa[1] = QPoint( _x-4, _y+5 );
		pa[2] = QPoint( _x-2, _y );
	}
	p.setBrush( p.pen().color() );
	p.drawPolygon(pa);
	
	deinitPainter(p);
}
void ZoomableAssemblyOverview::drawSelection(QPainter & p) {
    cachedSelection = calcCurrentSelection();
    //if selection is TOO small - enlarge it a bit
    if(0 == cachedSelection.width())  {
        cachedSelection.setWidth(1);
    }
    if(0 == cachedSelection.height()) {
        cachedSelection.setHeight(1);
    }

    //cached selection can be outside the visible range, so intersect it with it
    QRect selectionToDraw = rect().intersected(cachedSelection);
    if(selectionToDraw.isNull()) {
        return;
    }
    if(isRectVerySmall(selectionToDraw)) {
        //draw red cross
        QPoint c = selectionToDraw.center();
        QPen oldPen = p.pen();
        p.setPen(Qt::red);
        p.drawLine(c - CROSS_LEFT_CORNER, c + CROSS_LEFT_CORNER);
        p.drawLine(c - CROSS_RIGHT_CORNER, c + CROSS_RIGHT_CORNER);
        p.setPen(oldPen);
    } else {
        //draw transparent rectangle
        if(selectionToDraw.width() < 5 || selectionToDraw.height() < 5) {
            //red borders if rect is thin
            p.setPen(Qt::red);
        }
        p.fillRect(selectionToDraw, QColor(230, 230, 230, 180));
        p.drawRect(selectionToDraw.adjusted(0, 0, -1, -1));
    }
}
Example #15
0
void plotClippedPolygon(QPainter& painter,
			QRectF rect,
			const QPolygonF& inpoly,
			bool autoexpand)
{
  if ( autoexpand )
    {
      const qreal lw = painter.pen().widthF();
      if( painter.pen().style() != Qt::NoPen )
	rect.adjust(-lw, -lw, lw, lw);
    }

  QPolygonF plt;
  polygonClip(inpoly, rect, plt);
  painter.drawPolygon(plt);
}
Example #16
0
void plotBoxesToPainter(QPainter& painter,
			const Numpy1DObj& x1, const Numpy1DObj& y1,
			const Numpy1DObj& x2, const Numpy1DObj& y2,
			const QRectF* clip, bool autoexpand)
{
  // if autoexpand, expand rectangle by line width
  QRectF clipcopy(QPointF(-32767,-32767), QPointF(32767,32767));
  if ( clip != 0 && autoexpand )
    {
      const qreal lw = painter.pen().widthF();
      qreal x1, y1, x2, y2;
      clip->getCoords(&x1, &y1, &x2, &y2);
      clipcopy.setCoords(x1, y1, x2, y2);
      clipcopy.adjust(-lw, -lw, lw, lw);
    }

  const int maxsize = min(x1.dim, x2.dim, y1.dim, y2.dim);

  QVector<QRectF> rects;
  for(int i = 0; i < maxsize; ++i)
    {
      QPointF pt1(x1(i), y1(i));
      QPointF pt2(x2(i), y2(i));
      const QRectF rect(pt1, pt2);

      if( clipcopy.intersects(rect) )
	{
	  rects << clipcopy.intersected(rect);
	}
    }

  if( ! rects.isEmpty() )
    painter.drawRects(rects);
}
Example #17
0
void FancyRectangle::drawShape(QPainter &p)
{
    QPen oldPen = p.pen();

    // draw rectangle
    p.setPen(QPen(QColor(118, 118, 118), 1));
    p.drawRect((int)x(), (int)y(),
               width(), height());

    // draw decorations
    p.setPen(QPen(QColor(192, 192, 192), 1));
    p.drawPoint((int)x(), (int)y());
    p.drawPoint((int)x(), (int)y() + height() - 1);
    p.drawPoint((int)x() + width() - 1, (int)y());
    p.drawPoint((int)x() + width() - 1, (int)y() + height() - 1);

    //    p.setPen(QPen(QColor(196, 194, 205), 1));
    p.setPen(QPen(p.brush().color().dark(120), 1));
    p.drawLine((int)x() + 1, (int)y() + height() - 2,
               (int)x() + width() - 2, (int)y() + height() - 2);
    p.drawLine((int)x() + width() - 2, (int)y() + height() - 1,
               (int)x() + width() - 2, (int)y() + 1);

    p.setPen(oldPen);
}
void QgsMeshVectorRenderer::draw()
{
  // Set up the render configuration options
  QPainter *painter = mContext.painter();
  painter->save();
  if ( mContext.flags() & QgsRenderContext::Antialiasing )
    painter->setRenderHint( QPainter::Antialiasing, true );

  painter->setRenderHint( QPainter::Antialiasing );
  QPen pen = painter->pen();
  pen.setCapStyle( Qt::FlatCap );
  pen.setJoinStyle( Qt::MiterJoin );

  double penWidth = mContext.convertToPainterUnits( mCfg.lineWidth(),
                    QgsUnitTypes::RenderUnit::RenderMillimeters );
  pen.setWidthF( penWidth );
  pen.setColor( mCfg.color() );
  painter->setPen( pen );

  if ( mDataOnVertices )
    drawVectorDataOnVertices();
  else
    drawVectorDataOnFaces();

  painter->restore();
}
Example #19
0
// ********************************************************
ImageBufferData::ImageBufferData(const IntSize& size, bool accelerated)
{
    QPainter* painter = new QPainter;
    m_painter = adoptPtr(painter);

#if ENABLE(ACCELERATED_2D_CANVAS)
    if (accelerated) {
        m_impl = adoptPtr(new ImageBufferDataPrivateAccelerated(size));
    } else
#endif
        m_impl = adoptPtr(new ImageBufferDataPrivateUnaccelerated(size));

    if (!m_impl->paintDevice())
        return;
    if (!painter->begin(m_impl->paintDevice()))
        return;

    painter->setRenderHints(QPainter::Antialiasing | QPainter::HighQualityAntialiasing);
    QPen pen = painter->pen();
    pen.setColor(Qt::black);
    pen.setWidth(1);
    pen.setCapStyle(Qt::FlatCap);
    pen.setJoinStyle(Qt::SvgMiterJoin);
    pen.setMiterLimit(10);
    painter->setPen(pen);
    QBrush brush = painter->brush();
    brush.setColor(Qt::black);
    painter->setBrush(brush);
    painter->setCompositionMode(QPainter::CompositionMode_SourceOver);
}
void TextRenderable::render(QPainter &painter, const RenderConfig &config) const
{
	painter.save();
	
	bool disable_antialiasing = config.options.testFlag(RenderConfig::Screen) && !(Settings::getInstance().getSettingCached(Settings::MapDisplay_TextAntialiasing).toBool());
	if (disable_antialiasing)
	{
		painter.setRenderHint(QPainter::Antialiasing, false);
		painter.setRenderHint(QPainter::TextAntialiasing, false);
	}
	
	if (framing_line)
	{
		QPen pen(painter.pen());
		pen.setJoinStyle(Qt::MiterJoin);
		pen.setMiterLimit(0.5);
		painter.setPen(pen);
	}
	
	painter.translate(anchor_x, anchor_y);
	if (rotation != 0)
		painter.rotate(-rotation * 180 / M_PI);
	painter.scale(scale_factor, scale_factor);
	painter.drawPath(path);
	
	painter.restore();
}
QRect AGenericBrush::release(const QString & brush ,QPainter &  painter, const QPoint &  pos )
{
	int smoothness = m_configurator->exactness();
	
	if ( m_firstPoint == pos && m_path.elementCount() == 1)
	{
		smoothness = 0;
		m_path.addEllipse(pos.x(), pos.y(), painter.pen().width(),painter.pen().width());
		painter.drawPath(m_path);
	}
	
	m_firstPoint = QPoint(0,0);
	
	
	QPolygonF pol;
	QList<QPolygonF> polygons = m_path.toSubpathPolygons();
	
	QList<QPolygonF>::iterator it = polygons.begin();
	
	
	QPolygonF::iterator pointIt;
	while(it != polygons.end() )
	{
		pointIt = (*it).begin();
		
		while(pointIt <= (*it).end()-2)
		{
			pol << (*pointIt);
			pointIt += 2;
		}
		++it;
	}
	
	if(smoothness > 0)
	{
		m_path = KTGraphicalAlgorithm::bezierFit(pol, smoothness);
		emit requestRedraw();
		return QRect(0, 0, 0, 0);
	}
	else
	{
		m_path = QPainterPath();
		m_path.addPolygon(pol);
	}
	
	return m_path.boundingRect().toRect().normalized().adjusted(-painter.pen().width(), -painter.pen().width(), +painter.pen().width(), +painter.pen().width());;
}
void CanvasRenderingContext2D::stroke()
{
    GraphicsContext* c = drawingContext();
    if (!c)
        return;
    // FIXME: Do this through platform-independent GraphicsContext API.
#if PLATFORM(CG)
    CGContextBeginPath(c->platformContext());
    CGContextAddPath(c->platformContext(), state().m_path.platformPath());

    if (!state().m_path.isEmpty()) {
        float lineWidth = state().m_lineWidth;
        float inset = -lineWidth / 2;
        CGRect boundingRect = CGRectInset(CGContextGetPathBoundingBox(c->platformContext()), inset, inset);
        willDraw(boundingRect);
    }

    if (state().m_strokeStyle->gradient()) {
        // Shading works on the entire clip region, so convert the current path to a clip.
        c->save();
        CGContextReplacePathWithStrokedPath(c->platformContext());
        CGContextClip(c->platformContext());
        CGContextDrawShading(c->platformContext(), state().m_strokeStyle->gradient()->platformShading());        
        c->restore();
    } else {
        if (state().m_strokeStyle->pattern())
            applyStrokePattern();
        CGContextStrokePath(c->platformContext());
    }
#elif PLATFORM(QT)
    QPainterPath* path = state().m_path.platformPath();
    QPainter* p = static_cast<QPainter*>(c->platformContext());
    willDraw(path->controlPointRect());
    if (state().m_strokeStyle->gradient()) {
        p->save();
        p->setBrush(*(state().m_strokeStyle->gradient()->platformShading()));
        p->strokePath(*path, p->pen());
        p->restore();
    } else {
        if (state().m_strokeStyle->pattern())
            applyStrokePattern();
        p->strokePath(*path, p->pen());
    }
#endif

    clearPathForDashboardBackwardCompatibilityMode();
}
Example #23
0
void ComponentWidget::draw(QPainter & p, int offsetX, int offsetY) {
    UMLComponent *umlcomp = static_cast<UMLComponent*>(m_pObject);
    if (umlcomp == NULL)
        return;
    UMLWidget::setPen(p);
    if ( umlcomp->getExecutable() ) {
        QPen thickerPen = p.pen();
        thickerPen.setWidth(2);
        p.setPen(thickerPen);
    }
    if ( UMLWidget::getUseFillColour() ) {
        p.setBrush( UMLWidget::getFillColour() );
    } else {
        p.setBrush( m_pView->viewport()->backgroundColor() );
    }

    const int w = width();
    const int h = height();
    QFont font = UMLWidget::getFont();
    font.setBold(true);
    const QFontMetrics &fm = getFontMetrics(FT_BOLD);
    const int fontHeight = fm.lineSpacing();
    QString name = getName();
    const QString stereotype = m_pObject->getStereotype();

    p.drawRect(offsetX + 2*COMPONENT_MARGIN, offsetY, w - 2*COMPONENT_MARGIN, h);
    p.drawRect(offsetX, offsetY + h/2 - fontHeight/2 - fontHeight, COMPONENT_MARGIN*4, fontHeight);
    p.drawRect(offsetX, offsetY + h/2 + fontHeight/2, COMPONENT_MARGIN*4, fontHeight);

    p.setPen( QPen(Qt::black) );
    p.setFont(font);

    int lines = 1;

    if (!stereotype.isEmpty()) {
        p.drawText(offsetX + (COMPONENT_MARGIN*4), offsetY + (h/2) - fontHeight,
                   w - (COMPONENT_MARGIN*4), fontHeight, Qt::AlignCenter,
                   m_pObject->getStereotype(true));
        lines = 2;
    }

    if ( UMLWidget::getIsInstance() ) {
        font.setUnderline(true);
        p.setFont(font);
        name = UMLWidget::getInstanceName() + " : " + name;
    }

    if (lines == 1) {
        p.drawText(offsetX + (COMPONENT_MARGIN*4), offsetY + (h/2) - (fontHeight/2),
                   w - (COMPONENT_MARGIN*4), fontHeight, Qt::AlignCenter, name );
    } else {
        p.drawText(offsetX + (COMPONENT_MARGIN*4), offsetY + (h/2),
                   w - (COMPONENT_MARGIN*4), fontHeight, Qt::AlignCenter, name );
    }

    if(m_bSelected) {
        drawSelected(&p, offsetX, offsetY);
    }
}
Example #24
0
//! [2]
QRect BasicToolsPlugin::mouseMove(const QString &brush, QPainter &painter,
                                  const QPoint &oldPos, const QPoint &newPos)
{
    painter.save();

    int rad = painter.pen().width() / 2;
    QRect boundingRect = QRect(oldPos, newPos).normalized()
                         .adjusted(-rad, -rad, +rad, +rad);
    QColor color = painter.pen().color();
    int thickness = painter.pen().width();
    QColor transparentColor(color.red(), color.green(), color.blue(), 0);
//! [2] //! [3]

    if (brush == tr("Pencil")) {
        painter.drawLine(oldPos, newPos);
    } else if (brush == tr("Air Brush")) {
        int numSteps = 2 + (newPos - oldPos).manhattanLength() / 2;

        painter.setBrush(QBrush(color, Qt::Dense6Pattern));
        painter.setPen(Qt::NoPen);

        for (int i = 0; i < numSteps; ++i) {
            int x = oldPos.x() + i * (newPos.x() - oldPos.x()) / (numSteps - 1);
            int y = oldPos.y() + i * (newPos.y() - oldPos.y()) / (numSteps - 1);

            painter.drawEllipse(x - (thickness / 2), y - (thickness / 2),
                                thickness, thickness);
        }
    } else if (brush == tr("Random Letters")) {
        QChar ch('A' + (qrand() % 26));

        QFont biggerFont = painter.font();
        biggerFont.setBold(true);
        biggerFont.setPointSize(biggerFont.pointSize() + thickness);
        painter.setFont(biggerFont);

        painter.drawText(newPos, QString(ch));

        QFontMetrics metrics(painter.font());
        boundingRect = metrics.boundingRect(ch);
        boundingRect.translate(newPos);
        boundingRect.adjust(-10, -10, +10, +10);
    }
    painter.restore();
    return boundingRect;
}
QPen GraphicsContext::pen()
{
    if (paintingDisabled())
        return QPen();

    QPainter *p = m_data->p();
    return p->pen();
}
Example #26
0
static inline void drawEllipse(const QPointF &center, qreal hDiameter, qreal vDiameter, const QColor &color, QPainter &painter)
{
    const QPen oldPen = painter.pen();
    QPen pen = oldPen;
    pen.setColor(color);
    painter.setPen(pen);
    painter.drawEllipse(center, hDiameter / 2, vDiameter / 2);
    painter.setPen(oldPen);
}
Example #27
0
QPainter *BrushTool::getPainter(QPaintDevice *device)
{
    QPainter *painter = Tool::getPainter(device);
    QPen pen = painter->pen();
    pen.setCapStyle(Qt::RoundCap);
    painter->setPen(pen);

    return painter;
}
void GraphicsContext::setPlatformStrokeColor(const Color& color)
{
    if (paintingDisabled())
        return;
    QPainter *p = m_data->p();
    QPen newPen(p->pen());
    newPen.setColor(color);
    p->setPen(newPen);
}
void GraphicsContext::setPlatformStrokeStyle(const StrokeStyle& strokeStyle)
{
    if (paintingDisabled())
        return;
    QPainter *p = m_data->p();
    QPen newPen(p->pen());
    newPen.setStyle(toQPenStyle(strokeStyle));
    p->setPen(newPen);
}
void GraphicsContext::setPlatformStrokeThickness(float thickness)
{
    if (paintingDisabled())
        return;
    QPainter *p = m_data->p();
    QPen newPen(p->pen());
    newPen.setWidthF(thickness);
    p->setPen(newPen);
}