-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraphicelement.h
186 lines (130 loc) · 4.3 KB
/
graphicelement.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#ifndef GRAPHICELEMENT_H
#define GRAPHICELEMENT_H
#include <QGraphicsItem>
#include <QGraphicsPixmapItem>
#include <QKeySequence>
#include "nodes/qneport.h"
//#include "common.h"
#include "itemwithid.h"
enum class ElementType {
UNKNOWN, BUTTON, SWITCH, LED, NOT, AND, OR, NAND, NOR, CLOCK, XOR, XNOR, VCC, GND, DISPLAY,
DLATCH, JKLATCH, DFLIPFLOP, JKFLIPFLOP, SRFLIPFLOP, TFLIPFLOP, TLATCH, BOX, NODE, MUX, DEMUX
};
enum class ElementGroup {
UNKNOWN, OTHER, BOX, INPUT, GATE, MEMORY, OUTPUT, MUX
};
#define MAXIMUMVALIDINPUTSIZE 256
class GraphicElement : public QGraphicsObject, public ItemWithId {
Q_OBJECT
public:
enum { Type = QGraphicsItem::UserType + 3 };
explicit GraphicElement( int minInputSz, int maxInputSz, int minOutputSz, int maxOutputSz,
QGraphicsItem *parent = 0 );
virtual ~GraphicElement( );
private:
QPixmap * pixmap;
QString currentPixmapPath;
/* GraphicElement interface. */
public:
virtual ElementType elementType( ) = 0;
virtual ElementGroup elementGroup( ) = 0;
virtual void save( QDataStream &ds );
virtual void load( QDataStream &ds, QMap< quint64, QNEPort* > &portMap, double version );
virtual void updatePorts( );
virtual void updateLogic( ) = 0;
/* QGraphicsItem interface */
public:
int type( ) const {
return( Type );
}
virtual QRectF boundingRect( ) const;
virtual void paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget );
QNEPort* addPort( const QString &name, bool isOutput, int flags = 0, int ptr = 0 );
void addInputPort( const QString &name = QString( ) );
void addOutputPort( const QString &name = QString( ) );
virtual void setPortName( QString name );
int topPosition( ) const;
int bottomPosition( ) const;
int maxInputSz( ) const;
int maxOutputSz( ) const;
bool outputsOnTop( ) const;
QVector< QNEPort* > inputs( ) const;
void setInputs( const QVector< QNEPort* > &inputs );
QVector< QNEPort* > outputs( ) const;
QNEPort* input( int pos = 0 ) const;
QNEPort* output( int pos = 0 ) const;
void setOutputs( const QVector< QNEPort* > &outputs );
int minInputSz( ) const;
int minOutputSz( ) const;
int inputSize( );
void setInputSize( int size );
int outputSize( );
void setOutputSize( int size );
// virtual float getFrequency( );
// virtual void setFrequency( float freq );
void setPixmap(const QString &pixmapPath , QRect size = QRect());
bool rotatable( ) const;
bool hasLabel( ) const;
bool hasFrequency( ) const;
bool hasColors( ) const;
bool hasTrigger( ) const;
virtual void setColor( QString getColor );
virtual QString getColor( );
/*
* bool beingVisited( ) const;
* void setBeingVisited( bool beingVisited );
*/
/*
* bool visited( ) const;
* void setVisited( bool visited );
*/
bool isValid( );
void setLabel( QString label );
QString getLabel( );
void disable( );
void enable( );
bool disabled( );
QPixmap getPixmap( ) const;
QKeySequence getTrigger( ) const;
void setTrigger( const QKeySequence &trigger );
virtual QString genericProperties( );
protected:
void setRotatable( bool rotatable );
void setHasLabel( bool hasLabel );
// void setHasFrequency( bool hasFrequency );
void setHasColors( bool hasColors );
void setHasTrigger( bool hasTrigger );
void setMinInputSz( int minInputSz );
void setMinOutputSz( int minOutputSz );
void setOutputsOnTop( bool outputsOnTop );
void setMaxOutputSz( int maxOutputSz );
void setMaxInputSz( int maxInputSz );
void setTopPosition( int topPosition );
void setBottomPosition( int bottomPosition );
/* virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *e); */
QVariant itemChange( GraphicsItemChange change, const QVariant &value );
private:
QGraphicsTextItem *label;
int m_topPosition;
int m_bottomPosition;
quint64 m_maxInputSz;
quint64 m_maxOutputSz;
quint64 m_minInputSz;
quint64 m_minOutputSz;
bool m_outputsOnTop;
bool m_rotatable;
bool m_hasLabel;
bool m_hasFrequency;
bool m_hasColors;
bool m_hasTrigger;
bool m_disabled;
QString m_labelText;
QKeySequence m_trigger;
protected:
QVector< QNEPort* > m_inputs;
QVector< QNEPort* > m_outputs;
/* QGraphicsItem interface */
protected:
/* virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent * event); */
};
#endif /* GRAPHICELEMENT_H */