• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

C:/CVUT/diplomka/Automata_editor/sources/stateNormal.cpp

Go to the documentation of this file.
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; // w/o correction
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 //<-- Export support functions -------------------------------------------------
00047 /*
00048 QString StateNormal::getEPS() const
00049 {
00050   QString s = "";
00051   int r, g, b;
00052   float rf, gf, bf;
00053   QColor lineC, labelC, fillC;
00054   Qt::PenStyle lineS;
00055   float lineWidth, lineSep = 0;
00056     
00057   if (dimmed){
00058     lineC = dimStateLineColor;
00059     labelC = dimStateLabelColor;
00060     lineS = dimStateLineStyle;
00061     fillC = dimStateFillColor;
00062     lineWidth = editor->stateLineWidth * dimStateLineCoef; // nasobi se jeste pres zmenu na stavu
00063   }
00064   else{
00065     lineC = stateLineColor;
00066     labelC = stateLabelColor;
00067     lineS = stateLineStyle;
00068     fillC = stateFillColor;
00069     lineWidth = editor->stateLineWidth * stateLineWidth;
00070   }
00071   
00072   // draw state
00073   // x y radius lineWidth r g b x y radius r g b sCircle
00074   // x y radius x y radius lineWidth r g b x y radius r g b sDbCircle
00075   s += trLineStyle(lineS); // TODO: make "none" better
00076   if (doubleBorder){
00077     lineSep = lineWidth * stateLineDoubleSep;
00078     lineWidth *= stateLineDoubleCoef;
00079     s += QString (" %1 %2 %3")
00080            .arg(x())
00081            .arg(scene()->height()-2 - y())
00082            .arg(-S_LX+lineSep/2+lineWidth);
00083   }
00084   lineC.getRgb(&r,&g,&b);
00085   rf = r / 255.; gf = g / 255.; bf = b / 255.;
00086   s += QString (" %1 %2 %3 %4 %5 %6 %7 %1 %2 %3")
00087          .arg(x())
00088          .arg(scene()->height()-2 - y())
00089          .arg(-S_LX-lineSep/2)
00090          .arg(lineWidth)
00091          .arg(rf).arg(gf).arg(bf);
00092   fillC.getRgb(&r,&g,&b);
00093   rf = r / 255.; gf = g / 255.; bf = b / 255.;  
00094   s += QString (" %1 %2 %3")
00095          .arg(rf).arg(gf).arg(bf);
00096   
00097   if (doubleBorder){
00098     s += " sDbCircle\n";
00099   }
00100   else
00101     s += " sCircle\n";
00102 
00103   // draw label
00104   if (label != "")
00105       s += stringProcessor->getEPS(QPointF(x() - stringProcessor->getWidth()/2,
00106                                    scene()->height()-2 - y() - (getTextAscent() - getTextDescent())/2));
00107 
00108   return s;
00109 }
00110 */
00111 //------------------------------------------------- Export support functions -->
00112 
00113 
00114 
00115 //<-- QGraphicsItem functions --------------------------------------------------
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     // BUG in manual, recomputed stateLineWidth is used for doubleLine
00148     doubleLineSep = m_lineWidth * stateLineDoubleSep / STATE_LINE_VIEW_COEF; // w/o correction
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     // TODO: hold right doubleLineSep?
00163     painter->drawEllipse(ellipseRect.adjusted(-doubleLineSep-doubleLineWidth,
00164                                               -doubleLineSep-doubleLineWidth,
00165                                               doubleLineSep+doubleLineWidth,
00166                                               doubleLineSep+doubleLineWidth));
00167     }
00168 
00169     if (stateFillStatus != Qt::SolidPattern) {// only for better edge visibility TODO: maybe not necessary more
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 //-------------------------------------------------- QGraphicsItem functions -->

Generated on Tue Jan 4 2011 03:03:24 for Autoamata editor by  doxygen 1.7.0