File indexing completed on 2024-04-28 05:38:13
0001 /*************************************************************************** 0002 * Copyright (C) 2010 by Renaud Guezennec * 0003 * * 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 VISUALITEM_H 0021 #define VISUALITEM_H 0022 0023 #include <QAction> 0024 #include <QGraphicsObject> 0025 #include <QPointer> 0026 #include <QVector> 0027 0028 #include "childpointitem.h" 0029 #include "controller/item_controllers/visualitemcontroller.h" 0030 #include "media/mediatype.h" 0031 #include "rwidgets_global.h" 0032 0033 class NetworkMessageWriter; 0034 class NetworkMessageReader; 0035 0036 /** 0037 * @brief abstract class which defines interface for all map items. 0038 */ 0039 class RWIDGET_EXPORT VisualItem : public QGraphicsObject 0040 { 0041 Q_OBJECT 0042 public: 0043 VisualItem(vmap::VisualItemController* ctrl); 0044 virtual ~VisualItem(); 0045 0046 vmap::VisualItemController* controller() const; 0047 virtual void setNewEnd(const QPointF& nend)= 0; 0048 virtual vmap::VisualItemController::ItemType getType() const; 0049 virtual void resizeContents(const QRectF& rect, int pointId, 0050 Core::TransformType transformType= Core::TransformType::KeepRatio); 0051 virtual void endOfGeometryChange(ChildPointItem::Change change); 0052 virtual void addActionContextMenu(QMenu&); 0053 bool hasFocusOrChild(); 0054 virtual void setModifiers(Qt::KeyboardModifiers modifiers); 0055 virtual VisualItem* promoteTo(vmap::VisualItemController::ItemType); 0056 virtual void setSize(QSizeF size); 0057 virtual void updateItemFlags(); 0058 virtual bool isLocal() const; 0059 QVariant itemChange(GraphicsItemChange change, const QVariant& value); 0060 0061 quint16 getPenWidth() const; 0062 void setPenWidth(const quint16& penWidth); 0063 0064 QString uuid()const; 0065 0066 QColor color() const; 0067 virtual bool canBeMoved() const; 0068 0069 static int getHighlightWidth(); 0070 static void setHighlightWidth(int highlightWidth); 0071 0072 static QColor getHighlightColor(); 0073 static void setHighlightColor(const QColor& highlightColor); 0074 0075 signals: 0076 void itemGeometryChanged(VisualItem*); 0077 void itemRemoved(QString, bool, bool); 0078 void itemLayerChanged(VisualItem*); 0079 void promoteItemTo(VisualItem*, vmap::VisualItemController::ItemType); 0080 void selectStateChange(bool); 0081 0082 public slots: 0083 void setColor(QColor color); 0084 void evaluateVisible(); 0085 0086 protected: 0087 virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent* event); 0088 virtual void mousePressEvent(QGraphicsSceneMouseEvent* event); 0089 virtual void mouseMoveEvent(QGraphicsSceneMouseEvent* event); 0090 virtual void keyPressEvent(QKeyEvent* event); 0091 void init(); 0092 virtual void updateChildPosition(); 0093 virtual void setChildrenVisible(bool b); 0094 bool hasPermissionToMove(bool allowCharacter= true) const; 0095 0096 protected: 0097 QPointF computeClosePoint(QPointF pos); 0098 void addPromoteItemMenu(QMenu*); 0099 void promoteItem(); 0100 0101 protected: 0102 QPointer<vmap::VisualItemController> m_ctrl; 0103 static QColor m_highlightColor; 0104 static QColor m_selectedColor; 0105 static int m_highlightWidth; 0106 QVector<ChildPointItem*> m_children; 0107 QPoint m_menuPos; 0108 QVector<vmap::VisualItemController::ItemType> m_promoteTypeList; 0109 0110 private: 0111 static QStringList s_type2NameList; 0112 }; 0113 0114 #endif // VISUALITEM_H