00001 #include "constants.h"
00002
00003 #include "stateVar.h"
00004 #include "transforms.h"
00005
00006 #include <QtDebug>
00007
00008 StateVar::StateVar(const QPoint &position, Editor *parent, const QString l,
00009 const QString n, bool dBorder, bool dim)
00010 : State(position, parent, l, n, dBorder, dim)
00011 {
00012
00013 updateMyPolygon();
00014 }
00015
00016 QString StateVar::getTypeName() const
00017 {
00018 return doubleBorder ? "FinalStateVar" : "StateVar";
00019 }
00020
00021 void StateVar::updateMyPolygon()
00022 {
00023
00024
00025
00026 QRectF ellipseRect(-getWidth()/2,-getHeight()/2,getWidth(),getHeight());
00027 float adjust;
00028
00029 if (doubleBorder)
00030 {
00031 float doubleLineSep = m_lineWidth * stateLineDoubleSep / STATE_LINE_VIEW_COEF;
00032 float doubleLineWidth = m_lineWidth * stateLineDoubleCoef * STATE_DOUBLE_LINE_VIEW_COEF;
00033 adjust = doubleLineSep + doubleLineWidth*1.5;
00034 }
00035 else
00036 {
00037 adjust = m_lineWidth/2;
00038 }
00039
00040
00041 myPath = QPainterPath();
00042 myPath.addRoundedRect(ellipseRect.adjusted(-adjust,-adjust,
00043 adjust, adjust),
00044 (doubleBorder) ? VAR_STATE_R_X_DBL : VAR_STATE_R_X,
00045 VAR_STATE_R_Y);
00046 myPolygon = myPath.toFillPolygon();
00047 }
00048
00049 void StateVar::setLabel(const QString &label)
00050 {
00051 State::setLabel(label);
00052 updateMyPolygon();
00053 adjustTransitions();
00054 }
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135 QPainterPath StateVar::shape() const
00136 {
00137 return myPath;
00138 }
00139
00140 void StateVar::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
00141 {
00142 QColor lineC, labelC, fillC;
00143 Qt::PenStyle lineS;
00144 float doubleLineSep, doubleLineWidth;
00145
00146 if (dimmed){
00147 lineC = dimStateLineColor;
00148 labelC = dimStateLabelColor;
00149 lineS = dimStateLineStyle;
00150 fillC = dimStateFillColor;
00151 }
00152 else{
00153 lineC = stateLineColor;
00154 labelC = stateLabelColor;
00155 lineS = stateLineStyle;
00156 fillC = stateFillColor;
00157 }
00158
00159 #ifdef TESTING_PAINTING
00160 fillC.setAlpha(100);
00161 #endif
00162
00163 doubleLineSep = m_lineWidth * stateLineDoubleSep / STATE_LINE_VIEW_COEF;
00164 doubleLineWidth = m_lineWidth * stateLineDoubleCoef * STATE_DOUBLE_LINE_VIEW_COEF;
00165
00166 QRectF ellipseRect(-getWidth()/2, -getHeight()/2, getWidth(), getHeight());
00167 (doubleBorder) ? painter->setPen(QPen(lineC,doubleLineWidth,lineS)) :
00168 painter->setPen(QPen(lineC,m_lineWidth,lineS));
00169
00170 if (doubleBorder)
00171 {
00172 if (stateFillStatus != Qt::NoBrush)
00173 {
00174 painter->setBrush(QColor("white"));
00175 }
00176 else
00177 {
00178 painter->setBrush(Qt::NoBrush);
00179 }
00180
00181 painter->drawRoundedRect(ellipseRect.adjusted(-doubleLineSep-doubleLineWidth,
00182 -doubleLineSep-doubleLineWidth,
00183 doubleLineSep+doubleLineWidth,
00184 doubleLineSep+doubleLineWidth),
00185 VAR_STATE_R_X_DBL, VAR_STATE_R_Y);
00186
00187 }
00188
00189 if (stateFillStatus != Qt::SolidPattern)
00190 {
00191 fillC = "black";
00192 if (stateFillStatus != Qt::NoBrush)
00193 {
00194 painter->setBrush(QBrush("white",Qt::SolidPattern));
00195 if (doubleBorder)
00196 {
00197 painter->drawRoundedRect(ellipseRect.adjusted(doubleLineSep,doubleLineSep,-doubleLineSep,-doubleLineSep)
00198 , VAR_STATE_R_X, VAR_STATE_R_Y);
00199 }
00200 else
00201 {
00202 painter->drawRoundedRect(ellipseRect
00203 , VAR_STATE_R_X, VAR_STATE_R_Y);
00204 }
00205 }
00206 }
00207
00208 if (checked)
00209 {
00210 painter->setBrush(checkedColor);
00211 }
00212 else
00213 {
00214 painter->setBrush(QBrush(fillC,stateFillStatus));
00215 }
00216
00217 if (doubleBorder)
00218 {
00219 painter->drawRoundedRect(ellipseRect.adjusted(doubleLineSep,doubleLineSep,-doubleLineSep,-doubleLineSep),
00220 VAR_STATE_R_X, VAR_STATE_R_Y);
00221 }
00222 else
00223 {
00224 painter->drawRoundedRect(ellipseRect, VAR_STATE_R_X, VAR_STATE_R_Y);
00225 }
00226
00227 painter->setPen(labelC);
00228 if (stringProcessor->text() != "")
00229 {
00230 QPointF point(-getTextWidth()/2, (getTextAscent() - getTextDescent())/2);
00231 stringProcessor->drawText(painter, point);
00232 }
00233
00234 paintSelectionDecoration(painter);
00235
00236 #ifdef TESTING_PAINTING
00237 # ifdef TESTING_BOUNDING_RECT_PAINTING
00238 painter->setBrush(QBrush(QColor(50,255,0,80)));
00239 painter->fillRect(boundingRect(), painter->brush());
00240 # endif
00241
00242 painter->setBrush(QBrush(QColor(0,0,255,50)));
00243 painter->fillPath(shape(), painter->brush());
00244 #endif
00245 }
00246
00247