QSapecNG
 All Classes Functions Enumerations Properties
graphicsnode.h
00001 /*
00002     QSapecNG - Qt based SapecNG GUI front-end
00003     Copyright (C) 2009, Michele Caini
00004 
00005     This program is free software: you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation, either version 3 of the License, or
00008     (at your option) any later version.
00009 
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 FITNESS FOR A PARTICULAR PURPOSE.  See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017 */
00018 
00019 
00020 #ifndef GRAPHICSNODE_H
00021 #define GRAPHICSNODE_H
00022 
00023 
00024 #include "gui/editor/inode.h"
00025 #include "gui/editor/item.h"
00026 
00027 #include <QtGui/QGraphicsItem>
00028 #include <QtGui/QPainterPath>
00029 
00030 #include <QtCore/QExplicitlySharedDataPointer>
00031 #include <QtCore/QSet>
00032 
00033 
00034 namespace qsapecng
00035 {
00036 
00037 
00038 class GraphicsNode: public QGraphicsItem
00039 {
00040 
00041 public:
00042   enum { Type = UserType + 128 };
00043   enum { Radius = 1 };
00044 
00045 public:
00046   GraphicsNode(
00047     QGraphicsItem* parent = 0,
00048     QGraphicsScene* scene = 0
00049   );
00050   virtual ~GraphicsNode();
00051 
00052   inline int type() const { return GraphicsNode::Type; }
00053 
00054   void paint(
00055     QPainter* painter,
00056     const QStyleOptionGraphicsItem* option,
00057     QWidget* widget
00058   );
00059 
00060   QRectF boundingRect() const;
00061   QPainterPath shape() const;
00062 
00063   void attach(GraphicsNode* item);
00064   void detach(GraphicsNode* item);
00065 
00066   void setNode(Node* node);
00067   const Node* constNode() const;
00068   Node* node() const;
00069 
00070   void updateItemSet();
00071   const QSet<GraphicsNode*>& itemSet() const;
00072   bool isColliding() const;
00073 
00074   void showNodeValue();
00075   void hideNodeValue();
00076 
00077   void setOwner(Item* owner);
00078   Item* owner() const;
00079 
00080 protected:
00081   virtual QVariant itemChange(GraphicsItemChange change, const QVariant& value);
00082 
00083 private:
00084   void updateLabelPosition();
00085 
00086 private:
00087   Item* owner_;
00088 
00089   bool colliding_;
00090   QSet<GraphicsNode*> itemSet_;
00091   QExplicitlySharedDataPointer<Node> dataPointer_;
00092 
00093   QGraphicsTextItem* label_;
00094   QPainterPath path_;
00095 
00096 };
00097 
00098 
00099 }
00100 
00101 
00102 #endif // GRAPHICSNODE_H
 All Classes Functions Enumerations Properties