Use QGraphicsObject's signalling to enable/disable MapRuler
This commit is contained in:
parent
bc0127430b
commit
6ca4802948
2 changed files with 20 additions and 20 deletions
|
@ -10,24 +10,13 @@ class MapRuler : public QGraphicsObject, private QLine
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MapRuler(QColor innerColor = Qt::yellow, QColor borderColor = Qt::black) :
|
||||
innerColor(innerColor),
|
||||
borderColor(borderColor),
|
||||
mapSize(QSize()),
|
||||
statusMessage(QString()),
|
||||
xRuler(QRect()),
|
||||
yRuler(QRect()),
|
||||
cornerTick(QLine()),
|
||||
anchored(false),
|
||||
locked(false)
|
||||
{ }
|
||||
MapRuler(QColor innerColor = Qt::yellow, QColor borderColor = Qt::black);
|
||||
|
||||
QRectF boundingRect() const override;
|
||||
QPainterPath shape() const override;
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override;
|
||||
bool eventFilter(QObject *, QEvent *event) override;
|
||||
|
||||
void setEnabled(bool enabled);
|
||||
bool isAnchored() const { return anchored; }
|
||||
bool isLocked() const { return locked; }
|
||||
|
||||
|
|
|
@ -8,6 +8,23 @@
|
|||
int MapRuler::thickness = 3;
|
||||
|
||||
|
||||
MapRuler::MapRuler(QColor innerColor, QColor borderColor) :
|
||||
innerColor(innerColor),
|
||||
borderColor(borderColor),
|
||||
mapSize(QSize()),
|
||||
statusMessage(QString()),
|
||||
xRuler(QRect()),
|
||||
yRuler(QRect()),
|
||||
cornerTick(QLine()),
|
||||
anchored(false),
|
||||
locked(false)
|
||||
{
|
||||
connect(this, &QGraphicsObject::enabledChanged, [this]() {
|
||||
if (!isEnabled() && anchored)
|
||||
init();
|
||||
});
|
||||
}
|
||||
|
||||
QRectF MapRuler::boundingRect() const {
|
||||
return QRectF(-thickness, -thickness, pixWidth() + thickness * 2, pixHeight() + thickness * 2);
|
||||
}
|
||||
|
@ -18,9 +35,9 @@ QPainterPath MapRuler::shape() const {
|
|||
ruler.addRect(xRuler);
|
||||
ruler.addRect(yRuler);
|
||||
ruler = ruler.simplified();
|
||||
for (int x = 17.5; x < pixWidth(); x += 16)
|
||||
for (int x = 17; x < pixWidth(); x += 16)
|
||||
ruler.addRect(x, xRuler.y(), 0, thickness);
|
||||
for (int y = 17.5; y < pixHeight(); y += 16)
|
||||
for (int y = 17; y < pixHeight(); y += 16)
|
||||
ruler.addRect(yRuler.x(), y, thickness, 0);
|
||||
return ruler;
|
||||
}
|
||||
|
@ -65,12 +82,6 @@ void MapRuler::setMapDimensions(const QSize &size) {
|
|||
init();
|
||||
}
|
||||
|
||||
void MapRuler::setEnabled(bool enabled) {
|
||||
QGraphicsItem::setEnabled(enabled);
|
||||
if (!enabled && anchored)
|
||||
init();
|
||||
}
|
||||
|
||||
void MapRuler::init() {
|
||||
prepareGeometryChange();
|
||||
hide();
|
||||
|
|
Loading…
Reference in a new issue