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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2015-10-05 01:43:48 +02:00
|
|
|
painter->setPen(Qt::red);
|
|
|
|
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;
|
|
|
|
}
|