2017-08-02 15:26:14 +00:00
|
|
|
/*
|
2020-08-16 09:40:14 +02:00
|
|
|
Copyright 2006-2020 The QElectroTech Team
|
|
|
|
This file is part of QElectroTech.
|
2017-08-02 15:26:14 +00:00
|
|
|
|
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.
|
2017-08-02 15:26:14 +00:00
|
|
|
|
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.
|
2017-08-02 15:26:14 +00:00
|
|
|
|
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/>.
|
2017-08-02 15:26:14 +00:00
|
|
|
*/
|
|
|
|
#include "qetgraphicshandleritem.h"
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QDebug>
|
2018-07-19 14:14:31 +00:00
|
|
|
#include <utility>
|
2017-08-02 15:26:14 +00:00
|
|
|
|
|
|
|
/**
|
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
|
|
|
*/
|
2017-08-02 15:26:14 +00:00
|
|
|
QetGraphicsHandlerItem::QetGraphicsHandlerItem(qreal size) :
|
2020-10-13 21:51:34 +02:00
|
|
|
m_size(size)
|
2018-06-29 07:55:48 +00:00
|
|
|
{
|
|
|
|
setFlag(QGraphicsItem::ItemIgnoresTransformations);
|
2020-10-13 21:51:34 +02:00
|
|
|
|
2018-06-29 07:55:48 +00:00
|
|
|
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);
|
|
|
|
}
|
2017-08-02 15:26:14 +00:00
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief QetGraphicsHandlerItem::boundingRect
|
2020-10-13 21:51:34 +02:00
|
|
|
@return
|
2020-08-16 11:19:36 +02:00
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
QRectF QetGraphicsHandlerItem::boundingRect() const
|
|
|
|
{
|
2018-06-29 07:55:48 +00:00
|
|
|
return m_br;
|
2017-08-02 15:26:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
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
|
|
|
*/
|
2017-08-02 15:26:14 +00:00
|
|
|
void QetGraphicsHandlerItem::setColor(QColor color)
|
|
|
|
{
|
2018-07-19 14:14:31 +00:00
|
|
|
m_color = std::move(color);
|
2017-08-02 15:26:14 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief QetGraphicsHandlerItem::paint
|
|
|
|
@param painter
|
|
|
|
@param option
|
|
|
|
@param widget
|
|
|
|
*/
|
2020-08-16 14:22:12 +02:00
|
|
|
void QetGraphicsHandlerItem::paint(QPainter *painter,
|
|
|
|
const QStyleOptionGraphicsItem *option,
|
|
|
|
QWidget *widget)
|
2017-08-02 15:26:14 +00:00
|
|
|
{
|
2020-02-02 16:33:19 +01:00
|
|
|
Q_UNUSED(option)
|
|
|
|
Q_UNUSED(widget)
|
2017-08-02 15:26:14 +00:00
|
|
|
|
2020-08-16 14:22:12 +02:00
|
|
|
painter->save();
|
|
|
|
painter->setBrush(QBrush(m_color));
|
|
|
|
QPen pen(QBrush(m_color),
|
|
|
|
2,
|
|
|
|
Qt::SolidLine,
|
|
|
|
Qt::SquareCap,
|
|
|
|
Qt::MiterJoin);
|
2017-08-02 15:26:14 +00:00
|
|
|
pen.setCosmetic(true);
|
2020-08-16 14:22:12 +02:00
|
|
|
painter->setPen(pen);
|
2017-08-02 15:26:14 +00:00
|
|
|
painter->setRenderHint(QPainter::Antialiasing, true);
|
2020-08-16 14:22:12 +02:00
|
|
|
painter->drawEllipse(m_handler_rect);
|
2017-08-02 15:26:14 +00:00
|
|
|
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
|
|
|
|
*/
|
2020-08-16 14:22:12 +02:00
|
|
|
QVector<QetGraphicsHandlerItem *> QetGraphicsHandlerItem::handlerForPoint(
|
|
|
|
const QVector<QPointF> &points,
|
|
|
|
int size)
|
2017-08-02 15:26:14 +00:00
|
|
|
{
|
2020-08-16 14:22:12 +02:00
|
|
|
QVector <QetGraphicsHandlerItem *> list_;
|
|
|
|
for (QPointF point : points)
|
|
|
|
{
|
|
|
|
QetGraphicsHandlerItem *qghi = new QetGraphicsHandlerItem(size);
|
|
|
|
qghi->setPos(point);
|
|
|
|
list_ << qghi;
|
|
|
|
}
|
2017-08-02 15:26:14 +00:00
|
|
|
|
|
|
|
return list_;
|
|
|
|
}
|