本文整理汇总了C++中QPainter::renderHints方法的典型用法代码示例。如果您正苦于以下问题:C++ QPainter::renderHints方法的具体用法?C++ QPainter::renderHints怎么用?C++ QPainter::renderHints使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QPainter
的用法示例。
在下文中一共展示了QPainter::renderHints方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: paintGrid
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);
}
示例2: drawPattern
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);
}
示例3: paintPixmap
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);
}
示例4: Draw
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;
}
示例5: applySizeScale
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 ] );
}
}
示例6: paintIndentMarker
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 );
}
示例7: render
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);
//.........这里部分代码省略.........
示例8: applyDataDefinedSymbology
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();
}
}
示例9: applyDataDefinedSymbology
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 ) );
}
}