From 19eb9bec34a6bd700e6d563c33568f6de5fdc756 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Fri, 5 Feb 2021 21:42:22 +0200 Subject: [PATCH] Refactor drawing of lines in TimelineBar They're now drawn as CE_StyledFrame controls, with either HLine or VLine shape as appropriate for the orientation of the line. This will go into RDStyle when the light or dark UI theme is selected, allowing appropriate colors to be used. --- qrenderdoc/Windows/TimelineBar.cpp | 49 ++++++++++++++++++++++-------- qrenderdoc/Windows/TimelineBar.h | 4 ++- 2 files changed, 40 insertions(+), 13 deletions(-) diff --git a/qrenderdoc/Windows/TimelineBar.cpp b/qrenderdoc/Windows/TimelineBar.cpp index 70c215139..7ea4a4d85 100644 --- a/qrenderdoc/Windows/TimelineBar.cpp +++ b/qrenderdoc/Windows/TimelineBar.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include "Code/QRDUtils.h" #include "Code/Resources.h" @@ -457,7 +458,7 @@ void TimelineBar::leaveEvent(QEvent *e) void TimelineBar::paintEvent(QPaintEvent *e) { - QPainter p(viewport()); + QStylePainter p(viewport()); p.setFont(font()); p.setRenderHint(QPainter::TextAntialiasing); @@ -468,11 +469,17 @@ void TimelineBar::paintEvent(QPaintEvent *e) p.fillRect(r, palette().brush(QPalette::Window)); - r = r.marginsRemoved(QMargins(borderWidth + margin, borderWidth + margin, borderWidth + margin, - borderWidth + margin)); + QRectF borderRect = r.marginsRemoved(uniformMargins(margin)); + r = borderRect.marginsRemoved(uniformMargins(borderWidth)); p.fillRect(r, palette().brush(QPalette::Base)); - p.drawRect(r); + + QStyleOptionFrame frameOpt; + frameOpt.initFrom(viewport()); + frameOpt.rect = borderRect.toRect(); + frameOpt.frameShape = QFrame::Box; + frameOpt.lineWidth = 1; + p.drawControl(QStyle::CE_ShapedFrame, frameOpt); } QTextOption to; @@ -492,15 +499,16 @@ void TimelineBar::paintEvent(QPaintEvent *e) titleRect.setLeft(titleRect.left() - margin); titleRect.setTop(titleRect.top() - margin); - p.drawLine(titleRect.bottomLeft(), titleRect.bottomRight()); - p.drawLine(titleRect.topRight(), titleRect.bottomRight()); + + drawLine(p, titleRect.bottomLeft(), titleRect.bottomRight()); + drawLine(p, titleRect.topRight(), titleRect.bottomRight()); } QRectF eidAxisRect = m_eidAxisRect; - p.drawLine(eidAxisRect.bottomLeft(), eidAxisRect.bottomRight() + QPointF(margin, 0)); + drawLine(p, eidAxisRect.bottomLeft(), eidAxisRect.bottomRight() + QPointF(margin, 0)); - p.drawLine(m_highlightingRect.topLeft(), m_highlightingRect.topRight()); + drawLine(p, m_highlightingRect.topLeft(), m_highlightingRect.topRight()); if(m_Draws.isEmpty()) return; @@ -553,8 +561,8 @@ void TimelineBar::paintEvent(QPaintEvent *e) hoverRect = hoverRect.marginsAdded(QMargins(0, margin, 0, 0)); if(hoverRect.left() >= m_eidAxisRect.left()) - p.drawLine(hoverRect.topLeft(), hoverRect.bottomLeft()); - p.drawLine(hoverRect.topRight(), hoverRect.bottomRight()); + drawLine(p, hoverRect.topLeft(), hoverRect.bottomLeft()); + drawLine(p, hoverRect.topRight(), hoverRect.bottomRight()); // shrink the rect a bit for clipping against labels below hoverRect.setX(qRound(hoverRect.x() + 0.5)); @@ -626,7 +634,8 @@ void TimelineBar::paintEvent(QPaintEvent *e) QRectF currentBackRect = currentRect.marginsAdded(QMargins(0, margin, 0, 0)); p.fillRect(currentBackRect, palette().brush(QPalette::Base)); - p.drawRect(currentBackRect); + drawLine(p, currentBackRect.topLeft(), currentBackRect.bottomLeft()); + drawLine(p, currentBackRect.topRight(), currentBackRect.bottomRight()); // draw the 'current marker' pixmap const QPixmap &px = Pixmaps::flag_green(devicePixelRatio()); @@ -644,7 +653,7 @@ void TimelineBar::paintEvent(QPaintEvent *e) QPointF currentBottom = currentTop; currentBottom.setY(m_markerRect.bottom()); - p.drawLine(currentTop, currentBottom); + drawLine(p, currentTop, currentBottom); } to.setAlignment(Qt::AlignLeft | Qt::AlignTop); @@ -890,6 +899,22 @@ TimelineBar::Marker *TimelineBar::findMarker(QVector &markers, QRectF ma return NULL; } +void TimelineBar::drawLine(QStylePainter &p, QPointF start, QPointF end) +{ + if(start.x() == end.x() || start.y() == end.y()) + { + QStyleOptionFrame opt; + opt.initFrom(viewport()); + opt.rect = QRectF(start, end).toRect(); + opt.frameShape = (start.y() == end.y() ? QFrame::HLine : QFrame::VLine); + p.drawControl(QStyle::CE_ShapedFrame, opt); + } + else + { + p.drawLine(start, end); + } +} + void TimelineBar::paintMarkers(QPainter &p, const QVector &markers, const QVector &draws, QRectF markerRect) { diff --git a/qrenderdoc/Windows/TimelineBar.h b/qrenderdoc/Windows/TimelineBar.h index b4a3bb358..0d5a72172 100644 --- a/qrenderdoc/Windows/TimelineBar.h +++ b/qrenderdoc/Windows/TimelineBar.h @@ -25,6 +25,7 @@ #pragma once #include +#include #include "Code/Interface/QRDInterface.h" class TimelineBar : public QAbstractScrollArea, public ITimelineBar, public ICaptureViewer @@ -82,7 +83,7 @@ private: QString m_UsageTarget; QList m_UsageEvents; - const qreal margin = 2.0; + const qreal margin = 3.0; const qreal borderWidth = 1.0; const QString eidAxisTitle = lit("EID:"); const int dataBarHeight = 16; @@ -110,6 +111,7 @@ private: qreal offsetOf(uint32_t eid); uint32_t processDraws(QVector &markers, QVector &draws, const rdcarray &curDraws); + void drawLine(QStylePainter &p, QPointF start, QPointF end); void paintMarkers(QPainter &p, const QVector &markers, const QVector &draws, QRectF markerRect); Marker *findMarker(QVector &markers, QRectF markerRect, QPointF pos);