/*! \brief Qt Paint Event \param event Paint event */ void QwtWheel::paintEvent( QPaintEvent *event ) { QPainter painter( this ); painter.setClipRegion( event->region() ); QStyleOption opt; opt.init(this); style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this); qDrawShadePanel( &painter, contentsRect(), palette(), true, d_data->borderWidth ); drawWheelBackground( &painter, wheelRect() ); drawTicks( &painter, wheelRect() ); if ( hasFocus() ) QwtPainter::drawFocusRect( &painter, this ); }
/*! \brief Redraw the wheel \param painter painter \param r contents rectangle */ void QwtWheel::drawWheel( QPainter *painter, const QRect &r ) { // // draw background gradient // drawWheelBackground( painter, r ); if ( maxValue() == minValue() || d_data->totalAngle == 0.0 ) return; #if QT_VERSION < 0x040000 const QColor light = colorGroup().light(); const QColor dark = colorGroup().dark(); #else const QColor light = palette().color(QPalette::Light); const QColor dark = palette().color(QPalette::Dark); #endif const double sign = (minValue() < maxValue()) ? 1.0 : -1.0; double cnvFactor = qwtAbs(d_data->totalAngle / (maxValue() - minValue())); const double halfIntv = 0.5 * d_data->viewAngle / cnvFactor; const double loValue = value() - halfIntv; const double hiValue = value() + halfIntv; const double tickWidth = 360.0 / double(d_data->tickCnt) / cnvFactor; const double sinArc = sin(d_data->viewAngle * M_PI / 360.0); cnvFactor *= M_PI / 180.0; // // draw grooves // if ( orientation() == Qt::Horizontal ) { const double halfSize = double(r.width()) * 0.5; int l1 = r.y() + d_data->intBorder; int l2 = r.y() + r.height() - d_data->intBorder - 1; // draw one point over the border if border > 1 if ( d_data->intBorder > 1 ) { l1 --; l2 ++; } const int maxpos = r.x() + r.width() - 2; const int minpos = r.x() + 2; // // draw tick marks // for ( double tickValue = ceil(loValue / tickWidth) * tickWidth; tickValue < hiValue; tickValue += tickWidth ) { // // calculate position // const int tickPos = r.x() + r.width() - int( halfSize * (sinArc + sign * sin((tickValue - value()) * cnvFactor)) / sinArc); // // draw vertical line // if ( (tickPos <= maxpos) && (tickPos > minpos) ) { painter->setPen(dark); painter->drawLine(tickPos -1 , l1, tickPos - 1, l2 ); painter->setPen(light); painter->drawLine(tickPos, l1, tickPos, l2); } } } else if ( orientation() == Qt::Vertical ) { const double halfSize = double(r.height()) * 0.5; int l1 = r.x() + d_data->intBorder; int l2 = r.x() + r.width() - d_data->intBorder - 1; if ( d_data->intBorder > 1 ) { l1--; l2++; } const int maxpos = r.y() + r.height() - 2; const int minpos = r.y() + 2; // // draw tick marks // for ( double tickValue = ceil(loValue / tickWidth) * tickWidth; tickValue < hiValue; tickValue += tickWidth ) { // // calculate position // const int tickPos = r.y() + int( halfSize * (sinArc + sign * sin((tickValue - value()) * cnvFactor)) / sinArc); // // draw horizontal line // if ( (tickPos <= maxpos) && (tickPos > minpos) ) { painter->setPen(dark); painter->drawLine(l1, tickPos - 1 ,l2, tickPos - 1); painter->setPen(light); painter->drawLine(l1, tickPos, l2, tickPos); } } } }