Skip to content

Commit ec0b6d6

Browse files
committed
Chevron changed for triangles, added coordinate origin
Signed-off-by: zesk1999 <zesk1999@gmail.com>
1 parent d83f983 commit ec0b6d6

2 files changed

Lines changed: 57 additions & 36 deletions

File tree

include/eprosimashapesdemo/qt/AxisArrowOverlay.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@ class ShapesDemo;
2929
* together with "X" / "Y" labels in the outer-margin corners.
3030
*
3131
* Not inverted (origin top-left):
32-
* ">" tip at the top-right corner (X axis →), "X" label in the right margin
33-
* "v" tip at the bottom-left corner (Y axis ↓), "Y" label in the left margin
32+
* filled-triangle tip at the top-right corner (X axis →), "X" label in the right margin
33+
* filled-triangle tip at the bottom-left corner (Y axis ↓), "Y" label in the left margin
34+
* origin dot at the top-left corner
3435
*
3536
* Inverted (origin bottom-left):
36-
* ">" tip at the bottom-right corner (X axis →), "X" label in the right margin
37-
* "^" tip at the top-left corner (Y axis ↑), "Y" label in the left margin
37+
* filled-triangle tip at the bottom-right corner (X axis →), "X" label in the right margin
38+
* filled-triangle tip at the top-left corner (Y axis ↑), "Y" label in the left margin
39+
* origin dot at the bottom-left corner
3840
*
3941
* Polls ShapesDemoOptions::m_invertYAxis every 100 ms to react to option changes.
4042
*/

src/qt/AxisArrowOverlay.cpp

Lines changed: 51 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,14 @@
2323
#include <QFontMetrics>
2424
#include <QPainter>
2525
#include <QPen>
26+
#include <QPolygon>
2627
#include <QResizeEvent>
2728

28-
// Half-width of the arrowhead chevron (pixels from tip to each arm end)
29-
static const int ARROW = 6;
29+
// Filled-triangle arrowhead dimensions
30+
static const int TRI_LEN = 5; // tip to base (along the axis)
31+
static const int TRI_HALF = 4; // base half-width (perpendicular to axis)
32+
// Origin dot radius
33+
static const int DOT_R = 2;
3034

3135
AxisArrowOverlay::AxisArrowOverlay(
3236
QWidget* parent,
@@ -78,8 +82,7 @@ void AxisArrowOverlay::paintEvent(
7882
const QRect fd2 = mp_fd2->geometry();
7983

8084
QPainter p(this);
81-
p.setRenderHint(QPainter::Antialiasing, false);
82-
p.setPen(QPen(Qt::black, 1));
85+
p.setRenderHint(QPainter::Antialiasing, true);
8386

8487
QFont f = font();
8588
f.setPointSize(7);
@@ -90,43 +93,59 @@ void AxisArrowOverlay::paintEvent(
9093
const int xw = fm.horizontalAdvance("X") + 2;
9194
const int yw = fm.horizontalAdvance("Y") + 2;
9295

93-
// Label positions in the outer margin, anchored to fd2's corners.
94-
// RIGHT margin: X labels — to the right of fd2.right()
95-
// LEFT margin: Y labels — to the left of fd2.left()
96+
// Label corner positions in the outer margin, anchored to fd2's corners.
9697
const int rightX = fd2.right() + 4;
9798
const int topY = qMax(0, fd2.top() - lh);
9899
const int bottomY = fd2.bottom() - 1;
99100
const int leftX = qMax(0, fd2.left() - yw - 3);
100101

101-
// X arrowhead ">": tip at the right end of the axis border.
102-
// Not inverted: top border (origin top-left). Inverted: bottom border.
103-
// Label "X" in the right-margin corner adjacent to the arrowhead.
102+
// Draw filled shapes (no outline)
103+
p.setPen(Qt::NoPen);
104+
p.setBrush(Qt::black);
105+
106+
// Origin dot at the corner where both axes meet.
107+
// Not inverted: top-left corner. Inverted: bottom-left corner.
108+
const QPoint origin(fd2.left() + 1, invertY ? fd2.bottom() : fd2.top() + 1);
109+
p.drawEllipse(origin, DOT_R, DOT_R);
110+
111+
// X arrowhead: right-pointing filled triangle, tip 1px past fd2's right border.
112+
// Not inverted: aligned with the top border. Inverted: with the bottom border.
104113
{
114+
const int xTip = fd2.right() + 1;
105115
const int yAxis = invertY ? fd2.bottom() : fd2.top();
106-
const QPoint tip(fd2.right(), yAxis);
107-
p.drawLine(tip, QPoint(tip.x() - ARROW, tip.y() - ARROW));
108-
p.drawLine(tip, QPoint(tip.x() - ARROW, tip.y() + ARROW));
109-
p.drawText(QRect(rightX, invertY ? bottomY : topY, xw, lh),
110-
Qt::AlignLeft | Qt::AlignTop, "X");
116+
QPolygon tri;
117+
tri << QPoint(xTip, yAxis)
118+
<< QPoint(xTip - TRI_LEN, yAxis - TRI_HALF)
119+
<< QPoint(xTip - TRI_LEN, yAxis + TRI_HALF);
120+
p.drawPolygon(tri);
111121
}
112122

113-
// Y arrowhead "v"/"^": tip at the end of the left border.
114-
// Not inverted: bottom end, pointing down. Inverted: top end, pointing up.
115-
// Label "Y" in the left-margin corner adjacent to the arrowhead.
116-
if (!invertY)
123+
// Y arrowhead: down/up-pointing filled triangle, tip 1px inside fd2's left border.
124+
// Not inverted: aligned with the bottom border. Inverted: with the top border.
117125
{
118-
const QPoint tip(fd2.left(), fd2.bottom());
119-
p.drawLine(tip, QPoint(tip.x() - ARROW, tip.y() - ARROW));
120-
p.drawLine(tip, QPoint(tip.x() + ARROW, tip.y() - ARROW));
121-
p.drawText(QRect(leftX, bottomY, yw, lh),
122-
Qt::AlignLeft | Qt::AlignTop, "Y");
123-
}
124-
else
125-
{
126-
const QPoint tip(fd2.left(), fd2.top());
127-
p.drawLine(tip, QPoint(tip.x() - ARROW, tip.y() + ARROW));
128-
p.drawLine(tip, QPoint(tip.x() + ARROW, tip.y() + ARROW));
129-
p.drawText(QRect(leftX, topY, yw, lh),
130-
Qt::AlignLeft | Qt::AlignTop, "Y");
126+
const int xTip = fd2.left() + 1;
127+
if (!invertY)
128+
{
129+
QPolygon tri;
130+
tri << QPoint(xTip, fd2.bottom())
131+
<< QPoint(xTip - TRI_HALF, fd2.bottom() - TRI_LEN)
132+
<< QPoint(xTip + TRI_HALF, fd2.bottom() - TRI_LEN);
133+
p.drawPolygon(tri);
134+
}
135+
else
136+
{
137+
QPolygon tri;
138+
tri << QPoint(xTip, fd2.top())
139+
<< QPoint(xTip - TRI_HALF, fd2.top() + TRI_LEN)
140+
<< QPoint(xTip + TRI_HALF, fd2.top() + TRI_LEN);
141+
p.drawPolygon(tri);
142+
}
131143
}
144+
145+
// Axis labels
146+
p.setPen(Qt::black);
147+
p.drawText(QRect(rightX, invertY ? bottomY : topY, xw, lh),
148+
Qt::AlignLeft | Qt::AlignTop, "X");
149+
p.drawText(QRect(leftX, invertY ? topY : bottomY, yw, lh),
150+
Qt::AlignLeft | Qt::AlignTop, "Y");
132151
}

0 commit comments

Comments
 (0)