Esempio n. 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();
}
Esempio n. 2
0
void CanvasRenderer::paintGrid( QPainter& painter )
{
    int gridSize = mOptions.nGridSize;

    QRectF rect = painter.viewport();
    QRectF boundingRect = mViewTransform.inverted().mapRect( rect );
    int w = boundingRect.width();
    int h = boundingRect.height();

    //qDebug() << mViewTransform;
    //qDebug() << mViewTransform.inverted();

    int left = round100( boundingRect.left(), gridSize ) - gridSize;
    int right = round100( boundingRect.right(), gridSize ) + gridSize;
    int top = round100( boundingRect.top(), gridSize ) - gridSize;
    int bottom = round100( boundingRect.bottom(), gridSize ) + gridSize;
    
    QPen pen( Qt::lightGray );
    pen.setCosmetic( true );
    painter.setPen( pen );
    painter.setWorldMatrixEnabled( true );
    painter.setBrush( Qt::NoBrush );
    QPainter::RenderHints previous_renderhints = painter.renderHints();
    painter.setRenderHint( QPainter::Antialiasing, false );
    for ( int x = left; x < right; x += gridSize )
    {
        painter.drawLine( x, top, x, bottom );
    }

    for ( int y = top; y < bottom; y += gridSize )
    {
        painter.drawLine( left, y, right, y );
    }
    painter.setRenderHints(previous_renderhints);
}
Esempio n. 3
0
void Image::drawPattern(GraphicsContext* ctxt, const FloatRect& tileRect, const AffineTransform& patternTransform,
                        const FloatPoint& phase, ColorSpace, CompositeOperator op, const FloatRect& destRect)
{
    QPixmap* framePixmap = nativeImageForCurrentFrame();
    if (!framePixmap) // If it's too early we won't have an image yet.
        return;

    // Qt interprets 0 width/height as full width/height so just short circuit.
    QRectF dr = QRectF(destRect).normalized();
    QRect tr = QRectF(tileRect).toRect().normalized();
    if (!dr.width() || !dr.height() || !tr.width() || !tr.height())
        return;

    QPixmap pixmap = *framePixmap;
    if (tr.x() || tr.y() || tr.width() != pixmap.width() || tr.height() != pixmap.height())
        pixmap = pixmap.copy(tr);

    CompositeOperator previousOperator = ctxt->compositeOperation();

    ctxt->setCompositeOperation(!pixmap.hasAlpha() && op == CompositeSourceOver ? CompositeCopy : op);

    QPainter* p = ctxt->platformContext();
    QTransform transform(patternTransform);

    // If this would draw more than one scaled tile, we scale the pixmap first and then use the result to draw.
    if (transform.type() == QTransform::TxScale) {
        QRectF tileRectInTargetCoords = (transform * QTransform().translate(phase.x(), phase.y())).mapRect(tr);

        bool tileWillBePaintedOnlyOnce = tileRectInTargetCoords.contains(dr);
        if (!tileWillBePaintedOnlyOnce) {
            QSizeF scaledSize(float(pixmap.width()) * transform.m11(), float(pixmap.height()) * transform.m22());
            QPixmap scaledPixmap(scaledSize.toSize());
            if (pixmap.hasAlpha())
                scaledPixmap.fill(Qt::transparent);
            {
                QPainter painter(&scaledPixmap);
                painter.setCompositionMode(QPainter::CompositionMode_Source);
                painter.setRenderHints(p->renderHints());
                painter.drawPixmap(QRect(0, 0, scaledPixmap.width(), scaledPixmap.height()), pixmap);
            }
            pixmap = scaledPixmap;
            transform = QTransform::fromTranslate(transform.dx(), transform.dy());
        }
    }

    /* Translate the coordinates as phase is not in world matrix coordinate space but the tile rect origin is. */
    transform *= QTransform().translate(phase.x(), phase.y());
    transform.translate(tr.x(), tr.y());

    QBrush b(pixmap);
    b.setTransform(transform);
    p->fillRect(dr, b);

    ctxt->setCompositeOperation(previousOperator);

    if (imageObserver())
        imageObserver()->didDraw(this);
}
Esempio n. 4
0
void Legend::paintPixmap(QPainter &painter, const KoViewConverter &converter)
{
    // Adjust the size of the painting area to the current zoom level
    const QSize paintRectSize = converter.documentToView(d->lastSize).toSize();
    d->image = QImage(paintRectSize, QImage::Format_ARGB32);

    QPainter pixmapPainter(&d->image);
    pixmapPainter.setRenderHints(painter.renderHints());
    pixmapPainter.setRenderHint(QPainter::Antialiasing, false);

    // Scale the painter's coordinate system to fit the current zoom level.
    applyConversion(pixmapPainter, converter);
    d->kdLegend->paint(&pixmapPainter);
}
Esempio n. 5
0
void ReinforcementPower::Draw(QPainter &painter)
{
    int w = painter.viewport().width(), h = painter.viewport().height();
    int graphW = 200, graphH = 100, graphPad = 10;
    int top = h - 10 - (graphH + 2*graphPad);
    int left = 10;
    QPainter::RenderHints hints = painter.renderHints();
    painter.setRenderHint(QPainter::Antialiasing, false);
    QFont font = painter.font();
    font.setPointSize(9);
    painter.setFont(font);

    // we draw the rectangle behind
    painter.setOpacity(1);
    painter.setBrush(Qt::NoBrush);
    painter.setPen(QPen(Qt::black, 2));
    painter.drawRect(left, top, graphW + 2*graphPad, graphH + 2*graphPad);
    painter.setOpacity(0.6);
    painter.setPen(Qt::NoPen);
    painter.setBrush(Qt::white);
    painter.drawRect(left, top, graphW + 2*graphPad, graphH + 2*graphPad);
    painter.setOpacity(1);
    painter.setBrush(Qt::black);
    painter.setPen(Qt::black);

    // we draw the values
    double maxValue = -DBL_MAX;
    FOR(i, historyValue.size()) maxValue = max(maxValue, historyValue[i]);
    int valueLimit = 4;
    double upperBound = ((int)ceil(maxValue)/valueLimit + 1)*valueLimit;
    painter.setPen(QPen(Qt::black, 2));
    QPointF oldPoint;
    FOR(i, graphW)
    {
        int index = i*historyValue.size()/graphW;
        QPointF point(i, graphH*(1.f - (historyValue[index]/upperBound)));
        point += QPointF(left + graphPad, top + graphPad);
        if(i) painter.drawLine(point, oldPoint);
        if(i==graphW-1)
        {
            painter.drawText(point + QPointF(-20,0), QString("%1").arg(historyValue.back(), 0, 'f', 2));
        }
        oldPoint = point;
    }
Esempio n. 6
0
void QgsSimpleLineSymbolLayerV2::renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context )
{
  QPainter* p = context.renderContext().painter();
  if ( !p )
  {
    return;
  }

  //size scaling by field
  if ( context.renderHints() & QgsSymbolV2::DataDefinedSizeScale )
  {
    applySizeScale( context, mPen, mSelPen );
  }

  double offset = mOffset;
  applyDataDefinedSymbology( context, mPen, mSelPen, offset );

  p->setPen( context.selected() ? mSelPen : mPen );

  // Disable 'Antialiasing' if the geometry was generalized in the current RenderContext (We known that it must have least #2 points).
  if ( points.size() <= 2 &&
       ( context.renderContext().vectorSimplifyMethod().simplifyHints() & QgsVectorSimplifyMethod::AntialiasingSimplification ) &&
       QgsAbstractGeometrySimplifier::isGeneralizableByDeviceBoundingBox( points, context.renderContext().vectorSimplifyMethod().threshold() ) &&
       ( p->renderHints() & QPainter::Antialiasing ) )
  {
    p->setRenderHint( QPainter::Antialiasing, false );
    p->drawPolyline( points );
    p->setRenderHint( QPainter::Antialiasing, true );
    return;
  }

  if ( qgsDoubleNear( offset, 0 ) )
  {
    p->drawPolyline( points );
  }
  else
  {
    double scaledOffset = QgsSymbolLayerV2Utils::convertToPainterUnits( context.renderContext(), offset, mOffsetUnit, mOffsetMapUnitScale );
    QList<QPolygonF> mline = ::offsetLine( points, scaledOffset, context.feature() ? context.feature()->constGeometry()->type() : QGis::Line );
    for ( int part = 0; part < mline.count(); ++part )
      p->drawPolyline( mline[ part ] );
  }
}
Esempio n. 7
0
void KateRenderer::paintIndentMarker(QPainter &paint, uint x, uint y /*row*/)
{
  QPen penBackup( paint.pen() );
  QPen myPen(config()->indentationLineColor());
  static const QVector<qreal> dashPattern = QVector<qreal>() << 1 << 1;
  myPen.setDashPattern(dashPattern);
  if (y % 2)
    myPen.setDashOffset(1);
  paint.setPen(myPen);

  const int height = fontHeight();
  const int top = 0;
  const int bottom = height-1;

  QPainter::RenderHints renderHints = paint.renderHints();
  paint.setRenderHints(renderHints, false);

  paint.drawLine(x + 2, top, x + 2, bottom);

  paint.setRenderHints(renderHints, true);

  paint.setPen( penBackup );
}
Esempio n. 8
0
void HeliCanvas::render(QPainter &p) {
	int fontHeight = p.fontMetrics().height();
	int h = _size.height() - fontHeight*160/100;

	if ( _rows.empty() ) {
		p.fillRect(QRect(_labelMargin,0,_size.width()-_labelMargin,h), _palette.color(QPalette::Base));
		return;
	}

	p.setClipRect(QRect(0,0,_size.width(),h));

	int rowHeight = h / (_rows.size()+2);
	int rowPos = rowHeight;
	int recordWidth = _size.width();
	Core::Time globalEnd = _records->empty()?Core::Time():_records->back()->endTime();

	int yGap = h - rowHeight*(_rows.size()+2);
	int remainingGap = yGap;
	int heightOfs = yGap > 0?1:0;
	int skipTextLines = (fontHeight*3/2) / rowHeight;
	int currentTextLine = skipTextLines;

	p.setPen(_palette.color(QPalette::Text));

	for ( int i = 0; i < _rows.size(); ++i, rowPos += rowHeight + heightOfs ) {
		if ( currentTextLine == 0 ) {
			p.drawText(QRect(0, rowPos-fontHeight, _labelMargin, rowHeight+2*fontHeight + heightOfs),
			           Qt::AlignLeft | Qt::AlignVCenter,
			           Gui::timeToString(_rows[i].time, "%H:%M"));
			currentTextLine = skipTextLines;
		}
		else
			--currentTextLine;

		--remainingGap;
		if ( remainingGap <= 0 )
			heightOfs = 0;
	}

	recordWidth -= _labelMargin;

	p.fillRect(QRect(_labelMargin, 0, recordWidth, h), _palette.color(QPalette::Base));

	heightOfs = yGap > 0?1:0;
	remainingGap = yGap;
	rowPos = rowHeight;

	for ( int i = 0; i < _rows.size(); ++i, rowPos += rowHeight + heightOfs ) {
		QColor gapColor = _gaps[i % 2];

		// Create new sequence
		if ( _rows[i].dirty ) {
			if ( !_rows[i].polyline )
				_rows[i].polyline = RecordPolylinePtr(new Gui::RecordPolyline);

			float ofs, min, max;
			Core::TimeWindow tw(_rows[i].time, _rows[i].time + Core::TimeSpan(_rowTimeSpan));
			minmax(_filteredRecords, tw, ofs, min, max);

			_rows[i].polyline->create(_filteredRecords,
			                          tw.startTime(), tw.endTime(),
			                          (double)recordWidth / (double)_rowTimeSpan,
			                          _amplitudeRange[0], _amplitudeRange[1], ofs, rowHeight);
			_rows[i].polyline->translate(_labelMargin, 0);
			_rows[i].dirty = false;
		}

		if ( _rows[i].polyline ) {
			if ( !_rows[i].polyline->empty() ) {
				// Draw front and back gaps
				if ( _rows[i].polyline->front().first().x() > _labelMargin )
					p.fillRect(_labelMargin, rowPos,
					           _rows[i].polyline->front().first().x() - _labelMargin,
					           rowHeight, gapColor);

				if ( (globalEnd - _rows[i].time) >= Core::TimeSpan(_rowTimeSpan) ) {
					if ( _rows[i].polyline->back().last().x() < _size.width()-2 )
						p.fillRect(_rows[i].polyline->back().last().x(),
						           rowPos, _size.width()-1 - _rows[i].polyline->back().last().x(),
						           rowHeight, gapColor);
				}
			}
			else if ( (globalEnd - _rows[i].time) >= Core::TimeSpan(_rowTimeSpan) )
				p.fillRect(QRect(_labelMargin, rowPos, recordWidth, rowHeight), gapColor);
		}

		--remainingGap;
		if ( remainingGap <= 0 )
			heightOfs = 0;
	}

	heightOfs = yGap > 0?1:0;
	remainingGap = yGap;
	rowPos = rowHeight;

	int rowColorIndex = 0;

	bool hadAntialiasing = (p.renderHints() & QPainter::Antialiasing) != 0;
	p.setRenderHint(QPainter::Antialiasing, _antialiasing);

	for ( int i = 0; i < _rows.size(); ++i, rowPos += rowHeight + heightOfs ) {
		QColor gapColor = _gaps[i & 1];
		QColor overlapColor = _gaps[i & 1];
		p.setPen(QPen(_rowColors[rowColorIndex], _lineWidth));

		++rowColorIndex;
		if ( rowColorIndex >= _rowColors.size() )
			rowColorIndex = 0;

		if ( !_rows[i].polyline ) continue;

		p.translate(0, rowPos);
		_rows[i].polyline->draw(p, 0, rowHeight, gapColor, overlapColor);
		p.translate(0, -rowPos);

		--remainingGap;
		if ( remainingGap <= 0 )
			heightOfs = 0;
	}

	p.setRenderHint(QPainter::Antialiasing, hadAntialiasing);

	p.setClipping(false);
	p.setPen(_palette.color(QPalette::Text));

	// Render timescale
	double pos = 0;
	double scale = (double)recordWidth / (double)_rowTimeSpan;
	double dx[2] = {_drx[0], _drx[1]};
	
	// Adapted from gui/libs/ruler
	int tickLong = fontHeight/2;
	int tickShort = tickLong/2;
	int startY = h;
	h = _size.height()-startY;

	//p.setPen(p.palette().color(QPalette::WindowText));
	p.drawLine(_labelMargin, startY, _size.width(), startY);

	for ( int k = 0; k < 2; ++k ) {
		double cpos = pos - fmod(pos, (double)dx[k]);

		int tick = k==0 ? tickLong : tickShort;

		int x = (int)((cpos-pos)*scale);
		while ( x < recordWidth ) {
			p.drawLine(_labelMargin+x, startY, _labelMargin+x, startY+tick);

			if ( k == 0 ) {
				QString str = formatAnnotation(cpos);

				int tw = p.fontMetrics().width(str);
				p.drawText(_labelMargin + x-tw/2, startY, tw, h,
				           Qt::AlignHCenter | Qt::AlignBottom, str);
			}

			cpos += dx[k];
			x = (int)((cpos-pos)*scale);
		}
	}
}
Esempio n. 9
0
void QgsSimpleLineSymbolLayerV2::renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context )
{
  QPainter* p = context.renderContext().painter();
  if ( !p )
  {
    return;
  }

  double offset = 0.0;
  applyDataDefinedSymbology( context, mPen, mSelPen, offset );

  p->setPen( context.selected() ? mSelPen : mPen );

  // Disable 'Antialiasing' if the geometry was generalized in the current RenderContext (We known that it must have least #2 points).
  if ( points.size() <= 2 && context.layer() && context.layer()->simplifyDrawingCanbeApplied( context.renderContext(), QgsVectorLayer::AntialiasingSimplification ) && QgsAbstractGeometrySimplifier::canbeGeneralizedByDeviceBoundingBox( points, context.layer()->simplifyMethod().threshold() ) && ( p->renderHints() & QPainter::Antialiasing ) )
  {
    p->setRenderHint( QPainter::Antialiasing, false );
    p->drawPolyline( points );
    p->setRenderHint( QPainter::Antialiasing, true );
    return;
  }

  if ( mDrawInsidePolygon )
  {
    //only drawing the line on the interior of the polygon, so set clip path for painter
    p->save();
    QPainterPath clipPath;
    clipPath.addPolygon( points );
    p->setClipPath( clipPath, Qt::IntersectClip );
  }

  if ( offset == 0 )
  {
    p->drawPolyline( points );
  }
  else
  {
    double scaledOffset = offset * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit );
    p->drawPolyline( ::offsetLine( points, scaledOffset ) );
  }

  if ( mDrawInsidePolygon )
  {
    //restore painter to reset clip path
    p->restore();
  }
}
Esempio n. 10
0
void QgsSimpleLineSymbolLayerV2::renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context )
{
  QPainter* p = context.renderContext().painter();
  if ( !p )
  {
    return;
  }

  double offset = 0.0;
  applyDataDefinedSymbology( context, mPen, mSelPen, offset );

  p->setPen( context.selected() ? mSelPen : mPen );

  // Disable 'Antialiasing' if the geometry was generalized in the current RenderContext (We known that it must have least #2 points).
#if 0 // TODO[MD]: after merge
  if ( points.size() <= 2 && context.layer() && context.layer()->simplifyDrawingCanbeApplied( context.renderContext(), QgsVectorSimplifyMethod::AntialiasingSimplification ) && QgsAbstractGeometrySimplifier::canbeGeneralizedByDeviceBoundingBox( points, context.layer()->simplifyMethod().threshold() ) && ( p->renderHints() & QPainter::Antialiasing ) )
  {
    p->setRenderHint( QPainter::Antialiasing, false );
    p->drawPolyline( points );
    p->setRenderHint( QPainter::Antialiasing, true );
    return;
  }
#endif

  if ( offset == 0 )
  {
    p->drawPolyline( points );
  }
  else
  {
    double scaledOffset = offset * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit );
    p->drawPolyline( ::offsetLine( points, scaledOffset ) );
  }
}