QElectroTech  0.70
qetgraphicshandleritem.cpp
Go to the documentation of this file.
1 /*
2  Copyright 2006-2019 The QElectroTech Team
3  This file is part of QElectroTech.
4 
5  QElectroTech is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 2 of the License, or
8  (at your option) any later version.
9 
10  QElectroTech is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #include "qetgraphicshandleritem.h"
19 #include <QPainter>
20 #include <QDebug>
21 #include <utility>
22 
28  m_size(size)
29 {
30  setFlag(QGraphicsItem::ItemIgnoresTransformations);
31 
32  m_handler_rect.setRect(0-m_size/2, 0-m_size/2, m_size, m_size);
33  m_br.setRect(-1-m_size/2, -1-m_size/2, m_size+2, m_size+2);
34 }
35 
41  return m_br;
42 }
43 
49 {
50  m_color = std::move(color);
51  update();
52 }
53 
60 void QetGraphicsHandlerItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
61 {
62  Q_UNUSED(option);
63  Q_UNUSED(widget);
64 
65  painter->save();
66  painter->setBrush(QBrush(m_color));
67  QPen pen(QBrush(m_color), 2, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin);
68  pen.setCosmetic(true);
69  painter->setPen(pen);
70  painter->setRenderHint(QPainter::Antialiasing, true);
71  painter->drawEllipse(m_handler_rect);
72  painter->restore();
73 }
74 
80 QVector<QetGraphicsHandlerItem *> QetGraphicsHandlerItem::handlerForPoint(const QVector<QPointF> &points, int size)
81 {
82  QVector <QetGraphicsHandlerItem *> list_;
83  for (QPointF point : points)
84  {
86  qghi->setPos(point);
87  list_ << qghi;
88  }
89 
90  return list_;
91 }
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
QetGraphicsHandlerItem::paint.
The QetGraphicsHandlerItem class This graphics item represents a point, destined to be used as an han...
void setColor(QColor color)
QetGraphicsHandlerItem::setColor.
QRectF boundingRect() const override
QetGraphicsHandlerItem::boundingRect.
QetGraphicsHandlerItem(qreal size=10)
QetGraphicsHandlerItem::QetGraphicsHandlerItem.
static QVector< QetGraphicsHandlerItem * > handlerForPoint(const QVector< QPointF > &points, int size=10)
QetGraphicsHandlerItem::handlerForPoint.