| 1596 | } |
| 1597 | |
| 1598 | void |
| 1599 | HistogramPrivate::drawScale() |
| 1600 | { |
| 1601 | // always running in the main thread |
| 1602 | assert( qApp && qApp->thread() == QThread::currentThread() ); |
| 1603 | assert( QOpenGLContext::currentContext() == widget->context() ); |
| 1604 | |
| 1605 | |
| 1606 | glCheckError(); |
| 1607 | QPointF btmLeft = zoomCtx.toZoomCoordinates(0, widget->height() - 1); |
| 1608 | QPointF topRight = zoomCtx.toZoomCoordinates(widget->width() - 1, 0); |
| 1609 | |
| 1610 | ///don't attempt to draw a scale on a widget with an invalid height |
| 1611 | if (widget->height() <= 1) { |
| 1612 | return; |
| 1613 | } |
| 1614 | |
| 1615 | QFontMetrics fm(*_textFont); |
| 1616 | const double smallestTickSizePixel = 5.; // tick size (in pixels) for alpha = 0. |
| 1617 | const double largestTickSizePixel = 1000.; // tick size (in pixels) for alpha = 1. |
| 1618 | |
| 1619 | |
| 1620 | { |
| 1621 | GLProtectAttrib a(GL_COLOR_BUFFER_BIT | GL_CURRENT_BIT | GL_ENABLE_BIT); |
| 1622 | |
| 1623 | glEnable(GL_BLEND); |
| 1624 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
| 1625 | |
| 1626 | for (int axis = 0; axis < 2; ++axis) { |
| 1627 | const double rangePixel = (axis == 0) ? widget->width() : widget->height(); // AXIS-SPECIFIC |
| 1628 | const double range_min = (axis == 0) ? btmLeft.x() : btmLeft.y(); // AXIS-SPECIFIC |
| 1629 | const double range_max = (axis == 0) ? topRight.x() : topRight.y(); // AXIS-SPECIFIC |
| 1630 | const double range = range_max - range_min; |
| 1631 | double smallTickSize; |
| 1632 | bool half_tick; |
| 1633 | ticks_size(range_min, range_max, rangePixel, smallestTickSizePixel, &smallTickSize, &half_tick); |
| 1634 | int m1, m2; |
| 1635 | const int ticks_max = 1000; |
| 1636 | double offset; |
| 1637 | ticks_bounds(range_min, range_max, smallTickSize, half_tick, ticks_max, &offset, &m1, &m2); |
| 1638 | std::vector<int> ticks; |
| 1639 | ticks_fill(half_tick, ticks_max, m1, m2, &ticks); |
| 1640 | const double smallestTickSize = range * smallestTickSizePixel / rangePixel; |
| 1641 | const double largestTickSize = range * largestTickSizePixel / rangePixel; |
| 1642 | #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0) |
| 1643 | const double minTickSizeTextPixel = ( (axis == 0) ? fm.horizontalAdvance( QLatin1String("00") ) : fm.height() ) / _screenPixelRatio; |
| 1644 | #else |
| 1645 | const double minTickSizeTextPixel = ( (axis == 0) ? fm.width( QLatin1String("00") ) : fm.height() ) / _screenPixelRatio; // AXIS-SPECIFIC |
| 1646 | #endif |
| 1647 | const double minTickSizeText = range * minTickSizeTextPixel / rangePixel; |
| 1648 | for (int i = m1; i <= m2; ++i) { |
| 1649 | double value = i * smallTickSize + offset; |
| 1650 | const double tickSize = ticks[i - m1] * smallTickSize; |
| 1651 | const double alpha = ticks_alpha(smallestTickSize, largestTickSize, tickSize); |
| 1652 | |
| 1653 | glColor4f(_baseAxisColor.redF(), _baseAxisColor.greenF(), _baseAxisColor.blueF(), alpha); |
| 1654 | |
| 1655 | glLineWidth(1. * _screenPixelRatio); |
no test coverage detected