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

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

Go to the documentation of this file.
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     //! all other functionality is in State constructor
00013     updateMyPolygon();
00014 }
00015 
00016 QString StateVar::getTypeName() const
00017 {
00018     return doubleBorder ? "FinalStateVar" : "StateVar";
00019 }
00020 
00021 void StateVar::updateMyPolygon()
00022 {
00023     // it's posible to find exact point, but VauCanSon don't do it too, reason is when large state is added
00024     // loop than does not seem well
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; // w/o correction
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     // exact polygon
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); // common functionality
00052     updateMyPolygon();
00053     adjustTransitions();
00054 }
00055 
00056 //<-- Export support functions -------------------------------------------------
00057 /*
00058 QString StateVar::getEPS() const
00059 {
00060   QString s = "";
00061   int r, g, b;
00062   float rf, gf, bf;
00063   QColor lineC, labelC, fillC;
00064   Qt::PenStyle lineS;
00065   float lineWidth, lineSep = 0;
00066     
00067   if (dimmed){
00068     lineC = dimStateLineColor;
00069     labelC = dimStateLabelColor;
00070     lineS = dimStateLineStyle;
00071     fillC = dimStateFillColor;
00072     lineWidth = editor->stateLineWidth * dimStateLineCoef; // nasobi se jeste pres zmenu na stavu
00073   }
00074   else{
00075     lineC = stateLineColor;
00076     labelC = stateLabelColor;
00077     lineS = stateLineStyle;
00078     fillC = stateFillColor;
00079     lineWidth = editor->stateLineWidth * stateLineWidth;
00080   }
00081   
00082   // draw variable state
00083   // x y width height radius linewidth r g b rfill gfill bfill sBubble
00084   s += trLineStyle(lineS); // TODO: make "none" better
00085   if (doubleBorder){
00086     lineSep = lineWidth * stateLineDoubleSep;
00087     lineWidth *= stateLineDoubleCoef;    
00088   }
00089 
00090   QString tmp;
00091   lineC.getRgb(&r,&g,&b);
00092   rf = r / 255.; gf = g / 255.; bf = b / 255.;
00093   tmp += QString (" %1 %2 %3 %4")         
00094          .arg(lineWidth)
00095          .arg(rf).arg(gf).arg(bf);
00096   fillC.getRgb(&r,&g,&b);
00097   rf = r / 255.; gf = g / 255.; bf = b / 255.;  
00098   tmp += QString (" %1 %2 %3")
00099          .arg(rf).arg(gf).arg(bf);
00100 
00101   if (doubleBorder)
00102   {
00103       s += QString(" %1 %2 %3 %4 %5")
00104           .arg(x())
00105           .arg(scene()->height()-2 - y())
00106           .arg(getWidth() + lineSep*2)
00107           .arg(getHeight() + lineSep*2)
00108           .arg(18);
00109       s += tmp;
00110       s += " sBubble\n";  
00111   }
00112 
00113   s += QString(" %1 %2 %3 %4 %5")
00114           .arg(x())
00115           .arg(scene()->height()-2 - y())
00116           .arg(getWidth() - lineSep*2)
00117           .arg(getHeight() - lineSep*2)
00118           .arg(18);
00119       s += tmp;
00120       s += " sBubble\n";   
00121    
00122   if (label != "")
00123       s += stringProcessor->getEPS(QPointF(x() - getTextWidth()/2,
00124                                            scene()->height()-2 - y() - getTextDescent()));
00125   
00126   return s;
00127 }
00128 */
00129 //------------------------------------------------- Export support functions -->
00130 
00131 
00132 
00133 //<-- QGraphicsItem functions --------------------------------------------------
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; // w/o correction
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         // TODO: create right doubleLineSep!
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     { // only for better edge visibility TODO: maybe not necessary more
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 //-------------------------------------------------- QGraphicsItem functions -->

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