Monitor
|
00001 /**************************************************************************** 00002 ** 00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). 00004 ** All rights reserved. 00005 ** Contact: Nokia Corporation (qt-info@nokia.com) 00006 ** 00007 ** This file is part of the examples of the Qt Toolkit. 00008 ** 00009 ** $QT_BEGIN_LICENSE:BSD$ 00010 ** You may use this file under the terms of the BSD license as follows: 00011 ** 00012 ** "Redistribution and use in source and binary forms, with or without 00013 ** modification, are permitted provided that the following conditions are 00014 ** met: 00015 ** * Redistributions of source code must retain the above copyright 00016 ** notice, this list of conditions and the following disclaimer. 00017 ** * Redistributions in binary form must reproduce the above copyright 00018 ** notice, this list of conditions and the following disclaimer in 00019 ** the documentation and/or other materials provided with the 00020 ** distribution. 00021 ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor 00022 ** the names of its contributors may be used to endorse or promote 00023 ** products derived from this software without specific prior written 00024 ** permission. 00025 ** 00026 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00027 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00028 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00029 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00030 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00031 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00032 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00033 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00034 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00035 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00036 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 00037 ** $QT_END_LICENSE$ 00038 ** 00039 ****************************************************************************/ 00040 00041 #ifndef NODE_H 00042 #define NODE_H 00043 00044 #include <QGraphicsItem> 00045 #include <stdint.h> 00046 #include <QList> 00047 #include "stub/my-commmodel.h" 00048 #include <stdlib.h> 00049 00050 class Edge; 00051 class GraphWidget; 00052 QT_BEGIN_NAMESPACE 00053 class QGraphicsSceneMouseEvent; 00054 QT_END_NAMESPACE 00055 00059 class Node : public QGraphicsItem 00060 { 00061 public: 00062 Node(GraphWidget *graphWidget, bool _center, uint32_t _ip_addr, node* _node); 00063 00064 void addEdge(Edge *edge); 00065 QList<Edge *> edges() const; 00066 00067 enum { Type = UserType + 1 }; 00068 int type() const { return Type; } 00069 00070 void calculateForces(bool doPhysics); 00071 bool advance(); 00072 00073 QRectF boundingRect() const; 00074 QPainterPath shape() const; 00075 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); 00076 00077 uint32_t getIpAddr() const; 00078 00079 QString getIpAddrQString() const; 00080 00081 bool isActive() const; 00082 void setInactive(); 00083 void setActive(); 00084 QPointF getPosition(); 00085 node* getNodePointer(); 00086 00087 void settPosition(QPointF * np); 00088 00093 static bool macEqual(mac_t m1, mac_t m2) 00094 { 00095 for(int i = 0; i < 6; i++) 00096 { 00097 if(m1.addr[i] != m2.addr[i]) 00098 return false; 00099 } 00100 return true; 00101 } 00102 00103 00104 protected: 00105 QVariant itemChange(GraphicsItemChange change, const QVariant &value); 00106 00107 void mousePressEvent(QGraphicsSceneMouseEvent *event); 00108 void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); 00109 00110 00111 private: 00112 QList<Edge *> edgeList; 00113 QPointF newPos; 00114 GraphWidget *graph; 00115 bool center; 00116 QString ip_addr_string; 00117 uint32_t ip_addr; 00118 bool active; 00119 node * myNode; 00120 }; 00121 00122 #endif