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

[yavgui] Enable state properties dialog.

Note: initial and final transition labels cannot be set (yet).

* yavgui/src/Makefile.am: Add files.
* yavgui/src/dialog_properties_state.cc,
* yavgui/src/dialog_properties_state.hh: Fixes and tweaks.
* yavgui/src/g_scene.cc,
* yavgui/src/g_scene.hh,
* yavgui/src/g_state.cc,
* yavgui/src/g_state.hh,
* yavgui/src/g_state.hxx: Add signal/slots/connections
* yavgui/src/g_vcsn_handler.cc,
* yavgui/src/g_vcsn_handler.hh,
* yavgui/src/g_vcsn_handler.hxx: Implement functions.
parent a0577521
2009-08-06 d-halluin <d-halluin@lrde.epita.fr>
[yavgui] Enable state properties dialog.
Note: initial and final transition labels cannot be set (yet).
* yavgui/src/Makefile.am: Add files.
* yavgui/src/dialog_properties_state.cc,
* yavgui/src/dialog_properties_state.hh: Fixes and tweaks.
* yavgui/src/g_scene.cc,
* yavgui/src/g_scene.hh,
* yavgui/src/g_state.cc,
* yavgui/src/g_state.hh,
* yavgui/src/g_state.hxx: Add signal/slots/connections.
* yavgui/src/g_vcsn_handler.cc,
* yavgui/src/g_vcsn_handler.hh,
* yavgui/src/g_vcsn_handler.hxx: Implement functions.
2009-08-05 d-halluin <d-halluin@lrde.epita.fr>
 
[yavgui] Fix transition hover detection.
......
......@@ -29,6 +29,8 @@ COMMON_SOURCES = main.cc \
dialog_get_automaton_type.moc.cc \
dialog_get_layout.cc \
dialog_get_layout.moc.cc \
dialog_properties_state.cc \
dialog_properties_state.moc.cc \
g_view.cc \
g_view.moc.cc \
g_scene.cc \
......
......@@ -30,11 +30,11 @@ namespace gui
{
DialogPropertiesState::DialogPropertiesState (GState* state)
: state_ (state),
input_ (new QTextEdit (state->label ()))
input_ (new QLineEdit (state->label ())),
initial_ (new QCheckBox ("Initial")),
final_ (new QCheckBox ("Final")),
initial_entry_ (new QTextEdit (state->initial_entry_)),
final_entry_ (new QTextEdit (state->final_entry_))
initial_entry_ (new QLineEdit (state->initial_entry())),
final_entry_ (new QLineEdit (state->final_entry()))
{
QPushButton *closeButton = new QPushButton(tr("Ok"));
connect(closeButton, SIGNAL(clicked()), this, SLOT(done()));
......@@ -44,6 +44,9 @@ namespace gui
QLabel* input_label = new QLabel("Label:");
initial_->setChecked(!state->initial_entry().isNull());
final_->setChecked(!state->final_entry().isNull());
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(input_label);
mainLayout->addWidget(input_);
......@@ -60,33 +63,33 @@ namespace gui
void DialogPropertiesState::done ()
{
if (state)
if (state_)
{
state->set_label (input_->toPlainText ());
state_->set_label (input_->text());
QColor color ("white");
if (initial_->isChecked ())
{
state->set_initial_entry(initial_entry_->toPlainText ());
state_->set_initial(initial_entry_->text());
color.setGreen (color.green () - 30);
color.setRed (color.red () - 30);
}
else
{
state->set_initial_entry(0);
state_->set_initial(0);
}
if (final_->isChecked ())
{
state->set_final_entry(final_entry_->toPlainText ());
state_->set_final(final_entry_->text());
color.setGreen (color.green () - 30);
color.setRed (color.red () - 30);
}
else
{
state->set_final_entry(0);
state_->set_final(0);
}
state->set_default_color (color);
state_->set_default_color (color);
state->refresh ();
state_->refresh ();
}
emit close ();
......
......@@ -29,6 +29,9 @@
# include "common.hh"
# include "g_common.hh"
# include "g_state.hh"
using namespace gui::display;
namespace gui
{
......@@ -39,7 +42,7 @@ namespace gui
Q_OBJECT
public:
DialogPropertiesState (GState* state);
DialogPropertiesState(GState* state);
public slots:
void done ();
......@@ -47,11 +50,11 @@ namespace gui
private:
GState* state_;
QTextEdit* input_;
QLineEdit* input_;
QCheckBox* initial_;
QCheckBox* final_;
QTextEdit* initial_entry_;
QTextEdit* initial_entry_;
QLineEdit* initial_entry_;
QLineEdit* final_entry_;
};
......
......@@ -49,6 +49,10 @@ namespace gui
{
connect(state, SIGNAL(delState()),
this, SLOT(delState()));
connect(state, SIGNAL(setInitial(QString)),
this, SLOT(setInitial(QString)));
connect(state, SIGNAL(setFinal(QString)),
this, SLOT(setFinal(QString)));
connect(state, SIGNAL(selected()),
this, SLOT(itemSelected()));
connect(state, SIGNAL(deselected()),
......@@ -72,6 +76,18 @@ namespace gui
emit delState(dynamic_cast<GState*>(sender()));
}
void
GScene::setInitial(QString entry)
{
emit setInitial(dynamic_cast<GState*>(sender()), entry);
}
void
GScene::setFinal(QString entry)
{
emit setFinal(dynamic_cast<GState*>(sender()), entry);
}
void
GScene::delTransition()
{
......
......@@ -47,9 +47,11 @@ namespace gui
void mousePressEvent(QGraphicsSceneMouseEvent* event);
public slots:
// Connect GState::delState() to this.
// Connect GState::delState() to these.
void delState();
void delTransition();
void setInitial(QString entry);
void setFinal(QString entry);
// Used to ignore right click events.
void itemSelected();
......@@ -60,6 +62,8 @@ namespace gui
// Connect GVcsnHandler to those.
void delState(GState* state);
void addState(QPointF pos);
void setInitial(GState* state, QString entry);
void setFinal(GState* state, QString entry);
void delTransition(GTransition* transition);
private:
......
......@@ -29,6 +29,8 @@
#include <QCursor>
#include "g_state.hh"
#include "dialog_properties_state.hh"
#include "common.hh"
namespace gui
......@@ -185,6 +187,25 @@ namespace gui
QGraphicsItem::mousePressEvent(event);
}
void
GState::mouseDoubleClickEvent (QGraphicsSceneMouseEvent* event)
{
if (!selected_)
{
event->ignore();
return;
}
if (event->button () == Qt::LeftButton)
{
event->accept();
dialogs::DialogPropertiesState dlg(this);
dlg.exec();
return;
}
QGraphicsItem::mousePressEvent(event);
}
void
GState::refresh ()
{
......
......@@ -57,6 +57,7 @@ namespace gui
void hoverEnterEvent (QGraphicsSceneHoverEvent* event);
void hoverLeaveEvent (QGraphicsSceneHoverEvent* event);
void mousePressEvent (QGraphicsSceneMouseEvent* event);
void mouseDoubleClickEvent (QGraphicsSceneMouseEvent* event);
inline int looping_transitions ();
inline void set_looping_transitions (int);
......@@ -72,9 +73,16 @@ namespace gui
inline QString label ();
inline void set_label (QString label);
// Use set_initial and set_final to set the entry in the vcsn
// automaton.
// Use set_initial_entry and set_final_entry to set the
// displayed label (called through set_initial and set_final if
// necessary).
inline void set_initial (QString initial_entry);
inline void set_initial_entry (QString initial_entry);
inline QString initial_entry ();
inline void set_final (QString final_entry);
inline void set_final_entry (QString final_entry);
inline QString final_entry ();
......@@ -93,6 +101,9 @@ namespace gui
// Ask to delete itself.
void delState();
void setInitial(QString entry);
void setFinal(QString entry);
private:
// Background colors
......
......@@ -70,6 +70,11 @@ namespace gui
return initial_entry_;
}
void GState::set_initial (QString initial_entry)
{
emit setInitial(initial_entry);
}
void GState::set_initial_entry (QString initial_entry)
{
initial_entry_ = initial_entry;
......@@ -80,6 +85,11 @@ namespace gui
return final_entry_;
}
void GState::set_final (QString final_entry)
{
emit setFinal(final_entry);
}
void GState::set_final_entry (QString final_entry)
{
final_entry_ = final_entry;
......
......@@ -64,6 +64,44 @@ namespace gui
boost::apply_visitor(op, **(info_.automaton));
}
GVcsnHandler::SetInitial::SetInitial(SceneInfo& i, GState* s, QString e)
: info(i),
state(s),
entry(e)
{
}
void
GVcsnHandler::setInitial(GState* state, QString entry)
{
if (! *(info_.automaton))
throw exceptions::NoAutomatonStructure ();
if (!state)
throw exceptions::NullParameter ();
SetInitial op(info_, state, entry);
boost::apply_visitor(op, **(info_.automaton));
}
GVcsnHandler::SetFinal::SetFinal(SceneInfo& i, GState* s, QString e)
: info(i),
state(s),
entry(e)
{
}
void
GVcsnHandler::setFinal(GState* state, QString entry)
{
if (! *(info_.automaton))
throw exceptions::NoAutomatonStructure ();
if (!state)
throw exceptions::NullParameter ();
SetFinal op(info_, state, entry);
boost::apply_visitor(op, **(info_.automaton));
}
GVcsnHandler::DelTransition::DelTransition(SceneInfo& i, GTransition* t)
: info(i),
transition(t)
......@@ -93,6 +131,10 @@ namespace gui
this, SLOT(addState(QPointF)));
connect(scene, SIGNAL(delState(GState*)),
this, SLOT(delState(GState*)));
connect(scene, SIGNAL(setInitial(GState*, QString)),
this, SLOT(setInitial(GState*, QString)));
connect(scene, SIGNAL(setFinal(GState*, QString)),
this, SLOT(setFinal(GState*, QString)));
connect(scene, SIGNAL(delTransition(GTransition*)),
this, SLOT(delTransition(GTransition*)));
}
......
......@@ -66,6 +66,9 @@ namespace gui
void delState(GState* state);
void delTransition(GTransition* transition);
void setInitial(GState* state, QString entry);
void setFinal(GState* state, QString entry);
private:
struct AddState: public boost::static_visitor<>
......@@ -104,6 +107,34 @@ namespace gui
GTransition* transition;
};
struct SetInitial: public boost::static_visitor<>
{
SetInitial(SceneInfo& info,
GState* state,
QString entry);
template<typename Automaton>
void operator()(Automaton& automaton);
SceneInfo& info;
GState* state;
QString entry;
};
struct SetFinal: public boost::static_visitor<>
{
SetFinal(SceneInfo& info,
GState* state,
QString entry);
template<typename Automaton>
void operator()(Automaton& automaton);
SceneInfo& info;
GState* state;
QString entry;
};
SceneInfo info_;
};
} // ! namespace display
......
......@@ -30,6 +30,7 @@
# include "common.hh"
# include <cmath>
# include <sstream>
# include <vaucanson/misc/usual_macros.hh>
......@@ -77,6 +78,55 @@ namespace gui
info.scene->itemDeselected();
transition = 0;
}
template<typename Automaton>
void
GVcsnHandler::SetInitial::operator()(Automaton& automaton)
{
using namespace vcsn::boolean_automaton;
int i = state->index();
if (entry.isNull())
{
automaton.unset_initial(i);
state->set_initial_entry(0);
}
else
{
// FIXME: handle entries.
automaton.set_initial(i);
std::stringstream str;
str << automaton.get_initial(i);
state->set_initial_entry(str.str().c_str());
}
state->update();
}
template<typename Automaton>
void
GVcsnHandler::SetFinal::operator()(Automaton& automaton)
{
AUTOMATON_TYPES(Automaton)
int i = state->index();
if (entry.isNull())
{
automaton.unset_final(i);
state->set_final_entry(0);
}
else
{
// FIXME: Handle entries.
automaton.set_final(i);
std::stringstream s;
s << automaton.get_final(i);
state->set_final_entry(s.str().c_str());
}
state->update();
}
} // ! namespace display
} // ! namespace gui
......
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