00001 #ifndef STATE_H_5737489843734890 00002 #define STATE_H_5737489843734890 00003 00004 #include <QList> 00005 #include <QGraphicsEllipseItem> 00006 #include "editor.h" 00007 #include "stringProcessor.h" 00008 00009 class QPoint; 00010 class QPointF; 00011 class Transition; 00012 class TransitionLine; 00013 class QTextStream; 00014 00015 struct StatePrevParams 00016 { 00017 Qt::PenStyle stateLineStyle; 00018 float stateLineWidth; 00019 QString stateLineColor; 00020 QString stateLabelColor; 00021 float stateLabelScale; 00022 Qt::BrushStyle stateFillStatus; 00023 QString stateFillColor; 00024 00025 float stateLineDoubleCoef; 00026 float stateLineDoubleSep; 00027 00028 Qt::PenStyle dimStateLineStyle; 00029 QString dimStateLineColor; 00030 float dimStateLineCoef; 00031 QString dimStateLabelColor; 00032 QString dimStateFillColor; 00033 }; 00034 00035 class State : public QGraphicsItem 00036 { 00037 public: 00038 State(const QPoint &position, Editor *parent,const QString label = "", 00039 const QString name = "", bool dBorder = false, bool dim = false); 00040 00041 virtual ~State(); 00042 00043 State(){}; 00044 00045 friend class Parser; 00046 friend class StateExtendedDialog; 00047 friend class StateEditWithDelCommand; 00048 friend class StateEditExtendedCommand; 00049 friend class StateStyleChangeCommand; 00050 friend void Editor::exportToGraphML(const QString &fn); 00051 friend struct StateSerializer; 00052 00053 virtual QRectF boundingRect() const; 00054 virtual QPainterPath shape() const = 0; 00055 virtual void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) = 0; 00056 virtual void paintSelectionDecoration(QPainter *painter); 00057 00058 void setChecked(bool checked = true); 00059 00060 virtual int getWidth() const = 0; 00061 virtual int getHeight() const = 0; 00062 00063 int getTextWidth() const { return stringProcessor->getWidth(); } 00064 int getTextHeight() const { return stringProcessor->getHeight(); } 00065 int getTextAscent() const { return stringProcessor->getAscent(); } 00066 int getTextDescent() const { return stringProcessor->getDescent(); } 00067 00068 virtual void setLabel(const QString &label); 00069 virtual void setName(const QString &name); 00070 virtual void setDoubleBorder(bool dBroder); 00071 virtual void setDimmed(bool dim); 00072 virtual void setAutoNammed(bool autoNammed); 00073 00074 virtual QString getLabel() const { return label; } 00075 virtual bool isDoubleBorder() const { return doubleBorder; } 00076 virtual QString getName() const { return name; } 00077 virtual bool isDimmed() const { return dimmed; } 00078 virtual bool isAutoNammed() const { return autoNammed; } 00079 00080 virtual QString getTypeName() const = 0; 00081 00082 virtual void addTransition(Transition* transition); 00083 virtual void removeTransition(Transition* transition); 00084 00085 virtual void deleteTransitions(); 00086 00087 QList<Transition *> getTransitionList() { return transitionList; } 00088 void setTransitionList(const QList<Transition*> &trList) { transitionList = trList; } 00089 void clearTransitionList() { transitionList.clear(); } 00090 void adjustTransitions(); 00091 00092 virtual QPolygonF getMyPolygon() const; 00093 00094 // for export 00095 virtual bool getVCParams(QTextStream &out, StatePrevParams &prevParams); 00096 00097 virtual QString getVCCommand() const; 00098 00099 //virtual QString getEPS() const = 0; 00100 00101 void setStateLabelScale(float labelScale); 00102 void setStateLineWidth(float lineWidth); 00103 void setDimStateLineCoef(float lineCoef); 00104 00105 void setStateLineDoubleCoef(float lineCoef); 00106 void setStateLineDoubleSep(float lineSep); 00107 00108 void setMarked(bool marked); 00109 00110 protected: 00111 //! give know about moving with state to all connected trasitions 00112 virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); 00113 //! compute states polygon 00114 virtual void updateMyPolygon() = 0; 00115 00116 //! mouseEvents 00117 void mousePressEvent(QGraphicsSceneMouseEvent *event); 00118 void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); 00119 void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); 00120 //! moving with state 00121 void mouseMoveEvent(QGraphicsSceneMouseEvent *event); 00122 00123 Editor *editor; 00124 QPointF oldPos; //!< due to Undo and Redo 00125 00126 QPolygonF myPolygon; //!< polygon to finding intersection with transitions 00127 QPainterPath myPath; //!< state painter path, corresponding to myPolygon 00128 00129 //! transitions connected to state 00130 QList<Transition *> transitionList; 00131 00132 bool autoNammed; //!< atomatic naming 00133 QString name; //!< name of state 00134 00135 QString label; //!< original label 00136 StringProcessor *stringProcessor; //!< handles greek symbols, provide painting and export funcitons 00137 00138 bool dimmed; //!< by default solid gray 00139 00140 bool doubleBorder; //!< if true, it is FinalState 00141 00142 //! \name state parameters 00143 //! \{ 00144 Qt::PenStyle stateLineStyle; 00145 float stateLineWidth; 00146 QString stateLineColor; 00147 QString stateLabelColor; 00148 float stateLabelScale; 00149 Qt::BrushStyle stateFillStatus; 00150 QString stateFillColor; 00151 //! \} 00152 00153 //! \name state parametres dimmed 00154 //! \{ 00155 Qt::PenStyle dimStateLineStyle; 00156 QString dimStateLineColor; 00157 float dimStateLineCoef; 00158 QString dimStateLabelColor; 00159 QString dimStateFillColor; 00160 //! \} 00161 00162 //! \name state parametres double 00163 //! \{ 00164 float stateLineDoubleCoef; 00165 float stateLineDoubleSep; 00166 //! \} 00167 00168 int stateLabelSize; 00169 float m_lineWidth; 00170 00171 bool checked; 00172 const QColor checkedColor; 00173 00174 QString m_origColor; //!< stores original color before state is marked 00175 bool m_marked; 00176 00177 bool m_otherMoved; //!< for moving with multiple states 00178 00179 EMouseClick m_lastMouseClickType; 00180 00181 public: 00182 //! \name Support methods for IState creation 00183 //! \{ 00184 bool isInitial() const; 00185 bool isFinal() const; 00186 00187 QList<State*> getAccessibleStates() const; //!< returns list of accessible states from this state on sigle transition, ignores orientation 00188 QList<Transition*> getOutgoingTransitions() const; //<! returns only transitions which goes from this state, without initals and finals 00189 //! \} 00190 }; 00191 00192 #endif