File indexing completed on 2024-05-19 16:43:51

0001 /***************************************************************************
0002  *   Copyright (C) 2010 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 #ifndef VMAP_H
0021 #define VMAP_H
0022 
0023 #include <QColor>
0024 #include <QGraphicsScene>
0025 #include <QUndoStack>
0026 
0027 #include "controller/view_controller/vectorialmapcontroller.h"
0028 #include "data/person.h"
0029 #include "media/mediatype.h"
0030 #include "rwidgets/graphicsItems/griditem.h"
0031 #include "rwidgets/graphicsItems/pathitem.h"
0032 #include "rwidgets/graphicsItems/sightitem.h"
0033 #include "rwidgets/graphicsItems/visualitem.h"
0034 #include "rwidgets/toolbars/vtoolbar.h"
0035 #include "rwidgets_global.h"
0036 
0037 /**
0038  * @page VMap
0039  * @tableofcontents
0040  * @section Intro Introduction
0041  * VMap is vectorial map system to draw map on the fly.<br/>
0042  * It has been introduced in rolisteam v1.8.
0043  *
0044  *
0045  * @section item Type of Items:
0046  * @section action Actions on Items:
0047  * @section Selection Selection:
0048  * @section Vision Vision:
0049  * @section fow Fog of war:
0050  *
0051  *
0052  */
0053 class CharacterItem;
0054 class AnchorItem;
0055 class RuleItem;
0056 class AddVmapItemCommand;
0057 namespace vmap
0058 {
0059 class RectController;
0060 class EllipseController;
0061 class LineController;
0062 class ImageItemController;
0063 class PathController;
0064 class TextController;
0065 } // namespace vmap
0066 /**
0067  * @brief allows users to draw a map on the fly. It manages several kinds of items (VisualItem): rect, line...
0068  * It is using the QGraphicsScene from Qt.
0069  */
0070 class RWIDGET_EXPORT VMap : public QGraphicsScene
0071 {
0072     Q_OBJECT
0073 public:
0074     explicit VMap(VectorialMapController* ctrl, QObject* parent= nullptr);
0075 
0076     void manageAnchor();
0077     const QString& getLocalUserId() const;
0078     bool isNormalItem(const QGraphicsItem* item)  const;
0079     VisualItem *getNormalItem(QGraphicsItem *item);
0080 
0081     GridItem* gridItem() const;
0082 
0083 public slots:
0084     void computePattern();
0085 
0086 private slots:
0087     void updateItem(const QPointF& end);
0088     void promoteItemInType(VisualItem*, vmap::VisualItemController::ItemType);
0089 
0090 protected:
0091     virtual void mouseMoveEvent(QGraphicsSceneMouseEvent* mouseEvent)override;
0092     virtual void mousePressEvent(QGraphicsSceneMouseEvent* mouseEvent)override;
0093     virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent* mouseEvent)override;
0094     virtual void dragEnterEvent(QGraphicsSceneDragDropEvent* event)override;
0095     virtual void dragMoveEvent(QGraphicsSceneDragDropEvent* event)override;
0096     virtual void dropEvent(QGraphicsSceneDragDropEvent* event)override;
0097     virtual void keyPressEvent(QKeyEvent* event)override;
0098 
0099 
0100     void insertItem(const QPointF& end);
0101     void addAndInit(QGraphicsItem* item);
0102     void addVisualItem(vmap::VisualItemController* ctrl);
0103     void addExistingItems();
0104     void addRectItem(vmap::RectController* rectCtrl, bool editing);
0105     void addEllipseItem(vmap::EllipseController* ellisCtrl, bool editing);
0106     void addLineItem(vmap::LineController* lineCtrl, bool editing);
0107     void addImageItem(vmap::ImageItemController* imgCtrl);
0108     void addPathItem(vmap::PathController* pathCtrl, bool editing);
0109     void addTextItem(vmap::TextController* textCtrl);
0110     void addCharaterItem(vmap::CharacterItemController* itemCtrl);
0111 
0112 private:
0113     VisualItem* visualItemUnder(const QPointF& pos);
0114 
0115 private:
0116     std::unique_ptr<GridItem> m_gridItem;
0117     QPointer<SightItem> m_sightItem;
0118     QPointer<VectorialMapController> m_ctrl;
0119     QPointer<VisualItem> m_currentItem;
0120     QPointer<AnchorItem> m_parentItemAnchor;
0121     QPointer<RuleItem> m_ruleItem;
0122     QPointer<PathItem> m_currentPath= nullptr;
0123     QList<VisualItem*> m_movingItems;
0124     QList<QPointF> m_oldPos;
0125 };
0126 #endif // VMAP_H