Commit dc4a5568 authored by Yann Boucher's avatar Yann Boucher
Browse files

Can now add different toggle rules for GridView

parent dd944119
......@@ -88,6 +88,11 @@ public:
//! \param checked_state L'état lorsqu'une cellule est sélectionnée
//! \param unchecked_state L'état d'une cellule non sélectionnée
void enable_toggle_mode(unsigned checked_state, unsigned unchecked_state = 0);
//! \brief Ajoute une règle au mode "toggle", qui permet de changer l'état d'une cellule de manière cyclique en cliquant dessus, passant d'un état check à uncheck, et inversement si cliqué à nouveau.
//! \brief Cette fonction permet d'ajouter une nouvellle paire d'états cycliques, pour pouvoir par exemple permettre de passer entre 0-1 et 2-3, indépendamment.
//! \param checked_state L'état d'une cellule sélectionnée
//! \param unchecked_state L'état d'une cellule non sélectionnée
void add_toggle_rule(unsigned checked_state, unsigned unchecked_state = 0);
//! \brief Désactive le mode "toggle".
void disable_toggle_mode();
//! \brief Retourne un booléen indiquant si le mode actuel est le mode "toggle".
......@@ -170,7 +175,7 @@ private:
QPixmap m_grid_pixmap;
Grid m_grid;
bool m_in_toggle_mode;
unsigned m_checked_state, m_unchecked_state;
std::vector<std::pair<unsigned, unsigned>> m_toggle_states;
std::vector<QGraphicsRectItem*> m_selection_rects;
bool m_handling_rubberband;
DragDropHandlerItem* m_drag_drop_handler;
......
......@@ -353,8 +353,12 @@ unsigned GridView::current_pen() const
void GridView::enable_toggle_mode(unsigned checked_state, unsigned unchecked_state)
{
m_in_toggle_mode = true;
m_checked_state = checked_state;
m_unchecked_state = unchecked_state;
add_toggle_rule(checked_state, unchecked_state);
}
void GridView::add_toggle_rule(unsigned checked_state, unsigned unchecked_state)
{
m_toggle_states.push_back({checked_state, unchecked_state});
}
void GridView::disable_toggle_mode()
......@@ -530,10 +534,19 @@ void GridView::click_on(Coord coord)
else
{
unsigned prev_state = get_grid().get_state(coord);
if (prev_state == m_checked_state)
set_cell_state(coord, m_unchecked_state);
else
set_cell_state(coord, m_checked_state);
for (auto toggle_pair : m_toggle_states)
{
if (prev_state == toggle_pair.first)
{
set_cell_state(coord, toggle_pair.second);
break;
}
else if (prev_state == toggle_pair.second)
{
set_cell_state(coord, toggle_pair.first);
break;
}
}
}
}
......
......@@ -22,6 +22,7 @@ SOURCES += \
../src/history.cpp \
../src/grid.cpp \
../src/neighborhood_rules/mooreNeighborhoodRule.cpp \
../src/neighborhood_rules/vonNeumannNeighborhoodRule.cpp \
../src/transition_rules/lifegametransition.cpp \
../src/transition_rules/circulartransition.cpp \
../src/transition_rules/totalistictransition.cpp \
......
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