コード例 #1
0
ファイル: canvas.cpp プロジェクト: ghetzel/zee
void Canvas::paintEvent(QPaintEvent *e)
{
    QPainter *p = new QPainter(this);
    QPen pen(QColor(0,0,0,255));
    qreal curangle = 0.0;

    if(p->isActive()){
        p->setRenderHint(QPainter::Antialiasing);
        pen.setWidth(1);
        p->setPen(pen);

        p->save();
        pen.setColor(QColor(255,0,0,255));
        p->setPen(pen);

        foreach(qreal v, _values){
		qreal span = (5760.0 / _valueSum) * v;

		cout << "Value: " << v << " (sum="<<_valueSum<<") , span = " << span << "/5760, curangle = " << curangle;

		p->drawPie(rect(), curangle, span);
		curangle += span;

		cout << ", newangle = " << curangle << endl;
	}
コード例 #2
0
void CannonField::paintCannon(QPainter &painter)
{
	painter.setPen(Qt::NoPen);
	painter.setBrush(Qt::blue);

	painter.save();	
	painter.translate(0, height());
	painter.drawPie(QRect(-35, -35, 70, 70), 0, 90*16);
	painter.rotate(-currentAngle);
	painter.drawRect(QRect(30, -5, 20, 10));
	painter.restore();
}
コード例 #3
0
void RangeSensorWidget::paintEvent(QPaintEvent*)
{
  if (scan_ && scanDescription_) {

    QPainter p;
    p.begin(this);

    // draw new lines
    p.setPen(Qt::red);
    p.setBrush(Qt::blue);

    for (unsigned int j = 0; j < scanDescription_->group[group_].sensor.length(); ++j) {
    
      if (scan_->range[j] >= 0) {

	if (!drawCones_) {
	  Vector2d a(scanDescription_->group[group_].sensor[j].distance);
	  a *= Vector2d(-sin(scanDescription_->group[group_].sensor[j].alpha),
			cos(scanDescription_->group[group_].sensor[j].alpha));
      
	  Vector2d b(scan_->range[j], 0.);
	  b *= Vector2d(-sin(scanDescription_->group[group_].sensor[j].alpha +
			     scanDescription_->group[group_].sensor[j].beta),
			cos(scanDescription_->group[group_].sensor[j].alpha +
			    scanDescription_->group[group_].sensor[j].beta));
      
	  Vector2d c(a + b);
      
	  p.drawLine(x0_ + (int) rint(a.real() * scaling_), y0_ - (int) rint(a.imag() * scaling_), 
		     x0_ + (int) rint(c.real() * scaling_), y0_ - (int) rint(c.imag() * scaling_));
	}
	else {
	  int delta = (int) rint(scan_->range[j] * scaling_);
	  int angle = (int) rint( ((double) (scanDescription_->group[group_].sensor[j].alpha +
					     scanDescription_->group[group_].sensor[j].beta) *
				   180. / M_PI + 90.) 
				  * 16. );
	  int apex = (int) rint( ( (double) (scanDescription_->group[group_].description.focus) *
				   16. * 180. / M_PI) 
				 / 2.);
			      
      
	  p.drawPie(x0_ - delta, y0_ - delta,
		    2 * delta, 2 * delta,
		    angle - apex, 
		    2 * apex);
	}
      }
    }

    p.end();
  }
}
コード例 #4
0
ファイル: VQMCChannelRenderer.hpp プロジェクト: sfegan/ChiLA
    static void draw(unsigned icam, unsigned ncam,
		     QPainter& painter, bool draw_fast) 
    { 
      int a0 = int(round(double(icam)/double(ncam)*5760));
      int a1 = int(round(double(icam+1)/double(ncam)*5760));
      if(painter.brush().style() == Qt::NoBrush)
	{
	  painter.drawArc(QRectF(-1,-1,2,2),a0,a1-a0);
	}
      else if(painter.pen().color() != painter.brush().color())
	{
	  QPen pen = painter.pen();
	  painter.setPen(QPen(painter.brush().color()));
	  painter.drawPie(QRectF(-1,-1,2,2),a0,a1-a0);
	  painter.setPen(pen);
	  painter.drawArc(QRectF(-1,-1,2,2),a0,a1-a0);
	}
      else
	{
	  painter.drawPie(QRectF(-1,-1,2,2),a0,a1-a0);
	}
    }
コード例 #5
0
ファイル: wtfwidget.cpp プロジェクト: leepood/ucweblike
void WTFWidget::drawCircle(QPainter& painter){
    QRect rect = this->contentsRect();
    QPoint center = rect.center();
    float max = 1.0f;
    qreal alpha = qMax(0.0f,qMin(max,this->_percent)) * 0xff;
    QBrush brush(QColor::fromRgb(11,160,238,alpha));
    painter.setBrush(brush);
    QRect pieRect(center.x() - CIRCLE_RADIUS,
                  center.y() - CIRCLE_RADIUS,
                  CIRCLE_RADIUS * 2,
                  CIRCLE_RADIUS * 2);
    painter.drawPie(pieRect,1440,-this->_percent * 5760);
}
コード例 #6
0
ファイル: sani_drawing.cpp プロジェクト: camio/sani
 void operator()
     ( QPainter & painter
     , const DrawPie & d
     ) const
 {
     painter.setPen( d.pen );
     painter.setBrush( d.brush );
     painter.drawPie
         ( d.rect
         , degToDeg16( d.startAngle )
         , degToDeg16( d.spanAngle )
         );
 }
コード例 #7
0
ファイル: ringchart.cpp プロジェクト: houzhenggang/qsint
void RingChart::drawSegment(QPainter &p, const QRect& pieRect,
                           const QModelIndex &index, double /*value*/,
                           double angle1, double angle2,
                           bool isHighlighted)
{
    int r = index.row();

    p.setPen(m_itemPen);

    QBrush brush(qvariant_cast<QBrush>(m_model->headerData(r, Qt::Vertical, Qt::BackgroundRole)));
    p.setBrush(brush);

    p.drawPie(pieRect, int(angle1*16), int(angle2*16));

	// draw over if highlighted
    if (isHighlighted)
    {
        p.setPen(m_hlPen);
        p.setBrush(m_hlBrush);

        p.drawPie(pieRect, int(angle1*16), int(angle2*16));
    }
}
コード例 #8
0
ファイル: editorarea.cpp プロジェクト: archTk/arch-ne
void EditorArea::paintHighlightingNode(QPainter& painter)
{
    QMap<QString, int> supportNodes(workspace->getSupportNodes());

    QPointF screenXY = graph2screen(workspace->getNodePosition(supportNodes.value("highlightingNode")));

    qreal radius = size2screen(14);
    qreal rectX = radius;
    qreal rectY = radius;
    qreal width = radius * 2;
    qreal height = radius * 2;

    int translateX = screenXY.x();
    int translateY = screenXY.y();
    painter.translate(translateX, translateY);
    painter.drawPie(QRect(- rectX, - rectY, width, height), 0, 360 *16);

    painter.translate( - translateX, - translateY);
}
コード例 #9
0
void CannonField::paintCannon( QPainter *p )
{
    QRect    cr = cannonRect();
    QPixmap  pix( cr.size() );
    QPainter tmp;

    pix.fill( this, cr.topLeft() );

    tmp.begin( &pix );
    tmp.setBrush( blue );
    tmp.setPen( NoPen );

    tmp.translate( 0, pix.height() - 1 );
    tmp.drawPie( QRect( -35,-35, 70, 70 ), 0, 90*16 );
    tmp.rotate( -ang );
    tmp.drawRect( barrel_rect );
    tmp.end();

    p->drawPixmap( cr.topLeft(), pix );
}
コード例 #10
0
ファイル: editorarea.cpp プロジェクト: archTk/arch-ne
void EditorArea::paintSupportNodes4selecting(QPainter &painter)
{
    QVector<int> supportNodes4selecting(workspace->getSupportNodes4selecting());

    qreal radius = size2screen(9);
    qreal rectX = radius;
    qreal rectY = radius;
    qreal width = radius * 2;
    qreal height = radius * 2;

    for (int i = 0; i < supportNodes4selecting.size(); i++) {
        QPointF screenXY = graph2screen(workspace->getNodePosition(supportNodes4selecting[i]));

        int translateX = screenXY.x();
        int translateY = screenXY.y();
        painter.translate(translateX, translateY);
        painter.drawPie(QRect(- rectX, - rectY, width, height), 0, 360 *16);

        painter.translate( - translateX, - translateY);
    }

}
コード例 #11
0
ファイル: editorarea.cpp プロジェクト: archTk/arch-ne
void EditorArea::paintTooCloseNodes(QPainter& painter)
{
    QMap<QString, int> supportNodes(workspace->getSupportNodes());
    QMapIterator<QString, int> nodesIterator(supportNodes);

    qreal radius = size2screen(10);
    qreal rectX = radius;
    qreal rectY = radius;
    qreal width = radius * 2;
    qreal height = radius * 2;

    while (nodesIterator.hasNext()) {
        nodesIterator.next();
        if (nodesIterator.key() == "tooCloseNode") {
            QPointF screenXY = graph2screen(workspace->getNodePosition(nodesIterator.value()));
            int translateX = screenXY.x();
            int translateY = screenXY.y();
            painter.translate(translateX, translateY);
            painter.drawPie(QRect(- rectX, - rectY, width, height), 0, 360 *16);

            painter.translate( - translateX, - translateY);
        }
    }
}
コード例 #12
0
//------------------------------------------------------------------------------
//
void QEAnalogIndicator::drawMeter (QPainter & painter, QRect &area, const double fraction)
{
   // Macro function to create a point based on centre positon, radius and direction (s, c).
   //
   #define RPOINT(f)  QPoint (int (centre_x + f*radius*s),  int (centre_y - f*radius*c))

   const int width_span = area.right () - area.left ();
   const int height_span = area.bottom () - area.top ();

   double centre_x, centre_y;
   double radius;
   double s, c;
   QPen pen;
   QBrush brush;
   int j;
   double lowerAngle;
   double upperAngle;
   double angle;
   double minS, maxS, minC, maxC;
   double gap;
   QRect dialRect;
   BandList bandList;
   bool ok;
   bool isMajor;
   double value;
   double f;
   QPoint p1, p2;

   // Working in degrees.
   //
   lowerAngle = this->mCentreAngle - this->mSpanAngle / 2.0;
   upperAngle = this->mCentreAngle + this->mSpanAngle / 2.0;

   // Find min and max sin/cosine so that we can find optimum centre.
   //
   minS = maxS = minC = maxC = 0.0;
   angle = lowerAngle;
   while (true) {
      s = sin (angle * RADIANS_PER_DEGREE);
      c = cos (angle * RADIANS_PER_DEGREE);

      minS = MIN (minS, s);
      maxS = MAX (maxS, s);
      minC = MIN (minC, c);
      maxC = MAX (maxC, c);

      if (angle >= upperAngle) break;

      // Determine next angle.
      //
      if      (angle < -360.0) { angle = -360.0; }
      else if (angle < -270.0) { angle = -270.0; }
      else if (angle < -180.0) { angle = -180.0; }
      else if (angle < -90.0)  { angle = -90.0;  }
      else if (angle < 0.0)    { angle =  0.0;   }
      else if (angle < 90.0)   { angle =  90.0;  }
      else if (angle < 180.0)  { angle = 180.0;  }
      else if (angle < 270.0)  { angle = 270.0;  }
      else if (angle < 360.0)  { angle = 360.0;  }

      angle = MIN (angle, upperAngle);
   }

   // Determine centre.
   //
   gap  = 6.0;     // gap around edge

   f = (-minS) / (maxS - minS);
   centre_x = gap + f * (width_span - 2.0 * gap);

   f = (+maxC) / (maxC - minC);
   centre_y = 6.0 + f * (height_span - 2.0 * gap);

   radius = MIN (width_span, height_span);
   if (maxS > 0) radius = MIN (radius, ((area.right () - gap)  - centre_x) /maxS);
   if (minS < 0) radius = MIN (radius, ((area.left () + gap)   - centre_x) /minS);
   if (maxC > 0) radius = MIN (radius, (centre_y -    (area.top () + gap)) /maxC);
   if (minC < 0) radius = MIN (radius, (centre_y - (area.bottom () - gap)) /minC);


   // Draw band/colour based annulus.  We do this as two sets of drawPie
   // calls: one set with full radius and one with 97% radius.
   //
   dialRect.setLeft   (int (centre_x - radius));
   dialRect.setRight  (int (centre_x + radius));
   dialRect.setTop    (int (centre_y - radius));
   dialRect.setBottom (int (centre_y + radius));

   // Note: this is a dispatching call.
   //
   bandList = this->getBandList ();
   for (j = 0; j < bandList.count (); j++) {
      Band band = bandList.at (j);
      double fl;
      double fu;
      double al;
      double au;
      int startAngle;
      int spanAngle;

      pen.setWidth (0);
      pen.setColor (band.colour);
      painter.setPen (pen);

      brush.setColor (band.colour);
      brush.setStyle (Qt::SolidPattern);
      painter.setBrush (brush);

      fl = this->calcFraction (band.lower);
      fu =  this->calcFraction (band.upper);

      al = lowerAngle +  fl * (upperAngle - lowerAngle);
      au = lowerAngle +  fu * (upperAngle - lowerAngle);

      // The startAngle and spanAngle must be specified in 1/16th of a degree,
      // i.e. a full circle equals 5760 (16 * 360). Positive values for the
      // angles mean counter-clockwise while negative values mean the clockwise
      // direction. Zero degrees is at the 3 o'clock position.
      //
      startAngle = int ((90.0 - au) * 16.0);
      if (startAngle < 0) {
         startAngle +=  5760;
      }
      spanAngle = int ((au - al) * 16.0);
      if (spanAngle < 0) {
         spanAngle +=  5760;
      }

      painter.drawPie (dialRect, startAngle, spanAngle);
   }

   if (bandList.count () > 0) {
      int startAngle;
      int spanAngle;

      dialRect.setLeft   (int (centre_x - 0.97 * radius));
      dialRect.setRight  (int (centre_x + 0.97 * radius));
      dialRect.setTop    (int (centre_y - 0.97 * radius));
      dialRect.setBottom (int (centre_y + 0.97 * radius));

      pen.setWidth (0);
      pen.setColor (this->getBackgroundPaintColour ());
      painter.setPen (pen);

      brush.setColor (this->getBackgroundPaintColour ());
      brush.setStyle (Qt::SolidPattern);
      painter.setBrush (brush);

      startAngle = int ((90.0 - upperAngle) * 16.0) - 1;
      if (startAngle < 0) {
         startAngle +=  5760;
      }
      spanAngle = int ((upperAngle - lowerAngle) * 16.0) + 4;
      if (spanAngle < 0) {
         spanAngle +=  5760;
      }

      painter.drawPie (dialRect, startAngle, spanAngle);
   }

   // Draw axis
   //
   pen.setWidth (1);
   pen.setColor (this->getFontPaintColour ());
   painter.setPen (pen);

   painter.setRenderHint (QPainter::Antialiasing, true);

   // Iterate over interval values.
   //
   for (ok = this->firstValue (j, value, isMajor); ok;
        ok = this->nextValue  (j, value, isMajor)) {

      f = this->calcFraction (value);

      angle = lowerAngle +  f * (upperAngle - lowerAngle);
      s = sin (angle * RADIANS_PER_DEGREE);
      c = cos (angle * RADIANS_PER_DEGREE);

      if (isMajor) {
         p1 = RPOINT (0.94);
      } else {
         p1 = RPOINT (0.97);
      }
      p2 = RPOINT (1.0);

      painter.drawLine (p1, p2);

      if (isMajor) {
         QString vt;

         if (this->getLogScale () ) {
            vt.sprintf ("%.0e", value);
         } else {
            vt.sprintf ("%.1f", value);
         }
         p1 = RPOINT (0.88);
         this->drawText (painter, p1, vt, 7);
      }
   }

   angle = lowerAngle + fraction *(upperAngle - lowerAngle);
   s = sin (angle * RADIANS_PER_DEGREE);
   c = cos (angle * RADIANS_PER_DEGREE);

   pen.setColor (this->getForegroundPaintColour ());
   p1 = RPOINT (0.0);

   p2 = RPOINT (1.0);
   pen.setWidth (2);
   painter.setPen (pen);
   painter.drawLine (p1, p2);

   p2 = RPOINT (0.75);
   pen.setWidth (3);
   painter.setPen (pen);
   painter.drawLine (p1, p2);

   p2 = RPOINT (0.5);
   pen.setWidth (4);
   painter.setPen (pen);
   painter.drawLine (p1, p2);

   p2 = RPOINT (0.25);
   pen.setWidth (5);
   painter.setPen (pen);
   painter.drawLine (p1, p2);

#undef RPOINT
}
コード例 #13
0
ファイル: map.cpp プロジェクト: KDE/krusader
void
RadialMap::Map::paint(unsigned int scaleFactor)
{
    if (scaleFactor == 0)  //just in case
        scaleFactor = 1;

    QPainter paint;
    QRect rect = m_rect;
    int step = m_ringBreadth;
    int excess = -1;

    //scale the pixmap, or do intelligent distribution of excess to prevent nasty resizing
    if (scaleFactor > 1) {
        int x1, y1, x2, y2;
        rect.getCoords(&x1, &y1, &x2, &y2);
        x1 *= scaleFactor;
        y1 *= scaleFactor;
        x2 *= scaleFactor;
        y2 *= scaleFactor;
        rect.setCoords(x1, y1, x2, y2);

        step *= scaleFactor;
        QPixmap::operator=(QPixmap(this->size() * (int)scaleFactor));
    } else if (m_ringBreadth != MAX_RING_BREADTH && m_ringBreadth != MIN_RING_BREADTH) {
        excess = rect.width() % m_ringBreadth;
        ++step;
    }

    //**** best option you can think of is to make the circles slightly less perfect,
    //  ** i.e. slightly eliptic when resizing inbetween


    paint.begin(this);

    fill(); //erase background

    for (int x = m_visibleDepth; x >= 0; --x) {
        int width = rect.width() / 2;
        //clever geometric trick to find largest angle that will give biggest arrow head
        int a_max = int(acos((double)width / double((width + 5) * scaleFactor)) * (180 * 16 / M_PI));

        for (ConstIterator<Segment> it = m_signature[x].constIterator(); it != m_signature[x].end(); ++it) {
            //draw the pie segments, most of this code is concerned with drawing the little
            //arrows on the ends of segments when they have hidden files

            paint.setPen((*it)->pen());

            if ((*it)->hasHiddenChildren()) {
                //draw arrow head to indicate undisplayed files/directories
                QPolygon pts(3);
                QPoint pos, cpos = rect.center();
                int a[3] = {static_cast<int>((*it)->start()), static_cast<int>((*it)->length()), 0 };

                a[2] = a[0] + (a[1] / 2); //assign to halfway between
                if (a[1] > a_max) {
                    a[1] = a_max;
                    a[0] = a[2] - a_max / 2;
                }

                a[1] += a[0];

                for (int i = 0, radius = width; i < 3; ++i) {
                    double ra = M_PI / (180 * 16) * a[i], sinra, cosra;

                    if (i == 2)
                        radius += 5 * scaleFactor;
#if 0
                    sincos(ra, &sinra, &cosra);
#endif
                    sinra = sin(ra); cosra = cos(ra);
                    pos.rx() = cpos.x() + static_cast<int>(cosra * radius);
                    pos.ry() = cpos.y() - static_cast<int>(sinra * radius);
                    pts.setPoint(i, pos);
                }

                paint.setBrush((*it)->pen());
                paint.drawPolygon(pts);
            }

            paint.setBrush((*it)->brush());
            paint.drawPie(rect, (*it)->start(), (*it)->length());

            if ((*it)->hasHiddenChildren()) {
                //**** code is bloated!
                paint.save();
                QPen pen = paint.pen();
                int width = 2 * scaleFactor;
                pen.setWidth(width);
                paint.setPen(pen);
                QRect rect2 = rect;
                width /= 2;
                rect2.adjust(width, width, -width, -width);
                paint.drawArc(rect2, (*it)->start(), (*it)->length());
                paint.restore();
            }
        }

        if (excess >= 0) {  //excess allows us to resize more smoothly (still crud tho)
            if (excess < 2)  //only decrease rect by more if even number of excesses left
                --step;
            excess -= 2;
        }

        rect.adjust(step, step, -step, -step);
    }

    //  if( excess > 0 ) rect.adjust( excess, excess, 0, 0 ); //ugly

    paint.setPen(COLOR_GREY);
    paint.setBrush(Qt::white);
    paint.drawEllipse(rect);

    if (scaleFactor > 1) {
        //have to end in order to smoothscale()
        paint.end();

        int x1, y1, x2, y2;
        rect.getCoords(&x1, &y1, &x2, &y2);
        x1 /= scaleFactor;
        y1 /= scaleFactor;
        x2 /= scaleFactor;
        y2 /= scaleFactor;
        rect.setCoords(x1, y1, x2, y2);

        QImage img = this->toImage();
        img = img.scaled(this->size() / (int)scaleFactor, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
        this->QPixmap::operator=(fromImage(img, Qt::AutoColor));

        paint.begin(this);
        paint.setPen(COLOR_GREY);
        paint.setBrush(Qt::white);
    }

    paint.drawText(rect, Qt::AlignCenter, m_centerText);

    m_innerRadius = rect.width() / 2; //rect.width should be multiple of 2

    paint.end();
}
コード例 #14
0
	void KviCanvasPie::drawContent(QPainter &p)
	{
		int iStartAngle = m_properties["iStartAngle"].asInt() * 16;
		int iEndAngle = m_properties["iExtensionAngle"].asInt() * 16;
		p.drawPie((int)x(),(int)y(),width(),height(),iStartAngle,iEndAngle);
	}
コード例 #15
0
ファイル: manometer.cpp プロジェクト: humlium/rainSimulation
void ManoMeter::paintBackground(QPainter & painter)
{
	static const int scaleTriangle[6] = { -6,141,6,141,0,129 };
	initCoordinateSystem(painter);

        // Painting Malowanie obwiedni tarczy. Bia³a tarcza z czarn± skal±
        QPen Pen(QColor(0,0,0)); Pen.setWidth(4);
        painter.setPen(Pen);

        QRadialGradient back1(QPointF(0.0,0.0),180.0,QPointF(-35.0,145.0));
	back1.setColorAt(0.0,QColor(250,250,250));
	back1.setColorAt(1.0,QColor(20,20,20));

	QRadialGradient back2(QPointF(0.0,0.0),225.0,QPointF(76.5,135.0));
	back2.setColorAt(0.0,QColor(10,10,10));
	back2.setColorAt(1.0,QColor(250,250,250));

	painter.setBrush(QBrush(back1));
	painter.drawEllipse(-162,-162,324,324);
	painter.setPen(Qt::NoPen);
        painter.setBrush(QBrush(back2));
        painter.drawEllipse(-152,-152,304,304);

        QRadialGradient shield(QPointF(0,0),182,QPointF(-12.0,-15.0));
	shield.setColorAt(0.0,Qt::white);
	shield.setColorAt(0.5,QColor(240,240,240));
	shield.setColorAt(1.0,QColor(215,215,215));


	// internal scale circle 
	painter.setBrush(QBrush(shield));
	painter.setPen(Pen);
	painter.drawEllipse(-142,-142,284,284);

	  painter.setPen(Qt::NoPen);
          // nominal
	  painter.setBrush(QColor(0,200,0));
	  assert(m_max-m_min != 0);
	  int angle = static_cast<int>( (3840 * ( m_nominal - m_min ))/(m_max-m_min) );
	  if (m_min <= m_nominal && m_nominal < m_max )
           painter.drawPie(QRect(-141,-141,282,282),-480,3840 - angle % 5760 );
	  // Critical

	  painter.setBrush(QBrush(Qt::red));
	  angle = static_cast<int>( (3840 * ( m_critical - m_min ))/(m_max-m_min) );
	  if ( m_min <= m_critical && m_critical < m_max  )
	  painter.drawPie(QRect(-141,-141,282,282),-480, 3840 - angle % 5760  ); //-480, 3840*( m_max-m_min - critical()-abs(m_min) )/static_cast<double>(m_max-m_min));
	  // bia³a obwiednia
	  painter.setBrush(QBrush(shield));
	  painter.drawEllipse(-129,-129,258,258);

        // Ustawienie siê na pocz±tku skali

        painter.rotate(60.0);

 	// Rysowanie skali kreski
	painter.save();
        painter.setBrush(QBrush(Qt::black));
  	int line_length=10;
	for (int i=0;i<33;i++)
	{
	  painter.setPen(Pen);

          if (i % 4) painter.drawLine(0,140,0,140-line_length);
          else {
	    painter.setPen(Qt::NoPen);
	    painter.drawConvexPolygon(QPolygon(3, scaleTriangle));
	  }

	  painter.rotate(7.5);

	Pen.setWidth(3);

 	  if (i % 2)  line_length=10;
	  else        line_length=5;
	}
	painter.restore();

        // Rysowanie skali liczby .

	if (true || digitOffset())
        {
          painter.setPen(Qt::black);
          painter.rotate(-60.0);
	  painter.setFont(digitFont());
	  for (int i=0;i<9;i++)
	  {
	    double v = m_min + i*(m_max - m_min)/8.0;
	    if (fabs(v) < 0.000001 ) v = 0.0;
	    QString val = QString("%1").arg(v);
            QSize Size = painter.fontMetrics().size(Qt::TextSingleLine, val);
            painter.save();
	    painter.translate( digitOffset() * cos((5+i)*PI/6.0), digitOffset() * sin((5+i)*PI/6.0));
	    painter.drawText( QPointF( Size.width()/ -2.0,  Size.height() / 4.0), val);
            painter.restore();
	  }
	}



}// paintBackground
コード例 #16
0
QImage* QgsPieDiagramFactory::createDiagram( int size, const QgsFeature& f, const QgsRenderContext& renderContext ) const
{
  QgsAttributeMap dataValues = f.attributeMap();
  double sizeScaleFactor = diagramSizeScaleFactor( renderContext );

  //create transparent QImage
  int imageSideLength = size * sizeScaleFactor * renderContext.rasterScaleFactor() + 2 * mMaximumPenWidth + 2 * mMaximumGap;
  QImage* diagramImage = new QImage( QSize( imageSideLength, imageSideLength ), QImage::Format_ARGB32_Premultiplied );
  diagramImage->fill( qRgba( 0, 0, 0, 0 ) ); //transparent background
  QPainter p;
  p.begin( diagramImage );
  p.setRenderHint( QPainter::Antialiasing );
  p.setPen( Qt::NoPen );

  //calculate sum of data values
  double sum = 0;
  QList<double> valueList; //cash the values to use them in drawing later

  QgsAttributeMap::const_iterator value_it;
  QList<QgsDiagramCategory>::const_iterator it = mCategories.constBegin();
  for ( ; it != mCategories.constEnd(); ++it )
  {
    value_it = dataValues.find( it->propertyIndex() );
    valueList.push_back( value_it->toDouble() );
    if ( value_it != dataValues.constEnd() )
    {
      sum += value_it->toDouble();
    }
  }

  if ( doubleNear( sum, 0.0 ) )
  {
    p.end();
    delete diagramImage;
    return 0;
  }

  //draw pies

  int totalAngle = 0;
  int currentAngle, currentGap;
  int xGapOffset = 0;
  int yGapOffset = 0;

  QList<QgsDiagramCategory>::const_iterator category_it = mCategories.constBegin();
  QList<double>::const_iterator valueList_it = valueList.constBegin();

  for ( ; category_it != mCategories.constEnd() && valueList_it != valueList.constEnd(); ++category_it, ++valueList_it )
  {
    p.setPen( category_it->pen() );
    currentAngle = ( int )(( *valueList_it ) / sum * 360 * 16 );
    p.setBrush( category_it->brush() );

    xGapOffset = 0;
    yGapOffset = 0;
    currentGap = category_it->gap();
    if ( currentGap != 0 )
    {
      //qt angles are degrees*16
      gapOffsetsForPieSlice( currentGap, totalAngle + currentAngle / 2, xGapOffset, yGapOffset );
    }

    p.drawPie( mMaximumPenWidth * renderContext.rasterScaleFactor() + mMaximumGap + xGapOffset, mMaximumPenWidth * renderContext.rasterScaleFactor() + mMaximumGap - yGapOffset, sizeScaleFactor * renderContext.rasterScaleFactor() * size, sizeScaleFactor * renderContext.rasterScaleFactor() * size, totalAngle, currentAngle );
    totalAngle += currentAngle;
  }
  p.end();

  return diagramImage;
}
コード例 #17
0
void number::paintDigit(QPainter &p, int number) const
{
	// make gcc  happy
	const int *n = m_number0;
	int shape;
	
	switch (number)
	{
		case 1:
			n = m_number1;
		break;
		
		case 2:
			n = m_number2;
		break;
		
		case 3:
			n = m_number3;
		break;
		
		case 4:
			n = m_number4;
		break;
		
		case 5:
			n = m_number5;
		break;
		
		case 6:
			n = m_number6;
		break;
		
		case 7:
			n = m_number7;
		break;
		
		case 8:
			n = m_number8;
		break;
		
		case 9:
			n = m_number9;
		break;
	}
	
	p.setBrush(Qt::red);
	p.setPen(Qt::red);
	for (int i = 0; i < 5; i++)
	{
		for (int j = 0; j < 4; j++)
		{
			shape = n[j + i * 4];
			if (shape == 0)
			{
				p.fillRect(7 * (j-1), 7 * (i-1), 6, 6, Qt::red);
			}
			else if (shape != 5)
			{
				if (shape == 1) p.translate(7 * (j-1), 7 * (i-1));
				else if (shape == 2)
				{
					p.translate(7 * j - 2, 7 * (i-1));
					p.rotate(90);
				}
				else if (shape == 3)
				{
					p.translate(7 * j - 2, 7 * i - 2);
					p.rotate(180);
				}
				else if (shape == 4)
				{
					p.translate(7 * (j-1), 7 * i - 2);
					p.rotate(270);
				}
				
				p.drawPie(0, 0, 11, 11, 90 * 16, 16 * 90);
				
				if (shape == 1) p.translate(-7 * (j-1), -7 * (i-1));
				else if (shape == 2)
				{
					p.rotate(-90);
					p.translate(-(7 * j - 2), -7 * (i-1));

				}
				else if (shape == 3)
				{
					p.rotate(-180);
					p.translate(-(7 * j - 2), -(7 * i - 2));
				}
				else if (shape == 4)
				{
					p.rotate(-270);
					p.translate(- (7 * (j-1)), -(7 * i - 2));
				}
			}
		}
	}
}
コード例 #18
0
ファイル: G_arcSector.cpp プロジェクト: yuryfdr/kseg
//drawing:
void G_arcSector::draw(QPainter &p, const G_drawstyle &d, bool selected)
{ //FIXME!
  double r = arc.getRadius();
  QRect re = p.window();

  if(!inRect(re)) return;

  if(r > DRAW_MAX / 2) {
    //draw big arc...

    return;
  }

  p.setBrush(d.getBrush());
  p.setPen(QPen(Qt::NoPen));

  const double angle_scale = -16 * 180. / M_PI;
  
  if(/*p.device()->isExtDev() ||*/ p.hasViewXForm()) { //draw at higher accuracy to a printer or image
    p.scale(0.125, .125);

    p.drawPie(ROUND((arc.getCenter().getX() - r) * 8),
	      ROUND((arc.getCenter().getY() - r) * 8),
	      ROUND(r * 16), ROUND(r * 16),
	      ROUND(((arc.getP2() - arc.getCenter()).angle() -
		     acos(arc.getCosangle())) * angle_scale),
	      ROUND(angle_scale * acos(arc.getCosangle()) * 2));

    p.scale(8, 8);
    return;
  }

  p.drawPie(ROUND(arc.getCenter().getX() - r),
	    ROUND(arc.getCenter().getY() - r),
	    ROUND(r * 2), ROUND(r * 2),
	    ROUND(((arc.getP2() - arc.getCenter()).angle() -
		   acos(arc.getCosangle())) * angle_scale),
	    ROUND(angle_scale * acos(arc.getCosangle()) * 2));
  
  if(selected) {
    if(KSegView::getSelectType() == KSegView::BORDER_SELECT) {
      p.setBrush(QBrush(G_drawstyle::getBorderColor(d.getBrush().color()), Qt::BDiagPattern));
    }
    if(selected && KSegView::getSelectType() == KSegView::BLINKING_SELECT) {
      QColor c(QTime::currentTime().msec() * 17, 255, 255, QColor::Hsv);
      
      p.setBrush(QBrush(c, Qt::BDiagPattern));
    }
    
    p.drawPie(ROUND(arc.getCenter().getX() - r),
	      ROUND(arc.getCenter().getY() - r),
	      ROUND(r * 2), ROUND(r * 2),
	      ROUND(((arc.getP2() - arc.getCenter()).angle() -
		     acos(arc.getCosangle())) * angle_scale),
	      ROUND(angle_scale * acos(arc.getCosangle()) * 2));    

  }

  p.setBrush(QBrush());

  return;

}
コード例 #19
0
ファイル: QHA.cpp プロジェクト: menu-a/llf-snir
void QHA::drawForeground(QPainter& painter )
{
        painter.save();
        qfiBackground(painter, m_radius[QHE], 100) ;
        painter.restore();
    QColor	black1(230,230,230) ;
    QColor	black2(160,160,160) ;
    QColor	yellow(250,250,0) ; //couleur triangle
    QColor  white (250,250,250);
    QFont	fo1("Arial", 100 ) ;
    QFont	fo2("Arial", 50 ) ;
    QColor  bleuexterieur (83,123,216);
    QColor  marronexterieur (76,36,11);
    QColor  bleuinterieur (83,123,216);
    QColor  marroninterieur (76,36,11);

   // fond




        QConicalGradient cg(QPointF(0.0, 0.0), 360 ) ;
        cg.setColorAt(0.0, Qt::white ) ;
        cg.setColorAt(1.0, QColor (139,69,19) ) ;

        //pies bague
        painter.save();
        painter.rotate(0+value(QHE));
        painter.setBrush(bleuexterieur);
                                        //largeur                hauteur              élargie largeur        elargie hauteur
        painter.drawPie             (-0.831*QFI_RADIUS,     -0.83*QFI_RADIUS,       2.075*0.8*QFI_RADIUS,    2.07*0.8*QFI_RADIUS,    16*0,16*180);
        painter.restore();


        painter.save();
        painter.rotate(0+value(QHE));
        painter.setBrush(marronexterieur);
        painter.drawPie               (-0.831*QFI_RADIUS,-0.83*QFI_RADIUS, 2.075*0.8* QFI_RADIUS,   2.08*0.8 * QFI_RADIUS,   16*180,16*180);
        painter.restore();

        //pies rond central




        painter.save();
        painter.rotate(0+value(QHE));
        painter.setBrush(bleuinterieur);
                                  //largeur             hauteur                élargie largeur                 elargie hauteur
        painter.drawPie     (-0.635*QFI_RADIUS,     -0.64*QFI_RADIUS,       1.59*0.8*QFI_RADIUS,           1.61*0.8*QFI_RADIUS,     16*0,16*180);
        painter.restore();


        painter.save();
        painter.rotate(0+value(QHE));
        //painter.translate(60, 60);
        painter.setBrush(marroninterieur);
        painter.drawPie               (-0.635*QFI_RADIUS,-0.63*QFI_RADIUS, 1.59*0.8* QFI_RADIUS,   1.58*0.8 * QFI_RADIUS,      16*180,16*180);
        painter.restore();


painter.save();
painter.rotate(0+value(QHE));
        //triangles
        float w = 0;
        float h = 30;
        float r = 0.64*QFI_RADIUS;
        float hbis = h + 5 ;
        QPolygon    triangle, triangle2, triangle3;


    triangle  << QPoint ( r, 0) << QPoint (r + 1.5 * hbis, - 0.75 * hbis) << QPoint(r + 1.5 * hbis, 0.75* hbis) ;
    triangle2 << QPoint ( r, 0) << QPoint (0.82*QFI_RADIUS, - hbis) << QPoint(0.82*QFI_RADIUS, hbis) ;
    triangle3 << QPoint ( r, 0) << QPoint (0.45*QFI_RADIUS, - hbis) << QPoint(0.45*QFI_RADIUS, hbis );



   painter.save();



// traingle graduation
  painter.rotate(-90);

        for ( int i = 0 ; i < 360 ; ++i) {
            painter.save();
            painter.setBrush(white);
  if (i == 0) painter.drawConvexPolygon(triangle2);
  painter.restore();

  painter.save();
  painter.setBrush(yellow);

  if (i == 0) painter.drawConvexPolygon(triangle3);
  painter.restore();

  painter.save();
  painter.setBrush(white);
   if (i == 45)painter.drawConvexPolygon(triangle);
   if (i == 315)painter.drawConvexPolygon(triangle);// BY AXEL
  painter.restore();

    if (i % 5 == 0)   painter.drawRect(r, 10000, hbis, hbis );
    else if (i % 5 == 0 )   painter.drawEllipse(r, 10000, hbis, hbis);
    else                      qfiMarker(painter, white, r + h, QSize(w, h) ) ;
    painter.rotate(1.0) ;
        }
        painter.restore();



      //2 lignes rond central + ligne d'horiz

        painter.setPen(QPen(Qt::white,3));
        painter.save();
        painter.drawLine(-314, 0, 317, 0);
        painter.rotate(0+value(QHE2));
         painter.restore();

        painter.drawLine(-45, -150, 45, -150); //1 ligne (P)
        painter.drawLine(-45, -100, 45, -100); //2 ligne (P)



    // graduations
        painter.save() ;
        painter.rotate(180.0) ;
        QPen pen( Qt::white ) ;
        pen.setWidth(5) ;
        painter.setPen( pen ) ;
        for ( int i = 0 ; i < 31 ; ++i ) {
            int len = ( (i % 5) == 0 ? 90: 0 ) ;
            if (i != 15){
                if (( i== 12) || (i == 13) | (i == 17) || (i == 18 ))
                    len = 45 ;

            if (len != 0)

                painter.drawLine(0.82 * QFI_RADIUS - 90, 0,0.82 * QFI_RADIUS - 90 + len, 0 );
            }
            painter.rotate(6.0) ;
        }
        painter.restore() ;

    }
コード例 #20
0
ファイル: dockpopup.cpp プロジェクト: icefox/kinkatta
void DockPopup::paintEvent(QPaintEvent *e){
	QPainter p;
	QColor mBackground = mPalette.active().background();
	QColor mForeground = mPalette.active().foreground();

	if(mText.isEmpty() || mText.isNull())
		return QWidget::paintEvent(e);

	//Use a mLabel to draw our stuff so that RichText will appear correctly
	mLabel->setText( mText );
	mLabel->resize( mLabel->width(), mLabel->height() );
	//QRect s = mLabel->contentsRect();
	//mLabel->resize( s.width(), s.height() );

	QRect bound = QRect( 0, 0, mLabel->width(), mLabel->height() );

	//Resize this to bound (on both sides/top/bottom)
	resize( bound.width() + 2, bound.height() + 2 );

	//Move this to the correct position, based on mAnchor and mAnchorPosition
	switch( mAnchorPosition ){
		case BottomRight:
			move( mAnchor.x( ) - width( ), mAnchor.y( ) - height( ) );
			break;
		case BottomLeft:
			move( mAnchor.x( ), mAnchor.y( ) - height( ) );
			break;
		case TopLeft:
			move( mAnchor.x( ), mAnchor.y( ) );
			break;
		case TopRight:
			move( mAnchor.x( ) - width( ), mAnchor.y( ) );
			break;
		default:
			//Shouldn't get here! Assume BottomRight.
			move( mAnchor.x( ) - width( ), mAnchor.y( ) - height( ) );
			qDebug( "dockPopup: mAnchorPosition not set\n" );
			break;
	}

	//The pixmap that holds the text:
	mTextPixmap->resize( bound.size() );
	p.begin( mTextPixmap );
	p.setBrush( mBackground );
	p.setPen( mBackground );
	p.drawRect( 0, 0, bound.width(), bound.height() );
	mLabel->drawContents( &p );
	p.end();

	//The actual roundRect and the text
	p.begin( this );
	p.setBrush( mBackground );
	p.drawRect(0, 0, width(), height() );
	p.drawPixmap( 1, 1, *mTextPixmap );
	p.end();

	//The little anchor indicator
	if(drawAnchorPosition){
		p.begin( this );
		//p.setPen( Qt::red );
		p.setPen( mForeground );
		p.setBrush( mForeground );
		int radius = 4;
		QPoint hDelta( radius, 0 );
		QPoint vDelta( 0, radius );

		//The four corners, clockwise order
		QPoint A( 0, 0 );
		QPoint B( width() -2, 0 );
		QPoint C( width() -2, height()-2  );
		QPoint D( 0, height()-2 );
		switch( mAnchorPosition ){
			case TopLeft:
				p.drawPie( QRect( A - hDelta - vDelta, A + hDelta + vDelta ), 0, -4*360 );
				break;
			case TopRight:
				p.drawPie( QRect( B + hDelta - vDelta, B - hDelta + vDelta ), 12*360, -4*360 );
				break;
			case BottomRight:
				p.drawPie( QRect( C + hDelta + vDelta, C - hDelta - vDelta ), 8*360, -4*360 );
				break;
			case BottomLeft:
				p.drawPie( QRect( D - hDelta + vDelta, D + hDelta - vDelta ), 4*360, -4*360 );
				break;
		}
		p.end();
	}

	/* XXX: This is mainly for if the shape requires an alpha mask, e.g. a round
	 * rect or something.  Right now it's just a regular rect, so I'm commenting
	 * it out.
	 
	mMask->resize( size() );
	mMask->fill( Qt::color0 ); //transparent
	p.begin( mMask );
	p.setPen( Qt::color1 );
	p.setBrush( Qt::color1 );
	p.drawRect(0, 0, width(), height() );
	p.end();
	setMask( *mMask );
	**/

	QWidget::paintEvent(e);
}
コード例 #21
0
ファイル: qgspiediagram.cpp プロジェクト: Nald/Quantum-GIS
void QgsPieDiagram::renderDiagram( const QgsAttributeMap& att, QgsRenderContext& c, const QgsDiagramSettings& s, const QPointF& position )
{
  QPainter* p = c.painter();
  if ( !p )
  {
    return;
  }

  //get sum of values
  QList<double> values;
  double currentVal = 0;
  double valSum = 0;
  int valCount = 0;

  QList<int>::const_iterator catIt = s.categoryIndices.constBegin();
  for ( ; catIt != s.categoryIndices.constEnd(); ++catIt )
  {
    currentVal = att[*catIt].toDouble();
    values.push_back( currentVal );
    valSum += currentVal;
    if ( currentVal ) valCount++;
  }

  //draw the slices
  double totalAngle = 0;
  double currentAngle;

  //convert from mm / map units to painter units
  QSizeF spu = sizePainterUnits( s.size, s, c );
  double w = spu.width();
  double h = spu.height();

  double baseX = position.x();
  double baseY = position.y() - h;

  mPen.setColor( s.penColor );
  setPenWidth( mPen, s, c );
  p->setPen( mPen );

  // there are some values > 0 available
  if ( valSum > 0 )
  {
    QList<double>::const_iterator valIt = values.constBegin();
    QList< QColor >::const_iterator colIt = s.categoryColors.constBegin();
    for ( ; valIt != values.constEnd(); ++valIt, ++colIt )
    {
      currentAngle =  *valIt / valSum * 360 * 16;
      mCategoryBrush.setColor( *colIt );
      p->setBrush( mCategoryBrush );
      // if only 1 value is > 0, draw a circle
      if ( valCount == 1 )
      {
        p->drawEllipse( baseX, baseY, w, h );
      }
      else
      {
        p->drawPie( baseX, baseY, w, h, totalAngle, currentAngle );
      }
      totalAngle += currentAngle;
    }
  }
  else // valSum > 0
  {
    // draw empty circle if no values are defined at all
    mCategoryBrush.setColor( Qt::transparent );
    p->setBrush( mCategoryBrush );
    p->drawEllipse( baseX, baseY, w, h );
  }
}
コード例 #22
0
/*!

 */
void
PlayerPainter::drawViewArea( QPainter & painter,
                             const PlayerPainter::Param & param ) const
{
    const Options & opt = Options::instance();

    const int visible_radius = opt.scale( M_main_data.serverParam().visible_distance_ );
    const double head = param.player_.body_ + param.player_.neck_;
    const int view_start_angle = static_cast< int >( rint( ( -head - param.player_.view_width_ * 0.5 ) * 16 ) );
    const int span_angle = static_cast< int >( rint( param.player_.view_width_ * 16 ) );


    if ( opt.selectedPlayer( param.player_.side(),
                             param.player_.unum_ ) )
    {
        // draw large view area
        const int UNUM_FAR = opt.scale( 20.0 );
        const int TEAM_FAR = opt.scale( 40.0 );
        const int TEAM_TOOFAR = opt.scale( 60.0 );

        painter.setPen( M_large_view_area_pen );
        painter.setBrush( Qt::NoBrush );

        painter.drawArc( param.x_ - UNUM_FAR, // left x
                         param.y_ - UNUM_FAR, // toop y
                         UNUM_FAR * 2, // width
                         UNUM_FAR * 2, // height
                         view_start_angle,
                         span_angle );
        painter.drawArc( param.x_ - TEAM_FAR, // left x
                         param.y_ - TEAM_FAR, // toop y
                         TEAM_FAR * 2, // width
                         TEAM_FAR * 2, // height
                         view_start_angle,
                         span_angle );
        // pie, no an arc
        painter.drawArc( param.x_ - TEAM_TOOFAR, // left x
                         param.y_ - TEAM_TOOFAR, // toop y
                         TEAM_TOOFAR * 2, // width
                         TEAM_TOOFAR * 2, // height
                         view_start_angle,
                         span_angle );

        // draw feeling area circle
        painter.drawArc( param.x_ - visible_radius,
                         param.y_ - visible_radius,
                         visible_radius * 2,
                         visible_radius * 2,
                         0,
                         360 * 16 );

        const double view_start_angle_real = ( head - param.player_.view_width_ * 0.5 ) * DEG2RAD;
        const double view_end_angle_real = ( head + param.player_.view_width_ * 0.5 ) * DEG2RAD;;
        // left side view cone end point x
        int lx = param.x_
            + opt.scale( 60.0 * std::cos( view_start_angle_real ) );
        // left side view cone end point y
        int ly = param.y_
            + opt.scale( 60.0  * std::sin( view_start_angle_real ) );
        // right side view cone end point x
        int rx = param.x_
            + opt.scale( 60.0 * std::cos( view_end_angle_real ) );
        // right side view cone end point y
        int ry = param.y_
            + opt.scale( 60.0 * std::sin( view_end_angle_real ) );
        painter.drawLine( lx, ly, param.x_, param.y_ );
        painter.drawLine( rx, ry, param.x_, param.y_ );

    }
    else
    {
        // draw small view area
        painter.setPen( M_view_area_pen );
        painter.setBrush( Qt::NoBrush );

        painter.drawPie( param.x_ - visible_radius,
                         param.y_ - visible_radius,
                         visible_radius * 2,
                         visible_radius * 2,
                         view_start_angle,
                         span_angle );
    }
}