diff --git a/src/infoitem.cpp b/src/infoitem.cpp index 99982696..00dd1148 100644 --- a/src/infoitem.cpp +++ b/src/infoitem.cpp @@ -3,7 +3,6 @@ #include "config.h" #include "infoitem.h" - #define PADDING 10 InfoItem::InfoItem(QGraphicsItem *parent) : QGraphicsItem(parent) @@ -11,24 +10,21 @@ InfoItem::InfoItem(QGraphicsItem *parent) : QGraphicsItem(parent) } -QRectF InfoItem::boundingRect() const +void InfoItem::updateBoundingRect() { QFont font; font.setPixelSize(FONT_SIZE); font.setFamily(FONT_FAMILY); QFontMetrics fm(font); QList::const_iterator i; - int width = 0; - - if (_list.isEmpty()) - return QRectF(); + qreal width = 0; for (i = _list.constBegin(); i != _list.constEnd(); i++) { width += fm.width(i->key + ": "); width += fm.width(i->value) + ((i == _list.end() - 1) ? 0 : PADDING); } - return QRectF(0, 0, width, fm.height()); + _boundingRect = QRectF(0, 0, width, _list.isEmpty() ? 0 : fm.height()); } void InfoItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, @@ -74,5 +70,13 @@ void InfoItem::insert(const QString &key, const QString &value) else _list[i] = kv; + updateBoundingRect(); + prepareGeometryChange(); +} + +void InfoItem::clear() +{ + _list.clear(); + updateBoundingRect(); prepareGeometryChange(); } diff --git a/src/infoitem.h b/src/infoitem.h index fda481aa..74fa6fcc 100644 --- a/src/infoitem.h +++ b/src/infoitem.h @@ -9,14 +9,16 @@ class InfoItem : public QGraphicsItem public: InfoItem(QGraphicsItem *parent = 0); - QRectF boundingRect() const; + QRectF boundingRect() const {return _boundingRect;} void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); void insert(const QString &key, const QString &value); - void clear() {_list.clear();} + void clear(); private: + void updateBoundingRect(); + class KV { public: QString key; @@ -29,6 +31,7 @@ private: }; QList _list; + QRectF _boundingRect; }; #endif // INFOITEM_H diff --git a/src/scaleitem.cpp b/src/scaleitem.cpp index 714f8cae..122e2a37 100644 --- a/src/scaleitem.cpp +++ b/src/scaleitem.cpp @@ -17,11 +17,9 @@ ScaleItem::ScaleItem(QGraphicsItem *parent) : QGraphicsItem(parent) _units = Metric; _zoom = ZOOM_MIN; _lat = 0; - - computeScale(); } -QRectF ScaleItem::boundingRect() const +void ScaleItem::updateBoundingRect() { QFont font; font.setPixelSize(FONT_SIZE); @@ -33,7 +31,7 @@ QRectF ScaleItem::boundingRect() const es = fm.tightBoundingRect(QString::number(_length * SEGMENTS)); us = fm.tightBoundingRect(units()); - return QRectF(-ss.width()/2, 0, + _boundingRect = QRectF(-ss.width()/2, 0, _width * SEGMENTS + ss.width()/2 + qMax(us.width() + PADDING, es.width()/2), SCALE_HEIGHT + PADDING + ss.height() + 2*fm.descent()); } @@ -110,6 +108,7 @@ void ScaleItem::setLatitude(qreal lat) { _lat = lat; computeScale(); + updateBoundingRect(); prepareGeometryChange(); } @@ -117,6 +116,7 @@ void ScaleItem::setZoom(int z) { _zoom = z; computeScale(); + updateBoundingRect(); prepareGeometryChange(); } @@ -124,5 +124,6 @@ void ScaleItem::setUnits(enum Units units) { _units = units; computeScale(); + updateBoundingRect(); prepareGeometryChange(); } diff --git a/src/scaleitem.h b/src/scaleitem.h index 059e9f0e..895490a5 100644 --- a/src/scaleitem.h +++ b/src/scaleitem.h @@ -9,7 +9,7 @@ class ScaleItem : public QGraphicsItem public: ScaleItem(QGraphicsItem *parent = 0); - QRectF boundingRect() const; + QRectF boundingRect() const {return _boundingRect;} void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); @@ -18,6 +18,7 @@ public: void setUnits(enum Units units); private: + void updateBoundingRect(); void computeScale(); QString units() const; @@ -27,6 +28,8 @@ private: qreal _length; Units _units; bool _scale; + + QRectF _boundingRect; }; #endif // SCALEITEM_H diff --git a/src/track.cpp b/src/track.cpp index 044652d9..1613bc90 100644 --- a/src/track.cpp +++ b/src/track.cpp @@ -21,6 +21,9 @@ Track::Track(QWidget *parent) setScene(_scene); setCacheMode(QGraphicsView::CacheBackground); setDragMode(QGraphicsView::ScrollHandDrag); +#ifdef Q_OS_MAC + setViewportUpdateMode(QGraphicsView::FullViewportUpdate); +#endif // Q_OS_MAC setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); @@ -388,7 +391,8 @@ void Track::paintEvent(QPaintEvent *e) { QPointF scenePos = mapToScene(rect().bottomLeft() + QPoint(SCALE_OFFSET, -(SCALE_OFFSET + _mapScale->boundingRect().height()))); - _mapScale->setPos(scenePos); + if (_mapScale->pos() != scenePos) + _mapScale->setPos(scenePos); QGraphicsView::paintEvent(e); }