本文整理汇总了C++中QPainter::setRasterOp方法的典型用法代码示例。如果您正苦于以下问题:C++ QPainter::setRasterOp方法的具体用法?C++ QPainter::setRasterOp怎么用?C++ QPainter::setRasterOp使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QPainter
的用法示例。
在下文中一共展示了QPainter::setRasterOp方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: paintEvent
void WGraphFrame::paintEvent(QPaintEvent *e) {
QPainter p;
p.begin(this);
drawFrame(&p);
p.end();
emit aboutToDraw();
if (paintPixmap.size()!=contentsRect().size())
paintPixmap.resize(contentsRect().size());
if (p.begin(&paintPixmap,this)) {
p.setRasterOp(XorROP);
if (oldZoomRect.normalize().isValid()) {
p.setPen(zoomRectPen);
p.drawRect(oldZoomRect);
}
p.setRasterOp(CopyROP);
parent->drawContent(p, e->erased() || needsRedraw);
needsRedraw=false;
drawGrid(p);
p.setRasterOp(XorROP);
if (zoomRect.normalize().isValid()) {
p.setPen(zoomRectPen);
p.drawRect(zoomRect);
}
oldZoomRect=zoomRect;
p.end();
bitBlt(this,contentsRect().topLeft(),&paintPixmap);
}
}
示例2: mouseReleaseEvent
void AreaSelect::mouseReleaseEvent(QMouseEvent *e)
{
int x,y;
QPainter paint;
QWMatrix m;
KDEBUG(KDEBUG_INFO, 3000, "AreaSelect::mouseReleaseEvent() handler called\n");
if (isActive() && (e->button() == LeftButton)) {
x= (e->pos()).x();
y= (e->pos()).y();
// Erase old line
paint.begin(canvas->zoomedPixmap());
paint.setPen(QPen(green, 0, DashLine));
paint.setRasterOp(DEFAULT_RASTER_OP);
paint.drawRect(startx, starty, lastx-startx, lasty-starty);
paint.end();
m.scale((float) 100/(canvas->zoom()), (float) 100/(canvas->zoom()));
paint.begin(canvas->pixmap());
// paint.setPen(pen);
paint.setWorldMatrix(m);
paint.setRasterOp(CopyROP);
canvas->setSelection(QRect(startx, starty, x-startx, y-starty));
paint.end();
drawing= FALSE;
canvas->updateZoomed();
canvas->repaint(0);
startTimer(TIMER_INTERVALL);
showedSF= false;
}
else {
KDEBUG(KDEBUG_WARN, 3000, "Warning event received when inactive (ignoring)\n");
}
}
示例3: draw
void KviCanvasPolygon::draw(QPainter &p)
{
if(isEnabled())
{
p.setBrush(brush());
p.setPen(pen());
p.drawPolygon(areaPoints());
}
if(isSelected())
{
p.setRasterOp(NotROP);
p.setPen(QPen(DotLine));
p.drawPolygon(areaPoints());
p.setBrush(QBrush());
double dVal = 10;
p.drawEllipse((int)(x() - dVal),(int)(y() - dVal),(int)(dVal * 2),(int)(dVal * 2));
p.drawLine((int)(x() - (dVal * 2)),(int)y(),(int)(x() + (dVal * 2)),(int)y());
p.drawLine((int)x(),(int)(y() - (dVal * 2)),(int)x(),(int)(y() + (dVal * 2)));
p.setRasterOp(CopyROP);
canvas()->setChanged(QRect((int)(x() - dVal),(int)(y() - dVal),(int)(dVal * 4),(int)(dVal * 4)));
}
}
示例4: eraseTheLastDrawnLine
void ClusterView::eraseTheLastDrawnLine(QColor polygonColor){
//Paint in the buffer to allow the selection to be redrawn after a refresh
QPainter painter;
painter.begin(&doublebuffer);
//set the window (part of the word I want to show)
QRect r((QRect)window);
painter.setWindow(r.left(),r.top(),r.width()-1,r.height()-1);//hack because Qt QRect is used differently in this function
painter.setRasterOp(XorROP);
painter.setPen(polygonColor);
//The user did not move since the last left click (no mouseMoveEvent)
if(nbSelectionPoints == selectionPolygon.size()){
//Treat the case when we reach the first point of the selection
if(nbSelectionPoints == 1){
//Resize selectionPolygon to remove the point from selectionPolygon
selectionPolygon.resize(0);
nbSelectionPoints = 0;
}
else{
//Erase the last line drawn
painter.drawPolyline(selectionPolygon,selectionPolygon.size()-2);
//Resize selectionPolygon to remove the last point from selectionPolygon
selectionPolygon.resize(selectionPolygon.size()-1);
nbSelectionPoints = selectionPolygon.size();
}
}
//The user moved since the last left click, a line has been drawn in the mouseMoveEvent
else{
//Treat the case when we reach the first point of the selection
if(nbSelectionPoints == 1){
//Erase the last line drawn (in mouseMoveEvent).
painter.drawPolyline(selectionPolygon,selectionPolygon.size()-2);
}
else{
//CAUTION, Do not remove this line otherwise strang dots will appear
painter.drawPoint(selectionPolygon.point(selectionPolygon.size()-2));
//Erase the last line drawn (in mouseMoveEvent) plus the line between the 2 last selected points
//(selected by a left click of the user)
painter.drawPolyline(selectionPolygon,selectionPolygon.size()-3);
}
//Resize selectionPolygon to remove the 2 last points
//(the last selected and the one set in mouseMoveEvent) from selectionPolygon
selectionPolygon.resize(selectionPolygon.size()-2);
nbSelectionPoints = selectionPolygon.size();
}
painter.end();
}
示例5: drawOutline
/*!
draw an outline
\warning Outlining functionality is obsolete: use QwtPlotPicker or
QwtPlotZoomer.
*/
void QwtPlotCanvas::drawOutline(QPainter &p)
{
const QRect &r = contentsRect();
QColor bg = ((QwtPlot *)parent())->canvasBackground();
QPen pn = d_pen;
pn.setColor(QColor(bg.rgb() ^ d_pen.color().rgb()));
p.setPen(pn);
p.setRasterOp(XorROP);
p.setClipRect(r);
p.setClipping(TRUE);
switch(d_outline)
{
case Qwt::VLine:
QwtPainter::drawLine(&p, d_lastPoint.x(),
r.top(), d_lastPoint.x(), r.bottom());
break;
case Qwt::HLine:
QwtPainter::drawLine(&p, r.left(),
d_lastPoint.y(), r.right(), d_lastPoint.y());
break;
case Qwt::Cross:
QwtPainter::drawLine(&p, r.left(),
d_lastPoint.y(), r.right(), d_lastPoint.y());
QwtPainter::drawLine(&p, d_lastPoint.x(),
r.top(), d_lastPoint.x(), r.bottom());
break;
case Qwt::Rect:
QwtPainter::drawRect(&p, d_entryPoint.x(), d_entryPoint.y(),
d_lastPoint.x() - d_entryPoint.x() + 1,
d_lastPoint.y() - d_entryPoint.y() + 1);
break;
case Qwt::Ellipse:
p.drawEllipse(d_entryPoint.x(), d_entryPoint.y(),
d_lastPoint.x() - d_entryPoint.x() + 1,
d_lastPoint.y() - d_entryPoint.y() + 1);
break;
default:
break;
}
}
示例6: pressMove
void KstGfxEllipseMouseHandler::pressMove(KstTopLevelViewPtr view, const QPoint& pos, bool shift, const QRect& geom) {
if (_cancelled || !_mouseDown) {
return;
}
QRect old = _prevBand;
_prevBand = KstGfxMouseHandlerUtils::newRectCentered(pos, _mouseOrigin, geom, shift);
if (old != _prevBand) {
QPainter p;
p.begin(view->widget());
p.setPen(QPen(Qt::black, 0, Qt::SolidLine));
p.setRasterOp(Qt::NotROP);
if (old.topLeft() != QPoint(-1, -1)) {
p.drawEllipse(old);
}
p.drawEllipse(_prevBand);
p.end();
}
}
示例7: resetSelectionPolygon
void ClusterView::resetSelectionPolygon(){
if(selectionPolygon.size()>0){
//Erase the existing polygon
//Select the appropriate color
QColor color = selectPolygonColor(mode);
//if the polygon was closed, erase the closing line
if(polygonClosed){
QPainter painter;
painter.begin(&doublebuffer);
//set the window (part of the word I want to show)
QRect r((QRect)window);
painter.setWindow(r.left(),r.top(),r.width()-1,r.height()-1);//hack because Qt QRect is used differently in this function
painter.setRasterOp(XorROP);
painter.setPen(color);
//Erase the closing line
painter.drawLine(selectionPolygon.point(0),selectionPolygon.point(selectionPolygon.size()-1));
if(existLastMovingLine)painter.drawPoint(selectionPolygon.point(selectionPolygon.size()-1));
//reset existLastMovingLine
existLastMovingLine = false;
painter.end();
polygonClosed = false;
}
while(selectionPolygon.size()>0) eraseTheLastDrawnLine(color);
//Reset the variables associates with the polygon
//Resize selectionPolygon to remove all the last selected area, reinitialize nbSelectionPoints accordingly
selectionPolygon.resize(0);
nbSelectionPoints = 0;
}
}
示例8: mouseMoveEvent
void Line::mouseMoveEvent(QMouseEvent *e)
{
int x,y;
QPainter paint;
if (isActive()) {
x= (e->pos()).x();
y= (e->pos()).y();
if ((lastx != x) || (lasty != y)) {
if (drawing) {
paint.begin(canvas->zoomedPixmap());
if (activeButton == LeftButton)
paint.setPen(leftpen);
else
paint.setPen(rightpen);
paint.setRasterOp(DEFAULT_RASTER_OP);
// Draw new line
paint.drawLine(startx, starty, x, y);
// Erase old line
paint.drawLine(startx, starty, lastx, lasty);
lastx= x;
lasty= y;
paint.end();
canvas->repaint(0);
}
}
}
else {
KDEBUG(KDEBUG_WARN, 3000, "Line: Warning event received when inactive (ignoring)\n");
}
}
示例9: mouseMoveEvent
void ClusterView::mouseMoveEvent(QMouseEvent* e){
//Write the current coordinates in the statusbar.
QPoint current = viewportToWorld(e->x(),e->y());
if(dimensionX == timeDimension){
int timeInS = static_cast<int>(current.x() * samplingInterval / static_cast<double>(1000000));
statusBar->changeItem("Coordinates: (" + QString("%1").arg(timeInS) + ", " + QString("%1").arg(-current.y()) + ")",1);
}
else if(dimensionY == timeDimension){
int timeInS = static_cast<int>(current.y() * samplingInterval / static_cast<double>(1000000));
statusBar->changeItem("Coordinates: (" + QString("%1").arg(current.x()) + ", " + QString("%1").arg(-timeInS) + ")",1);
}
else statusBar->changeItem("Coordinates: (" + QString("%1").arg(current.x()) + ", " + QString("%1").arg(-current.y()) + ")",1);
//The parent implementation takes care of the rubber band
ViewWidget::mouseMoveEvent(e);
//If the user is closing the polygon do not take mousemove event into account
if(!polygonClosed){
//In one of the selection modes we draw the tracking line
if(mode == DELETE_NOISE || mode == DELETE_ARTEFACT || mode == NEW_CLUSTER || mode == NEW_CLUSTERS){
//Select the appropriate color
QColor color = selectPolygonColor(mode);
//If there is no selection point, do not draw a tracking line
if(selectionPolygon.size() == 0) return;
//Paint in the buffer to allow the selection to be redrawn after a refresh
QPainter painter;
painter.begin(&doublebuffer);
//set the window (part of the word I want to show)
QRect r((QRect)window);
painter.setWindow(r.left(),r.top(),r.width()-1,r.height()-1);//hack because Qt QRect is used differently in this function
painter.setRasterOp(XorROP);
painter.setPen(color);
//First mouseMoveEvent after the last mousePressEvent
if(nbSelectionPoints == selectionPolygon.size()){
//Add the current point to the array
selectionPolygon.putPoints(selectionPolygon.size(), 1, current.x(),current.y());
painter.drawPolyline(selectionPolygon,selectionPolygon.size()-2);
}
else{
//Erase the previous drawn line
painter.drawPolyline(selectionPolygon,selectionPolygon.size()-2);
//Replace the last point by the current one
selectionPolygon.setPoint(selectionPolygon.size()-1,current);
//Draw the new line
painter.drawPolyline(selectionPolygon,selectionPolygon.size()-2);
}
painter.end();
//Draw the new doublebuffer onto the widget
QPainter p(this);
p.drawPixmap(0, 0, doublebuffer);
}
}
}
示例10: mousePressEvent
void ClusterView::mousePressEvent(QMouseEvent* e){
//Defining a time window t oupdate the Traceview
if(mode == SELECT_TIME){
QPoint current = viewportToWorld(e->x(),e->y());
if(dimensionX == timeDimension){
dataType time = static_cast<dataType>(current.x() * samplingInterval / static_cast<double>(1000));
emit moveToTime(time);
}
else if(dimensionY == timeDimension){
dataType time = -static_cast<dataType>(current.y() * samplingInterval / static_cast<double>(1000));
emit moveToTime(time);
}
}
//The parent implementation takes care of the mode ZOOM
//(rubber band and calculation of the firstClick)
ViewWidget::mousePressEvent(e);
//If there is a polygon to draw (one of the selection modes)
if(mode == DELETE_NOISE || mode == DELETE_ARTEFACT || mode == NEW_CLUSTER || mode == NEW_CLUSTERS){
//Select the appropriate color
QColor color = selectPolygonColor(mode);
//Erase the last line drawn
if(e->button() == QMouseEvent::RightButton){
if(selectionPolygon.size() == 0) return;
//Erase the last drawn line by drawing into the buffer
eraseTheLastDrawnLine(color);
//Draw the new doublebuffer onto the widget
QPainter p(this);
p.drawPixmap(0, 0, doublebuffer);
}
//Close the polygon of selection and trigger the right action depending on the mode
if(e->button() == QMouseEvent::MidButton && selectionPolygon.size()>0){
QRegion selectionArea;
//Paint into the buffer to allow the selection to be redrawn after a refresh
QPainter painter;
painter.begin(&doublebuffer);
//set the window (part of the word I want to show)
QRect r((QRect)window);
painter.setWindow(r.left(),r.top(),r.width()-1,r.height()-1);//hack because Qt QRect is used differently in this function
painter.setPen(color);
//If, once the last moving line erase, the polygon exists and has at least 3 points, draw it
if(selectionPolygon.size()>2){
//erase the last line drawn if the user moved since the last click
eraseTheLastMovingLine(color);
//Draw the closing line of the polygon
painter.setRasterOp(XorROP);
painter.drawLine(selectionPolygon.point(0),selectionPolygon.point(selectionPolygon.size()-1));
polygonClosed = true;
//Send an event to inform that the data have to be recompute accordingly to the selection polygon.
//This asynchronous event will allow the widget to close the polygon
//before asking the document to compute the data.
ComputeEvent* event = getComputeEvent(selectionPolygon.copy());
QApplication::postEvent(this,event);
}
//reset the polygon
else resetSelectionPolygon();
painter.end();
//Draw the new doublebuffer onto the widget (show the closed polygon)
QPainter p(this);
p.drawPixmap(0, 0, doublebuffer);
statusBar->clear();
}
if (e->button() == QMouseEvent::LeftButton){
QPoint selectedPoint = viewportToWorld(e->x(),e->y());
if(nbSelectionPoints == 0) selectionPolygon.putPoints(0, 1, selectedPoint.x(),selectedPoint.y());
//If the array is not empty, the last point has been put into the array in mouseMoveEvent
nbSelectionPoints = selectionPolygon.size();
}
}
}
示例11: drawContent
void WSpacePlot::drawContent(QPainter &p,bool) {
QBrush brush;
QColor color;
int hue, selectHue, s, v;
paintColor.getHsv(hue,s,v);
colorGroup().highlight().getHsv(selectHue,s,v);
QArray<SpaceCell>::Iterator it;
QArray<SpaceCell>::Iterator end=cellData.end();
if (drawGrid) {
p.eraseRect(p.window());
for (it=cellData.begin(); it!=end; ++it) {
if (it->attr & selected) {
p.fillRect(it->rect,colorGroup().highlight());
p.setPen(colorGroup().highlight().light());
} else p.setPen(colorGroup().mid());
p.drawRect(it->rect);
}
} else {
p.setBackgroundMode(OpaqueMode);
p.setBackgroundColor(QColor(64,64,64));
p.fillRect(p.window(),QBrush(black,Dense6Pattern));
for (it=cellData.begin(); it!=end; ++it)
if (it->visible)
if (it->attr&normal) {
float val=clampf(dataRange.scaleValue(it->data));
if (finite(val)) {
if (it->attr & selected)
color.setHsv(selectHue,128,int((0.5+0.5*val)*255));
else
color.setHsv(hue,255,int(val*255));
p.fillRect(it->rect,color);
if (it->attr&marked) {
if (it->attr&selected)
color.setHsv(hue,255,int(val*255));
else
color.setHsv(selectHue,128,int((0.5+0.5*val)*255));
p.setPen(color);
p.drawRect(it->rect);
}
} else
p.fillRect(it->rect,QBrush(paintColor,DiagCrossPattern));
}
}
if (hasFocus() && QRect(QPoint(0,0),viewSize).contains(currCell)) {
p.setRasterOp(XorROP);
p.setPen(white);
p.drawRect(cellData[currCell.x()+currCell.y()*viewSize.width()].rect);
p.setRasterOp(CopyROP);
}
if (!cellLabelRect.isEmpty()) {
p.setBackgroundMode(TransparentMode);
p.setPen(QToolTip::palette().active().text());
p.fillRect(cellLabelRect,QToolTip::palette().active().background());
p.drawRect(cellLabelRect);
p.drawText(cellLabelRect,AlignCenter,cellLabelString);
}
}
示例12: drawTemporaryShape
void RectangleTool::drawTemporaryShape(QPainter& p)
{
p.setRasterOp(Qt::NotROP);
p.drawRect(QRect(m_polyline[2], m_polyline[1]));
p.drawRect(QRect(m_polyline[2], m_polyline[0]));
}
示例13: userResize
//.........这里部分代码省略.........
// ### check the resize is not going out of bounds.
if(m_resizing && evt->id() == EventImpl::MOUSEUP_EVENT)
{
setResizing(false);
KApplication::restoreOverrideCursor();
if(m_vSplit != -1 )
{
#ifdef DEBUG_LAYOUT
kdDebug( 6031 ) << "split xpos=" << _x << endl;
#endif
int delta = m_vSplitPos - _x;
m_gridDelta[1][m_vSplit] -= delta;
m_gridDelta[1][m_vSplit+1] += delta;
}
if(m_hSplit != -1 )
{
#ifdef DEBUG_LAYOUT
kdDebug( 6031 ) << "split ypos=" << _y << endl;
#endif
int delta = m_hSplitPos - _y;
m_gridDelta[0][m_hSplit] -= delta;
m_gridDelta[0][m_hSplit+1] += delta;
}
// this just schedules the relayout
// important, otherwise the moving indicator is not correctly erased
setNeedsLayout(true);
}
else if (m_resizing || evt->id() == EventImpl::MOUSEUP_EVENT) {
#if APPLE_CHANGES
KHTMLView *v = canvas()->view();
QPainter paint;
v->disableFlushDrawing();
v->lockDrawingFocus();
#else
QPainter paint( canvas()->view() );
#endif
paint.setPen( Qt::gray );
paint.setBrush( Qt::gray );
#if !APPLE_CHANGES
paint.setRasterOp( Qt::XorROP );
#endif
QRect r(xPos(), yPos(), width(), height());
const int rBord = 3;
int sw = element()->border();
int p = m_resizing ? (m_vSplit > -1 ? _x : _y) : -1;
if (m_vSplit > -1) {
if ( m_oldpos >= 0 )
#if APPLE_CHANGES
v->updateContents( m_oldpos + sw/2 - rBord , r.y(), 2*rBord, r.height(), true );
#else
paint.drawRect( m_oldpos + sw/2 - rBord , r.y(),
2*rBord, r.height() );
#endif
if ( p >= 0 ){
#if APPLE_CHANGES
paint.setPen( Qt::NoPen );
paint.setBrush( Qt::gray );
v->setDrawingAlpha((float)0.25);
paint.drawRect( p + sw/2 - rBord, r.y(), 2*rBord, r.height() );
v->setDrawingAlpha((float)1.0);
#else
paint.drawRect( p + sw/2 - rBord, r.y(), 2*rBord, r.height() );
#endif
}
} else {
if ( m_oldpos >= 0 )
#if APPLE_CHANGES
v->updateContents( r.x(), m_oldpos + sw/2 - rBord, r.width(), 2*rBord, true );
#else
paint.drawRect( r.x(), m_oldpos + sw/2 - rBord,
r.width(), 2*rBord );
#endif
if ( p >= 0 ){
#if APPLE_CHANGES
paint.setPen( Qt::NoPen );
paint.setBrush( Qt::gray );
v->setDrawingAlpha((float)0.25);
paint.drawRect( r.x(), p + sw/2 - rBord, r.width(), 2*rBord );
v->setDrawingAlpha((float)1.0);
#else
paint.drawRect( r.x(), p + sw/2 - rBord, r.width(), 2*rBord );
#endif
}
}
m_oldpos = p;
#if APPLE_CHANGES
v->unlockDrawingFocus();
v->enableFlushDrawing();
#endif
}
return res;
}