Go to the documentation of this file.00001 #ifndef TRANSITION_H_21234567890987654
00002 #define TRANSITION_H_21234567890987654
00003
00004 #include "editor.h"
00005 #include "stringProcessor.h"
00006 #include "labelSyntaxChecker.h"
00007
00008 #include "itransition.h"
00009
00010 #include <QGraphicsItem>
00011
00012 class State;
00013 class QTextStream;
00014 class QPolygonF;
00015 class QPointF;
00016 class LabelX;
00017
00018 struct EdgePrevParams{
00019 Qt::PenStyle edgeLineStyle;
00020 float edgeLineWidth;
00021 QString edgeLineColor;
00022 QString edgeLabelColor;
00023 float edgeLabelScale;
00024 bool edgeLineDblStatus;
00025
00026 float edgeLineBorderCoef;
00027 QString edgeLineBorderColor;
00028 float edgeLineDblCoef;
00029 float edgeLineDblSep;
00030
00031 Qt::PenStyle dimEdgeLineStyle;
00032 QString dimEdgeLineColor;
00033 float dimEdgeLineCoef;
00034 QString dimEdgeLabelColor;
00035 };
00036
00037 class Transition : public QGraphicsItem
00038 {
00039 public:
00040 typedef QList<LabelX *> TLabelXList;
00041
00042 Transition(Editor *parent, State *ss, State *es, bool dimmed);
00043 virtual ~Transition();
00044
00045 friend class Parser;
00046 friend class TransitionExtendedDialog;
00047 friend class NextLabelsDialog;
00048 friend class TransitionEditWithDelCommand;
00049 friend class TransitionEditExtendedCommand;
00050 friend class TransitionStyleChangeCommand;
00051 friend struct TransitionSerializer;
00052 friend void Editor::exportToGraphML(const QString &fn);
00053
00054 QString getLabelText() const;
00055 void setLabelText(const QString &label);
00056 virtual void setLabelPosition();
00057 virtual void setLabelPosition(LabelX *pLabel, float pos, bool isLeft, int width, int height);
00058
00059 LabelX *getLabel() const;
00060 const TLabelXList& getNextLabels() const { return nextLabels; }
00061
00062 void setLabelPos(float pos);
00063 float getLabelPos() const;
00064
00065 QColor getColor() { return dimmed ? QColor(dimEdgeLineColor) : QColor(edgeLineColor); }
00066 QColor getLabelColor() { return dimmed ? QColor(dimEdgeLabelColor) : QColor(edgeLabelColor); }
00067
00068 void addNextLabel(LabelX *pLabel);
00069 void removeNextLabel(LabelX *pLabel);
00070
00071 virtual void adjust() = 0;
00072
00073
00074 virtual QPainterPath path() const { return p; }
00075
00076 virtual QRectF boundingRect() const;
00077 virtual QPainterPath shape() const;
00078 virtual void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
00079 virtual void paintSelectionDecoration(QPainter *painter);
00080
00081 virtual QString getTypeName() const = 0;
00082 virtual QString getTypeNameSuffix() const { return ""; }
00083
00084
00085 virtual void assign() = 0;
00086 virtual void unassign() = 0;
00087
00088 virtual void setDirection(int){}
00089 virtual int getDirection() const {return 0;}
00090
00091 virtual void setArcAngle(int){}
00092 virtual void setNCurv(float){}
00093 virtual int getArcAngle() const {return 0;}
00094 virtual float getNCurv() const {return 0;}
00095
00096
00097 virtual void setArcAngleB(int){}
00098 virtual int getArcAngleB() const {return 0;}
00099
00100 bool isDimmed();
00101 void setDimmed(bool dim);
00102
00103 void setChecked(bool checked = true);
00104 void setSelected(bool selected = true);
00105
00106 State* getStartState() const { return startState; }
00107 virtual State* getEndState() const { if (endState) return endState; else return 0; }
00108
00109
00110 bool hasEndState() const { if (endState) return true; else return false; }
00111
00112 QString getStartStateName() const;
00113 QString getEndStateName() const;
00114
00115
00116 void setStartState(State *state);
00117 void setEndState(State *state);
00118
00119 Editor * getEditor() const { return editor; }
00120
00121
00122 bool getVCParams(QTextStream &out, EdgePrevParams &prevParams) const;
00123 virtual QString getNextLabelsVCCommand() const;
00124
00125 virtual QString getVCCommand() const = 0;
00126
00127
00128 virtual QString getGraphMLParams() const { return ""; }
00129
00130
00131
00132 void setEdgeLabelScale(float labelScale);
00133 void setDimEdgeLineCoef(float lineCoef);
00134 void setEdgeLineWidth(float lineWidth);
00135
00136 protected:
00137 virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
00138 virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) = 0;
00139 virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
00140
00141 enum EIntersectionFindMethod {eFIND_FIRST, eFIND_TWO, eFIND_ALL};
00142
00143
00144 void createStrokes(const QPainterPath &path);
00145 const QPainterPath& getClickPath() const;
00146 const QPainterPath& getSelectionPath() const;
00147
00148 QPainterPath createShape(const QPainterPath &path, int bounds) const;
00149
00150 QPainterPath m_clickPath;
00151 QPainterPath m_selectionPath;
00152
00153 static QPolygonF findIntersectedPoints(const QPolygonF &curve, const QPolygonF &polygon,
00154 const EIntersectionFindMethod method);
00155
00156
00157
00158 QPolygonF getArrowPolygon(const QPainterPath &path);
00159 QPolygonF m_arrowPoints;
00160
00161 Editor *editor;
00162
00163 State *startState, *endState;
00164 QPointF startPoint, endPoint;
00165
00166 int m_labelFontSize;
00167 LabelX *label;
00168
00169
00170 TLabelXList nextLabels;
00171
00172 QPolygonF pa;
00173 QPainterPath p;
00174
00175 bool dimmed;
00176 bool leftOriented;
00177
00178
00179
00180 Qt::PenStyle edgeLineStyle;
00181 float edgeLineWidth;
00182 QString edgeLineColor;
00183 QString edgeLabelColor;
00184 float edgeLabelScale;
00185 bool edgeLineDblStatus;
00186
00187
00188
00189
00190 float edgeLineBorderCoef;
00191 QString edgeLineBorderColor;
00192
00193 float edgeLineDblCoef;
00194 float edgeLineDblSep;
00195
00196
00197
00198
00199 Qt::PenStyle dimEdgeLineStyle;
00200 QString dimEdgeLineColor;
00201 float dimEdgeLineCoef;
00202 QString dimEdgeLabelColor;
00203
00204
00205 float m_lineWidth;
00206
00207 bool checked;
00208 const QColor checkedColor;
00209
00210 EMouseClick m_lastMouseClickType;
00211
00212
00213
00214 public:
00215 QString getSourceState() const;
00216 QString getDestinationState() const;
00217
00218
00219
00220
00221 void getCharactersOccurences(ITransition::TCharSet &characters) const;
00222
00223
00224 bool getCharacters(ITransition::TCharSet &characters,
00225 const ITransition::TCharSet &alphabet,
00226 const QString &alphabetSymbol,
00227 const QString &epsilonSymbol) const;
00228
00229 protected:
00230 void showErrorReport(const QString &reportText = QString("")) const;
00231
00232
00233 void dismemberCharacters(const QStringList &occurences,
00234 ITransition::TCharSet &characters) const;
00235
00236 };
00237
00238 #endif //TRANSITION_H_21234567890987654