Commit 835c251b authored by Florent D'Halluin's avatar Florent D'Halluin
Browse files

[yavgui] Handle state addition/deletion.

Right click on empty space to add a state.
Right click on a state to delete it.

* yavgui/src/automaton_instance.cc: Cosmetic.
* yavgui/src/g_painter.cc: Do not delete the scene when refreshing;
update it instead.
* yavgui/src/g_painter.hxx,
* yavgui/src/g_scene.cc,
* yavgui/src/g_scene.hh,
* yavgui/src/g_state.cc,
* yavgui/src/g_state.hh,
* yavgui/src/g_vcsn_handler.cc,
* yavgui/src/g_vcsn_handler.hh,
* yavgui/src/g_vcsn_handler.hxx,
* yavgui/src/g_transition.cc: Add necessary signal/slots/connections.
* yavgui/src/vcsn_automaton.cc,
* yavgui/src/g_view.cc,
* yavgui/src/g_view.hh: Remove obsolete signal/slots/connections.
parent bdce50ed
2009-08-04 d-halluin <d-halluin@lrde.epita.fr>
[yavgui] Handle state addition/deletion.
Right click on empty space to add a state.
Right click on a state to delete it.
* yavgui/src/automaton_instance.cc: Cosmetic.
* yavgui/src/g_painter.cc: Do not delete the scene when refreshing;
update it instead.
* yavgui/src/g_painter.hxx,
* yavgui/src/g_scene.cc,
* yavgui/src/g_scene.hh,
* yavgui/src/g_state.cc,
* yavgui/src/g_state.hh,
* yavgui/src/g_vcsn_handler.cc,
* yavgui/src/g_vcsn_handler.hh,
* yavgui/src/g_vcsn_handler.hxx,
* yavgui/src/g_transition.cc: Add necessary signal/slots/connections.
* yavgui/src/vcsn_automaton.cc,
* yavgui/src/g_view.cc,
* yavgui/src/g_view.hh: Remove obsolete signal/slots/connections.
2009-08-04 d-halluin <d-halluin@lrde.epita.fr>
 
[yavgui] Add NullParameter exception.
......
......@@ -24,6 +24,8 @@
#include "automaton_instance.hh"
#include "exceptions.hh"
namespace gui
{
AutomatonInstance::AutomatonInstance (QString filename)
......@@ -37,7 +39,7 @@ namespace gui
view_->setScene (scene_);
scene_->setSceneRect(-SCENE_SIZE / 2, -SCENE_SIZE / 2,
SCENE_SIZE, SCENE_SIZE);
vcsn_automaton_.set_vcsn_handler (&scene_, &view_);
vcsn_automaton_.set_vcsn_handler(&scene_, &view_);
}
AutomatonInstance::AutomatonInstance (const AutomatonInstance&)
......
......@@ -43,13 +43,9 @@ namespace gui
void GPainter::clear ()
{
GScene* sc = new GScene ();
(sc)->setSceneRect(-SCENE_SIZE / 2, -SCENE_SIZE / 2,
SCENE_SIZE, SCENE_SIZE);
(*view_)->setScene (sc);
delete (*scene_);
*scene_ = sc;
(*scene_)->clear();
(*scene_)->setSceneRect(-SCENE_SIZE / 2, -SCENE_SIZE / 2,
SCENE_SIZE, SCENE_SIZE);
}
......
......@@ -76,6 +76,7 @@ namespace gui
states.push_back(state);
(*scene_)->addItem (state);
state_map[*istate] = state;
(*scene_)->connectState(state);
}
position (states);
......
......@@ -22,6 +22,7 @@
*
*/
#include <iostream>
#include "g_scene.hh"
namespace gui
......@@ -29,8 +30,49 @@ namespace gui
namespace display
{
GScene::GScene ()
: state_selected_(false)
{
}
void
GScene::mousePressEvent(QGraphicsSceneMouseEvent* event)
{
if (state_selected_ == false && event->button() == Qt::RightButton)
{
emit addState(event->scenePos ());
}
this->QGraphicsScene::mousePressEvent(event);
}
void
GScene::connectState(GState* state)
{
connect(state, SIGNAL(delState()),
this, SLOT(delState()));
connect(state, SIGNAL(selected()),
this, SLOT(stateSelected()));
connect(state, SIGNAL(deselected()),
this, SLOT(stateDeselected()));
}
void
GScene::delState()
{
state_selected_ = false;
emit delState(dynamic_cast<GState*>(sender()));
}
void
GScene::stateSelected()
{
state_selected_ = true;
}
void
GScene::stateDeselected()
{
state_selected_ = false;
}
} // ! namespace display
} // ! namespace gui
......@@ -39,14 +39,27 @@ namespace gui
Q_OBJECT
public:
GScene ();
GScene();
void connectState(GState* state);
void mousePressEvent(QGraphicsSceneMouseEvent* event);
public slots:
// Connect GState::delState() to this.
void delState();
// Used to ignore right click events.
void stateSelected();
void stateDeselected();
signals:
void stateSelected (GState* state);
void stateDeselected (GState* state);
void delState (GState* state);
void addState (QPointF pos);
// Automaton structure modification requests.
// Connect GVcsnHandler to those.
void delState(GState* state);
void addState(QPointF pos);
private:
bool state_selected_;
};
} // ! namespace display
......
......@@ -168,6 +168,23 @@ namespace gui
deselect ();
}
void
GState::mousePressEvent (QGraphicsSceneMouseEvent* event)
{
if (!selected_)
{
event->ignore();
return;
}
if (event->button () == Qt::RightButton)
{
event->accept();
emit delState();
return;
}
QGraphicsItem::mousePressEvent(event);
}
void
GState::refresh ()
{
......
......@@ -56,6 +56,7 @@ namespace gui
void hoverEnterEvent (QGraphicsSceneHoverEvent* event);
void hoverLeaveEvent (QGraphicsSceneHoverEvent* event);
void mousePressEvent (QGraphicsSceneMouseEvent* event);
inline int looping_transitions ();
inline void set_looping_transitions (int);
......@@ -89,6 +90,9 @@ namespace gui
void selected ();
void deselected ();
// Ask to delete itself.
void delState();
private:
// Background colors
......
......@@ -59,6 +59,8 @@ namespace gui
{
QObject::connect (&from, SIGNAL(moved ()),
this, SLOT(refresh ()));
QObject::connect (&from, SIGNAL(destroyed ()),
this, SLOT(deleteLater ()));
angle_ = transition_index_ * 5
+ PI / 2;
}
......@@ -68,6 +70,10 @@ namespace gui
this, SLOT(refresh ()));
QObject::connect (&from, SIGNAL(moved ()),
this, SLOT(refresh ()));
QObject::connect (&to, SIGNAL(destroyed ()),
this, SLOT(deleteLater ()));
QObject::connect (&from, SIGNAL(destroyed ()),
this, SLOT(deleteLater ()));
}
refresh ();
}
......
......@@ -22,7 +22,7 @@
* FIXME
*/
# include "g_vcsn_handler.hh"
#include "g_vcsn_handler.hh"
using namespace gui::display;
......@@ -37,15 +37,32 @@ namespace gui
}
void
GVcsnHandler::add_state(QPointF pos)
GVcsnHandler::addState(QPointF pos)
{
AddState op(info_, pos);
if (! *(info_.automaton))
throw exceptions::NoAutomatonStructure ();
AddState op(info_, pos);
boost::apply_visitor (op, **(info_.automaton));
}
GVcsnHandler::DelState::DelState(SceneInfo& i, GState* s)
: info(i),
state(s)
{
}
void
GVcsnHandler::delState(GState* state)
{
if (! *(info_.automaton))
throw exceptions::NoAutomatonStructure ();
if (!state)
throw exceptions::NullParameter ();
DelState op(info_, state);
boost::apply_visitor (op, **(info_.automaton));
}
GVcsnHandler::GVcsnHandler (GScene** scene,
GView** view,
......@@ -54,6 +71,10 @@ namespace gui
info_.scene = scene;
info_.view = view;
info_.automaton = automaton;
connect(*scene, SIGNAL(addState(QPointF)),
this, SLOT(addState(QPointF)));
connect(*scene, SIGNAL(delState(GState*)),
this, SLOT(delState(GState*)));
}
GVcsnHandler::~GVcsnHandler ()
......
......@@ -62,7 +62,8 @@ namespace gui
virtual ~GVcsnHandler();
public slots:
void add_state(QPointF pos);
void addState(QPointF pos);
void delState(GState* state);
private:
......
......@@ -48,6 +48,7 @@ namespace gui
GState *state = new GState(i, QColor("white"));
state->setPos(pos);
(*(info.scene))->addItem(state);
(*(info.scene))->connectState(state);
}
template<typename Automaton>
......@@ -58,8 +59,7 @@ namespace gui
automaton.del_state(state->index());
//(*(info.scene))->removeItem(state);
delete (state);
delete (state); // removes it from the scene properly.
state = 0;
}
} // ! namespace display
......
......@@ -22,6 +22,8 @@
*
*/
#include <iostream>
#include "g_view.hh"
namespace gui
......@@ -55,15 +57,6 @@ namespace gui
this->QGraphicsView::mouseMoveEvent (event);
}
void GView::mousePressEvent (QMouseEvent* event)
{
if (event->button () == Qt::RightButton)
{
emit rightClick (mapToScene (event->pos ()));
}
this->QGraphicsView::mousePressEvent (event);
}
void GView::wheelEvent (QWheelEvent* event)
{
setLowQuality ();
......
......@@ -42,7 +42,6 @@ namespace gui
void wheelEvent (QWheelEvent* event);
void mouseMoveEvent (QMouseEvent* event);
void mousePressEvent (QMouseEvent* event);
public slots:
......@@ -50,9 +49,6 @@ namespace gui
void setHighQuality ();
void setLowQuality ();
signals:
void rightClick (QPointF);
private:
QTimer timer_;
bool is_low_quality_;
......
......@@ -54,9 +54,6 @@ namespace gui
delete vcsn_handler_;
vcsn_handler_ = new display::GVcsnHandler (scene, view, &automaton_);
// Disabled until the whole system is in place
QObject::connect (*view, SIGNAL(rightClick(QPointF)),
vcsn_handler_, SLOT(add_state(QPointF)));
}
void VcsnAutomaton::load (QString filename)
......
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