Add tick marks to MapRuler
This commit is contained in:
parent
ca6969564f
commit
9565b677d2
2 changed files with 11 additions and 0 deletions
|
@ -57,6 +57,7 @@ public:
|
||||||
private:
|
private:
|
||||||
QRect xRuler;
|
QRect xRuler;
|
||||||
QRect yRuler;
|
QRect yRuler;
|
||||||
|
QLineF cornerTick;
|
||||||
QRect widthTextBox;
|
QRect widthTextBox;
|
||||||
QRect heightTextBox;
|
QRect heightTextBox;
|
||||||
QColor interiorColor;
|
QColor interiorColor;
|
||||||
|
|
|
@ -28,6 +28,10 @@ QPainterPath MapRuler::shape() const {
|
||||||
ruler.addRect(xRuler);
|
ruler.addRect(xRuler);
|
||||||
ruler.addRect(yRuler);
|
ruler.addRect(yRuler);
|
||||||
ruler = ruler.simplified();
|
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;
|
return ruler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,6 +39,8 @@ void MapRuler::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidge
|
||||||
painter->setPen(exteriorColor);
|
painter->setPen(exteriorColor);
|
||||||
painter->setBrush(QBrush(interiorColor));
|
painter->setBrush(QBrush(interiorColor));
|
||||||
painter->drawPath(shape());
|
painter->drawPath(shape());
|
||||||
|
if (width() && height())
|
||||||
|
painter->drawLine(cornerTick);
|
||||||
painter->drawText(widthTextBox, Qt::AlignCenter, QString("%1").arg(width()));
|
painter->drawText(widthTextBox, Qt::AlignCenter, QString("%1").arg(width()));
|
||||||
painter->drawText(heightTextBox, Qt::AlignCenter, QString("%1").arg(height()));
|
painter->drawText(heightTextBox, Qt::AlignCenter, QString("%1").arg(height()));
|
||||||
}
|
}
|
||||||
|
@ -70,24 +76,28 @@ void MapRuler::updateShape() {
|
||||||
// Top-left
|
// Top-left
|
||||||
xRuler = QRect(0, pixHeight(), pixWidth() + thickness, thickness);
|
xRuler = QRect(0, pixHeight(), pixWidth() + thickness, thickness);
|
||||||
yRuler = QRect(0, 0, thickness, pixHeight() + 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);
|
widthTextBox = QRect(0, pixHeight(), pixWidth(), padding);
|
||||||
heightTextBox = QRect(-padding, 0, padding, pixHeight());
|
heightTextBox = QRect(-padding, 0, padding, pixHeight());
|
||||||
} else if (deltaX() < 0) {
|
} else if (deltaX() < 0) {
|
||||||
// Bottom-left
|
// Bottom-left
|
||||||
xRuler = QRect(0, 0, pixWidth() + thickness, thickness);
|
xRuler = QRect(0, 0, pixWidth() + thickness, thickness);
|
||||||
yRuler = QRect(0, 0, thickness, pixHeight() + 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);
|
widthTextBox = QRect(0, -padding, pixWidth(), padding);
|
||||||
heightTextBox = QRect(-padding, 0, padding, pixHeight());
|
heightTextBox = QRect(-padding, 0, padding, pixHeight());
|
||||||
} else if (deltaY() < 0) {
|
} else if (deltaY() < 0) {
|
||||||
// Top-right
|
// Top-right
|
||||||
xRuler = QRect(0, pixHeight(), pixWidth() + thickness, thickness);
|
xRuler = QRect(0, pixHeight(), pixWidth() + thickness, thickness);
|
||||||
yRuler = QRect(pixWidth(), 0, thickness, pixHeight() + 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);
|
widthTextBox = QRect(0, pixHeight(), pixWidth(), padding);
|
||||||
heightTextBox = QRect(pixWidth(), 0, padding, pixHeight());
|
heightTextBox = QRect(pixWidth(), 0, padding, pixHeight());
|
||||||
} else {
|
} else {
|
||||||
// Bottom-right
|
// Bottom-right
|
||||||
xRuler = QRect(0, 0, pixWidth() + thickness, thickness);
|
xRuler = QRect(0, 0, pixWidth() + thickness, thickness);
|
||||||
yRuler = QRect(pixWidth(), 0, thickness, pixHeight() + 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);
|
widthTextBox = QRect(0, -padding, pixWidth(), padding);
|
||||||
heightTextBox = QRect(pixWidth(), 0, padding, pixHeight());
|
heightTextBox = QRect(pixWidth(), 0, padding, pixHeight());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue