本文整理汇总了C++中QPainter::setClipRegion方法的典型用法代码示例。如果您正苦于以下问题:C++ QPainter::setClipRegion方法的具体用法?C++ QPainter::setClipRegion怎么用?C++ QPainter::setClipRegion使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QPainter
的用法示例。
在下文中一共展示了QPainter::setClipRegion方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: UpdateGC
void nsRenderingContextQt::UpdateGC()
{
QPainter *pGC;
QColor color(NS_GET_R(mCurrentColor),
NS_GET_G(mCurrentColor),
NS_GET_B(mCurrentColor));
QPen pen(color,0,mQLineStyle);
QBrush brush(color);
pGC = mSurface->GetGC();
pGC->setPen(pen);
pGC->setBrush(brush);
pGC->setRasterOp(mFunction);
if (mCurrentFont)
pGC->setFont(mCurrentFont->font);
if (mClipRegion) {
QRegion *rgn = nsnull;
pGC->setClipping(TRUE);
mClipRegion->GetNativeRegion((void*&)rgn);
pGC->setClipRegion(*rgn);
}
else {
pGC->setClipping(FALSE);
}
}
示例2: render
void QQuickShapeSoftwareRenderNode::render(const RenderState *state)
{
if (m_sp.isEmpty())
return;
QSGRendererInterface *rif = m_item->window()->rendererInterface();
QPainter *p = static_cast<QPainter *>(rif->getResource(m_item->window(), QSGRendererInterface::PainterResource));
Q_ASSERT(p);
const QRegion *clipRegion = state->clipRegion();
if (clipRegion && !clipRegion->isEmpty())
p->setClipRegion(*clipRegion, Qt::ReplaceClip); // must be done before setTransform
p->setTransform(matrix()->toTransform());
p->setOpacity(inheritedOpacity());
for (const ShapePathRenderData &d : qAsConst(m_sp)) {
if (d.hidden) {
continue;
}
// QTransform oldTransform = p->transform();
// p->setTransform(d.transform, true);
// p->setOpacity(inheritedOpacity() * d.opacity);
p->setPen(d.strokeWidth >= 0.0f && d.pen.color() != Qt::transparent ? d.pen : Qt::NoPen);
p->setBrush(d.brush.color() != Qt::transparent ? d.brush : Qt::NoBrush);
p->drawPath(d.path);
// p->setTransform(oldTransform);
}
}
示例3: grabRect
void FreeRegionGrabber::grabRect()
{
QPolygon pol = selection;
if ( !pol.isEmpty() )
{
grabbing = true;
int xOffset = pixmap.rect().x() - pol.boundingRect().x();
int yOffset = pixmap.rect().y() - pol.boundingRect().y();
QPolygon translatedPol = pol.translated(xOffset, yOffset);
QPixmap pixmap2(pol.boundingRect().size());
pixmap2.fill(Qt::transparent);
QPainter pt;
pt.begin(&pixmap2);
if (pt.paintEngine()->hasFeature(QPaintEngine::PorterDuff)) {
pt.setRenderHints(QPainter::Antialiasing | QPainter::HighQualityAntialiasing | QPainter::SmoothPixmapTransform, true);
pt.setBrush(Qt::black);
pt.setPen(QPen(QBrush(Qt::black), 0.5));
pt.drawPolygon(translatedPol);
pt.setCompositionMode(QPainter::CompositionMode_SourceIn);
} else {
pt.setClipRegion(QRegion(translatedPol));
pt.setCompositionMode(QPainter::CompositionMode_Source);
}
pt.drawPixmap(pixmap2.rect(), pixmap, pol.boundingRect());
pt.end();
emit freeRegionUpdated(pol);
emit freeRegionGrabbed(pixmap2);
}
}
示例4: paintEvent
void ScopeViewBase::paintEvent( QPaintEvent * event )
{
QRect r = event->rect();
if (b_needRedraw)
{
//CALLGRIND_TOGGLE_COLLECT();
updateOutputHeight();
QPainter p;
m_pixmap->fill( paletteBackgroundColor() );
p.begin(m_pixmap);
p.setClipRegion(event->region());
//let the subclass draw the background (grids, etc.)
drawBackground(p);
// drawProbeMap(p, Oscilloscope::self()->m_logicProbeDataMap);
// drawProbeMap(p, Oscilloscope::self()->m_floatingProbeDataMap);
p.setPen(Qt::black);
p.drawRect( frameRect() );
b_needRedraw = false;
//CALLGRIND_TOGGLE_COLLECT();
}
bitBlt( this, r.x(), r.y(), m_pixmap, r.x(), r.y(), r.width(), r.height() );
}
示例5: drawCurves
void Plotter::drawCurves(QPainter& painter)
{
noOfCurves = curveDataMap.count();
QRect rect = this->printRect();
double x=0,y=0;
double width = rect.width() - 1;
double height = rect.height() - 1;
double yCount = maxY - minY;
if(antiAliasing)
painter.setRenderHints(QPainter::Antialiasing);
painter.setClipRegion(rect);
painter.translate(Margin + 1,rect.bottom()-1);
for(int i=0; i < noOfCurves ; i++)
{
QPolygonF polyline;
QList<double>* dataPtr = curveDataMap[i] ;
for(int j = 0 ; j <= noOfPoints ; j++)
{
x = (width * j)/noOfPoints;
y = (height * (dataPtr->value(j) -minY))/yCount;
polyline << QPoint(x,-y);
//qDebug() << y;
}
painter.setPen(colorMap.value(i));
painter.drawPolyline(polyline);
}
}
示例6: paint_selection
void text_display::paint_selection(QPainter &painter, selection &selection_area, const QColor &color)
{
if(focusPolicy() == Qt::NoFocus){
return; //Anything which doesn't accept focus can't be highlighted
}
QPoint position1 = clip_screen(nibble_to_screen(selection_area.get_start_aligned()));
QPoint position2 = clip_screen(nibble_to_screen(selection_area.get_end_aligned()));
QRegion area = QRect(0, position1.y(), get_line_characters() * editor_font::get_width(),
position2.y() - position1.y() + editor_font::get_height());
if(position1.x()){
area -= QRect(0, position1.y(), position1.x(), editor_font::get_height());
}
if(position2.x() < width()){
area -= QRect(position2.x(), position2.y(),
get_line_characters() * editor_font::get_width() - position2.x(),
editor_font::get_height());
}
if(position2.y() >= get_rows() * editor_font::get_height()){
area -= QRect(0, get_rows() * editor_font::get_height(),
get_line_characters() * editor_font::get_width(), position2.y());
}
painter.setClipRegion(area);
painter.fillRect(0, position1.y(), get_line_characters() * editor_font::get_width(),
position2.y() - position1.y() + editor_font::get_height(), color);
}
示例7: setClipRegion
/**
* Set the clip region for specified painter. The clip region is the widget
* portion in which we can draw. For a plot, is the region of the widget that
* stay inside the padding area.
*
* @param[inout] painter Painter for which clip region must be specified.
* @param[in] plot Plot.
*/
void Graph::setClipRegion(QPainter &painter, Plot2D *plot) {
QPoint upperLeftCorner = plot->scalePoint(plot->getUpperLeftCorner()).toPoint();
QPoint lowerRightCorner = plot->scalePoint(plot->getLowerRightCorner()).toPoint();
upperLeftCorner.setY(plot->height() - lowerRightCorner.y());
lowerRightCorner.setX(plot->width() - upperLeftCorner.x());
QRegion clipRegion(QRect(upperLeftCorner, lowerRightCorner));
painter.setClipRegion(clipRegion);
}
示例8: drawMarker
void MapWidget::drawMarker(const MapMarker &marker, QPainter &painter, const QPointF &markerPosition, const QPointF &rectPosition)
{
QRectF markerRect = getMarkerRect(marker, rectPosition);
QColor bgColor = getMarkerTextBackgroundColor();
painter.setBrush(QBrush(bgColor));
// drawing the line connector
painter.setPen(bgColor);
painter.setClipping(true);
painter.setClipRegion(QRegion(rect()).subtracted(markerRect.toRect()));
painter.drawLine(markerRect.center(), markerPosition);
// drawing the transparent background
painter.setClipping(false);
painter.setPen(Qt::NoPen);
painter.drawRect(markerRect);
// drawing the player marker
const static qreal markerSize = 1.6;
painter.setBrush(getMarkerColor());
painter.drawEllipse(markerPosition, markerSize, markerSize);
qreal hOffset = rectPosition.x() + TEXT_MARGIM; // left margin
// draw the player name text
QString playerName = marker.getPlayerName();
painter.setFont(userFont);
QFontMetrics metrics = painter.fontMetrics();
qreal playerNameWidth = metrics.width(playerName);
painter.setPen(getMarkerTextColor());
qreal textY = rectPosition.y() + TEXT_MARGIM + metrics.descent()/2.0;
painter.drawText(hOffset, textY, playerName);
hOffset += playerNameWidth + TEXT_MARGIM * 3;
// draw the player country name
painter.setFont(countryFont);
metrics = painter.fontMetrics();
QColor countryNameColor(getMarkerTextColor());
countryNameColor.setAlpha(180); // country name is drawed using some alpha
painter.setPen(countryNameColor);
QString countryName = marker.getCountryName();
painter.drawText(hOffset, textY, countryName);
hOffset += metrics.width(countryName);
painter.setFont(userFont); //restore the normal font
metrics = painter.fontMetrics();
// draw the player country flag
const QImage &image = marker.getFlag();
qreal imageX = hOffset + TEXT_MARGIM;
qreal imageY = rectPosition.y() - image.height()/2.0;
painter.drawImage(QPointF(imageX, imageY), image);
}
示例9: paintEvent
void TorrentProgressWidget::paintEvent(QPaintEvent* event)
{
QPainter painter;
painter.begin(this);
painter.setRenderHint(QPainter::Antialiasing);
painter.setClipRegion(event->region());
QImage bdraw = m_image.scaled(size());
painter.drawImage(0, 0, bdraw);
painter.end();
}
示例10: paintCameraBorder
void CanvasRenderer::paintCameraBorder(QPainter &painter)
{
for ( int i = 0; i < mObject->getLayerCount(); ++i )
{
Layer* layer = mObject->getLayer( i );
if ( layer->type() == Layer::CAMERA && (i == mLayerIndex || mOptions.nShowAllLayers > 0) && layer->visible() ) {
if ( i == mLayerIndex || mOptions.nShowAllLayers != 1 )
{
painter.setOpacity( 1.0 );
}
else {
painter.setOpacity( 0.8 );
}
QRectF viewRect = painter.viewport();
QRect boundingRect = mViewTransform.inverted().mapRect( viewRect ).toRect();
LayerCamera* cameraLayer = dynamic_cast< LayerCamera* >( layer );
QRect cameraRect = cameraLayer->getViewRect();
painter.setWorldMatrixEnabled( true );
painter.setPen( Qt::NoPen );
painter.setBrush( QColor( 0, 0, 0, 160 ) );
QRegion rg1(boundingRect);
QRegion rg2(cameraRect);
QRegion rg3=rg1.subtracted(rg2);
painter.setClipRegion(rg3);
painter.drawRect( boundingRect );
painter.setClipping(false);
painter.setPen( Qt::black );
painter.setBrush( Qt::NoBrush );
painter.drawRect( cameraRect );
}
}
}
示例11: paint
/*!
\internal
Paints all the dirty regions into \a pixmap.
Returns the regions that have been repainted.
*/
void QWSManagerPrivate::paint(QPaintDevice *paintDevice, const QRegion ®ion)
{
if (dirtyRegions.empty() || !paintDevice || !paintDevice->paintEngine())
return;
QTLWExtra *topextra = managed->d_func()->extra->topextra;
Q_ASSERT(topextra && topextra->backingStore);
QWidgetBackingStore *bs = topextra->backingStore;
const QRect clipRect = managed->rect().translated(bs->topLevelOffset());
QDecoration &dec = QApplication::qwsDecoration();
QWSWindowSurface *surface;
surface = static_cast<QWSWindowSurface*>(bs->windowSurface);
const QRegion clippedRegion = region & surface->clipRegion();
const QRegion surfaceClip = clippedRegion.translated(bs->topLevelOffset());
paintDevice->paintEngine()->setSystemClip(surfaceClip);
QPainter *painter = 0;
const int numDirty = dirtyRegions.size();
for (int i = 0; i < numDirty; ++i) {
int r = dirtyRegions.at(i);
QDecoration::DecorationState state = dirtyStates.at(i);
QRegion clipRegion = dec.region(managed, clipRect, r);
if (!clipRegion.isEmpty()) {
if (!painter) {
painter = new QPainter(paintDevice);
painter->setFont(qApp->font());
painter->translate(bs->topLevelOffset());
}
clipRegion.translate(-bs->topLevelOffset());
painter->setClipRegion(clipRegion);
dec.paint(painter, managed, r, state);
}
}
dirtyRegions.clear();
dirtyStates.clear();
delete painter;
}
示例12: profiler
void
Panner::paintEvent(QPaintEvent *e)
{
Profiler profiler("Panner::paintEvent");
QPaintEvent *e2 = new QPaintEvent(e->region().boundingRect());
QGraphicsView::paintEvent(e2);
QPainter paint;
paint.begin(viewport());
paint.setClipRegion(e->region());
QPainterPath path;
path.addRect(rect());
path.addPolygon(mapFromScene(m_pannedRect));
QColor c(GUIPalette::getColour(GUIPalette::PannerOverlay));
c.setAlpha(80);
paint.setPen(Qt::NoPen);
paint.setBrush(c);
paint.drawPath(path);
paint.setBrush(Qt::NoBrush);
paint.setPen(QPen(GUIPalette::getColour(GUIPalette::PannerOverlay), 0));
paint.drawConvexPolygon(mapFromScene(m_pannedRect));
if (m_pointerVisible && scene()) {
QPoint top = mapFromScene(m_pointerTop);
float height = m_pointerHeight;
if (height == 0.f) height = scene()->height();
QPoint bottom = mapFromScene
(QPointF(m_pointerTop.x(), m_pointerTop.y() + height));
paint.setPen(QPen(GUIPalette::getColour(GUIPalette::Pointer), 2));
paint.drawLine(top, bottom);
}
RG_DEBUG << "draw polygon: " << mapFromScene(m_pannedRect);
paint.end();
emit pannerChanged(m_pannedRect);
}
示例13: drawGrid
void Plotter::drawGrid(QPainter &painter)
{
// noOfCurves = curveDataMap.count();
QRect rect = this->printRect();
//// qDebug() << rect;
//// double x=0,y=0;
double width = rect.width() - 1;
double height = rect.height() - 1;
double yStep;
int div = 50;
if((height/100) >= 5)
{
yStep = height / 100;
div = 100;
}
else
{
yStep = height/ 50;
div = 50;
}
double bottom = rect.bottom();
double right = rect.right();
double xStep = width / 100.0;
painter.setClipRegion(rect);
painter.save();
painter.setPen(QPen(gridColor));
painter.translate(rect.left(),rect.top() + 1);
for( int i = 1 ; i < 100 ; i++)
{
painter.drawLine(xStep*i , 0 , xStep*i ,bottom);
}
for( int i = 1 ; i < div ; i++)
{
painter.drawLine(1 , yStep*i , right ,yStep*i);
}
painter.restore();
}
示例14: repaintScreen
void QDial::repaintScreen( const QRect *cr )
{
QPainter p;
p.begin( this );
bool resetClipping = FALSE;
// calculate clip-region for erasing background
if ( cr ) {
p.setClipRect( *cr );
} else if ( !d->onlyOutside && d->eraseAreaValid ) {
QRegion reg = d->eraseArea;
double a;
reg = reg.subtract( calcArrow( a ) );
p.setClipRegion( reg );
resetClipping = TRUE;
}
QRect br( calcDial() );
p.setPen( NoPen );
// if ( style() == MotifStyle )
// p.setBrush( colorGroup().brush( QColorGroup::Mid ) );
// else {
QBrush b;
if ( colorGroup().brush( QColorGroup::Light ).pixmap() )
b = QBrush( colorGroup().brush( QColorGroup::Light ) );
else
b = QBrush( colorGroup().light(), Dense4Pattern );
p.setBrush( b );
p.setBackgroundMode( OpaqueMode );
// }
QRect te = br;
te.setWidth(te.width()+2);
te.setHeight(te.height()+2);
// erase background of dial
if ( !d->onlyOutside ) {
p.drawEllipse( te );
}
// erase remaining space around the dial
QRegion remaining( 0, 0, width(), height() );
remaining = remaining.subtract( QRegion( te, QRegion::Ellipse ) );
if ( p.hasClipping() )
remaining = remaining.intersect( p.clipRegion() );
erase(remaining);
if ( resetClipping ) {
if ( cr )
p.setClipRect( *cr );
else
p.setClipRect( QRect( 0, 0, width(), height() ) );
}
// draw notches
if ( d->showNotches ) {
calcLines();
p.setPen( colorGroup().foreground() );
p.drawLineSegments( d->lines );
}
// calculate and paint arrow
p.setPen( QPen( colorGroup().dark() ) );
p.drawArc( te, 60 * 16, 180 * 16 );
p.setPen( QPen( colorGroup().light() ) );
p.drawArc( te, 240 * 16, 180 * 16 );
double a;
QPointArray arrow( calcArrow( a ) );
QRect ea( arrow.boundingRect() );
d->eraseArea = ea;
d->eraseAreaValid = TRUE;
p.setPen( NoPen );
p.setBrush( colorGroup().brush( QColorGroup::Button ) );
if ( !d->onlyOutside )
p.drawPolygon( arrow );
a = angle( QPoint( width() / 2, height() / 2 ), arrow[ 0 ] );
p.setBrush( Qt::NoBrush );
// that's still a hack...
if ( a <= 0 || a > 200 ) {
p.setPen( colorGroup().light() );
p.drawLine( arrow[ 2 ], arrow[ 0 ] );
p.drawLine( arrow[ 1 ], arrow[ 2 ] );
p.setPen( colorGroup().dark() );
p.drawLine( arrow[ 0 ], arrow[ 1 ] );
} else if ( a > 0 && a < 45 ) {
p.setPen( colorGroup().light() );
p.drawLine( arrow[ 2 ], arrow[ 0 ] );
p.setPen( colorGroup().dark() );
p.drawLine( arrow[ 1 ], arrow[ 2 ] );
p.drawLine( arrow[ 0 ], arrow[ 1 ] );
} else if ( a >= 45 && a < 135 ) {
p.setPen( colorGroup().dark() );
p.drawLine( arrow[ 2 ], arrow[ 0 ] );
p.drawLine( arrow[ 1 ], arrow[ 2 ] );
p.setPen( colorGroup().light() );
p.drawLine( arrow[ 0 ], arrow[ 1 ] );
//.........这里部分代码省略.........
示例15: paintEvent
void OscilloscopeView::paintEvent( QPaintEvent *e)
{
QRect r = e->rect();
if(b_needRedraw)
{
updateOutputHeight();
const double pixelsPerSecond = Oscilloscope::self()->pixelsPerSecond();
if (!m_pixmap) {
qWarning() << Q_FUNC_INFO << " unexpected null m_pixmap in " << this;
return;
}
QPainter p;
//m_pixmap->fill( paletteBackgroundColor());
m_pixmap->fill( palette().color( backgroundRole() ));
const bool startSuccess = p.begin(m_pixmap);
if ((!startSuccess) || (!p.isActive())) {
qWarning() << Q_FUNC_INFO << " painter is not active";
}
p.setClipRegion(e->region());
//BEGIN Draw vertical marker lines
const double divisions = 5.0;
const double min_sep = 10.0;
double spacing = pixelsPerSecond/(std::pow( divisions, std::floor(std::log(pixelsPerSecond/min_sep)/std::log(divisions))));
// Pixels offset is the number of pixels that the view is scrolled along
const int64_t pixelsOffset = int64_t(Oscilloscope::self()->scrollTime()*pixelsPerSecond/LOGIC_UPDATE_RATE);
double linesOffset = - lld_modulus( pixelsOffset, spacing);
int blackness = 256 - int(184.0 * spacing / (min_sep*divisions*divisions));
p.setPen( QColor( blackness, blackness, blackness));
for( double i = linesOffset; i <= frameRect().width(); i += spacing)
p.drawLine( int(i), 1, int(i), frameRect().height()-2);
spacing *= divisions;
linesOffset = - lld_modulus( pixelsOffset, spacing);
blackness = 256 - int(184.0 * spacing / (min_sep*divisions*divisions));
p.setPen( QColor( blackness, blackness, blackness));
for( double i = linesOffset; i <= frameRect().width(); i += spacing)
p.drawLine( int(i), 1, int(i), frameRect().height()-2);
spacing *= divisions;
linesOffset = - lld_modulus( pixelsOffset, spacing);
blackness = 256 - int(184.0);
p.setPen( QColor( blackness, blackness, blackness));
for( double i = linesOffset; i <= frameRect().width(); i += spacing)
p.drawLine( int(i), 1, int(i), frameRect().height()-2);
//END Draw vertical marker lines
drawLogicData(p);
drawFloatingData(p);
p.setPen(Qt::black);
p.drawRect( frameRect());
b_needRedraw = false;
}
//bitBlt( this, r.x(), r.y(), m_pixmap, r.x(), r.y(), r.width(), r.height()); // 2018.12.07
QPainter p;
const bool paintStarted = p.begin(this);
if (!paintStarted) {
qWarning() << Q_FUNC_INFO << " failed to start painting ";
}
p.drawImage(r, m_pixmap->toImage(), r);
}