File indexing completed on 2024-04-28 05:38:11
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 "griditem.h" 0022 0023 #include <QDebug> 0024 #include <QGraphicsScene> 0025 #include <QGraphicsView> 0026 #include <QMenu> 0027 #include <QPainter> 0028 #include <QStyleOptionGraphicsItem> 0029 #include <math.h> 0030 0031 #include "controller/item_controllers/visualitemcontroller.h" 0032 #include "media/mediatype.h" 0033 0034 // constexpr float PI{3.14159265}; 0035 0036 ///////////////////////////////// 0037 /// Code SightItem 0038 ///////////////////////////////// 0039 0040 GridItem::GridItem(vmap::GridController* ctrl) : VisualItem(ctrl), m_gridCtrl(ctrl) 0041 { 0042 setZValue(std::numeric_limits<qreal>::max()); 0043 setFlag(QGraphicsItem::ItemUsesExtendedStyleOption); 0044 setAcceptedMouseButtons(Qt::NoButton); 0045 setAcceptHoverEvents(false); 0046 if(m_gridCtrl) 0047 m_ctrl->setLayer(Core::Layer::GRIDLAYER); 0048 setFlags(QGraphicsItem::ItemSendsGeometryChanges); 0049 setFlag(QGraphicsItem::ItemIsSelectable, false); 0050 0051 connect(m_gridCtrl, &vmap::GridController::gridPatternChanged, this, [this]() { update(); }); 0052 connect(m_gridCtrl, &vmap::GridController::rectChanged, this, [this]() { update(); }); 0053 0054 connect(this, &QGraphicsObject::parentChanged, this, 0055 [this]() 0056 { 0057 connect(scene(), &QGraphicsScene::sceneRectChanged, m_gridCtrl, &vmap::GridController::setRect); 0058 m_gridCtrl->setRect(scene()->sceneRect()); 0059 }); 0060 } 0061 0062 GridItem::~GridItem() {} 0063 0064 void GridItem::setNewEnd(const QPointF &nend) 0065 { 0066 Q_UNUSED(nend); 0067 } 0068 0069 void GridItem::updateItemFlags() 0070 { 0071 VisualItem::updateItemFlags(); 0072 setAcceptedMouseButtons(Qt::NoButton); 0073 setFlag(QGraphicsItem::ItemIsMovable, false); 0074 } 0075 QRectF GridItem::boundingRect() const 0076 { 0077 return m_gridCtrl ? m_gridCtrl->rect() : QRectF{}; 0078 } 0079 0080 void GridItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) 0081 { 0082 Q_UNUSED(option) 0083 Q_UNUSED(widget) 0084 if(!m_gridCtrl->visible()) 0085 return; 0086 0087 painter->fillRect(boundingRect(), QBrush(m_gridCtrl->gridPattern())); 0088 }