/*! \brief Draw the contents inside the frame QPalette::Window is the background color outside of the frame. QPalette::Base is the background color inside the frame. QPalette::WindowText is the background color inside the scale. \param painter Painter \sa boundingRect(), innerRect(), scaleInnerRect(), QWidget::setPalette() */ void QwtDial::drawContents( QPainter *painter ) const { if ( testAttribute( Qt::WA_NoSystemBackground ) || palette().brush( QPalette::Base ) != palette().brush( QPalette::Window ) ) { const QRectF br = boundingRect(); painter->save(); painter->setPen( Qt::NoPen ); painter->setBrush( palette().brush( QPalette::Base ) ); painter->drawEllipse( br ); painter->restore(); } const QRectF insideScaleRect = scaleInnerRect(); if ( palette().brush( QPalette::WindowText ) != palette().brush( QPalette::Base ) ) { painter->save(); painter->setPen( Qt::NoPen ); painter->setBrush( palette().brush( QPalette::WindowText ) ); painter->drawEllipse( insideScaleRect ); painter->restore(); } const QPointF center = insideScaleRect.center(); const double radius = 0.5 * insideScaleRect.width(); double direction = d_data->origin; if ( isValid() ) { direction = d_data->minScaleArc; if ( maxValue() > minValue() && d_data->maxScaleArc > d_data->minScaleArc ) { const double ratio = ( value() - minValue() ) / ( maxValue() - minValue() ); direction += ratio * ( d_data->maxScaleArc - d_data->minScaleArc ); } if ( d_data->direction == QwtDial::CounterClockwise ) direction = d_data->maxScaleArc - ( direction - d_data->minScaleArc ); direction += d_data->origin; if ( direction >= 360.0 ) direction -= 360.0; else if ( direction < 0.0 ) direction += 360.0; } double origin = d_data->origin; if ( mode() == RotateScale ) { origin -= direction - d_data->origin; direction = d_data->origin; } painter->save(); drawScale( painter, center, radius, origin, d_data->minScaleArc, d_data->maxScaleArc ); painter->restore(); painter->save(); drawScaleContents( painter, center, radius ); painter->restore(); if ( isValid() ) { QPalette::ColorGroup cg; if ( isEnabled() ) cg = hasFocus() ? QPalette::Active : QPalette::Inactive; else cg = QPalette::Disabled; painter->save(); drawNeedle( painter, center, radius, direction, cg ); painter->restore(); } }
/*! \brief Draw the contents inside the frame QColorGroup::Background is the background color outside of the frame. QColorGroup::Base is the background color inside the frame. QColorGroup::Foreground is the background color inside the scale. \param painter Painter \sa QwtDial::boundingRect, QwtDial::contentsRect, QwtDial::scaleContentsRect, QWidget::setPalette */ void QwtDial::drawContents(QPainter *painter) const { if ( backgroundMode() == NoBackground || colorGroup().brush(QColorGroup::Base) != colorGroup().brush(QColorGroup::Background) ) { // Don´t use QPainter::drawEllipse. There are some pixels // different compared to the region in the mask, leaving // them in background color. painter->save(); painter->setPen(Qt::NoPen); painter->setBrush(colorGroup().brush(QColorGroup::Base)); // Even if we want to fill the contentsRect only, we fill the // complete boundingRect. The frame will be painted later // above, but we want to have the base color below it // because round objects doesn´t cover all pixels. QRect br = boundingRect(); #if QT_VERSION < 300 #ifdef _WS_WIN32_ // Qt-230-NC draws ellipses not as nicely as Qt-2.3.x on X Windows br.setTop(br.top()-1); br.setLeft(br.left()-1); br.setBottom(br.bottom()+1); br.setRight(br.right()+1); #endif #endif painter->setClipRegion(QRegion(painter->xForm(br), QRegion::Ellipse)); painter->drawRect(br); painter->restore(); } const QRect insideScaleRect = scaleContentsRect(); if ( colorGroup().brush(QColorGroup::Foreground) != colorGroup().brush(QColorGroup::Base) ) { painter->save(); painter->setPen(Qt::NoPen); painter->setBrush(colorGroup().brush(QColorGroup::Foreground)); painter->setClipRegion( QRegion(painter->xForm(insideScaleRect), QRegion::Ellipse)); painter->drawRect(insideScaleRect); painter->restore(); } const QPoint center = insideScaleRect.center(); const int radius = insideScaleRect.width() / 2; painter->save(); drawScaleContents(painter, center, radius); painter->restore(); double direction = d_origin; if (isValid()) { direction = d_origin + d_minScaleArc; if ( maxValue() > minValue() && d_maxScaleArc > d_minScaleArc ) { const double ratio = (value() - minValue()) / (maxValue() - minValue()); direction += ratio * (d_maxScaleArc - d_minScaleArc); } if ( direction >= 360.0 ) direction -= 360.0; } double origin = d_origin; if ( mode() == RotateScale ) { origin -= direction - d_origin; direction = d_origin; } painter->save(); drawScale(painter, center, radius, origin, d_minScaleArc, d_maxScaleArc); painter->restore(); if ( isValid() ) { QPalette::ColorGroup cg; if ( isEnabled() ) cg = hasFocus() ? QPalette::Active : QPalette::Inactive; else cg = QPalette::Disabled; painter->save(); drawNeedle(painter, center, radius, direction, cg); painter->restore(); } }