-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroundabouttestitem.h
226 lines (204 loc) · 7.89 KB
/
roundabouttestitem.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#ifndef ROUNDABOUTTESTITEM_H
#define ROUNDABOUTTESTITEM_H
/*
Copyright 2011 Arne Jacobs <[email protected]>
This file is part of Roundabout.
Roundabout is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Roundabout is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Roundabout. If not, see <http://www.gnu.org/licenses/>.
*/
#include "roundaboutscene.h"
#include <QGraphicsEllipseItem>
#include <QGraphicsProxyWidget>
#include <QTimer>
class RoundaboutTestSwitchEditItem : public QGraphicsPathItem
{
public:
RoundaboutTestSwitchEditItem(QGraphicsItem *parent = 0);
private:
QColor normalColor, backgroundColor;
};
class RoundaboutTestPlayItem : public QObject, public QGraphicsPathItem
{
Q_OBJECT
public:
RoundaboutTestPlayItem(QRectF rect, QGraphicsItem *parent = 0);
signals:
void changedState(bool playing);
protected:
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent * event);
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent * event);
virtual void mousePressEvent(QGraphicsSceneMouseEvent * event);
private:
QColor normalColor, hoverColor;
bool state, hover;
QPainterPath playPath, pausePath;
};
class RoundaboutTestCenterItem : public QGraphicsEllipseItem
{
public:
RoundaboutTestCenterItem(QRectF rect, QGraphicsItem *parent = 0);
private:
QColor normalColor;
};
class RoundaboutTestDragItem : public QGraphicsPathItem
{
public:
RoundaboutTestDragItem(QGraphicsItem *parent = 0);
protected:
virtual void mousePressEvent(QGraphicsSceneMouseEvent * event);
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent * event);
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * event);
};
class RoundaboutTestButtonItem : public QObject, public QGraphicsPathItem
{
Q_OBJECT
public:
RoundaboutTestButtonItem(const QPainterPath &innerPath, QGraphicsItem *parent = 0);
RoundaboutTestButtonItem(QRectF rect, QGraphicsItem *parent = 0);
signals:
void triggered();
protected:
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent * event);
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent * event);
virtual void mousePressEvent(QGraphicsSceneMouseEvent * event);
private:
QColor normalColor, hoverColor;
bool hover;
};
class RoundaboutSequencerItem;
class RoundaboutTestSegmentItem : public QGraphicsPathItem, public RoundaboutTestConnectable
{
public:
enum Shape {
NORMAL,
BENT_AT_BEGIN,
BENT_AT_END
};
RoundaboutTestSegmentItem(RoundaboutSequencerItem *sequencerItem, int step, QRectF innerRect, QRectF outerRect, qreal startAngle, qreal arcLength, QGraphicsItem *parent = 0);
int getStep() const;
RoundaboutSequencerItem *getSequencerItem();
void setHighlight(bool highlight);
bool getState() const;
void setShape(Shape shape);
virtual QPointF getConnectionAnchor(RoundaboutTestConnectionPoint point, qreal &angle) const;
protected:
virtual void connected(RoundaboutTestConnectionPoint point, RoundaboutTestConnectionItem *connectionItem);
virtual void disconnected();
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent * event);
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent * event);
virtual void mousePressEvent(QGraphicsSceneMouseEvent * event);
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * event);
virtual QVariant itemChange(GraphicsItemChange change, const QVariant & value);
private:
int step;
RoundaboutSequencerItem *sequencerItem;
Shape myShape;
QColor normalColor, highlightedColor, stateColor;
bool active, hover, highlight;
QPainterPath normalPath, bentAtBeginPath, bentAtEndPath;
QPointF bentAtEndAnchor, bentAtBeginAnchor;
qreal bentAtEndAngle, bentAtBeginAngle;
int branchFrequency, continueFrequency;
};
class RoundaboutTestArrowItem : public QGraphicsPathItem
{
public:
RoundaboutTestArrowItem(QRectF innerRect, QRectF outerRect, qreal angle, qreal tipOffset, QGraphicsItem *parent = 0);
RoundaboutTestArrowItem(QRectF rect, qreal tipOffset, QGraphicsItem *parent = 0);
private:
QColor normalColor;
};
class RoundaboutTestKeyItem : public QGraphicsPathItem
{
public:
enum KeyType {
BLACK,
WHITE
};
RoundaboutTestKeyItem(RoundaboutSequencerItem *sequencerItem, int step, int note, QRectF innerRect, QRectF outerRect, qreal startAngle, qreal arcLength, KeyType keyType, QGraphicsItem *parent = 0);
void setHighlight(bool highlight);
void setLowkey(bool lowkey);
protected:
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent * event);
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent * event);
virtual void mousePressEvent(QGraphicsSceneMouseEvent * event);
private:
RoundaboutSequencerItem *sequencerItem;
int step, note;
QColor normalColor, highlightedColor, stateColor, lowkeyColor;
bool state, hover, highlight, lowkey;
};
class RoundaboutTestKeyboardItem : public QGraphicsPathItem
{
public:
enum Direction {
INNER_TO_OUTER,
OUTER_TO_INNER
};
RoundaboutTestKeyboardItem(RoundaboutSequencerItem *sequencerItem, int step, QRectF innerRect, QRectF outerRect, Direction dir, qreal startAngle, qreal arcLength, QGraphicsItem *parent = 0);
void setHighlight(bool highlight);
void setLowkey(bool lowkey);
int getNrOfKeys() const;
RoundaboutTestKeyItem * getKeyItem(int index);
private:
QVector<RoundaboutTestKeyItem*> keyItems;
};
class RoundaboutTestSliceItem : public QGraphicsPathItem
{
public:
RoundaboutTestSliceItem(RoundaboutSequencerItem *sequencerItem, int step, QRectF innerRect, QRectF outerRect, RoundaboutTestKeyboardItem::Direction dir, qreal startAngle, qreal arcLength, QGraphicsItem *parent = 0);
void setHighlight(bool highlight);
RoundaboutTestKeyboardItem *getKeyboardItem();
RoundaboutTestSegmentItem *getSegmentItem();
protected:
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent * event);
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent * event);
private:
QColor normalColor;
RoundaboutTestKeyboardItem *keyboardItem;
RoundaboutTestSegmentItem *segmentItem;
};
class RoundaboutTestConductorItem : public QGraphicsRectItem, public RoundaboutTestConnectable, public RoundaboutTestConnectableHost
{
public:
RoundaboutTestConductorItem(QGraphicsItem *parent = 0, QGraphicsScene *scene = 0);
virtual QPointF getConnectionAnchor(RoundaboutTestConnectionPoint point, qreal &angle) const;
virtual RoundaboutTestConnectable * getConnectableAt(QPointF scenePos);
protected:
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * event);
private:
QColor normalColor;
QPointF anchor;
qreal angle;
};
class RoundaboutSequencer;
class RoundaboutSequencerItem : public QObject, public QGraphicsEllipseItem, public RoundaboutTestConnectableHost
{
Q_OBJECT
public:
RoundaboutSequencerItem(RoundaboutSequencer *sequencer, QGraphicsItem *parent = 0, QGraphicsScene *scene = 0);
RoundaboutSequencer * getSequencer();
virtual RoundaboutTestConnectable * getConnectableAt(QPointF scenePos);
public slots:
void onEnteredStep(int step);
void onLeftStep(int step);
protected:
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent * event);
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent * event);
private:
int steps;
qreal sliceAngle;
RoundaboutTestArrowItem *arrowItem;
QVector<RoundaboutTestSliceItem*> sliceItems;
RoundaboutSequencer *sequencer;
};
#endif // ROUNDABOUTTESTITEM_H