102 lines
2.4 KiB
C++
Raw Normal View History

/*
Copyright 2006-2020 The QElectroTech Team
2020-08-16 09:40:14 +02:00
This file is part of QElectroTech.
2020-08-16 09:40:14 +02:00
QElectroTech is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
2020-08-16 09:40:14 +02:00
QElectroTech is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
2020-08-16 09:40:14 +02:00
You should have received a copy of the GNU General Public License
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#include "qetgraphicshandleritem.h"
#include <QPainter>
#include <QDebug>
#include <utility>
/**
2020-08-16 11:19:36 +02:00
@brief QetGraphicsHandlerItem::QetGraphicsHandlerItem
2020-08-20 17:44:59 +02:00
@param size : the size of the handler
2020-08-16 11:19:36 +02:00
*/
QetGraphicsHandlerItem::QetGraphicsHandlerItem(qreal size) :
m_size(size)
{
setFlag(QGraphicsItem::ItemIgnoresTransformations);
m_handler_rect.setRect(0-m_size/2, 0-m_size/2, m_size, m_size);
m_br.setRect(-1-m_size/2, -1-m_size/2, m_size+2, m_size+2);
}
/**
2020-08-16 11:19:36 +02:00
@brief QetGraphicsHandlerItem::boundingRect
@return
*/
2020-09-07 22:03:40 +02:00
QRectF QetGraphicsHandlerItem::boundingRect() const
{
return m_br;
}
/**
2020-08-16 11:19:36 +02:00
@brief QetGraphicsHandlerItem::setColor
2020-08-20 17:44:59 +02:00
@param color : set the color of the handler
2020-08-16 11:19:36 +02:00
*/
void QetGraphicsHandlerItem::setColor(QColor color)
{
m_color = std::move(color);
update();
}
/**
2020-08-16 11:19:36 +02:00
@brief QetGraphicsHandlerItem::paint
@param painter
@param option
@param widget
*/
void QetGraphicsHandlerItem::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
Q_UNUSED(option)
Q_UNUSED(widget)
painter->save();
painter->setBrush(QBrush(m_color));
QPen pen(QBrush(m_color),
2,
Qt::SolidLine,
Qt::SquareCap,
Qt::MiterJoin);
pen.setCosmetic(true);
painter->setPen(pen);
painter->setRenderHint(QPainter::Antialiasing, true);
painter->drawEllipse(m_handler_rect);
painter->restore();
}
/**
2020-08-16 11:19:36 +02:00
@brief QetGraphicsHandlerItem::handlerForPoint
@param points
2020-08-20 17:44:59 +02:00
@param size
2020-08-16 11:19:36 +02:00
@return A list of handler with pos at point
*/
QVector<QetGraphicsHandlerItem *> QetGraphicsHandlerItem::handlerForPoint(
const QVector<QPointF> &points,
int size)
{
QVector <QetGraphicsHandlerItem *> list_;
for (QPointF point : points)
{
QetGraphicsHandlerItem *qghi = new QetGraphicsHandlerItem(size);
qghi->setPos(point);
list_ << qghi;
}
return list_;
}