File indexing completed on 2023-10-01 08:02:04
0001 /* 0002 SPDX-FileCopyrightText: 2007-2008 Thomas Gallinari <tg8187@yahoo.fr> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "elementitem.h" 0008 0009 ElementItem::ElementItem(Element *p_model) 0010 : QGraphicsSvgItem() 0011 { 0012 m_model = p_model; 0013 // Init the view coordinates 0014 setPos(p_model->getX() - boundingRect().width() / 2, p_model->getY() - boundingRect().height() / 2); 0015 // Connects the model to the view 0016 connect(p_model, &Element::moved, this, &ElementItem::update); 0017 setCacheMode(DeviceCoordinateCache); 0018 setMaximumCacheSize(QSize(500, 500)); 0019 } 0020 0021 ElementItem::~ElementItem() 0022 { 0023 delete m_model; 0024 } 0025 0026 Element *ElementItem::getModel() const 0027 { 0028 return m_model; 0029 } 0030 0031 QPainterPath ElementItem::shape() const 0032 { 0033 QPainterPath path; 0034 path.addEllipse(boundingRect()); 0035 return path; 0036 } 0037 0038 void ElementItem::update(qreal p_x, qreal p_y) 0039 { 0040 // Compute the top-right coordinates of the item 0041 qreal x = p_x - boundingRect().width() / 2; 0042 qreal y = p_y - boundingRect().height() / 2; 0043 0044 // Updates the view coordinates 0045 setPos(x, y); 0046 } 0047 0048 #include "moc_elementitem.cpp"