mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-24 03:35:53 +01:00
Fixed scale flicker issue on OS X
Performance improvements
This commit is contained in:
parent
9941faa218
commit
6acbf0d89f
@ -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<KV>::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();
|
||||
}
|
||||
|
@ -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<KV> _list;
|
||||
QRectF _boundingRect;
|
||||
};
|
||||
|
||||
#endif // INFOITEM_H
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user