| 629 | } |
| 630 | |
| 631 | void RemoteViewWidget::drawRuler(QPainter *p) |
| 632 | { |
| 633 | p->save(); |
| 634 | |
| 635 | const int hRulerHeight = horizontalRulerHeight(); |
| 636 | const int vRulerWidth = verticalRulerWidth(); |
| 637 | |
| 638 | const int viewTickStep = std::max<int>(2, m_zoom); |
| 639 | const int viewLabelDist = viewTickLabelDistance(); |
| 640 | const int sourceLabelDist = sourceTickLabelDistance(viewLabelDist); |
| 641 | |
| 642 | const auto activePen = QPen(QColor(255, 255, 255, 170)); |
| 643 | const auto inactivePen = QPen(QColor(0, 0, 0, 170)); |
| 644 | const auto selectedPen = QPen(palette().color(QPalette::Highlight)); |
| 645 | |
| 646 | // background |
| 647 | p->setPen(Qt::NoPen); |
| 648 | p->setBrush(QBrush(QColor(51, 51, 51, 170))); |
| 649 | p->drawRect(QRect(0, height() - hRulerHeight, width(), hRulerHeight)); |
| 650 | p->drawRect(QRect(width() - vRulerWidth, 0, vRulerWidth, height() - hRulerHeight)); |
| 651 | |
| 652 | // horizontal ruler at the bottom |
| 653 | p->save(); |
| 654 | p->translate(0, height() - hRulerHeight); |
| 655 | for (int i = (m_x % viewTickStep); i < contentWidth(); i += viewTickStep) { |
| 656 | const int sourcePos = (i - m_x) / m_zoom; |
| 657 | if (sourcePos == m_currentMousePosition.x()) { |
| 658 | p->setPen(selectedPen); |
| 659 | } else if (sourcePos < 0 || sourcePos > m_frame.viewRect().width()) { |
| 660 | p->setPen(inactivePen); |
| 661 | } else { |
| 662 | p->setPen(activePen); |
| 663 | } |
| 664 | |
| 665 | const int tickSize = tickLength(sourcePos, sourceLabelDist); |
| 666 | p->drawLine(i, 0, i, tickSize); |
| 667 | |
| 668 | if (sourcePos % sourceLabelDist == 0) { |
| 669 | if (sourcePos < 0 || sourcePos > m_frame.viewRect().width()) { |
| 670 | p->setPen(inactivePen); |
| 671 | } else { |
| 672 | p->setPen(activePen); |
| 673 | } |
| 674 | p->drawText(i - viewLabelDist / 2, tickSize, viewLabelDist, hRulerHeight - tickSize, |
| 675 | Qt::AlignHCenter | Qt::AlignVCenter, QString::number(sourcePos)); |
| 676 | } |
| 677 | } |
| 678 | p->restore(); |
| 679 | |
| 680 | // vertical ruler on the right |
| 681 | p->save(); |
| 682 | p->translate(width() - vRulerWidth, 0); |
| 683 | for (int i = (m_y % viewTickStep); i < contentHeight(); i += viewTickStep) { |
| 684 | const int sourcePos = (i - m_y) / m_zoom; |
| 685 | if (sourcePos == m_currentMousePosition.y()) { |
| 686 | p->setPen(selectedPen); |
| 687 | } else if (sourcePos < 0 || sourcePos > m_frame.viewRect().height()) { |
| 688 | p->setPen(inactivePen); |