Commit ed15236d authored by Florent D'Halluin's avatar Florent D'Halluin
Browse files

[yavgui] Handle intial & final labels.

* yavgui/src/g_painter.hxx,
* yavgui/src/g_state.cc,
* yavgui/src/g_state.hh,
* yavgui/src/g_state.hxx: Do that.
parent e053a3ea
2009-08-04 d-halluin <d-halluin@lrde.epita.fr>
[yavgui] Handle intial & final labels.
* yavgui/src/g_painter.hxx,
* yavgui/src/g_state.cc,
* yavgui/src/g_state.hh,
* yavgui/src/g_state.hxx: Do that.
2009-08-04 d-halluin <d-halluin@lrde.epita.fr>
 
[yavgui] Fix compilation.
......
......@@ -51,20 +51,28 @@ namespace yavgui
int i = 0;
for_all_states (istate, automaton)
{
QString initial_entry;
QString final_entry;
QColor color = "white";
if (automaton.is_final (*istate))
{
std::stringstream entry;
entry << automaton.get_final (*istate);
final_entry = entry.str().c_str();
color.setGreen (color.green () - 30);
color.setRed (color.red () - 30);
}
if (automaton.is_initial (*istate))
{
std::stringstream entry;
entry << automaton.get_initial (*istate);
initial_entry = entry.str().c_str();
color.setGreen (color.green () - 30);
color.setRed (color.red () - 30);
}
GState *state = new GState (i++, color,
automaton.is_initial (*istate),
automaton.is_final (*istate));
initial_entry,
final_entry);
states.push_back(state);
(*scene_)->addItem (state);
state_map[*istate] = state;
......
......@@ -36,13 +36,13 @@ namespace yavgui
namespace display
{
GState::GState (int index, QColor default_color,
bool initial, bool final)
QString initial_entry, QString final_entry)
: default_color_ (default_color),
highlight_color_ (255, 100, 100),
color_ (default_color_),
radius_ (20),
initial_ (initial),
final_ (final),
initial_entry_ (initial_entry),
final_entry_ (final_entry),
index_ (index),
selected_ (false),
looping_transitions_ (0)
......@@ -105,10 +105,10 @@ namespace yavgui
path.lineTo (c3);
path.lineTo (radius_ + 40, 0);
painter->setBrush (color_);
painter->drawPath (path);
painter->setBrush (QColor("black"));
painter->drawPath (path);
}
painter->drawText (QRect(radius_ + 40, -radius_, 40, radius_),
painter->drawText (QRect(radius_, -radius_, 40, radius_),
Qt::AlignCenter
| Qt::AlignTop,
final_entry_);
......@@ -139,9 +139,13 @@ namespace yavgui
path.lineTo (c3);
path.lineTo (- radius_, 0);
painter->setBrush (color_);
painter->drawPath (path);
painter->setBrush (QColor("black"));
painter->drawPath (path);
}
painter->drawText (QRect(-radius_ - 40, -radius_, 40, radius_),
Qt::AlignCenter
| Qt::AlignTop,
initial_entry_);
}
}
......
......@@ -39,8 +39,11 @@ namespace yavgui
Q_OBJECT
public:
// Initial_entry and final_entry are null if the state is not
// initial/final.
GState (int index = 0, QColor = "white",
bool initial = false, bool final = false);
QString initial_entry = 0,
QString final_entry = 0);
QRectF boundingRect () const;
QPainterPath shape () const;
......@@ -68,11 +71,11 @@ namespace yavgui
inline QString label ();
inline void set_label (QString label);
inline void set_initial (bool initial);
inline bool initial ();
inline void set_initial_entry (QString initial_entry);
inline QString initial_entry ();
inline void set_final (bool final);
inline bool final ();
inline void set_final_entry (QString final_entry);
inline QString final_entry ();
public slots:
void refresh ();
......@@ -94,8 +97,8 @@ namespace yavgui
qreal radius_;
// is initial;
bool initial_;
bool final_;
QString initial_entry_;
QString final_entry_;
// Index for display
int index_;
......
......@@ -65,24 +65,24 @@ namespace yavgui
label_ = label;
}
bool GState::initial ()
QString GState::initial_entry ()
{
return initial_;
return initial_entry_;
}
void GState::set_initial (bool initial)
void GState::set_initial_entry (QString initial_entry)
{
initial_ = initial;
initial_entry_ = initial_entry;
}
bool GState::final ()
QString GState::final_entry ()
{
return final_;
return final_entry_;
}
void GState::set_final (bool final)
void GState::set_final_entry (QString final_entry)
{
final_ = final;
final_entry_ = final_entry;
}
} // ! namespace display
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment