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

70 lines
1.4 KiB
C++
Raw Normal View History

2015-10-05 01:43:48 +02:00
#include <QPainter>
#include "slideritem.h"
2015-10-17 01:33:02 +02:00
#define SIZE 10
2015-10-05 01:43:48 +02:00
2016-09-19 00:56:10 +02:00
SliderItem::SliderItem(QGraphicsItem *parent) : QGraphicsObject(parent)
2015-10-05 01:43:48 +02:00
{
setFlag(ItemIsMovable);
setFlag(ItemSendsGeometryChanges);
2017-12-03 00:36:52 +01:00
_color = Qt::red;
2015-10-05 01:43:48 +02:00
}
QRectF SliderItem::boundingRect() const
{
return QRectF(-SIZE/2, -_area.height(), SIZE, _area.height());
}
void SliderItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
2016-10-17 23:14:07 +02:00
painter->setRenderHint(QPainter::Antialiasing, false);
2017-12-03 00:36:52 +01:00
painter->setPen(_color);
2015-10-05 01:43:48 +02:00
painter->drawLine(0, 0, 0, -_area.height());
2016-08-19 19:48:44 +02:00
// painter->drawRect(boundingRect());
2015-10-05 01:43:48 +02:00
}
QVariant SliderItem::itemChange(GraphicsItemChange change, const QVariant &value)
{
if (change == ItemPositionChange && scene()) {
QPointF pos = value.toPointF();
if (!_area.contains(QRectF(pos, boundingRect().size()))) {
pos.setX(qMin(_area.right(), qMax(pos.x(), _area.left())));
pos.setY(qMin(_area.bottom(), qMax(pos.y(), _area.top()
+ boundingRect().height())));
return pos;
}
}
2016-03-30 20:50:51 +02:00
if (change == ItemPositionHasChanged && scene())
2015-10-05 01:43:48 +02:00
emit positionChanged(value.toPointF());
return QGraphicsItem::itemChange(change, value);
}
2015-12-19 20:23:07 +01:00
void SliderItem::clear()
{
_area = QRectF();
setPos(QPointF());
}
2016-04-01 21:20:23 +02:00
void SliderItem::setArea(const QRectF &area)
{
prepareGeometryChange();
_area = area;
}
2017-12-03 00:36:52 +01:00
void SliderItem::setColor(const QColor &color)
{
_color = color;
update();
}