//--------------------------------------------------------------------------- // Draw an individual tick //--------------------------------------------------------------------------- void VisusBorderAxis::drawTick(const float low, const float high, const float axisPosition, const BBTickLine tickLineType) { float v[2]; if (tickLineType==BB_DASHED) { float delta = (high-low) / 50; float begin = low; for (int i=0; i<25; ++i) { drawTick(begin, begin+delta, axisPosition, BB_SOLID); begin += (delta*2); } return; } v[mDrawAxis] = axisPosition; v[mDrawOther]= low; glVertex2fv(v); v[mDrawOther]= high; glVertex2fv(v); }
//--------------------------------------------------------------------------- // Draw the major and minor tick marks //---------------------------------------------------------------------------- void VisusBorderAxis::renderTickMarks(const float borderWidth, const float borderLength, const BBAxis axis, const BBTickLine tickLineType) { // If drawing ticks is disabled, return if(!mDrawTicks) return; float low,high,minor_low,minor_high; float dimensions[2] = { borderLength, borderWidth }; int other = (axis+1) % 2; float width = dimensions[other]; float length = dimensions[axis]; // Get the current viewport GLdouble model[16]; GLdouble projection[16]; GLint viewport[4]; // x, y, width, height glGetDoublev(GL_PROJECTION_MATRIX, projection); glGetDoublev(GL_MODELVIEW_MATRIX, model); glGetIntegerv(GL_VIEWPORT,viewport); // Determine number of pixels per tick mark based on thickness (smallest 1) float minval = numPixels(model, projection, viewport, length, axis); const int numPixelPerMajorTick = std::max(1, (int)floor(minval*mMajorTickThickness)); const int numPixelPerMinorTick = std::max(1, (int)floor(minval*mMinorTickThickness)); float majorDelta = length / (mMajorTicks-1); float minorDelta = majorDelta / mMinorTicks; // Determine Tick Up/Down Positions low = minor_low = 0; high = minor_high = width; // If we need to draw tick on the normal side (below or right) if ((mTickPosition == AXIS_LOW) || (mTickPosition == AXIS_BOTH)) { low -= mMajorTickLength * width; // it needs to start this much below 0 minor_low -= mMinorTickLength * mMajorTickLength * width; } // If we need to draw tick on the opposite side (above or left) if ((mTickPosition == AXIS_HIGH) || (mTickPosition == AXIS_BOTH)) { high += mMajorTickLength * width; // it needs to end this much above the bar minor_high += mMinorTickLength * mMajorTickLength * width; } // Set the bounding box if (axis == BB_X_AXIS) { mDrawBox[0] = 0; mDrawBox[1] = low; mDrawBox[3] = length; mDrawBox[4] = high; } else { mDrawBox[0] = low; mDrawBox[1] = 0; mDrawBox[3] = high; mDrawBox[4] = length; } mWidth = width; mLength= length; mDrawAxis = axis; mDrawOther = other; if (! mDrawTicks) return; mTickColor.glColor(); // We can't change the thickness between a glBegin() and // glEnd(). Therefore, we first draw the major ticks then the minor // ones glLineWidth(numPixelPerMajorTick); glBegin(GL_LINES); float axisPosition = 0; for (int i=0;i<mMajorTicks; ++i, axisPosition+=majorDelta) { if (i==0 || i==(mMajorTicks-1)) drawTick(low, 0, axisPosition, BB_SOLID); else drawTick(low, high, axisPosition, tickLineType); } glEnd(); // Now draw the minor ticks glLineWidth(numPixelPerMinorTick); glBegin(GL_LINES); axisPosition = 0; for (int i=0;i<mMajorTicks-1; ++i, axisPosition+=majorDelta) { for (int j=0;j<mMinorTicks; ++j) { float position = axisPosition + (minorDelta*j); drawTick(minor_low, minor_high, position, tickLineType); } } glEnd(); }
void ClassicStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p, const QWidget *widget) const { if (cc != QStyle::CC_Dial) { QCommonStyle::drawComplexControl(cc, opt, p, widget); return; } const QStyleOptionSlider *dial = qstyleoption_cast<const QStyleOptionSlider *>(opt); if (dial == NULL) return; float angle = DIAL_MIN + (DIAL_RANGE * (float(dial->sliderValue - dial->minimum) / (float(dial->maximum - dial->minimum)))); int degrees = int(angle * 180.0 / M_PI); int ns = dial->tickInterval; int numTicks = 1 + (dial->maximum + ns - dial->minimum) / ns; int size = dial->rect.width() < dial->rect.height() ? dial->rect.width() : dial->rect.height(); int scale = 1; int width = size * scale; int indent = (int)(width * 0.15 + 1); QPalette pal = opt->palette; QColor knobColor = pal.mid().color(); //pal.background().color(); QColor meterColor = (dial->state & State_Enabled) ? pal.highlight().color() : pal.mid().color(); QPen pen; QColor c; p->save(); p->setRenderHint(QPainter::Antialiasing, true); p->translate(1+(dial->rect.width()-size)/2, 1+(dial->rect.height()-size)/2); // Knob body and face... pen.setColor(knobColor); pen.setWidth(scale * 2); pen.setCapStyle(Qt::FlatCap); p->setPen(pen); QRadialGradient gradient(size/2, size/2, size-indent, size/2-indent, size/2-indent); gradient.setColorAt(0, knobColor.light()); gradient.setColorAt(1, knobColor.dark()); p->setBrush(gradient); p->drawEllipse(indent, indent, width-2*indent, width-2*indent); // The bright metering bit... c = meterColor; pen.setColor(c); pen.setWidth(indent); p->setPen(pen); int arcLen = -(degrees - 45) * 16; if (arcLen == 0) arcLen = -16; p->drawArc(indent/2, indent/2, width-indent, width-indent, (180 + 45) * 16, arcLen); p->setBrush(Qt::NoBrush); // Tick notches... if (dial->subControls & QStyle::SC_DialTickmarks) { // std::cerr << "Notches visible" << std::endl; pen.setColor(pal.dark().color()); pen.setWidth(scale); p->setPen(pen); for (int i = 0; i < numTicks; ++i) { int div = numTicks; if (div > 1) --div; drawTick(p, DIAL_MIN + (DIAL_MAX - DIAL_MIN) * i / div, width, true); } } // Shadowing... pen.setWidth(scale); p->setPen(pen); // Knob shadow... int shadowAngle = -720; c = knobColor.dark(); for (int arc = 120; arc < 2880; arc += 240) { pen.setColor(c); p->setPen(pen); p->drawArc(indent, indent, width-2*indent, width-2*indent, shadowAngle + arc, 240); p->drawArc(indent, indent, width-2*indent, width-2*indent, shadowAngle - arc, 240); c = c.light(110); } // Scale shadow... shadowAngle = 2160; c = pal.dark().color(); for (int arc = 120; arc < 2880; arc += 240) { pen.setColor(c); p->setPen(pen); p->drawArc(scale/2, scale/2, width-scale, width-scale, shadowAngle + arc, 240); p->drawArc(scale/2, scale/2, width-scale, width-scale, shadowAngle - arc, 240); c = c.light(108); } // Undraw the bottom part... pen.setColor(pal.background().color()); pen.setWidth(scale * 4); p->setPen(pen); p->drawArc(scale/2, scale/2, width-scale, width-scale, -45 * 16, -90 * 16); // Pointer notch... float hyp = float(width) / 2.0; float len = hyp - indent; --len; float x0 = hyp; float y0 = hyp; float x = hyp - len * qSin(angle); float y = hyp + len * qCos(angle); c = pal.dark().color(); pen.setColor((dial->state & State_Enabled) ? c.dark(130) : c); pen.setWidth(scale * 2); p->setPen(pen); p->drawLine(int(x0), int(y0), int(x), int(y)); // done p->restore(); }
/*! \brief Draw the scale \param painter The painter \param palette Palette, text color is used for the labels, foreground color for ticks and backbone */ void QwtAbstractScaleDraw::draw( QPainter *painter, const QPalette& palette ) const { painter->save(); QPen pen = painter->pen(); pen.setWidth( d_data->penWidth ); pen.setCosmetic( false ); painter->setPen( pen ); if ( hasComponent( QwtAbstractScaleDraw::Labels ) ) { painter->save(); painter->setPen( palette.color( QPalette::Text ) ); // ignore pen style const QList<double> &majorTicks = d_data->scaleDiv.ticks( QwtScaleDiv::MajorTick ); for ( int i = 0; i < majorTicks.count(); i++ ) { const double v = majorTicks[i]; if ( d_data->scaleDiv.contains( v ) ) drawLabel( painter, v ); } painter->restore(); } if ( hasComponent( QwtAbstractScaleDraw::Ticks ) ) { painter->save(); QPen pen = painter->pen(); pen.setColor( palette.color( QPalette::WindowText ) ); pen.setCapStyle( Qt::FlatCap ); painter->setPen( pen ); for ( int tickType = QwtScaleDiv::MinorTick; tickType < QwtScaleDiv::NTickTypes; tickType++ ) { const QList<double> &ticks = d_data->scaleDiv.ticks( tickType ); for ( int i = 0; i < ticks.count(); i++ ) { const double v = ticks[i]; if ( d_data->scaleDiv.contains( v ) ) drawTick( painter, v, d_data->tickLength[tickType] ); } } painter->restore(); } if ( hasComponent( QwtAbstractScaleDraw::Backbone ) ) { painter->save(); QPen pen = painter->pen(); pen.setColor( palette.color( QPalette::WindowText ) ); pen.setCapStyle( Qt::FlatCap ); painter->setPen( pen ); drawBackbone( painter ); painter->restore(); } painter->restore(); }
const QColorGroup& colorGroup) const #else /*! \brief Draw the scale \param painter The painter \param palette Palette, text color is used for the labels, foreground color for ticks and backbone */ void QwtAbstractScaleDraw::draw(QPainter *painter, const QPalette& palette) const #endif { if ( hasComponent(QwtAbstractScaleDraw::Labels) ) { painter->save(); #if QT_VERSION < 0x040000 painter->setPen(colorGroup.text()); // ignore pen style #else painter->setPen(palette.color(QPalette::Text)); // ignore pen style #endif const QwtValueList &majorTicks = d_data->scldiv.ticks(QwtScaleDiv::MajorTick); for (int i = 0; i < (int)majorTicks.count(); i++) { const double v = majorTicks[i]; if ( d_data->scldiv.contains(v) ) drawLabel(painter, majorTicks[i]); } painter->restore(); } if ( hasComponent(QwtAbstractScaleDraw::Ticks) ) { painter->save(); QPen pen = painter->pen(); #if QT_VERSION < 0x040000 pen.setColor(colorGroup.foreground()); #else pen.setColor(palette.color(QPalette::Foreground)); #endif painter->setPen(pen); for ( int tickType = QwtScaleDiv::MinorTick; tickType < QwtScaleDiv::NTickTypes; tickType++ ) { const QwtValueList &ticks = d_data->scldiv.ticks(tickType); for (int i = 0; i < (int)ticks.count(); i++) { const double v = ticks[i]; if ( d_data->scldiv.contains(v) ) drawTick(painter, v, d_data->tickLength[tickType]); } } painter->restore(); } if ( hasComponent(QwtAbstractScaleDraw::Backbone) ) { painter->save(); QPen pen = painter->pen(); #if QT_VERSION < 0x040000 pen.setColor(colorGroup.foreground()); #else pen.setColor(palette.color(QPalette::Foreground)); #endif painter->setPen(pen); drawBackbone(painter); painter->restore(); } }
void ScaleDraw::draw(QPainter *p, const QPalette& palette, double curValue)// const { double val,hval,majTick; int i,k,kmax; // REMOVE Tim. Trackinfo. Added. p->setPen(palette.text().color()); const int majCnt = d_scldiv.majCnt(); const int minCnt = d_scldiv.minCnt(); // REMOVE Tim. Trackinfo. Changed. // for (i=0; i< d_scldiv.majCnt(); i++) for (i=0; i< majCnt; i++) { val = d_scldiv.majMark(i); drawTick(p, palette, curValue, val, d_majLen); // REMOVE Tim. Trackinfo. Removed. // drawLabel(p, palette, curValue, val); } // REMOVE Tim. Trackinfo. Added. for (i=0; i< majCnt; i++) { val = d_scldiv.majMark(i); drawLabel(p, palette, curValue, val, i == 0); } p->setPen(palette.text().color()); if (d_scldiv.logScale()) { // for (i=0; i< d_scldiv.minCnt(); i++) for (i=0; i< minCnt; i++) { drawTick(p,palette,curValue,d_scldiv.minMark(i),d_minLen); } } else { k = 0; // kmax = d_scldiv.majCnt() - 1; kmax = majCnt - 1; if (kmax > 0) { majTick = d_scldiv.majMark(0); hval = majTick - 0.5 * d_scldiv.majStep(); // for (i=0; i< d_scldiv.minCnt(); i++) for (i=0; i< minCnt; i++) { val = d_scldiv.minMark(i); if (val > majTick) { if (k < kmax) { k++; majTick = d_scldiv.majMark(k); } else { majTick += d_scldiv.majMark(kmax) + d_scldiv.majStep(); } hval = majTick - 0.5 * d_scldiv.majStep(); } if (MusECore::qwtAbs(val-hval) < step_eps * d_scldiv.majStep()) drawTick(p, palette, curValue, val, d_medLen); else drawTick(p, palette, curValue, val, d_minLen); } } } // // draw backbone // if (d_drawBackBone) drawBackbone(p, palette, curValue); }