forked from viktor-zin/afce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zvflowchart.h
187 lines (162 loc) · 5.83 KB
/
zvflowchart.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
/****************************************************************************
** **
** Copyright (C) 2009-2014 Victor Zinkevich. All rights reserved. **
** Contact: vicking@yandex.ru **
** **
** This file is part of the Algorithm Flowchart Editor project. **
** **
** This file may be used under the terms of the GNU **
** General Public License versions 2.0 or 3.0 as published by the Free **
** Software Foundation and appearing in the file LICENSE included in **
** the packaging of this file. **
** You can find license at http://www.gnu.org/licenses/gpl.html **
** **
****************************************************************************/
#ifndef QFlowChart_H
#define QFlowChart_H
#include <QtCore>
#include <QtGui>
#include <QWidget>
#include <QDomDocument>
#include "qflowchartstyle.h"
#define AFC_VERSION "1.2"
class QBlock;
class QFlowChart;
//class QBranch;
class QInsertionPoint
{
private:
QPointF fPoint;
QBlock *fBranch;
int fIndex;
public:
QInsertionPoint()
{
fPoint = QPoint();
fBranch = 0;
fIndex = -1;
}
QPointF point() const { return fPoint; }
QBlock *branch() const { return fBranch; }
int index() const { return fIndex; }
void setPoint(const QPointF &aPoint) { fPoint = aPoint; }
void setBranch(QBlock *aBranch) { fBranch = aBranch; }
void setIndex(int aIndex) { fIndex = aIndex; }
bool isNull() const { return fPoint.isNull() && fBranch == 0 && fIndex == -1; }
};
Q_DECLARE_TYPEINFO(QInsertionPoint, Q_MOVABLE_TYPE);
class QBlock : public QObject
{
Q_OBJECT
private:
QFlowChart *fFlowChart;
public:
QBlock();
explicit QBlock(const QString & aType);
~QBlock();
// QBlock(const QBlock & aBlock);
QHash<QString, QString> attributes;
double x, y, width, height;
QList<QBlock *> items;
QBlock *parent;
bool isBranch;
QBlock *root();
QString type() const { return attributes.value("type", QString()); }
void setType(const QString & newType) { attributes["type"] = newType; }
int index();
void insert(int newIndex, QBlock *aBlock);
void remove(QBlock *aBlock);
void append(QBlock *aBlock);
void deleteObject(int aIndex);
QBlock * item(int aIndex) const { return items.at(aIndex); }
void setItem(int aIndex, QBlock *aBlock);
QFlowChart * flowChart() const { return fFlowChart; }
void setFlowChart(QFlowChart * aFlowChart);
void clear();
void adjustSize(const double aZoom);
void adjustPosition(const double ox, const double oy);
void paint(QPainter *canvas, bool fontSizeInPoints = false) const;
double zoom() const;
QBlock * blockAt(int px, int py);
QDomElement xmlNode(QDomDocument & doc) const;
void setXmlNode(const QDomElement & node);
void insertXmlTree(int aIndex, const QDomElement & algorithm);
bool isActive() const;
double topMargin;
double bottomMargin;
double leftMargin;
double rightMargin;
static void drawCaption(QPainter *canvas, const QRectF & rect, const double zoomFactor, const QString & text);
void makeBackwardCompatibility();
};
class QFlowChart : public QWidget
{
Q_OBJECT
protected:
virtual void paintEvent(QPaintEvent *pEvent);
virtual void mousePressEvent(QMouseEvent *pEvent);
virtual void mouseMoveEvent(QMouseEvent *pEvent);
virtual void mouseDoubleClickEvent(QMouseEvent * event);
private:
QBlock *fRoot;
QBlock *fActiveBlock;
double fZoom;
int fStatus;
virtual QSize sizeHint() const;
QList<QInsertionPoint> insertionPoints;
QInsertionPoint fTargetPoint;
QString fBuffer;
bool fMultiInsert;
QFlowChartStyle fStyle;
QStack<QString> undoStack;
QStack<QString> redoStack;
public:
enum {Display, Selectable, Insertion};
QFlowChart(QWidget *pObj = 0);
~QFlowChart();
QDomDocument document() const;
QInsertionPoint targetPoint() const { return fTargetPoint; }
void paintTo(QPainter *canvas);
QBlock * root() const;
QBlock * activeBlock() const;
double zoom() const;
int status() const { return fStatus; }
void deleteBlock(QBlock *aBlock);
QInsertionPoint getNearistPoint(int x, int y) const;
void regeneratePoints();
void generatePoints(QBlock *aBlock); // recursive
static double calcLength(const QPointF & p1, const QPointF & p2);
QString buffer() const { return fBuffer; }
bool multiInsert() const { return fMultiInsert; }
QFlowChartStyle chartStyle() const { return fStyle; }
void setChartStyle(const QFlowChartStyle & aStyle);
static void drawBottomArrow(QPainter *canvas, const QPointF & aPoint, const QSizeF & aSize);
static void drawRightArrow(QPainter *canvas, const QPointF & aPoint, const QSizeF & aSize);
QString toString();
void fromString(const QString & str);
bool canUndo() const;
bool canRedo() const;
bool canPaste() const;
void makeChanged();
void makeUndo();
void makeBackwardCompatibility();
signals:
void zoomChanged(const double aZoom);
void statusChanged();
void editBlock(QBlock *block);
void changed();
void modified();
public slots:
void clear();
void selectAll();
void deselectAll();
void setZoom(const double aZoom);
void setStatus(int aStatus);
void deleteActiveBlock();
void realignObjects();
void setBuffer(const QString & aBuffer);
void setMultiInsert(bool aValue) { fMultiInsert = aValue; }
void undo();
void redo();
};
#endif // QFlowChart_H