// // The clock is painted using a 1000x1000 square coordinate system, in // the a centered square, as big as possible. The painter's pen and // brush colors are used. // void QTodoClock::drawClock( QPainter *paint ) { paint->save(); paint->setWindow( -500,-500, 1000,1000 ); QRect v = paint->viewport(); int d = QMIN( v.width(), v.height() ); paint->setViewport( v.left() + (v.width()-d)/2, v.top() + (v.height()-d)/2, d, d ); QPointArray pts; paint->save(); paint->rotate( 30*(time.hour()%12-3) + time.minute()/2 ); pts.setPoints( 4, -20,0, 0,-20, 300,0, 0,20 ); paint->drawConvexPolygon( pts ); paint->restore(); paint->save(); paint->rotate( (time.minute()-15)*6 ); pts.setPoints( 4, -10,0, 0,-10, 400,0, 0,10 ); paint->drawConvexPolygon( pts ); paint->restore(); for ( int i=0; i<12; i++ ) { paint->drawLine( 440,0, 460,0 ); paint->rotate( 30 ); } paint->restore(); }
void QWindowsStyle::drawArrow( QPainter *p, ArrowType type, bool down, int x, int y, int w, int h, const QColorGroup &g, bool enabled, const QBrush *fill ) { QPointArray a; // arrow polygon switch ( type ) { case UpArrow: a.setPoints( 7, -4,1, 2,1, -3,0, 1,0, -2,-1, 0,-1, -1,-2 ); break; case DownArrow: a.setPoints( 7, -4,-2, 2,-2, -3,-1, 1,-1, -2,0, 0,0, -1,1 ); break; case LeftArrow: a.setPoints( 7, 1,-3, 1,3, 0,-2, 0,2, -1,-1, -1,1, -2,0 ); break; case RightArrow: a.setPoints( 7, -1,-3, -1,3, 0,-2, 0,2, 1,-1, 1,1, 2,0 ); break; } if ( a.isNull() ) return; if ( down ) { x++; y++; } QPen savePen = p->pen(); // save current pen if (down) p->setBrushOrigin(p->brushOrigin() + QPoint(1,1)); if ( fill ) p->fillRect( x, y, w, h, *fill ); if (down) p->setBrushOrigin(p->brushOrigin() - QPoint(1,1)); if ( enabled ) { a.translate( x+w/2, y+h/2 ); p->setPen( g.buttonText() ); p->drawLineSegments( a, 0, 3 ); // draw arrow p->drawPoint( a[6] ); } else { a.translate( x+w/2+1, y+h/2+1 ); p->setPen( g.light() ); p->drawLineSegments( a, 0, 3 ); // draw arrow p->drawPoint( a[6] ); a.translate( -1, -1 ); p->setPen( g.mid() ); p->drawLineSegments( a, 0, 3 ); // draw arrow p->drawPoint( a[6] ); } p->setPen( savePen ); // restore pen }
static void qDrawWinArrow( QPainter *p, Qt::ArrowType type, bool down, int x, int y, int w, int h, const QColorGroup &g, bool enabled ) { QPointArray a; // arrow polygon switch ( type ) { case Qt::UpArrow: a.setPoints( 7, -3,1, 3,1, -2,0, 2,0, -1,-1, 1,-1, 0,-2 ); break; case Qt::DownArrow: a.setPoints( 7, -3,-1, 3,-1, -2,0, 2,0, -1,1, 1,1, 0,2 ); break; case Qt::LeftArrow: a.setPoints( 7, 1,-3, 1,3, 0,-2, 0,2, -1,-1, -1,1, -2,0 ); break; case Qt::RightArrow: a.setPoints( 7, -1,-3, -1,3, 0,-2, 0,2, 1,-1, 1,1, 2,0 ); break; } if ( a.isNull() ) return; if ( down ) { x++; y++; } QPen savePen = p->pen(); // save current pen if (down) p->setBrushOrigin(p->brushOrigin() + QPoint(1,1)); p->fillRect( x, y, w, h, g.brush( QColorGroup::Button ) ); if (down) p->setBrushOrigin(p->brushOrigin() - QPoint(1,1)); if ( enabled ) { a.translate( x+w/2, y+h/2 ); p->setPen( g.foreground() ); p->drawLineSegments( a, 0, 3 ); // draw arrow p->drawPoint( a[6] ); } else { a.translate( x+w/2+1, y+h/2+1 ); p->setPen( g.light() ); p->drawLineSegments( a, 0, 3 ); // draw arrow p->drawPoint( a[6] ); a.translate( -1, -1 ); p->setPen( g.mid() ); p->drawLineSegments( a, 0, 3 ); // draw arrow p->drawPoint( a[6] ); } p->setPen( savePen ); // restore pen }
void paintCar( QPainter *p ) // paint a car { QPointArray a; QBrush brush( Qt::yellow, Qt::SolidPattern ); p->setBrush( brush ); // use solid, yellow brush a.setPoints( 5, 50,50, 350,50, 450,120, 450,250, 50,250 ); p->drawPolygon( a ); // draw car body QFont f( "courier", 12, QFont::Bold ); p->setFont( f ); QColor windowColor( 120, 120, 255 ); // a light blue color brush.setColor( windowColor ); // set this brush color p->setBrush( brush ); // set brush p->drawRect( 80, 80, 250, 70 ); // car window p->drawText( 180, 80, 150, 70, Qt::AlignCenter, "-- Qt --\nTrolltech AS" ); QPixmap pixmap; if ( pixmap.load("flag.bmp") ) // load and draw image p->drawPixmap( 100, 85, pixmap ); p->setBackgroundMode( Qt::OpaqueMode ); // set opaque mode p->setBrush( Qt::DiagCrossPattern ); // black diagonal cross pattern p->drawEllipse( 90, 210, 80, 80 ); // back wheel p->setBrush( Qt::CrossPattern ); // black cross fill pattern p->drawEllipse( 310, 210, 80, 80 ); // front wheel }
void AnalogClock::paintEvent( QPaintEvent * ) // paint clock { if ( !isVisible() ) // is is invisible return; time = QTime::currentTime(); // save current time QPointArray pts; QPainter paint( this ); paint.setBrush( foregroundColor() ); // fill with foreground color QPoint cp = rect().center(); // widget center point int d = QMIN(width(),height()); // we want a circular clock QWMatrix matrix; // setup transformation matrix matrix.translate( cp.x(), cp.y() ); // origin at widget center matrix.scale( d/1000.0F, d/1000.0F ); // scale coordinate system float h_angle = 30*(time.hour()%12-3) + time.minute()/2; matrix.rotate( h_angle ); // rotate to draw hour hand paint.setWorldMatrix( matrix ); pts.setPoints( 4, -20,0, 0,-20, 300,0, 0,20 ); paint.drawPolygon( pts ); // draw hour hand matrix.rotate( -h_angle ); // rotate back to zero float m_angle = (time.minute()-15)*6; matrix.rotate( m_angle ); // rotate to draw minute hand paint.setWorldMatrix( matrix ); pts.setPoints( 4, -10,0, 0,-10, 400,0, 0,10 ); paint.drawPolygon( pts ); // draw minute hand matrix.rotate( -m_angle ); // rotate back to zero for ( int i=0; i<12; i++ ) { // draw hour lines paint.setWorldMatrix( matrix ); paint.drawLine( 450,0, 500,0 ); matrix.rotate( 30 ); } }
/*! Paints the resize grip - small diagonal textured lines in the lower right-hand corner. */ void QSizeGrip::paintEvent( QPaintEvent *e ) { QPainter painter( this ); painter.setClipRegion(e->region()); painter.translate( width()-13, height()-13 ); // paint in the corner QPointArray a; a.setPoints( 3, 1,12, 12,1, 12,12 ); painter.setPen( QPen( colorGroup().dark(), 1 ) ); painter.setBrush( colorGroup().dark() ); painter.drawPolygon( a ); painter.setPen( QPen( colorGroup().light(), 1 ) ); painter.drawLine( 0, 12, 13, -1 ); painter.drawLine( 4, 12, 13, 3 ); painter.drawLine( 8, 12, 13, 7 ); painter.setPen( QPen( colorGroup().background(), 1 ) ); painter.drawLine( 3, 12, 13, 2 ); painter.drawLine( 7, 12, 13, 6 ); painter.drawLine( 11, 12, 13, 10 ); painter.drawLine( 12, 12, 13, 11 ); }
void BW_LED_Number::drawSegment( const QPoint &pos, char seg_number, QPainter &p, int Segment_Length, bool erase){ QPoint pt = pos; QColorGroup g = colorGroup(); QColor lightColor,darkColor; if ( erase ){ lightColor = offcolor; darkColor = offcolor; } else { lightColor = g.light(); darkColor = g.dark(); } // int Width = (int) Segment_Length/5 ; // original int Width = (int) Segment_Length/4; QBrush brush(g.light()); QPointArray pts; pt.ry() += (QCOORD)Width/2; if (erase){ p.setBrush(offcolor); brush.setColor(offcolor); } else p.setBrush(g.light()); if(!smallLED){ switch ( seg_number ) { case 0 : if (erase) p.setPen(offcolor); pts.setPoints(3,pt.x(), pt.y() , pt.x(), pt.y()-Width +1, pt.x() + Width-1, pt.y()); p.drawPolygon(pts); pts.setPoints(3,pt.x(), pt.y() + Segment_Length -Width - Width/2 -1 , pt.x() + Width -1 , pt.y() -Width +Segment_Length - Width/2 -1, pt.x() , pt.y() + Segment_Length - 3*Width/4 -1); p.drawPolygon(pts); if (erase) p.setPen(g.light()); p.fillRect(pt.x(),pt.y()+ Width/2 -1, Width , Segment_Length - Width -Width +1 ,brush); break; case 1 : p.fillRect(pt.x()+Width,pt.y()- Width , Segment_Length -2* Width, Width ,brush); if (erase) p.setPen(offcolor); pts.setPoints(3,pt.x()+1, pt.y()-Width , pt.x()+Width, pt.y()-Width , pt.x() + Width, pt.y() -1 ); p.drawPolygon(pts); pts.setPoints(3,pt.x()+ Segment_Length - Width , pt.y() - Width, pt.x()+ Segment_Length -1, pt.y() - Width, pt.x() + Segment_Length - Width , pt.y() -1 ); p.drawPolygon(pts); if (erase) p.setPen(g.light()); break; case 2 : pt.rx() += (QCOORD)(Segment_Length); if (erase) p.setPen(offcolor); pts.setPoints(3,pt.x() , pt.y() , pt.x() , pt.y() - Width + 1, // changes from 1 to 2 pt.x() - Width +1, pt.y() ); p.drawPolygon(pts); pts.setPoints(3,pt.x() , pt.y() + Segment_Length - Width - Width/2 -1, pt.x() , pt.y() + Segment_Length - 3*Width/4 - 1, pt.x() - Width +1, pt.y() + Segment_Length - Width - Width/2 -1); p.drawPolygon(pts); if (erase) p.setPen(g.light()); p.fillRect(pt.x() - Width+1 ,pt.y() + Width/2- 1, Width , Segment_Length - Width - Width + 1 ,brush); break; case 3 : pt.ry() += (QCOORD)Segment_Length; p.setPen(g.background()); pts.setPoints(3,pt.x()-1 , pt.y() - Width/2 -1, pt.x() + Width+2, pt.y()-Width -1 ,// pt.x() + Width+2, pt.y() ); p.drawPolygon(pts); pts.setPoints(3,pt.x() + Segment_Length + 1, pt.y() - Width/2 -1 , pt.x() + Segment_Length - Width - 2 , pt.y() - Width -1, pt.x() + Segment_Length - Width - 2, pt.y() ); p.drawPolygon(pts); p.setPen(g.light()); p.fillRect(pt.x() + Width -1 ,pt.y() - Width, Segment_Length- 2* Width + 3, Width ,brush); break; case 4 : pt.ry() += (QCOORD)(Segment_Length +1); p.fillRect(pt.x(), pt.y(), Width , Segment_Length - Width - Width/2 ,brush); if (erase) p.setPen(offcolor); pts.setPoints(3,pt.x(), pt.y(), pt.x(), pt.y()-Width+1, pt.x() + Width-1, pt.y()); p.drawPolygon(pts); pts.setPoints(3,pt.x(), pt.y() + Segment_Length -Width - Width/2 -1 , pt.x() + Width -1 , pt.y() -Width +Segment_Length - Width/2 -1 , pt.x() , pt.y() + Segment_Length - 3*Width/4 -1); p.drawPolygon(pts); if (erase) p.setPen(g.light()); break; case 5 : pt.rx() += (QCOORD)(Segment_Length ); pt.ry() += (QCOORD)(Segment_Length +1); p.fillRect(pt.x() - Width +1 ,pt.y(), Width , Segment_Length - Width - Width/2 ,brush); if (erase) p.setPen(offcolor); pts.setPoints(3,pt.x() , pt.y(), pt.x() , pt.y() - Width +1, pt.x() - Width +1, pt.y()); p.drawPolygon(pts); pts.setPoints(3,pt.x() , pt.y() + Segment_Length - Width - Width/2 -1, pt.x() , pt.y() + Segment_Length - 3*Width/4 -1, pt.x() - Width +1, pt.y() + Segment_Length - Width - Width/2 -1); p.drawPolygon(pts); if (erase) p.setPen(g.light()); break; case 6 : pt.ry() += (QCOORD)(Segment_Length*2 ); p.fillRect(pt.x() + Width ,pt.y() -Width , Segment_Length -2* Width , Width ,brush); if (erase) p.setPen(offcolor); pts.setPoints(3,pt.x()+1, pt.y()-1, pt.x() + Width, pt.y() - Width, pt.x() + Width, pt.y() - 1 ); p.drawPolygon(pts); pts.setPoints(3, pt.x() + Segment_Length - 1, pt.y()-1, pt.x() + Segment_Length - Width , pt.y() - Width, pt.x() + Segment_Length - Width , pt.y() - 1 ); p.drawPolygon(pts); if (erase) p.setPen(g.light()); break; case 7 : pt.rx() += (QCOORD)(Segment_Length/2); pt.ry() += (QCOORD)(Segment_Length*2); p.fillRect(pt.x() ,pt.y() - Width , Width , Width ,brush); break; case 8 : pt.ry() += (QCOORD)(Segment_Length/2 + Width/2); pt.rx() += (QCOORD)(Segment_Length/2 - Width/2 + 1); if (!show_off_colon && erase) { p.setBrush(bgcolor); brush.setColor(bgcolor); } p.fillRect(pt.x() ,pt.y() - Width , Width , Width ,brush); p.moveTo(pt); if (!show_off_colon && erase) { p.setBrush(fgcolor); brush.setColor(fgcolor); } break; case 9 : pt.ry() += (QCOORD)(3*Segment_Length/2 + Width/2); pt.rx() += (QCOORD)(Segment_Length/2 - Width/2 + 1); if (!show_off_colon && erase) { p.setBrush(bgcolor); brush.setColor(bgcolor); } p.fillRect(pt.x() ,pt.y() - Width , Width , Width ,brush); if (!show_off_colon && erase) { p.setBrush(fgcolor); brush.setColor(fgcolor); } break; } } /* if (!smallLED) */ else{ pt.ry() += (QCOORD)Width/2; switch ( seg_number ) { case 0 : p.fillRect(pt.x(),pt.y()+ Width /2, Width , Segment_Length - Width -Width/2 ,brush); break; case 1 : p.fillRect(pt.x()+Width,pt.y()- Width , Segment_Length -2* Width, Width ,brush); break; case 2 : pt.rx() += (QCOORD)(Segment_Length); p.fillRect(pt.x()-Width,pt.y()+ Width/2, Width , Segment_Length - Width -Width/2 ,brush); break; case 3 : pt.ry() += (QCOORD)Segment_Length; p.fillRect(pt.x() + Width ,pt.y() - Width, Segment_Length- 2* Width, Width ,brush); break; case 4 : pt.ry() += (QCOORD)(Segment_Length ); p.fillRect(pt.x(), pt.y(), Width , Segment_Length - Width - Width/2 ,brush); break; case 5 : pt.rx() += (QCOORD)(Segment_Length ); pt.ry() += (QCOORD)(Segment_Length ); p.fillRect(pt.x() - Width ,pt.y(), Width , Segment_Length - Width - Width/2 ,brush); break; case 6 : pt.ry() += (QCOORD)(Segment_Length*2); p.fillRect(pt.x() + Width ,pt.y() -Width , Segment_Length -2* Width , Width ,brush); break; case 7 : pt.rx() += (QCOORD)(Segment_Length/2); pt.ry() += (QCOORD)(Segment_Length*2); p.fillRect(pt.x() ,pt.y() - Width , Width , Width ,brush); break; case 8 : pt.ry() += (QCOORD)(Segment_Length/2 + Width/2); pt.rx() += (QCOORD)(Segment_Length/2 - Width/2 + 1); if (!show_off_colon && erase) { p.setBrush(bgcolor); brush.setColor(bgcolor); } p.fillRect(pt.x() ,pt.y() - Width , Width , Width ,brush); p.moveTo(pt); if (!show_off_colon && erase) { p.setBrush(fgcolor); brush.setColor(fgcolor); } break; case 9 : pt.ry() += (QCOORD)(3*Segment_Length/2 + Width/2); pt.rx() += (QCOORD)(Segment_Length/2 - Width/2 + 1); if (!show_off_colon && erase) { p.setBrush(bgcolor); brush.setColor(bgcolor); } p.fillRect(pt.x() ,pt.y() - Width , Width , Width ,brush); if (!show_off_colon && erase) { p.setBrush(fgcolor); brush.setColor(fgcolor); } break; } } /* end smallLED */ }
void KdmClock::paintEvent( QPaintEvent * ) { if (!isVisible()) return; QPainter p( this ); drawFrame( &p ); QPixmap pm( contentsRect().size() ); QPainter paint; paint.begin( &pm ); paint.fillRect( contentsRect(), mBackgroundBrush ); // get current time QTime time = QTime::currentTime(); /* if (mDigital) { QString buf; if (mSecond) buf.sprintf( "%02d:%02d:%02d", time.hour(), time.minute(), time.second() ); else buf.sprintf( "%02d:%02d", time.hour(), time.minute() ); mFont.setPointSize( QMIN( (int)(width()/buf.length()*1.5),height() ) ); paint.setFont( mFont ); paint.setPen( backgroundColor() ); paint.drawText( contentsRect(),AlignHCenter|AlignVCenter, buf,-1,0,0 ); } else { */ QPointArray pts; QPoint cp = contentsRect().center() - QPoint( 2,2 ); int d = QMIN( contentsRect().width()-15,contentsRect().height()-15 ); paint.setPen( foregroundColor() ); paint.setBrush( foregroundColor() ); QWMatrix matrix; matrix.translate( cp.x(), cp.y() ); matrix.scale( d/1000.0F, d/1000.0F ); // Hour float h_angle = 30*(time.hour()%12-3) + time.minute()/2; matrix.rotate( h_angle ); paint.setWorldMatrix( matrix ); pts.setPoints( 4, -20,0, 0,-20, 300,0, 0,20 ); paint.drawPolygon( pts ); matrix.rotate( -h_angle ); // Minute float m_angle = (time.minute()-15)*6; matrix.rotate( m_angle ); paint.setWorldMatrix( matrix ); pts.setPoints( 4, -10,0, 0,-10, 400,0, 0,10 ); paint.drawPolygon( pts ); matrix.rotate( -m_angle ); // Second float s_angle = (time.second()-15)*6; matrix.rotate( s_angle ); paint.setWorldMatrix( matrix ); pts.setPoints( 4,0,0,0,0,400,0,0,0 ); if (mSecond) paint.drawPolygon( pts ); matrix.rotate( -s_angle ); // quadrante for (int i=0 ; i < 60 ; i++) { paint.setWorldMatrix( matrix ); if ((i % 5) == 0) paint.drawLine( 450,0, 500,0 ); // draw hour lines else paint.drawPoint( 480,0 ); // draw second lines matrix.rotate( 6 ); } // } // if (mDigital) paint.end(); // flicker free code by Remi Guyomarch <*****@*****.**> bitBlt( this, contentsRect().topLeft(), &pm ); }
// Mouse release event handler void MyMainWindow::mouseReleaseEvent(QMouseEvent* e) { if( e->button() == Qt::LeftButton ) { if ( image->isNull() ) { OnLoadImage(); } else { QPointArray a; // For any temporary pen and brush settings QPen tpen; QBrush tbrush; int mx, my; // displacements of user moving the mouse // close active painter if( paint->isActive () ) { paint->end(); } switch( selectedbutton ){ case DPen: // drawing with the Pen tool paint->begin( image ); // begin painting onto picture paint->setClipRect ( 0, 0, image->width(), image->height() ); // clipping paint->setPen( pendialog->pen ); // set the painter settings from the pen dialog // Set the array of points a.setPoints( 3, dx - xPos, dy - yPos, px - xPos, py - yPos, e->x() - xPos, e->y() - yPos ); paint->drawPolyline( a, 0, 3 ); // update the cursor positions dx = px; dy = py; px = e->x(); py = e->y(); paint->end(); break; case DLine: // drawing with the Line tool // TODO if(!linedialog->poly){ paint->begin( image ); // begin painting onto the picture paint->setClipRect ( 0, 0, image->width(), image->height() ); // clipping paint->setPen( linedialog->pen ); paint->drawLine(px-xPos, py-yPos, e->x()-xPos, e->y()-yPos); //store previous coord. for poly line paint->end(); } if(linedialog->poly && !linedialog->firstChoosePoly){ paint->begin( image ); // begin painting onto the picture paint->setClipRect ( 0, 0, image->width(), image->height() ); // clipping paint->setPen( linedialog->pen ); paint->drawLine(dx-xPos, dy-yPos, e->x()-xPos, e->y()-yPos); paint->end(); } dx = e->x(); dy = e->y(); if(linedialog->firstChoosePoly) linedialog->firstChoosePoly = false; if(linedialog->resetPoly){ linedialog->firstChoosePoly = true; linedialog->resetPoly = false; } break; case DEraser: // drawing with the Eraser tool // TODO break; case Drect: // drawing with the Rectangle tool // TODO // begins painting the pixmap image paint->begin(image); paint->setPen( rectdialog->pen ); // set the pen of the painter paint->setBrush(rectdialog->brush); // set the brush of the painter paint->setClipRect(0, 0, image->width(), image->height()); // enable drawing with a rectangular area only switch (rectdialog->drawtype){ case 0://rect paint->drawRect(px-xPos, py-yPos, e->x()-px, e->y()-py); // draw a rectangle of size determined dynamically break; case 1://round-rect paint->drawRoundRect(px-xPos, py-yPos, e->x()-px, e->y()-py); // draw a rectangle of size determined dynamically break; case 2://circle { double diagonal=sqrt(pow((double)(e->x()-px),2.0)+pow((double)(e->y()-py),2.0)); int negativeX, negativeY; if ((e->x()-px)>0) negativeX=1;else negativeX=-1; if ((e->y()-py)>0) negativeY=1;else negativeY=-1; paint->drawEllipse(px-xPos, py-yPos, negativeX*diagonal, negativeY*diagonal); // draw a rectangle of size determined dynamically break; } case 3://ellipse paint->drawEllipse(px-xPos, py-yPos, e->x()-px, e->y()-py); // draw a rectangle of size determined dynamically break; } paint->end(); break; } paintbmp(); } } redo = new QPixmap( *image ); mouseevent = 0; // reset the mouse event type }
// Mouse move event handler void MyMainWindow::mouseMoveEvent(QMouseEvent* e) { // dragging by left button click if( mouseevent == 1 ) { if ( image->isNull() ) { } else { QPointArray a; // For any temporary pen and brush settings QPen tpen; QBrush tbrush; // close active painter if( paint->isActive() ) { paint->end(); } // int mx, my; // displacements of user moving the mouse switch( selectedbutton ){ case DPen: // drawing with the Pen tool paint->begin( image ); // begin painting onto the picture paint->setClipRect ( 0, 0, image->width(), image->height() ); // clipping paint->setPen( pendialog->pen ); // set the painter settings from the pen dialog // Set the array of points a.setPoints( 3, dx - xPos, dy - yPos, px - xPos, py - yPos, e->x() - xPos, e->y() - yPos ); paint->drawPolyline( a, 0, 3 );//** // update the cursor positions dx = px; dy = py; px = e->x(); py = e->y(); paint->end(); // end painting onto the picture paintbmp(); break; case DLine: { // drawing with the Line tool paintbmp(); // TODO if(linedialog->poly){ px = dx; py = dy; } paint->begin( this ); // begin painting onto the picture paint->setClipRect ( xPos, yPos, image->width(), image->height() ); // clipping paint->setPen( linedialog->pen ); paint->drawLine(px, py, e->x(), e->y()); paint->end(); break; } case DEraser: { // drawing with the Eraser tool int size=eraserdialog->size; QPen pen(black, 1, Qt::SolidLine); QBrush brush(bgcolor); paintbmp(); // TODO //set widget eraser paint->begin( this ); // begin painting onto the picture paint->setPen(pen); paint->setBrush(brush); paint->setClipRect ( xPos, yPos, image->width(), image->height() ); // clipping paint->drawRect(e->x()-size/2, e->y()-size/2, size, size); paint->end(); //set Pixmap eraser paint->begin( image ); // begin painting onto the picture pen.setColor(bgcolor); paint->setPen(pen); paint->setBrush(brush); paint->setClipRect ( 0, 0, image->width(), image->height() ); // clipping paint->drawRect(e->x()-size/2-xPos, e->y()-size/2-yPos, size, size); paint->end(); break; } case Drect: // drawing with the Rectangle tool paintbmp(); // TODO // begins painting the widget paint->begin(this); paint->setPen( rectdialog->pen ); // set the pen of the painter paint->setBrush(rectdialog->brush); // set the brush of the painter paint->setClipRect(xPos, yPos, image->width(), image->height()); // enable drawing with a rectangular area only switch (rectdialog->drawtype){ case 0://rect paint->drawRect(px, py, e->x()-px, e->y()-py); // draw a rectangle of size determined dynamically break; case 1://round-rect paint->drawRoundRect(px, py, e->x()-px, e->y()-py); // draw a rectangle of size determined dynamically break; case 2://circle { double diagonal=sqrt(pow((double)(e->x()-px),2.0)+pow((double)(e->y()-py),2.0)); int negativeX, negativeY; if ((e->x()-px)>0) negativeX=1;else negativeX=-1; if ((e->y()-py)>0) negativeY=1;else negativeY=-1; paint->drawEllipse(px, py, negativeX*diagonal, negativeY*diagonal); // draw a rectangle of size determined dynamically break; } case 3://ellipse paint->drawEllipse(px, py, e->x()-px, e->y()-py); // draw a rectangle of size determined dynamically break; } paint->end(); break; } } } }
// motif arrows look the same whether they are used or not // is this correct? static void qDrawMotifArrow( QPainter *p, Qt::ArrowType type, bool down, int x, int y, int w, int h, const QColorGroup &g, bool ) { QPointArray bFill; // fill polygon QPointArray bTop; // top shadow. QPointArray bBot; // bottom shadow. QPointArray bLeft; // left shadow. #ifndef QT_NO_TRANSFORMATIONS QWMatrix matrix; // xform matrix #endif bool vertical = type == Qt::UpArrow || type == Qt::DownArrow; bool horizontal = !vertical; int dim = w < h ? w : h; int colspec = 0x0000; // color specification array if ( dim < 2 ) // too small arrow return; if ( dim > 3 ) { if ( dim > 6 ) bFill.resize( dim & 1 ? 3 : 4 ); bTop.resize( (dim/2)*2 ); bBot.resize( dim & 1 ? dim + 1 : dim ); bLeft.resize( dim > 4 ? 4 : 2 ); bLeft.putPoints( 0, 2, 0,0, 0,dim-1 ); if ( dim > 4 ) bLeft.putPoints( 2, 2, 1,2, 1,dim-3 ); bTop.putPoints( 0, 4, 1,0, 1,1, 2,1, 3,1 ); bBot.putPoints( 0, 4, 1,dim-1, 1,dim-2, 2,dim-2, 3,dim-2 ); for( int i=0; i<dim/2-2 ; i++ ) { bTop.putPoints( i*2+4, 2, 2+i*2,2+i, 5+i*2, 2+i ); bBot.putPoints( i*2+4, 2, 2+i*2,dim-3-i, 5+i*2,dim-3-i ); } if ( dim & 1 ) // odd number size: extra line bBot.putPoints( dim-1, 2, dim-3,dim/2, dim-1,dim/2 ); if ( dim > 6 ) { // dim>6: must fill interior bFill.putPoints( 0, 2, 1,dim-3, 1,2 ); if ( dim & 1 ) // if size is an odd number bFill.setPoint( 2, dim - 3, dim / 2 ); else bFill.putPoints( 2, 2, dim-4,dim/2-1, dim-4,dim/2 ); } } else { if ( dim == 3 ) { // 3x3 arrow pattern bLeft.setPoints( 4, 0,0, 0,2, 1,1, 1,1 ); bTop .setPoints( 2, 1,0, 1,0 ); bBot .setPoints( 2, 1,2, 2,1 ); } else { // 2x2 arrow pattern bLeft.setPoints( 2, 0,0, 0,1 ); bTop .setPoints( 2, 1,0, 1,0 ); bBot .setPoints( 2, 1,1, 1,1 ); } } if ( type == Qt::UpArrow || type == Qt::LeftArrow ) { #ifndef QT_NO_TRANSFORMATIONS // #### fix me! matrix.translate( x, y ); if ( vertical ) { matrix.translate( 0, h - 1 ); matrix.rotate( -90 ); } else { matrix.translate( w - 1, h - 1 ); matrix.rotate( 180 ); } #endif if ( down ) colspec = horizontal ? 0x2334 : 0x2343; else colspec = horizontal ? 0x1443 : 0x1434; } else if ( type == Qt::DownArrow || type == Qt::RightArrow ) { #ifndef QT_NO_TRANSFORMATIONS // #### fix me! matrix.translate( x, y ); if ( vertical ) { matrix.translate( w-1, 0 ); matrix.rotate( 90 ); } #endif if ( down ) colspec = horizontal ? 0x2443 : 0x2434; else colspec = horizontal ? 0x1334 : 0x1343; } QColor *cols[5]; cols[0] = 0; cols[1] = (QColor *)&g.button(); cols[2] = (QColor *)&g.mid(); cols[3] = (QColor *)&g.light(); cols[4] = (QColor *)&g.dark(); #define CMID *cols[ (colspec>>12) & 0xf ] #define CLEFT *cols[ (colspec>>8) & 0xf ] #define CTOP *cols[ (colspec>>4) & 0xf ] #define CBOT *cols[ colspec & 0xf ] QPen savePen = p->pen(); // save current pen QBrush saveBrush = p->brush(); // save current brush #ifndef QT_NO_TRANSFORMATIONS QWMatrix wxm = p->worldMatrix(); #endif QPen pen( Qt::NoPen ); const QBrush &brush = g.brush( QColorGroup::Button ); p->setPen( pen ); p->setBrush( brush ); #ifndef QT_NO_TRANSFORMATIONS p->setWorldMatrix( matrix, TRUE ); // set transformation matrix #endif p->drawPolygon( bFill ); // fill arrow p->setBrush( Qt::NoBrush ); // don't fill p->setPen( CLEFT ); p->drawLineSegments( bLeft ); p->setPen( CTOP ); p->drawLineSegments( bTop ); p->setPen( CBOT ); p->drawLineSegments( bBot ); #ifndef QT_NO_TRANSFORMATIONS p->setWorldMatrix( wxm ); #endif p->setBrush( saveBrush ); // restore brush p->setPen( savePen ); // restore pen #undef CMID #undef CLEFT #undef CTOP #undef CBOT }
void qDrawShadeLine( QPainter *p, int x1, int y1, int x2, int y2, const QColorGroup &g, bool sunken, int lineWidth, int midLineWidth ) { if (!( p && lineWidth >= 0 && midLineWidth >= 0 ) ) { #if defined(QT_CHECK_RANGE) qWarning( "qDrawShadeLine invalid parameters." ); #endif return; } int tlw = lineWidth*2 + midLineWidth; // total line width QPen oldPen = p->pen(); // save pen if ( sunken ) p->setPen( g.dark() ); else p->setPen( g.light() ); QPointArray a; int i; if ( y1 == y2 ) { // horizontal line int y = y1 - tlw/2; if ( x1 > x2 ) { // swap x1 and x2 int t = x1; x1 = x2; x2 = t; } x2--; for ( i=0; i<lineWidth; i++ ) { // draw top shadow a.setPoints( 3, x1+i, y+tlw-1-i, x1+i, y+i, x2-i, y+i ); p->drawPolyline( a ); } if ( midLineWidth > 0 ) { p->setPen( g.mid() ); for ( i=0; i<midLineWidth; i++ ) // draw lines in the middle p->drawLine( x1+lineWidth, y+lineWidth+i, x2-lineWidth, y+lineWidth+i ); } if ( sunken ) p->setPen( g.light() ); else p->setPen( g.dark() ); for ( i=0; i<lineWidth; i++ ) { // draw bottom shadow a.setPoints( 3, x1+i, y+tlw-i-1, x2-i, y+tlw-i-1, x2-i, y+i+1 ); p->drawPolyline( a ); } } else if ( x1 == x2 ) { // vertical line int x = x1 - tlw/2; if ( y1 > y2 ) { // swap y1 and y2 int t = y1; y1 = y2; y2 = t; } y2--; for ( i=0; i<lineWidth; i++ ) { // draw left shadow a.setPoints( 3, x+i, y2, x+i, y1+i, x+tlw-1, y1+i ); p->drawPolyline( a ); } if ( midLineWidth > 0 ) { p->setPen( g.mid() ); for ( i=0; i<midLineWidth; i++ ) // draw lines in the middle p->drawLine( x+lineWidth+i, y1+lineWidth, x+lineWidth+i, y2 ); } if ( sunken ) p->setPen( g.light() ); else p->setPen( g.dark() ); for ( i=0; i<lineWidth; i++ ) { // draw right shadow a.setPoints( 3, x+lineWidth, y2-i, x+tlw-i-1, y2-i, x+tlw-i-1, y1+lineWidth ); p->drawPolyline( a ); } } p->setPen( oldPen ); }
/*!\reimp */ void QPlatinumStyle::drawComplexControl( ComplexControl control, QPainter *p, const QWidget *widget, const QRect &r, const QColorGroup &cg, SFlags how, SCFlags sub, SCFlags subActive, const QStyleOption& opt ) const { switch ( control ) { case CC_ComboBox: { int x, y, w, h; r.rect( &x, &y, &w, &h ); p->fillRect( x + 2, y + 2, w - 4, h - 4, cg.brush(QColorGroup::Button) ); // the bright side p->setPen(cg.shadow()); p->drawLine( x, y, x + w - 1, y ); p->drawLine( x, y, x, y + h - 1 ); p->setPen( cg.light() ); p->drawLine( x + 1, y + 1, x + w - 2, y + 1 ); p->drawLine( x + 1, y + 1, x + 1, y + h - 2 ); // the dark side! p->setPen( cg.mid() ); p->drawLine( x + 2, y + h - 2, x + w - 2, y + h - 2 ); p->drawLine( x + w - 2, y + 2, x + w - 2, y + h - 2 ); p->setPen (cg.shadow() ); p->drawLine( x + 1, y + h - 1, x + w - 1, y + h - 1 ); p->drawLine( x + w - 1, y, x + w - 1, y + h - 1 ); // top left corner: p->setPen( cg.background() ); p->drawPoint( x, y ); p->drawPoint( x + 1, y ); p->drawPoint( x, y + 1 ); p->setPen( cg.shadow() ); p->drawPoint( x + 1, y + 1 ); p->setPen( white ); p->drawPoint( x + 3, y + 3 ); // bottom left corner: p->setPen( cg.background() ); p->drawPoint( x, y + h - 1 ); p->drawPoint( x + 1, y + h - 1 ); p->drawPoint( x, y + h - 2 ); p->setPen( cg.shadow() ); p->drawPoint( x + 1, y + h - 2 ); // top right corner: p->setPen( cg.background() ); p->drawPoint( x + w - 1, y ); p->drawPoint( x + w - 2, y ); p->drawPoint( x + w - 1, y + 1 ); p->setPen( cg.shadow() ); p->drawPoint( x + w - 2, y + 1 ); // bottom right corner: p->setPen( cg.background() ); p->drawPoint( x + w - 1, y + h - 1 ); p->drawPoint( x + w - 2, y + h - 1 ); p->drawPoint( x + w - 1, y + h - 2 ); p->setPen( cg.shadow() ); p->drawPoint( x + w - 2, y + h - 2 ); p->setPen( cg.dark() ); p->drawPoint( x + w - 3, y + h - 3 ); if ( sub & SC_ComboBoxArrow ) { QRect rTmp = querySubControlMetrics( CC_ComboBox, widget, SC_ComboBoxArrow, opt ); int xx = rTmp.x(), yy = rTmp.y(), ww = rTmp.width(), hh = rTmp.height(); // the bright side p->setPen( cg.mid() ); p->drawLine( xx, yy+2, xx, yy+hh-3 ); p->setPen( cg.button() ); p->drawLine( xx+1, yy+1, xx+ww-2, yy+1 ); p->drawLine( xx+1, yy+1, xx+1, yy+hh-2 ); p->setPen( cg.light() ); p->drawLine( xx+2, yy+2, xx+2, yy+hh-2 ); p->drawLine( xx+2, yy+2, xx+ww-2, yy+2 ); // the dark side! p->setPen( cg.mid() ); p->drawLine( xx+3, yy+hh-3 ,xx+ww-3, yy+hh-3 ); p->drawLine( xx+ww-3, yy+3, xx+ww-3, yy+hh-3 ); p->setPen( cg.dark() ); p->drawLine( xx+2, yy+hh-2 ,xx+ww-2, yy+hh-2 ); p->drawLine( xx+ww-2, yy+2, xx+ww-2, yy+hh-2 ); p->setPen( cg.shadow() ); p->drawLine( xx+1, yy+hh-1,xx+ww-1, yy+hh-1 ); p->drawLine( xx+ww-1, yy, xx+ww-1, yy+hh-1 ); // top right corner: p->setPen( cg.background() ); p->drawPoint( xx + ww - 1, yy ); p->drawPoint( xx + ww - 2, yy ); p->drawPoint( xx + ww - 1, yy + 1 ); p->setPen( cg.shadow() ); p->drawPoint( xx + ww - 2, yy + 1 ); // bottom right corner: p->setPen( cg.background() ); p->drawPoint( xx + ww - 1, yy + hh - 1 ); p->drawPoint( xx + ww - 2, yy + hh - 1 ); p->drawPoint( xx + ww - 1, yy + hh - 2 ); p->setPen( cg.shadow() ); p->drawPoint( xx + ww - 2, yy + hh - 2 ); p->setPen( cg.dark() ); p->drawPoint( xx + ww - 3, yy + hh - 3 ); p->setPen( cg.mid() ); p->drawPoint( xx + ww - 4, yy + hh - 4 ); // and the arrows p->setPen( cg.foreground() ); QPointArray a ; a.setPoints( 7, -3,1, 3,1, -2,0, 2,0, -1,-1, 1,-1, 0,-2 ); a.translate( xx + ww / 2, yy + hh / 2 - 3 ); p->drawLineSegments( a, 0, 3 ); // draw arrow p->drawPoint( a[6] ); a.setPoints( 7, -3,-1, 3,-1, -2,0, 2,0, -1,1, 1,1, 0,2 ); a.translate( xx + ww / 2, yy + hh / 2 + 2 ); p->drawLineSegments( a, 0, 3 ); // draw arrow p->drawPoint( a[6] ); } #ifndef QT_NO_COMBOBOX if ( sub & SC_ComboBoxEditField ) { const QComboBox *cmb; cmb = (const QComboBox*)widget; // sadly this is pretty much the windows code, except // for the first fillRect call... QRect re = QStyle::visualRect( querySubControlMetrics( CC_ComboBox, widget, SC_ComboBoxEditField ), widget ); if ( cmb->hasFocus() && !cmb->editable() ) p->fillRect( re.x() + 1, re.y() + 1, re.width() - 2, re.height() - 2, cg.brush( QColorGroup::Highlight ) ); if ( cmb->hasFocus() ) { p->setPen( cg.highlightedText() ); p->setBackgroundColor( cg.highlight() ); } else { p->setPen( cg.text() ); p->setBackgroundColor( cg.background() ); } if ( cmb->hasFocus() && !cmb->editable() ) { QRect re = QStyle::visualRect( subRect( SR_ComboBoxFocusRect, cmb ), widget ); drawPrimitive( PE_FocusRect, p, re, cg, Style_FocusAtBorder, QStyleOption(cg.highlight())); } if ( cmb->editable() ) { // need this for the moment... // was the code in comboButton rect QRect ir( x + 3, y + 3, w - 6 - 16, h - 6 ); if ( QApplication::reverseLayout() ) ir.moveBy( 16, 0 ); // end comboButtonRect... ir.setRect( ir.left() - 1, ir.top() - 1, ir.width() + 2, ir.height() + 2 ); qDrawShadePanel( p, ir, cg, TRUE, 2, 0 ); } } #endif break; } case CC_Slider: { #ifndef QT_NO_SLIDER const QSlider *slider = (const QSlider *) widget; int thickness = pixelMetric( PM_SliderControlThickness, widget ); int len = pixelMetric( PM_SliderLength, widget ); int ticks = slider->tickmarks(); QRect groove = querySubControlMetrics(CC_Slider, widget, SC_SliderGroove, opt), handle = querySubControlMetrics(CC_Slider, widget, SC_SliderHandle, opt); if ((sub & SC_SliderGroove) && groove.isValid()) { p->fillRect( groove, cg.brush(QColorGroup::Background) ); int x, y, w, h; int mid = thickness / 2; if ( ticks & QSlider::Above ) mid += len / 8; if ( ticks & QSlider::Below ) mid -= len / 8; if ( slider->orientation() == Horizontal ) { x = 0; y = groove.y() + mid - 3; w = slider->width(); h = 7; } else { x = groove.x() + mid - 3; y = 0; w = 7; h = slider->height(); } p->fillRect( x, y, w, h, cg.brush( QColorGroup::Dark )); // the dark side p->setPen( cg.dark() ); p->drawLine( x, y, x + w - 1, y ); p->drawLine( x, y, x, y + h - 1); p->setPen( cg.shadow() ); p->drawLine( x + 1, y + 1, x + w - 2, y + 1 ); p->drawLine( x + 1, y + 1, x + 1, y + h - 2 ); // the bright side! p->setPen(cg.shadow()); p->drawLine( x + 1, y + h - 2, x + w - 2, y + h - 2 ); p->drawLine( x + w - 2, y + 1, x + w - 2, y + h - 2 ); p->setPen( cg.light() ); p->drawLine( x, y + h - 1, x + w - 1, y + h - 1 ); p->drawLine( x + w - 1, y, x + w - 1, y + h - 1 ); // top left corner: p->setPen(cg.background()); p->drawPoint( x, y ); p->drawPoint( x + 1, y ); p->drawPoint( x, y + 1 ); p->setPen(cg.shadow()); p->drawPoint( x + 1, y + 1 ); // bottom left corner: p->setPen( cg.background() ); p->drawPoint( x, y + h - 1 ); p->drawPoint( x + 1, y + h - 1 ); p->drawPoint( x, y + h - 2 ); p->setPen( cg.light() ); p->drawPoint( x + 1, y + h - 2 ); // top right corner: p->setPen( cg.background() ); p->drawPoint( x + w - 1, y ); p->drawPoint( x + w - 2, y ); p->drawPoint( x + w - 1, y + 1 ); p->setPen( cg.dark() ); p->drawPoint( x + w - 2, y + 1 ); // bottom right corner: p->setPen( cg.background() ); p->drawPoint( x + w - 1, y + h - 1 ); p->drawPoint( x + w - 2, y + h - 1 ); p->drawPoint( x + w - 1, y + h - 2 ); p->setPen( cg.light() ); p->drawPoint( x + w - 2, y + h - 2 ); p->setPen( cg.dark() ); p->drawPoint( x + w - 3, y + h - 3 ); // ### end slider groove if ( how & Style_HasFocus ) drawPrimitive( PE_FocusRect, p, groove, cg ); } if ((sub & SC_SliderHandle) && handle.isValid()) { const QColor c0 = cg.shadow(); const QColor c1 = cg.dark(); const QColor c3 = cg.light(); int x1 = handle.x(); int x2 = handle.x() + handle.width() - 1; int y1 = handle.y(); int y2 = handle.y() + handle.height() - 1; int mx = handle.width() / 2; int my = handle.height() / 2; if ( slider->orientation() == Vertical ) { // Background QBrush oldBrush = p->brush(); p->setBrush( cg.brush( QColorGroup::Button ) ); p->setPen( NoPen ); QPointArray a(6); a.setPoint( 0, x1 + 1, y1 + 1 ); a.setPoint( 1, x2 - my + 2, y1 + 1 ); a.setPoint( 2, x2 - 1, y1 + my - 1 ); a.setPoint( 3, x2 - 1, y2 - my + 1 ); a.setPoint( 4, x2 - my + 2, y2 - 1 ); a.setPoint( 5, x1 + 1, y2 - 1 ); p->drawPolygon( a ); p->setBrush( oldBrush ); // shadow border p->setPen( c0 ); p->drawLine( x1, y1 + 1, x1,y2 - 1 ); p->drawLine( x2 - my + 2, y1, x2, y1 + my - 2 ); p->drawLine( x2 - my + 2, y2, x2, y1 + my + 2 ); p->drawLine( x2, y1 + my - 2, x2, y1 + my + 2 ); p->drawLine( x1 + 1, y1, x2 - my + 2, y1 ); p->drawLine( x1 + 1, y2, x2 - my + 2, y2 ); // light shadow p->setPen( c3 ); p->drawLine( x1 + 1, y1 + 2, x1 + 1, y2 - 2 ); p->drawLine( x1 + 1, y1 + 1, x2 - my + 2, y1 + 1 ); p->drawLine( x2 - my + 2, y1 + 1, x2 - 1, y1 + my - 2 ); // dark shadow p->setPen(c1); p->drawLine( x2 - 1, y1 + my - 2, x2 - 1, y1 + my + 2 ); p->drawLine( x2 - my + 2, y2 - 1, x2 - 1, y1 + my + 2 ); p->drawLine( x1 + 1, y2 - 1, x2 -my + 2, y2 - 1 ); drawRiffles( p, handle.x(), handle.y() + 2, handle.width() - 3, handle.height() - 4, cg, TRUE ); } else { // Horizontal QBrush oldBrush = p->brush(); p->setBrush( cg.brush( QColorGroup::Button ) ); p->setPen( NoPen ); QPointArray a(6); a.setPoint( 0, x2 - 1, y1 + 1 ); a.setPoint( 1, x2 - 1, y2 - mx + 2 ); a.setPoint( 2, x2 - mx + 1, y2 - 1 ); a.setPoint( 3, x1 + mx - 1, y2 - 1 ); a.setPoint( 4, x1 + 1, y2 - mx + 2 ); a.setPoint( 5, x1 + 1, y1 + 1 ); p->drawPolygon( a ); p->setBrush( oldBrush ); // shadow border p->setPen( c0 ); p->drawLine( x1 + 1, y1, x2 - 1, y1 ); p->drawLine( x1, y2 - mx + 2, x1 + mx - 2, y2 ); p->drawLine( x2, y2 - mx + 2, x1 + mx + 2, y2 ); p->drawLine( x1 + mx - 2, y2, x1 + mx + 2, y2 ); p->drawLine( x1, y1 + 1, x1, y2 - mx + 2 ); p->drawLine( x2, y1 + 1, x2, y2 - mx + 2 ); // light shadow p->setPen(c3); p->drawLine( x1 + 1, y1 + 1, x2 - 1, y1 + 1 ); p->drawLine( x1 + 1, y1 + 1, x1 + 1, y2 - mx + 2 ); // dark shadow p->setPen(c1); p->drawLine( x2 - 1, y1 + 1, x2 - 1, y2 - mx + 2 ); p->drawLine( x1 + 1, y2 - mx + 2, x1 + mx - 2, y2 - 1 ); p->drawLine( x2 - 1, y2 - mx + 2, x1 + mx + 2, y2 - 1 ); p->drawLine( x1 + mx - 2, y2 - 1, x1 + mx + 2, y2 - 1 ); drawRiffles( p, handle.x() + 2, handle.y(), handle.width() - 4, handle.height() - 5, cg, FALSE ); } } if ( sub & SC_SliderTickmarks ) QCommonStyle::drawComplexControl( control, p, widget, r, cg, how, SC_SliderTickmarks, subActive, opt ); #endif break; } default: QWindowsStyle::drawComplexControl( control, p, widget, r, cg, how, sub, subActive, opt ); break; } }
void qDrawShadeRect( QPainter *p, int x, int y, int w, int h, const QColorGroup &g, bool sunken, int lineWidth, int midLineWidth, const QBrush *fill ) { if ( w == 0 || h == 0 ) return; if ( ! ( w > 0 && h > 0 && lineWidth >= 0 && midLineWidth >= 0 ) ) { #if defined(QT_CHECK_RANGE) qWarning( "qDrawShadeRect(): Invalid parameters" ); #endif return; } QPen oldPen = p->pen(); if ( sunken ) p->setPen( g.dark() ); else p->setPen( g.light() ); int x1=x, y1=y, x2=x+w-1, y2=y+h-1; QPointArray a; if ( lineWidth == 1 && midLineWidth == 0 ) {// standard shade rectangle p->drawRect( x1, y1, w-1, h-1 ); if ( sunken ) p->setPen( g.light() ); else p->setPen( g.dark() ); a.setPoints( 8, x1+1,y1+1, x2-2,y1+1, x1+1,y1+2, x1+1,y2-2, x1,y2, x2,y2, x2,y1, x2,y2-1 ); p->drawLineSegments( a ); // draw bottom/right lines } else { // more complicated int m = lineWidth+midLineWidth; int i, j=0, k=m; for ( i=0; i<lineWidth; i++ ) { // draw top shadow a.setPoints( 8, x1+i, y2-i, x1+i, y1+i, x1+i, y1+i, x2-i, y1+i, x1+k, y2-k, x2-k, y2-k, x2-k, y2-k, x2-k, y1+k ); p->drawLineSegments( a ); k++; } p->setPen( g.mid() ); j = lineWidth*2; for ( i=0; i<midLineWidth; i++ ) { // draw lines in the middle p->drawRect( x1+lineWidth+i, y1+lineWidth+i, w-j, h-j ); j += 2; } if ( sunken ) p->setPen( g.light() ); else p->setPen( g.dark() ); k = m; for ( i=0; i<lineWidth; i++ ) { // draw bottom shadow a.setPoints( 8, x1+1+i,y2-i, x2-i, y2-i, x2-i, y2-i, x2-i, y1+i+1, x1+k, y2-k, x1+k, y1+k, x1+k, y1+k, x2-k, y1+k ); p->drawLineSegments( a ); k++; } } if ( fill ) { QBrush oldBrush = p->brush(); int tlw = lineWidth + midLineWidth; p->setPen( Qt::NoPen ); p->setBrush( *fill ); p->drawRect( x+tlw, y+tlw, w-2*tlw, h-2*tlw ); p->setBrush( oldBrush ); } p->setPen( oldPen ); // restore pen }
void ScalePlot::drawScale () { QPainter painter; painter.begin(&buffer); painter.setFont(plotFont); painter.setPen(QPen(borderColor, 1, QPen::SolidLine)); painter.fillRect(0, 0, buffer.width(), buffer.height(), backgroundColor); QMemArray<double> scaleArray; scaler.getScaleArray(scaleArray); QFontMetrics fm(plotFont); int x = 0; int loop; for (loop = 0; loop < (int) scaleArray.size(); loop++) { int y = scaler.convertToY(scaleArray[loop]); painter.drawLine (x, y, x + 4, y); // draw the text QString s; strip(scaleArray[loop], 4, s); // abbreviate too many (>=3) trailing zeroes in large numbers on y-axes if (! mainFlag) { bool flag = FALSE; if (s.toDouble() < 0) { flag = TRUE; s.remove(0, 1); } if (s.toDouble() >= 1000000000) { strip(s.toDouble() / 1000000000, 4, s); s.append("b"); } else { if (s.toDouble() >= 1000000) { strip(s.toDouble() / 1000000, 4, s); s.append("m"); } // else // { // if (s.toDouble() >= 1000) // { // strip(s.toDouble() / 1000, 4, s); // s.append("k"); // } // } } if (flag) s.prepend("-"); } painter.drawText(x + 7, y + (fm.height() / 2), s); } painter.drawLine (x, 0, x, buffer.height()); // draw the last value pointer on the scale of main plot int y = scaler.convertToY(close); QPointArray array; array.setPoints(3, x + 2, y, x + 8, y - 4, x + 8, y + 4); painter.setBrush(borderColor); painter.drawPolygon(array, TRUE, 0, -1); painter.end(); }
void ClsEPuckDisp::DrawSoma(QPainter *_Painter, int iWhiskersWidth){ int ii; int iWhiskFactor = iWhiskersMaxLength / 11; // printf("+++++++++++++++++++++++\n"); // for (ii = 0; ii<8 ; ii++){ // printf("Coll: %i, ", vaAmbient[ii]); // printf("IR: %g\n", vaProximity[ii]); // if (ii <= 2) printf("Motor: %g\n", afMotor[ii]); // } int iXCenter, iYCenter; int iWidth, iHeight; iWidth = 250; //this->width(); iHeight = 250; //this->height(); iXCenter = iWidth / 2 ; iYCenter = iHeight / 2 ; // Khepera body _Painter->setPen( QPen( colLines, 1, SolidLine ) ); _Painter->setBrush( colSoma ); _Painter->drawEllipse( iXCenter - iSomaDiameter / 2, iYCenter - iSomaDiameter / 2, iSomaDiameter, iSomaDiameter ); // ----------------------------- // Wheels _Painter->setPen( QPen( colLines, 1, SolidLine ) ); _Painter->setBrush( colMotor ); /* left */ _Painter->drawRect ( iXCenter - iSomaDiameter / 2 - iWheelWidth, iYCenter - iWheelHeight / 2, iWheelWidth, iWheelHeight); /* right */ _Painter->drawRect ( iXCenter + iSomaDiameter / 2, iYCenter - iWheelHeight / 2, iWheelWidth, iWheelHeight); /* wheel speedbars */ QPointArray qpaSpeedbar; _Painter->setBrush( QBrush( yellow, SolidPattern ) ); /* wheel speedbar left */ qpaSpeedbar.setPoints( 3, iXCenter - iSomaDiameter / 2 - iWheelWidth, iYCenter, iXCenter - iSomaDiameter / 2 - iWheelWidth - iWheelSpeedbarHeight, iYCenter, iXCenter - iSomaDiameter / 2 - iWheelWidth - iWheelSpeedbarHeight/2, iYCenter -(int)((double)iWheelSpeedbarWidth*afMotor[0])); _Painter->drawPolygon(qpaSpeedbar); /* wheel speedbar right */ qpaSpeedbar.setPoints( 3, iXCenter + iSomaDiameter / 2 + iWheelWidth, iYCenter, iXCenter + iSomaDiameter / 2 + iWheelWidth + iWheelSpeedbarHeight, iYCenter, iXCenter + iSomaDiameter / 2 + iWheelWidth + iWheelSpeedbarHeight/2, iYCenter -(int)((double)iWheelSpeedbarWidth*afMotor[1])); _Painter->drawPolygon(qpaSpeedbar); // ---------------------------- // Proximity and Ambient double fAngle; int iXPos, iYPos; int iCountSensor; int iAmbientColor; _Painter->setPen( QPen( colLines, 1, SolidLine ) ); iCountSensor = 0; for ( fAngle = 205; fAngle <= 255; fAngle += 25){ _Painter->setPen( QPen( colLines, 1, SolidLine ) ); iAmbientColor = (int)(vaAmbient[iCountSensor]*254.0); // cout << "iAmbientColor 0: " << iAmbientColor << endl; colCollision.setRgb(iAmbientColor,iAmbientColor,iAmbientColor); _Painter->setBrush( colCollision ); iXPos = (int)(cos( fAngle * PI / 180.0) * ((double)iSomaDiameter / 2.0 + iAmbientSensorDiameter / 2 )) + iXCenter; iYPos = (int)(sin( fAngle * PI / 180.0) * ((double)iSomaDiameter / 2.0 + iAmbientSensorDiameter / 2 )) + iYCenter; _Painter->drawEllipse( iXPos - iAmbientSensorDiameter / 2, iYPos - iAmbientSensorDiameter / 2 , iAmbientSensorDiameter, iAmbientSensorDiameter ); _Painter->setPen( QPen( colProximityWhisker, iWhiskersWidth, SolidLine ) ); _Painter->drawLine( iXPos, iYPos, (int)(cos ((double)aiProximitySensorPos[iCountSensor] * PI / 180.0) * (iWhiskersMaxLength-(double)vaProximity[iCountSensor] * iWhiskFactor)) + iXPos, (int)(sin ((double)aiProximitySensorPos[iCountSensor] * PI / 180.0) * (iWhiskersMaxLength-(double)vaProximity[iCountSensor] * iWhiskFactor)) + iYPos ); iCountSensor++; } for ( fAngle = 285; fAngle <=335; fAngle += 25){ _Painter->setPen( QPen( colLines, 1, SolidLine ) ); iAmbientColor = (int)(vaAmbient[iCountSensor]*254.0); // cout << "iAmbientColor 1: " << iAmbientColor << endl; colCollision.setRgb(iAmbientColor,iAmbientColor,iAmbientColor); _Painter->setBrush( colCollision ); iXPos = (int)(cos( fAngle * PI / 180.0) * ((double)iSomaDiameter / 2.0 + iAmbientSensorDiameter / 2 )) + iXCenter; iYPos = (int)(sin( fAngle * PI / 180.0) * ((double)iSomaDiameter / 2.0 + iAmbientSensorDiameter / 2 )) + iYCenter; _Painter->drawEllipse( iXPos - iAmbientSensorDiameter / 2, iYPos - iAmbientSensorDiameter / 2 , iAmbientSensorDiameter, iAmbientSensorDiameter ); _Painter->setPen( QPen( colProximityWhisker, iWhiskersWidth, SolidLine ) ); _Painter->drawLine( iXPos, iYPos, (int)(cos ((double)aiProximitySensorPos[iCountSensor] * PI / 180.0) * (iWhiskersMaxLength-(double)vaProximity[iCountSensor] * iWhiskFactor)) + iXPos, (int)(sin ((double)aiProximitySensorPos[iCountSensor] * PI / 180.0) * (iWhiskersMaxLength-(double)vaProximity[iCountSensor] * iWhiskFactor)) + iYPos ); iCountSensor++; } for ( fAngle = 70; fAngle <=110; fAngle += 40){ _Painter->setPen( QPen( colLines, 1, SolidLine ) ); iAmbientColor = (int)(vaAmbient[iCountSensor]*254.0); // cout << "iAmbientColor 2: " << iAmbientColor << endl; colCollision.setRgb(iAmbientColor,iAmbientColor,iAmbientColor); _Painter->setBrush( colCollision ); iXPos = (int)(cos( fAngle * PI / 180.0) * ((double)iSomaDiameter / 2.0 + iAmbientSensorDiameter / 2 )) + iXCenter; iYPos = (int)(sin( fAngle * PI / 180.0) * ((double)iSomaDiameter / 2.0 + iAmbientSensorDiameter / 2 )) + iYCenter; _Painter->drawEllipse( iXPos - iAmbientSensorDiameter / 2, iYPos - iAmbientSensorDiameter / 2 , iAmbientSensorDiameter, iAmbientSensorDiameter ); _Painter->setPen( QPen( colProximityWhisker, iWhiskersWidth, SolidLine ) ); _Painter->drawLine( iXPos, iYPos, (int)(cos ((double)aiProximitySensorPos[iCountSensor] * PI / 180.0) * (iWhiskersMaxLength-(double)vaProximity[iCountSensor] * iWhiskFactor)) + iXPos, (int)(sin ((double)aiProximitySensorPos[iCountSensor] * PI / 180.0) * (iWhiskersMaxLength-(double)vaProximity[iCountSensor] * iWhiskFactor)) + iYPos ); iCountSensor++; } // ----------------------------------- #ifdef SHOW_INHIBITION // Inhibition _Painter->setPen( QPen( colLines, 1, SolidLine ) ); _Painter->setBrush( colInhibit ); _Painter->drawRect ( (int)(iXCenter - (double)iSomaDiameter * (.4 * (double)iInhibit) / 30.0), (int)(iYCenter - (double)iSomaDiameter * .4 + (double)iSomaDiameter * .15), (int)((double)iSomaDiameter * (.4 * (double)iInhibit) / 15.0), (int)((double)iSomaDiameter * .8 -(double)iSomaDiameter * .6)); iInhibit = 10; _Painter->setBrush( NoBrush ); _Painter->drawRect ( (int)(iXCenter - (double)iSomaDiameter * (.4 * (double)iInhibit) / 30.0), (int)(iYCenter - (double)iSomaDiameter * .4 + (double)iSomaDiameter * .15), (int)((double)iSomaDiameter * (.4 * (double)iInhibit) / 15.0), (int)((double)iSomaDiameter * .8 -(double)iSomaDiameter * .6)); // ---------------------------- #endif #ifdef SHOW_APPETITIVE // Appetitive double fAppetitive; fAppetitive = 0; for (ii = 0; ii < 8; ii++){ fAppetitive += vaProximity[ii]; } fAppetitive /= 8.0; _Painter->setPen( QPen( colLines, 1, SolidLine ) ); _Painter->setBrush( colAppetitive ); _Painter->drawRect ( (int)(iXCenter ), (int)(iYCenter - (double)iSomaDiameter * .2 + (double)iSomaDiameter * .2), (int)((double)iSomaDiameter * (.4 * (double)fAppetitive) / 15.0), (int)((double)iSomaDiameter * .8 - (double)iSomaDiameter * .6)); fAppetitive = 10.0; _Painter->setBrush( NoBrush ); _Painter->drawRect ( (int)(iXCenter ), (int)(iYCenter - (double)iSomaDiameter * .2 + (double)iSomaDiameter * .2), (int)((double)iSomaDiameter * (.4 * (double)fAppetitive) / 15.0), (int)((double)iSomaDiameter * .8 - (double)iSomaDiameter * .6)); // ---------------------------- #endif #ifdef SHOW_AVERSIVE // Aversive // to the left double fAversive; fAversive = 0; for (ii = 0; ii < 8; ii++){ fAversive += (double)vaAmbient[ii]; } fAversive /= 8.0; _Painter->setPen( QPen( colLines, 1, SolidLine ) ); _Painter->setBrush( colAversive ); _Painter->drawRect ( (int)(iXCenter -((double)iSomaDiameter * (.4 * (double)fAversive) / 15.0) ), (int)(iYCenter - (double)iSomaDiameter * .2 + (double)iSomaDiameter * .2), (int)((double)iSomaDiameter * (.4 * (double)fAversive) / 15.0), (int)((double)iSomaDiameter * .8 - (double)iSomaDiameter * .6)); fAversive = 10.0; _Painter->setBrush( NoBrush ); _Painter->drawRect ( (int)(iXCenter -((double)iSomaDiameter * (.4 * (double)fAversive) / 15.0) ), (int)(iYCenter - (double)iSomaDiameter * .2 + (double)iSomaDiameter * .2), (int)((double)iSomaDiameter * (.4 * (double)fAversive) / 15.0), (int)((double)iSomaDiameter * .8 - (double)iSomaDiameter * .6)); // ---------------------------- #endif #ifdef USE_TRIANGLE /* Wheel direction */ _Painter->setPen( QPen( colLines, 1, SolidLine ) ); _Painter->setBrush( NoBrush ); _Painter->drawEllipse( iXCenter - iSomaDiameter / 3, iYCenter - iSomaDiameter / 3, (int)((double)iSomaDiameter / 1.5), (int)((double)iSomaDiameter / 1.5)); /* calculate the angle ^| is 0 degree! */ double fRest; double fFactor; fRest = atan ( 1.0 / 11.0 ) * 180.0 / PI; fFactor = 90.0 / ( 45.0 - fRest); fAngle = ((atan ((afMotor[0] + 1)/ (afMotor[1] + 1)) * 180 / PI) - fRest )* fFactor; fAngle -= 180; /* draw the triangle */ double fAngTmp; double fRadius; double fTriHeight; double fBaseWidth; int iXLeft, iXRight; int iYLeft, iYRight; int iXTip, iYTip; fRadius = iSomaDiameter / 3; fTriHeight = iSomaDiameter / 2 - iSomaDiameter / 1.5; fBaseWidth = (afMotor[0] + afMotor[1]) * 2; fAngTmp = fAngle - atan((fBaseWidth * 0.5) / fRadius) * 180 / PI; iXLeft = (int)(cos( fAngTmp * PI / 180.0) * fRadius ) + iXCenter; iYLeft = (int)(sin( fAngTmp * PI / 180.0) * fRadius ) + iYCenter; fAngTmp = fAngle + atan((fBaseWidth * 0.5) / fRadius) * 180 / PI; iXRight = (int)(cos( fAngTmp * PI / 180.0) * fRadius ) + iXCenter; iYRight = (int)(sin( fAngTmp * PI / 180.0) * fRadius ) + iYCenter; iXTip = (int)(cos( fAngle * PI / 180.0) * iSomaDiameter / 2 ) + iXCenter; iYTip = (int)(sin( fAngle * PI / 180.0) * iSomaDiameter / 2 ) + iYCenter; QPointArray a; _Painter->setBrush( QBrush( yellow, SolidPattern ) ); a.setPoints( 3, iXLeft,iYLeft, iXTip,iYTip, iXRight,iYRight); // _Painter->drawPoints( a ); _Painter->drawPolygon( a ); // _Painter->drawPolyline ( a ); #endif /* USE_TRIANGLE */ }
void MetalStyle::drawControl( ControlElement element, QPainter *p, const QWidget *widget, const QRect &r, const QColorGroup &cg, SFlags how, const QStyleOption& opt ) const { switch( element ) { case CE_PushButton: { const QPushButton *btn; btn = (const QPushButton*)widget; int x1, y1, x2, y2; r.coords( &x1, &y1, &x2, &y2 ); p->setPen( cg.foreground() ); p->setBrush( QBrush(cg.button(), NoBrush) ); QBrush fill; if ( btn->isDown() ) fill = cg.brush( QColorGroup::Mid ); else if ( btn->isOn() ) fill = QBrush( cg.mid(), Dense4Pattern ); else fill = cg.brush( QColorGroup::Button ); if ( btn->isDefault() ) { QPointArray a; a.setPoints( 9, x1, y1, x2, y1, x2, y2, x1, y2, x1, y1+1, x2-1, y1+1, x2-1, y2-1, x1+1, y2-1, x1+1, y1+1 ); p->setPen( Qt::black ); p->drawPolyline( a ); x1 += 2; y1 += 2; x2 -= 2; y2 -= 2; } SFlags flags = Style_Default; if ( btn->isOn() ) flags |= Style_On; if ( btn->isDown() ) flags |= Style_Down; if ( !btn->isFlat() && !btn->isDown() ) flags |= Style_Raised; drawPrimitive( PE_ButtonCommand, p, QRect( x1, y1, x2 - x1 + 1, y2 - y1 + 1), cg, flags, opt ); if ( btn->isMenuButton() ) { flags = Style_Default; if ( btn->isEnabled() ) flags |= Style_Enabled; int dx = ( y1 - y2 - 4 ) / 3; drawPrimitive( PE_ArrowDown, p, QRect(x2 - dx, dx, y1, y2 - y1), cg, flags, opt ); } if ( p->brush().style() != NoBrush ) p->setBrush( NoBrush ); break; } case CE_PushButtonLabel: { const QPushButton *btn; btn = (const QPushButton*)widget; int x, y, w, h; r.rect( &x, &y, &w, &h ); int x1, y1, x2, y2; r.coords( &x1, &y1, &x2, &y2 ); int dx = 0; int dy = 0; if ( btn->isMenuButton() ) dx = ( y2 - y1 ) / 3; if ( btn->isOn() || btn->isDown() ) { dx--; dy--; } if ( dx || dy ) p->translate( dx, dy ); x += 2; y += 2; w -= 4; h -= 4; drawItem( p, QRect( x, y, w, h ), AlignCenter|ShowPrefix, cg, btn->isEnabled(), btn->pixmap(), btn->text(), -1, (btn->isDown() || btn->isOn())? &cg.brightText() : &cg.buttonText() ); if ( dx || dy ) p->translate( -dx, -dy ); break; } default: QWindowsStyle::drawControl( element, p, widget, r, cg, how, opt ); break; } }
void QCDEStyle::drawArrow( QPainter *p, ArrowType type, bool down, int x, int y, int w, int h, const QColorGroup &g, bool enabled, const QBrush * /* fill */ ) { QPointArray bFill; // fill polygon QPointArray bTop; // top shadow. QPointArray bBot; // bottom shadow. QPointArray bLeft; // left shadow. QWMatrix matrix; // xform matrix bool vertical = type == UpArrow || type == DownArrow; bool horizontal = !vertical; int dim = w < h ? w : h; int colspec = 0x0000; // color specification array if ( dim < 2 ) // too small arrow return; // adjust size and center (to fix rotation below) if ( w > dim ) { x += (w-dim)/2; w = dim; } if ( h > dim ) { y += (h-dim)/2; h = dim; } if ( dim > 3 ) { bFill.resize( dim & 1 ? 3 : 4 ); bTop.resize( 2 ); bBot.resize( 2 ); bLeft.resize( 2 ); bLeft.putPoints( 0, 2, 0,0, 0,dim-1 ); bTop.putPoints( 0, 2, 1,0, dim-1, dim/2); bBot.putPoints( 0, 2, 1,dim-1, dim-1, dim/2); if ( dim > 6 ) { // dim>6: must fill interior bFill.putPoints( 0, 2, 1,dim-1, 1,1 ); if ( dim & 1 ) // if size is an odd number bFill.setPoint( 2, dim - 2, dim / 2 ); else bFill.putPoints( 2, 2, dim-2,dim/2-1, dim-2,dim/2 ); } } else { if ( dim == 3 ) { // 3x3 arrow pattern bLeft.setPoints( 4, 0,0, 0,2, 1,1, 1,1 ); bTop .setPoints( 2, 1,0, 1,0 ); bBot .setPoints( 2, 1,2, 2,1 ); } else { // 2x2 arrow pattern bLeft.setPoints( 2, 0,0, 0,1 ); bTop .setPoints( 2, 1,0, 1,0 ); bBot .setPoints( 2, 1,1, 1,1 ); } } if ( type == UpArrow || type == LeftArrow ) { matrix.translate( x, y ); if ( vertical ) { matrix.translate( 0, h - 1 ); matrix.rotate( -90 ); } else { matrix.translate( w - 1, h - 1 ); matrix.rotate( 180 ); } if ( down ) colspec = horizontal ? 0x2334 : 0x2343; else colspec = horizontal ? 0x1443 : 0x1434; } else if ( type == DownArrow || type == RightArrow ) { matrix.translate( x, y ); if ( vertical ) { matrix.translate( w-1, 0 ); matrix.rotate( 90 ); } if ( down ) colspec = horizontal ? 0x2443 : 0x2434; else colspec = horizontal ? 0x1334 : 0x1343; } QColor *cols[5]; if ( enabled ) { cols[0] = 0; cols[1] = (QColor *)&g.button(); cols[2] = (QColor *)&g.mid(); cols[3] = (QColor *)&g.light(); cols[4] = (QColor *)&g.dark(); } else { cols[0] = 0; cols[1] = (QColor *)&g.button(); cols[2] = (QColor *)&g.button(); cols[3] = (QColor *)&g.button(); cols[4] = (QColor *)&g.button(); } #define CMID *cols[ (colspec>>12) & 0xf ] #define CLEFT *cols[ (colspec>>8) & 0xf ] #define CTOP *cols[ (colspec>>4) & 0xf ] #define CBOT *cols[ colspec & 0xf ] QPen savePen = p->pen(); // save current pen QBrush saveBrush = p->brush(); // save current brush QWMatrix wxm = p->worldMatrix(); QPen pen( NoPen ); QBrush brush = g.brush( enabled?QColorGroup::Button:QColorGroup::Mid ); p->setPen( pen ); p->setBrush( brush ); p->setWorldMatrix( matrix, TRUE ); // set transformation matrix p->drawPolygon( bFill ); // fill arrow p->setBrush( NoBrush ); // don't fill p->setPen( CLEFT ); p->drawLineSegments( bLeft ); p->setPen( CBOT ); p->drawLineSegments( bBot ); p->setPen( CTOP ); p->drawLineSegments( bTop ); p->setWorldMatrix( wxm ); p->setBrush( saveBrush ); // restore brush p->setPen( savePen ); // restore pen #undef CMID #undef CLEFT #undef CTOP #undef CBOT }
/*! Draws the mask of a slider */ void QWindowsStyle::drawSliderMask( QPainter *p, int x, int y, int w, int h, Orientation orient, bool tickAbove, bool tickBelow ) { if ( tickAbove && tickBelow || !tickAbove && !tickBelow ) { p->fillRect(x, y, w, h, color1); return; } int x1 = x; int x2 = x+w-1; int y1 = y; int y2 = y+h-1; enum { SlUp, SlDown, SlLeft, SlRight } dir; if ( orient == Horizontal ) if ( tickAbove ) dir = SlUp; else dir = SlDown; else if ( tickAbove ) dir = SlLeft; else dir = SlRight; switch ( dir ) { case SlUp: y1 = y1 + w/2; break; case SlDown: y2 = y2 - w/2; break; case SlLeft: x1 = x1 + h/2; break; case SlRight: x2 = x2 - h/2; break; } QPointArray a; switch ( dir ) { case SlUp: a.setPoints(5, x1,y1, x1 + w/2, y1 - w/2, x2,y1, x2,y2, x1,y2); break; case SlDown: a.setPoints(5, x1,y1, x2,y1, x2,y2, x1 + w/2, y2 + w/2, x1,y2); break; case SlLeft: a.setPoints(5, x1,y1, x2,y1, x2,y2, x1,y2, x1 - h/2, y1 + h/2 ); break; case SlRight: a.setPoints(5, x1,y1, x2,y1, x2 + h/2, y1 + h/2, x2,y2, x1,y2); break; } p->setBrush(color1); p->setPen(color1); p->drawPolygon( a ); }
/*!\reimp */ void QWindowsStyle::drawSlider( QPainter *p, int x, int y, int w, int h, const QColorGroup &g, Orientation orient, bool tickAbove, bool tickBelow ) { #ifndef QT_NO_SLIDER // 4444440 // 4333310 // 4322210 // 4322210 // 4322210 // 4322210 // *43210* // **410** // ***0*** const QColor c0 = g.shadow(); const QColor c1 = g.dark(); // const QColor c2 = g.button(); const QColor c3 = g.midlight(); const QColor c4 = g.light(); int x1 = x; int x2 = x+w-1; int y1 = y; int y2 = y+h-1; p->fillRect( x, y, w, h, g.brush( QColorGroup::Background ) ); if ( tickAbove && tickBelow || !tickAbove && !tickBelow ) { qDrawWinButton( p, QRect(x,y,w,h), g, FALSE, &g.brush( QColorGroup::Button ) ); return; } enum { SlUp, SlDown, SlLeft, SlRight } dir; if ( orient == Horizontal ) if ( tickAbove ) dir = SlUp; else dir = SlDown; else if ( tickAbove ) dir = SlLeft; else dir = SlRight; QPointArray a; int d = 0; switch ( dir ) { case SlUp: y1 = y1 + w/2; d = (w + 1) / 2 - 1; a.setPoints(5, x1,y1, x1,y2, x2,y2, x2,y1, x1+d,y1-d ); break; case SlDown: y2 = y2 - w/2; d = (w + 1) / 2 - 1; a.setPoints(5, x1,y1, x1,y2, x1+d,y2+d, x2,y2, x2,y1 ); break; case SlLeft: d = (h + 1) / 2 - 1; x1 = x1 + h/2; a.setPoints(5, x1,y1, x1-d,y1+d, x1,y2, x2,y2, x2,y1); break; case SlRight: d = (h + 1) / 2 - 1; x2 = x2 - h/2; a.setPoints(5, x1,y1, x1,y2, x2,y2, x2+d,y1+d, x2,y1 ); break; } QBrush oldBrush = p->brush(); p->setBrush( g.brush( QColorGroup::Button ) ); p->setPen( NoPen ); p->drawRect( x1, y1, x2-x1+1, y2-y1+1 ); p->drawPolygon( a ); p->setBrush( oldBrush ); if ( dir != SlUp ) { p->setPen( c4 ); p->drawLine( x1, y1, x2, y1 ); p->setPen( c3 ); p->drawLine( x1, y1+1, x2, y1+1 ); } if ( dir != SlLeft ) { p->setPen( c3 ); p->drawLine( x1+1, y1+1, x1+1, y2 ); p->setPen( c4 ); p->drawLine( x1, y1, x1, y2 ); } if ( dir != SlRight ) { p->setPen( c0 ); p->drawLine( x2, y1, x2, y2 ); p->setPen( c1 ); p->drawLine( x2-1, y1+1, x2-1, y2-1 ); } if ( dir != SlDown ) { p->setPen( c0 ); p->drawLine( x1, y2, x2, y2 ); p->setPen( c1 ); p->drawLine( x1+1, y2-1, x2-1, y2-1 ); } switch ( dir ) { case SlUp: p->setPen( c4 ); p->drawLine( x1, y1, x1+d, y1-d); p->setPen( c0 ); d = w - d - 1; p->drawLine( x2, y1, x2-d, y1-d); d--; p->setPen( c3 ); p->drawLine( x1+1, y1, x1+1+d, y1-d ); p->setPen( c1 ); p->drawLine( x2-1, y1, x2-1-d, y1-d); break; case SlDown: p->setPen( c4 ); p->drawLine( x1, y2, x1+d, y2+d); p->setPen( c0 ); d = w - d - 1; p->drawLine( x2, y2, x2-d, y2+d); d--; p->setPen( c3 ); p->drawLine( x1+1, y2, x1+1+d, y2+d ); p->setPen( c1 ); p->drawLine( x2-1, y2, x2-1-d, y2+d); break; case SlLeft: p->setPen( c4 ); p->drawLine( x1, y1, x1-d, y1+d); p->setPen( c0 ); d = h - d - 1; p->drawLine( x1, y2, x1-d, y2-d); d--; p->setPen( c3 ); p->drawLine( x1, y1+1, x1-d, y1+1+d ); p->setPen( c1 ); p->drawLine( x1, y2-1, x1-d, y2-1-d); break; case SlRight: p->setPen( c4 ); p->drawLine( x2, y1, x2+d, y1+d); p->setPen( c0 ); d = h - d - 1; p->drawLine( x2, y2, x2+d, y2-d); d--; p->setPen( c3 ); p->drawLine( x2, y1+1, x2+d, y1+1+d ); p->setPen( c1 ); p->drawLine( x2, y2-1, x2+d, y2-1-d); break; } #endif }