QSapecNG
 All Classes Functions Enumerations Properties
component.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 COMPONENT_H
00021 #define COMPONENT_H
00022 
00023 
00024 #include "gui/editor/item.h"
00025 #include "gui/editor/vpiface.h"
00026 #include "gui/editor/propertytextitem.hpp"
00027 
00028 #include <QtCore/QList>
00029 #include <QtCore/QPointF>
00030 #include <QtCore/QVariant>
00031 #include <QtGui/QPainterPath>
00032 
00033 
00034 class QPainter;
00035 class QStyleOptionGraphicsItem;
00036 
00037 class QFocusEvent;
00038 class QGraphicsSceneMouseEvent;
00039 
00040 class QGraphicsTextItem;
00041 class PropertyTextItem;
00042 
00043 
00044 namespace qsapecng
00045 {
00046 
00047 
00048 class GraphicsNode;
00049 class SchematicScene;
00050 
00051 
00052 class Component: public Item, public ValuePropagationInterface
00053 {
00054 
00055 public:
00056   Component(
00057       QGraphicsItem* parent = 0,
00058       SchematicScene* scene = 0
00059     );
00060   Component(
00061       QPainterPath path,
00062       QGraphicsItem* parent = 0,
00063       SchematicScene* scene = 0
00064     );
00065   Component(
00066       QPainterPath path,
00067       QList<QPointF> nodes,
00068       QGraphicsItem* parent = 0,
00069       SchematicScene* scene = 0
00070     );
00071   Component(
00072       QPainterPath path,
00073       QPointF node,
00074       QGraphicsItem* parent = 0,
00075       SchematicScene* scene = 0
00076     );
00077   ~Component();
00078 
00079   QRectF boundingRect() const;
00080   void paint(
00081     QPainter* painter,
00082     const QStyleOptionGraphicsItem* option,
00083     QWidget* widget
00084   );
00085 
00086   virtual void mirror();
00087   virtual void rotate();
00088 
00089   inline PropertyTextItem* label() const { return label_; }
00090 
00091   void addNodes(QList<QPointF> nodes);
00092   void addNodes(QPointF node);
00093   QVector<int> nodes() const;
00094 
00095   inline void setPath(const QPainterPath& path) { path_ = path; }
00096   inline QPainterPath path() const { return path_; }
00097 
00098 public:
00099   int propagate(int value);
00100   void invalidate();
00101 
00102 protected:
00103   void focusInEvent(QFocusEvent* event);
00104   void focusOutEvent(QFocusEvent* event);
00105   QVariant itemChange(GraphicsItemChange change, const QVariant& value);
00106 
00107 private:
00108   void createNode(const QPointF& point);
00109 
00110 private:
00111   QList<GraphicsNode*> nodeList_;
00112   QPainterPath path_;
00113 
00114   PropertyTextItem* label_;
00115 
00116 };
00117 
00118 
00119 }
00120 
00121 
00122 #endif // COMPONENT_H
 All Classes Functions Enumerations Properties