Add tick marks to MapRuler

This commit is contained in:
BigBahss 2020-09-25 11:56:02 -04:00
parent ca6969564f
commit 9565b677d2
2 changed files with 11 additions and 0 deletions

View file

@ -57,6 +57,7 @@ public:
private:
QRect xRuler;
QRect yRuler;
QLineF cornerTick;
QRect widthTextBox;
QRect heightTextBox;
QColor interiorColor;

View file

@ -28,6 +28,10 @@ QPainterPath MapRuler::shape() const {
ruler.addRect(xRuler);
ruler.addRect(yRuler);
ruler = ruler.simplified();
for (int x = 17.5; x < pixWidth(); x += 16)
ruler.addRect(x, xRuler.y(), 0, thickness);
for (int y = 17.5; y < pixHeight(); y += 16)
ruler.addRect(yRuler.x(), y, thickness, 0);
return ruler;
}
@ -35,6 +39,8 @@ void MapRuler::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidge
painter->setPen(exteriorColor);
painter->setBrush(QBrush(interiorColor));
painter->drawPath(shape());
if (width() && height())
painter->drawLine(cornerTick);
painter->drawText(widthTextBox, Qt::AlignCenter, QString("%1").arg(width()));
painter->drawText(heightTextBox, Qt::AlignCenter, QString("%1").arg(height()));
}
@ -70,24 +76,28 @@ void MapRuler::updateShape() {
// Top-left
xRuler = QRect(0, pixHeight(), pixWidth() + thickness, thickness);
yRuler = QRect(0, 0, thickness, pixHeight() + thickness);
cornerTick = QLineF(yRuler.x() + 0.5, xRuler.y() + thickness - 0.5, yRuler.x() + thickness, xRuler.y());
widthTextBox = QRect(0, pixHeight(), pixWidth(), padding);
heightTextBox = QRect(-padding, 0, padding, pixHeight());
} else if (deltaX() < 0) {
// Bottom-left
xRuler = QRect(0, 0, pixWidth() + thickness, thickness);
yRuler = QRect(0, 0, thickness, pixHeight() + thickness);
cornerTick = QLineF(xRuler.x() + 0.5, xRuler.y() + 0.5, xRuler.x() + thickness, xRuler.y() + thickness);
widthTextBox = QRect(0, -padding, pixWidth(), padding);
heightTextBox = QRect(-padding, 0, padding, pixHeight());
} else if (deltaY() < 0) {
// Top-right
xRuler = QRect(0, pixHeight(), pixWidth() + thickness, thickness);
yRuler = QRect(pixWidth(), 0, thickness, pixHeight() + thickness);
cornerTick = QLineF(yRuler.x(), xRuler.y(), yRuler.x() + thickness - 0.5, xRuler.y() + thickness - 0.5);
widthTextBox = QRect(0, pixHeight(), pixWidth(), padding);
heightTextBox = QRect(pixWidth(), 0, padding, pixHeight());
} else {
// Bottom-right
xRuler = QRect(0, 0, pixWidth() + thickness, thickness);
yRuler = QRect(pixWidth(), 0, thickness, pixHeight() + thickness);
cornerTick = QLineF(yRuler.x(), yRuler.y() + thickness, yRuler.x() + thickness - 0.5, yRuler.y() + 0.5);
widthTextBox = QRect(0, -padding, pixWidth(), padding);
heightTextBox = QRect(pixWidth(), 0, padding, pixHeight());
}