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

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

Go to the documentation of this file.
00001 #include "constants.h"
00002 
00003 #include "transitionLine.h"
00004 #include "state.h"
00005 #include "label.h"
00006 #include "transforms.h"
00007 
00008 #include <math.h>
00009 
00010 #include <QtDebug>
00011 
00012 TransitionLine::TransitionLine(Editor *parent, State *ss, State *es, const QString &labelText,
00013                                bool lo, bool dimmed):
00014   TwoStatesTransition(parent, ss, es, lo, dimmed)
00015 {  
00016     setZValue(Z_TRANSITION);
00017     label = new LabelX(this, labelText, lo, m_labelFontSize,
00018             dimmed ? QColor(dimEdgeLabelColor) : QColor(edgeLabelColor));
00019     label->setZValue(Z_TR_LABEL);
00020     label->setPosParam(DEF_EDGE_LAB_POS);
00021     adjust();
00022     setLabelPosition();
00023 }
00024 
00025 void TransitionLine::adjust()
00026 {
00027     prepareGeometryChange();
00028     if ((!startState) || (!endState))
00029     {
00030         RELLOG("some of states NULL!");
00031         return;
00032     }
00033 
00034     startPoint = startState->pos();
00035     endPoint = endState->pos();
00036     
00037     // HACK for hold label on right position
00038     if (startPoint == endPoint)
00039     {
00040         startPoint -= QPointF(0.1f, 0.1f);
00041         endPoint += QPointF(0.1f, 0.1f);
00042     }
00043      
00044     QPolygonF line;
00045     line << endPoint << startPoint;
00046     QPolygonF p1 = findIntersectedPoints(line, mapFromItem(startState, startState->getMyPolygon()), eFIND_FIRST);
00047     line.clear();
00048     line << startPoint << endPoint;
00049     QPolygonF p2 = findIntersectedPoints(line, mapFromItem(endState, endState->getMyPolygon()), eFIND_FIRST);
00050     
00051     QPainterPath path;
00052     if (p1.empty() || p2.empty())
00053     {
00054         path.moveTo(line[0]);
00055         path.lineTo(line[1]);
00056     }
00057     else
00058     {
00059         path.moveTo(p1[0]);
00060         path.lineTo(p2[0]);
00061     }
00062     p = path;
00063 
00064     pa = getArrowPolygon(p);
00065     
00066     setLabelPosition();
00067     createStrokes(p);
00068 }
00069 
00070 TransitionLine::~TransitionLine()
00071 {
00072     DBGLOG("called");
00073 }
00074 
00075 QString TransitionLine::getTypeName() const
00076 {
00077     return "Edge";
00078 }
00079 
00080 void TransitionLine::setLabelPosition()
00081 {
00082     if (label)
00083     {
00084         Transition::setLabelPosition(label, label->posParam(), leftOriented, label->getWidth(), label->getHeight());
00085     } // if
00086     Transition::setLabelPosition();
00087 }
00088 
00089 /*void TransitionLine::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
00090 {
00091     if (startPoint == endPoint) return; // do not paint if states are overlapped    
00092   
00093     QColor lineC;
00094     Qt::PenStyle lineS;
00095     
00096     if (dimmed)
00097     {
00098         lineS = dimEdgeLineStyle;
00099         lineC = dimEdgeLineColor;
00100     } 
00101     else
00102     {
00103         lineS = edgeLineStyle;
00104         lineC = edgeLineColor;
00105     }
00106   
00107     if (checked)
00108     {
00109         painter->setPen(QPen(checkedColor, m_lineWidth, lineS));
00110         painter->setBrush(checkedColor);
00111     } 
00112     else
00113     {
00114         painter->setPen(QPen(lineC, m_lineWidth, lineS));
00115         painter->setBrush(lineC);
00116     }
00117 
00118     painter->strokePath(p, painter->pen());
00119     painter->drawPolygon(pa);
00120     
00121     paintSelectionDecoration(painter);
00122 
00123 #ifdef TESTING_PAINTING
00124 #   ifdef TESTING_BOUNDING_RECT_PAINTING
00125         painter->setBrush(QBrush(QColor(50,255,0,100)));
00126         painter->fillRect(boundingRect(), painter->brush());
00127 #   endif
00128 
00129     painter->setBrush(QBrush(QColor(0,0,255,150)));
00130     painter->fillPath(shape(), painter->brush());
00131 #endif
00132 }*/
00133 
00134 QString TransitionLine::getVCCommand() const
00135 {
00136     QString command = "\\";
00137 
00138     command += getTypeName();
00139     command += getTypeNameSuffix();
00140     
00141     Q_ASSERT(label != NULL);
00142     if (label->posParam() != DEF_EDGE_LAB_POS) 
00143         command += QString("[%1]").arg(label->posParam());
00144 
00145     command += "{" + startState->getName() + "}";
00146     command += "{" + endState->getName() + "}";
00147 
00148     command += "{" + label->text() + "}";
00149 
00150     command += getNextLabelsVCCommand();
00151 
00152     return command;
00153 }
00154 
00155 /*
00156 QString TransitionLine::getEPS() const
00157 {
00158   QString s = "";
00159   
00160   QColor lineC;
00161   Qt::PenStyle lineS;
00162   
00163   int r, g, b; float rf, gf, bf;
00164   
00165   if (dimmed)
00166   {
00167     lineS = dimEdgeLineStyle;
00168     lineC = dimEdgeLineColor;
00169   }
00170   else
00171   {
00172     lineS = edgeLineStyle;
00173     lineC = edgeLineColor;
00174   }
00175   lineC.getRgb(&r,&g,&b);
00176   rf = r / 255.; gf = g / 255.; bf = b / 255.;
00177   // r g b width lx ly mx my trLine 
00178   s += trLineStyle(lineS);
00179   s += QString(" %1 %2 %3 %4 %5 %6 %7 %8 trLine\n")
00180          .arg(rf).arg(gf).arg(bf)
00181          .arg(m_lineWidth)
00182          .arg(endPoint.x()).arg(scene()->height()-2 - endPoint.y())
00183          .arg(startPoint.x()).arg(scene()->height()-2 - startPoint.y()); 
00184   
00185   s += Transition::getEPS();   // label in the end
00186   return s;
00187 }
00188 */

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