2019-02-17 20:20:20 +01:00
|
|
|
#include <QFontMetrics>
|
|
|
|
#include <QPainter>
|
|
|
|
#include "font.h"
|
|
|
|
#include "coordinatesitem.h"
|
|
|
|
|
|
|
|
|
|
|
|
CoordinatesItem::CoordinatesItem(QGraphicsItem *parent) : QGraphicsItem(parent)
|
|
|
|
{
|
|
|
|
_format = DecimalDegrees;
|
|
|
|
|
|
|
|
_font.setPixelSize(FONT_SIZE);
|
|
|
|
_font.setFamily(FONT_FAMILY);
|
|
|
|
|
2019-04-02 22:40:46 +02:00
|
|
|
_digitalZoom = 0;
|
|
|
|
|
2019-04-03 09:18:33 +02:00
|
|
|
setAcceptHoverEvents(true);
|
|
|
|
|
2019-02-17 20:20:20 +01:00
|
|
|
updateBoundingRect();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CoordinatesItem::paint(QPainter *painter,
|
|
|
|
const QStyleOptionGraphicsItem *option, QWidget *widget)
|
|
|
|
{
|
|
|
|
Q_UNUSED(option);
|
|
|
|
Q_UNUSED(widget);
|
|
|
|
|
|
|
|
if (!_c.isValid())
|
|
|
|
return;
|
|
|
|
|
|
|
|
QFontMetrics fm(_font);
|
|
|
|
painter->setFont(_font);
|
2019-02-17 22:18:16 +01:00
|
|
|
painter->setPen(QPen(Qt::black));
|
2019-02-17 20:20:20 +01:00
|
|
|
painter->drawText(0, -fm.descent(), Format::coordinates(_c, _format));
|
|
|
|
|
|
|
|
/*
|
|
|
|
painter->setPen(Qt::red);
|
|
|
|
painter->drawRect(boundingRect());
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
void CoordinatesItem::setCoordinates(const Coordinates &c)
|
|
|
|
{
|
|
|
|
_c = c;
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CoordinatesItem::setFormat(const CoordinatesFormat &format)
|
|
|
|
{
|
|
|
|
prepareGeometryChange();
|
|
|
|
|
|
|
|
_format = format;
|
|
|
|
updateBoundingRect();
|
|
|
|
}
|
|
|
|
|
2019-04-02 22:40:46 +02:00
|
|
|
void CoordinatesItem::setDigitalZoom(qreal zoom)
|
|
|
|
{
|
|
|
|
_digitalZoom = zoom;
|
|
|
|
setScale(pow(2, -_digitalZoom));
|
|
|
|
}
|
|
|
|
|
2019-02-17 20:20:20 +01:00
|
|
|
void CoordinatesItem::updateBoundingRect()
|
|
|
|
{
|
|
|
|
QFontMetrics fm(_font);
|
|
|
|
_boundingRect = fm.tightBoundingRect(Format::coordinates(
|
|
|
|
Coordinates(-180, -90), _format));
|
|
|
|
_boundingRect.moveBottom(-fm.descent());
|
|
|
|
}
|