QSapecNG
 All Classes Functions Enumerations Properties
wire.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 WIRE_H
00021 #define WIRE_H
00022 
00023 
00024 #include "gui/editor/item.h"
00025 #include "gui/editor/vpiface.h"
00026 
00027 #include <QtCore/QLineF>
00028 #include <QtGui/QPainterPath>
00029 #include <QtGui/QPen>
00030 
00031 
00032 namespace qsapecng
00033 {
00034 
00035 
00036 class SchematicScene;
00037 class GraphicsNode;
00038 
00039 
00040 class Wire: public Item, public ValuePropagationInterface
00041 {
00042 
00043 public:
00044   Wire(
00045     QGraphicsItem* parent = 0,
00046     SchematicScene* scene = 0
00047   );
00048 
00049   Wire(
00050     const QLineF& wire,
00051     bool connectedJunctions = true,
00052     QGraphicsItem* parent = 0,
00053     SchematicScene* scene = 0
00054   );
00055 
00056   ~Wire();
00057 
00058   inline ItemType itemType() const { return Item::Wire; }
00059 
00060   QRectF boundingRect() const;
00061   void paint(
00062     QPainter* painter,
00063     const QStyleOptionGraphicsItem* option,
00064     QWidget* widget
00065   );
00066 
00067   Qt::Orientation orientation() const;
00068   void setWire(const QLineF& wire);
00069   QPointF fromPoint() const;
00070   QPointF toPoint() const;
00071 
00072   bool isJunctionsConnected() const;
00073   void setConnectedJunctions(bool state);
00074 
00075   void mirror() { }
00076   void rotate();
00077   void rotateBack();
00078 
00079   Wire* joined(Wire* wire);
00080 
00081 public:
00082   int propagate(int value);
00083   void invalidate();
00084 
00085 protected:
00086   void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event);
00087   void mouseReleaseEvent(QGraphicsSceneMouseEvent* event);
00088   QVariant itemChange(GraphicsItemChange change, const QVariant& value);
00089 
00090 private:
00091   void refreshNodeList();
00092 
00093 private:
00094   enum { COLOR_BORDER = 2 };
00095 
00096   QPainterPath path_;
00097 
00098   Qt::Orientation orientation_;
00099   QList<GraphicsNode*> nodes_;
00100   bool connectedJunctions_;
00101   bool mod_;
00102 
00103 };
00104 
00105 
00106 }
00107 
00108 
00109 #endif // WIRE_H
 All Classes Functions Enumerations Properties