Skip to content

Commit

Permalink
Make info_rect and currentTimeMarker not leaving the boundaries of th…
Browse files Browse the repository at this point in the history
…e graph
  • Loading branch information
jsalus committed Oct 18, 2023
1 parent eebc5df commit 3ae2f06
Showing 1 changed file with 54 additions and 22 deletions.
76 changes: 54 additions & 22 deletions libshvvisu/src/timeline/graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1158,6 +1158,15 @@ void Graph::drawCenterBottomText(QPainter *painter, const QPoint &top_center, co
br.adjust(-inset, 0, inset, 0);
br.moveCenter(top_center);
br.moveBottom(top_center.y());

if (br.right() > m_layout.xAxisRect.right()) {
br.moveRight(m_layout.xAxisRect.right() - 1);
}

if (br.left() < m_layout.xAxisRect.left()) {
br.moveLeft(m_layout.xAxisRect.left());
}

drawRectText(painter, br, text, font, color, background, inset);
}

Expand Down Expand Up @@ -1286,7 +1295,7 @@ void Graph::draw(QPainter *painter, const QRect &dirty_rect, const QRect &view_r
drawGrid(painter, i);
drawSamples(painter, i);
drawProbes(painter, i);
drawCrossHair(painter, i);
//drawCrossHair(painter, i);
draw_cross_hair_time_marker = true;
drawCurrentTime(painter, i);
}
Expand All @@ -1295,6 +1304,14 @@ void Graph::draw(QPainter *painter, const QRect &dirty_rect, const QRect &view_r
if(dirty_rect.intersects(ch->yAxisRect()))
drawYAxis(painter, i);
}

for (int i : visibleChannels()) {
const GraphChannel *ch = channelAt(i);
if(dirty_rect.intersects(ch->graphAreaRect())) {
drawCrossHair(painter, i);
}
}

if(draw_cross_hair_time_marker)
drawCrossHairTimeMarker(painter);
int minimap_bottom = view_rect.height() + view_rect.y();
Expand Down Expand Up @@ -2106,6 +2123,30 @@ void Graph::drawCrossHair(QPainter *painter, int channel_ix)
/// draw bulls-eye
painter->setPen(pen_solid);
painter->drawRect(bulls_eye_rect);

{
/// draw Y-marker
int tick_len = u2px(m_state.xAxis.tickLen)*2;
{
QRect r{0, 0, tick_len, 2 * tick_len};
r.moveCenter(p1);
r.moveLeft(p1.x());

QPainterPath pp;
pp.moveTo(r.bottomRight());
pp.lineTo(r.topRight());
pp.lineTo(r.left(), r.center().y());
pp.lineTo(r.bottomRight());
painter->fillPath(pp, color);
}
/// draw Y value
auto val = ch->posToValue(p1.y());
auto c_text = color;
auto c_background = effectiveStyle().colorBackground();
c_background.setAlphaF(0.5);
drawLeftCenterText(painter, p1 + QPoint{tick_len, 0}, QString::number(val), m_style.font(), c_text, c_background);
}

{
/// draw info
QString info_text;
Expand Down Expand Up @@ -2154,32 +2195,23 @@ void Graph::drawCrossHair(QPainter *painter, int channel_ix)
auto r2 = info_rect.adjusted(-offset, 0, offset, 0);
auto c = effectiveStyle().colorBackground();
c.setAlphaF(0.5);

if (r2.bottomRight().x() > m_layout.xAxisRect.right()) {
r2.moveRight(m_layout.xAxisRect.right() - 1);
info_rect.moveRight(m_layout.xAxisRect.right() - 1);
}

auto top = m_layout.xAxisRect.top() - m_layout.xAxisRect.height() - 2;
if (r2.bottomRight().y() > top) {
r2.moveBottom(top);
info_rect.moveBottom(top);
}

painter->fillRect(r2, c);
painter->drawText(info_rect, info_text);
painter->drawRect(r2);
}
}
{
/// draw Y-marker
int tick_len = u2px(m_state.xAxis.tickLen)*2;
{
QRect r{0, 0, tick_len, 2 * tick_len};
r.moveCenter(p1);
r.moveLeft(p1.x());
QPainterPath pp;
pp.moveTo(r.bottomRight());
pp.lineTo(r.topRight());
pp.lineTo(r.left(), r.center().y());
pp.lineTo(r.bottomRight());
painter->fillPath(pp, color);
}
/// draw Y value
auto val = ch->posToValue(p1.y());
auto c_text = color;
auto c_background = effectiveStyle().colorBackground();
c_background.setAlphaF(0.5);
drawLeftCenterText(painter, p1 + QPoint{tick_len, 0}, QString::number(val), m_style.font(), c_text, c_background);
}
{
/// draw point on current value graph
timemsec_t time = posToTime(crossbar_pos.x());
Expand Down

0 comments on commit 3ae2f06

Please sign in to comment.