File indexing completed on 2024-04-28 05:38:10
0001 /*************************************************************************** 0002 * Copyright (C) 2015 by Renaud Guezennec * 0003 * https://rolisteam.org/contact * 0004 * * 0005 * rolisteam is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, * 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0013 * GNU General Public License for more details. * 0014 * * 0015 * You should have received a copy of the GNU General Public License * 0016 * along with this program; if not, write to the * 0017 * Free Software Foundation, Inc., * 0018 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 0019 ***************************************************************************/ 0020 0021 #include "anchoritem.h" 0022 0023 #include <QPainter> 0024 0025 AnchorItem::AnchorItem() 0026 : m_pen(QColor(Qt::darkGray)) 0027 { 0028 0029 } 0030 0031 AnchorItem::~AnchorItem() {} 0032 QRectF AnchorItem::boundingRect() const 0033 { 0034 return QRectF(m_startPoint, m_endPoint); 0035 } 0036 0037 void AnchorItem::setNewEnd(const QPointF &nend) 0038 { 0039 if (nend.isNull()) 0040 return; 0041 0042 m_endPoint += nend; 0043 } 0044 void AnchorItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) 0045 { 0046 Q_UNUSED(widget) 0047 Q_UNUSED(option) 0048 0049 painter->save(); 0050 painter->setRenderHint(QPainter::Antialiasing, true); 0051 0052 m_pen.setWidth(3); 0053 m_pen.setColor(Qt::darkGray); 0054 painter->setPen(m_pen); 0055 QLineF line(m_startPoint, m_endPoint); 0056 painter->drawLine(line); 0057 painter->restore(); 0058 } 0059 0060 QPointF AnchorItem::getStart() const 0061 { 0062 return mapToScene(m_startPoint); 0063 } 0064 0065 QPointF AnchorItem::getEnd() const 0066 { 0067 return mapToScene(m_endPoint); 0068 }