diff --git a/include/ui/mapruler.h b/include/ui/mapruler.h index 11adc535..1fd97d84 100644 --- a/include/ui/mapruler.h +++ b/include/ui/mapruler.h @@ -57,6 +57,7 @@ public: private: QRect xRuler; QRect yRuler; + QLineF cornerTick; QRect widthTextBox; QRect heightTextBox; QColor interiorColor; diff --git a/src/ui/mapruler.cpp b/src/ui/mapruler.cpp index c1b74a25..f60f992b 100644 --- a/src/ui/mapruler.cpp +++ b/src/ui/mapruler.cpp @@ -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()); }