1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-28 13:41:16 +01:00
GPXSee/src/griditem.cpp

51 lines
1.1 KiB
C++
Raw Normal View History

2016-10-17 23:14:07 +02:00
#include <QPainter>
#include "griditem.h"
2016-10-23 14:36:50 +02:00
#define GRID_WIDTH 0
2016-10-17 23:14:07 +02:00
GridItem::GridItem(QGraphicsItem *parent) : QGraphicsItem(parent)
{
2016-12-07 00:44:32 +01:00
#ifndef Q_OS_MAC
setCacheMode(QGraphicsItem::DeviceCoordinateCache);
#endif // Q_OS_MAC
2016-10-17 23:14:07 +02:00
}
void GridItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
QBrush brush(Qt::gray);
QPen pen = QPen(brush, GRID_WIDTH, Qt::DotLine);
painter->setRenderHint(QPainter::Antialiasing, false);
painter->setPen(pen);
for (int i = 0; i < _xTicks.size(); i++)
painter->drawLine(_xTicks.at(i), 0, _xTicks.at(i),
-_boundingRect.height());
for (int i = 0; i < _yTicks.size(); i++)
painter->drawLine(0, -_yTicks.at(i), boundingRect().width(),
-_yTicks.at(i));
/*
painter->setPen(Qt::red);
painter->drawRect(boundingRect());
*/
}
void GridItem::setTicks(const QList<qreal> &x, const QList<qreal> &y)
{
_xTicks = x; _yTicks = y;
update();
}
void GridItem::setSize(const QSizeF &size)
{
prepareGeometryChange();
_boundingRect = QRectF(QPointF(0, -size.height()), size);
}