本文整理汇总了C++中QPainter::drawPie方法的典型用法代码示例。如果您正苦于以下问题:C++ QPainter::drawPie方法的具体用法?C++ QPainter::drawPie怎么用?C++ QPainter::drawPie使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QPainter
的用法示例。
在下文中一共展示了QPainter::drawPie方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: paintEvent
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: paintCannon
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: paintEvent
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: draw
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: drawCircle
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: operator
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: drawSegment
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: paintHighlightingNode
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:
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);
}
}
示例10: paintTooCloseNodes
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);
}
}
}
示例11: drawMeter
//.........这里部分代码省略.........
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
示例12: pts
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;
//.........这里部分代码省略.........
示例13: drawContent
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);
}
示例14: paintBackground
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();
}
}
//.........这里部分代码省略.........
示例15: createDiagram
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;
}