1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 /* 3 * This program is free software; you can redistribute it and/or modify 4 * it under the terms of the GNU General Public License version 2 as 5 * published by the Free Software Foundation; 6 * 7 * This program is distributed in the hope that it will be useful, 8 * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * GNU General Public License for more details. 11 * 12 * You should have received a copy of the GNU General Public License 13 * along with this program; if not, write to the Free Software 14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 15 * 16 * Author: John Abraham <john.abraham.in@gmail.com> 17 * Contributions: Makhtar Diouf <makhtar.diouf@gmail.com> 18 */ 19 20 #ifndef ANIMATORSCENE_H 21 #define ANIMATORSCENE_H 22 23 #include "common.h" 24 #include "animnode.h" 25 #include "animlink.h" 26 #include "resizeableitem.h" 27 #include "timevalue.h" 28 #include "animpacket.h" 29 30 31 32 namespace netanim 33 { 34 35 36 class AnimInterfaceText : public QGraphicsTextItem 37 { 38 public: 39 typedef enum textMode 40 { 41 NONE, 42 IPV4, 43 MAC, 44 BOTH 45 } TextMode_t; 46 47 AnimInterfaceText (QString description, bool leftAligned=false); 48 ~AnimInterfaceText (); 49 enum { Type = ANIMINTERFACE_TEXT_TYPE }; type()50 int type () const 51 { 52 return Type; 53 } 54 QPainterPath shape () const; 55 bool setLine (QLineF l); 56 QGraphicsLineItem * getLine (); 57 void setMode (bool showIpv4, bool showMac); 58 QString getText () const; 59 void setLeftAligned (bool leftAligned); 60 61 private: 62 bool m_leftAligned; 63 QGraphicsLineItem * m_line; 64 TextMode_t m_mode; 65 66 protected: 67 void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); 68 }; 69 70 71 72 class AnimatorScene : public QGraphicsScene 73 { 74 Q_OBJECT 75 public: 76 static AnimatorScene * getInstance (); 77 AnimatorScene (); 78 void mouseMoveEvent (QGraphicsSceneMouseEvent *event); 79 void mouseDoubleClickEvent (QGraphicsSceneMouseEvent *event); 80 void addWirelessPacket (AnimPacket * p); 81 void addWiredPacket (AnimPacket * p); 82 void removeWiredPacket (AnimPacket * p); 83 void removeWirelessPacket (AnimPacket * p); 84 void addNode (AnimNode * animNode); 85 void addLink (AnimLink * animLink); 86 void addWirelessCircle (QRectF r); 87 void purgeAnimatedPackets (); 88 void purgeWirelessPackets (); 89 void showAnimatedPackets (bool show); 90 void purgeAnimatedNodes (); 91 void purgeAnimatedLinks (); 92 void purgeNodeTrajectories (); 93 void setShowInterfaceTexts (bool showIp, bool showMac); 94 void addGrid (); 95 void resetGrid (); 96 void systemReset (); 97 QRectF getBoundaryRect (); 98 void setGridLinesCount (int nGridLines); 99 void setShowNodeTrajectory (AnimNode * animNode); 100 void setSceneInfoText (QString text, bool show); 101 void setSimulationBoundaries (QPointF minPoint, QPointF maxPoint); 102 void setBackgroundImage (QString fileName, qreal x, qreal y, qreal scaleX, qreal scaleY, qreal opacity); 103 QGraphicsPixmapItem * getBackgroundImage (); 104 void enableMousePositionLabel(bool enable); 105 106 void setBackgroundX (qreal x); 107 void setBackgroundY (qreal y); 108 void setBackgroundScaleX (qreal scaleX); 109 void setBackgroundScaleY (qreal scaleY); 110 void setBackgroundOpacity (qreal opacity); 111 112 // Port to Qt5 113 void setScale (QGraphicsPixmapItem* img, qreal x, qreal y); 114 115 public slots: 116 void testSlot (); 117 private: 118 typedef QVector <AnimInterfaceText *> AnimInterfaceTextVector_t; 119 typedef QVector <QGraphicsLineItem *> LineItemVector_t; 120 typedef QVector <QGraphicsSimpleTextItem*> GridCoordinatesVector_t; 121 typedef std::map <uint32_t, QGraphicsPathItem *> NodeTrajectoryMap_t; 122 123 TimeValue<AnimPacket *> m_testTimeValue; 124 QGraphicsSimpleTextItem * m_sceneInfoText; 125 126 QLabel * m_mousePositionLabel; 127 QGraphicsProxyWidget * m_mousePositionProxyWidget; 128 std::map <AnimPacket *, AnimPacket *> m_wirelessAnimatedPackets; 129 std::map <AnimPacket *, AnimPacket *> m_wiredAnimatedPackets; 130 131 QVector <AnimWirelessCircles *> m_animatedWirelessCircles; 132 QVector <AnimLink *> m_animatedLinks; 133 QVector<AnimNode *> m_animatedNodes; 134 bool m_showIpInterfaceTexts; 135 bool m_showMacInterfaceTexts; 136 AnimInterfaceTextVector_t m_interfaceATexts; 137 AnimInterfaceTextVector_t m_interfaceBTexts; 138 qreal m_leftTop; 139 qreal m_rightTop; 140 QList <QGraphicsItem *> getInterfaceTextCollisionList (AnimInterfaceText * text); 141 qreal m_gridStep; 142 bool m_showGrid; 143 int m_nGridLines; 144 LineItemVector_t m_gridLines; 145 GridCoordinatesVector_t m_gridCoordinates; 146 NodeTrajectoryMap_t m_nodeTrajectory; 147 QGraphicsPixmapItem * m_backgroundImage; 148 QPointF m_minPoint; 149 QPointF m_maxPoint; 150 QPointF m_sceneMinPoint; 151 QPointF m_sceneMaxPoint; 152 bool m_enableMousePositionLabel; 153 QTransform m_originalBackgroundTransform; 154 155 156 void repositionInterfaceText (AnimInterfaceText * textItem); 157 void resetInterfaceTexts (); 158 void removeInterfaceTextCollision (); 159 void resetInterfaceTextTop (); 160 161 void markGridCoordinates (); 162 void initGridCoordinates (); 163 QVector <QGraphicsSimpleTextItem *> getGridCoordinatesItems (); 164 void setMousePositionLabel (QPointF pos); 165 void showMousePositionLabel (bool show); 166 167 168 }; 169 170 } // namespace netanim 171 172 #endif // ANIMATORSCENE_H 173