00001 /*************************************************************************** 00002 * main.cpp 00003 * This file is part of the KDE project 00004 * copyright (C)2004-2007 by Tomaz Canabrava (tomaz.canabrava@gmail.com) 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Library General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2 of the License, or (at your option) any later version. 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNGraphScene::ESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Library General Public License for more details. 00014 * You should have received a copy of the GNU Library General Public License 00015 * along with this program; see the file COPYING. If not, write to 00016 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00017 * Boston, MA 02110-1301, USA. 00018 ***************************************************************************/ 00019 00020 #ifndef SUI_GRAPHSCENE_H 00021 #define SUI_GRAPHSCENE_H 00022 00023 #include <QGraphicsScene> 00024 #include <QMultiHash> 00025 00026 class AbstractAction; 00027 class QAction; 00028 class Node; 00029 class Edge; 00030 class QGraphicsItem; 00031 class GraphDocument; 00032 class Graph; 00033 class QGraphicsSceneMouseEvent; 00034 class QGraphicsSceneWheelEvent; 00035 class QKeyEvent; 00036 class NodePropertiesWidget; 00037 class EdgePropertiesWidget; 00038 00039 class GraphScene : public QGraphicsScene 00040 { 00041 Q_OBJECT 00042 public: 00043 GraphScene( QObject* parent ); 00044 void setAction( QAction* action ); 00045 void updateGraph( Graph* g ); 00046 void updateDocument(); 00047 void setActiveGraph( Graph* g ); 00048 void setActiveGraphDocument( GraphDocument* gd ); 00049 void clearGraph(); 00050 00051 void setHideEdges( bool h ); 00052 bool hideEdges(); 00053 QAction* action(); 00054 void updateAfter( QGraphicsItem* item ); 00055 bool fade() const 00056 { 00057 return _fade; 00058 } 00059 void fade( bool b ) 00060 { 00061 _fade = b; 00062 } 00063 void hideGraph( Graph* g, bool visibility ); 00064 00065 public slots: 00066 QGraphicsItem* createNode( Node* n ); 00067 QGraphicsItem* createEdge( Edge* e ); 00068 void connectGraphSignals( Graph* g ); 00069 void createItems(); 00070 signals: 00071 void forceUpdate(); 00072 00073 protected: 00074 void mouseMoveEvent( QGraphicsSceneMouseEvent* mouseEvent ); 00075 void mousePressEvent( QGraphicsSceneMouseEvent* mouseEvent ); 00076 void mouseReleaseEvent( QGraphicsSceneMouseEvent* mouseEvent ); 00077 void mouseDoubleClickEvent( QGraphicsSceneMouseEvent* mouseEvent ); 00078 void wheelEvent( QGraphicsSceneWheelEvent* wheelEvent ); 00079 void keyPressEvent( QKeyEvent* keyEvent ); 00080 00081 private: 00082 GraphDocument* _graphDocument; 00083 Graph* _graph; 00084 AbstractAction* _action; 00085 QMultiHash<Graph*, QGraphicsItem* > _hashGraphs; 00086 QList<QGraphicsItem*> _hidedEdges; 00087 bool _hideEdges; 00088 NodePropertiesWidget* _nodePropertiesWidget; 00089 EdgePropertiesWidget* _edgePropertiesWidget; 00090 bool _fade; 00091 QObject* _parent; 00092 }; 00093 00094 #endif