00001 #include "constants.h"
00002
00003 #include "stateNormal.h"
00004 #include "transforms.h"
00005
00006 #include <QtDebug>
00007
00008 StateNormal::StateNormal(const QPoint &position, Editor *parent, const QString& label,
00009 const QString &name, bool dBorder, bool dim)
00010 : State(position, parent, label, name, dBorder, dim)
00011 {
00012 updateMyPolygon();
00013 }
00014
00015 QString StateNormal::getTypeName() const
00016 {
00017 return doubleBorder ? "FinalState" : "State";
00018 }
00019
00020 void StateNormal::updateMyPolygon()
00021 {
00022 QPainterPath path;
00023 QRectF ellipseRect(S_LX,S_LY,S_W,S_H);
00024
00025 float adjust;
00026
00027 if (doubleBorder)
00028 {
00029 float doubleLineSep = m_lineWidth * stateLineDoubleSep / STATE_LINE_VIEW_COEF;
00030 float doubleLineWidth = m_lineWidth * stateLineDoubleCoef * STATE_DOUBLE_LINE_VIEW_COEF;
00031 adjust = doubleLineSep + doubleLineWidth*1.5;
00032 }
00033 else
00034 {
00035 adjust = m_lineWidth/2;
00036 }
00037
00038 myPath = QPainterPath();
00039 myPath.addEllipse(ellipseRect.adjusted(-adjust,-adjust,
00040 adjust, adjust));
00041 myPolygon = myPath.toFillPolygon();
00042 }
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
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 QPainterPath StateNormal::shape() const
00118 {
00119 return myPath;
00120 }
00121
00122 void StateNormal::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
00123 {
00124 QColor lineC, labelC, fillC;
00125 Qt::PenStyle lineS;
00126 float doubleLineSep, doubleLineWidth;
00127
00128 if (dimmed)
00129 {
00130 lineC = dimStateLineColor;
00131 labelC = dimStateLabelColor;
00132 lineS = dimStateLineStyle;
00133 fillC = dimStateFillColor;
00134 }
00135 else
00136 {
00137 lineC = stateLineColor;
00138 labelC = stateLabelColor;
00139 lineS = stateLineStyle;
00140 fillC = stateFillColor;
00141 }
00142
00143 #ifdef TESTING_PAINTING
00144 fillC.setAlpha(100);
00145 #endif
00146
00147
00148 doubleLineSep = m_lineWidth * stateLineDoubleSep / STATE_LINE_VIEW_COEF;
00149 doubleLineWidth = m_lineWidth * stateLineDoubleCoef * STATE_DOUBLE_LINE_VIEW_COEF;
00150
00151 QRectF ellipseRect = QRectF(S_LX,S_LY,S_W,S_H);
00152 (doubleBorder) ? painter->setPen(QPen(lineC,doubleLineWidth,lineS)) :
00153 painter->setPen(QPen(lineC,m_lineWidth,lineS));
00154
00155 if (doubleBorder){
00156 if (stateFillStatus != Qt::NoBrush){
00157 painter->setBrush(QColor("white"));
00158 }
00159 else {
00160 painter->setBrush(Qt::NoBrush);
00161 }
00162
00163 painter->drawEllipse(ellipseRect.adjusted(-doubleLineSep-doubleLineWidth,
00164 -doubleLineSep-doubleLineWidth,
00165 doubleLineSep+doubleLineWidth,
00166 doubleLineSep+doubleLineWidth));
00167 }
00168
00169 if (stateFillStatus != Qt::SolidPattern) {
00170 fillC = "black";
00171 if (stateFillStatus != Qt::NoBrush){
00172 painter->setBrush(QBrush("white",Qt::SolidPattern));
00173 if (doubleBorder){
00174 painter->drawEllipse(ellipseRect.adjusted(doubleLineSep,doubleLineSep,-doubleLineSep,-doubleLineSep));
00175 }
00176 else{
00177 painter->drawEllipse(ellipseRect);
00178 }
00179 }
00180 }
00181
00182 if (checked)
00183 {
00184 painter->setBrush(checkedColor);
00185 }
00186 else
00187 {
00188 painter->setBrush(QBrush(fillC,stateFillStatus));
00189 }
00190
00191 if (doubleBorder)
00192 {
00193 painter->drawEllipse(ellipseRect.adjusted(doubleLineSep,doubleLineSep,-doubleLineSep,-doubleLineSep));
00194 }
00195 else
00196 {
00197 painter->drawEllipse(ellipseRect);
00198 }
00199
00200 painter->setPen(labelC);
00201 if (stringProcessor->text() != "")
00202 {
00203 QPointF point(-getTextWidth()/2, (getTextAscent() - getTextDescent())/2);
00204 stringProcessor->drawText(painter, point);
00205 }
00206
00207 paintSelectionDecoration(painter);
00208
00209 #ifdef TESTING_PAINTING
00210 # ifdef TESTING_BOUNDING_RECT_PAINTING
00211 painter->setBrush(QBrush(QColor(50,255,0,80)));
00212 painter->fillRect(boundingRect(), painter->brush());
00213 # endif
00214
00215 painter->setBrush(QBrush(QColor(0,0,255,50)));
00216 painter->fillPath(shape(), painter->brush());
00217 #endif
00218 }
00219
00220