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

Ajout d'informations liées à la cellule survolée, résolution d'un bug où...

Ajout d'informations liées à la cellule survolée, résolution d'un bug où l'état n'était pas modulo après un changement d'alphabet
parent 2954d909
Pipeline #79320 canceled with stage
......@@ -16,6 +16,7 @@ Cette classe représente le widget utilisé pour l'affichage et l'interaction av
#include <QFrame>
#include <QGraphicsView>
#include <QLabel>
#include <QGraphicsRectItem>
......@@ -156,6 +157,7 @@ private:
void select_all();
void click_on(Coord coord);
void update_current_mouse_pos(Coord coord);
const QPixmap &grid_pixmap() const;
......@@ -173,7 +175,9 @@ private:
History m_undo_history;
QImage m_grid_image;
QPixmap m_grid_pixmap;
QLabel* m_mouse_pos_label;
Grid m_grid;
Coord m_last_mouse_pos;
bool m_in_toggle_mode;
std::vector<std::pair<unsigned, unsigned>> m_toggle_states;
std::vector<QGraphicsRectItem*> m_selection_rects;
......
......@@ -91,7 +91,6 @@ public:
DragDropHandlerItem(GridView& in_gridview, QGraphicsItem *parent = nullptr)
: QGraphicsRectItem(0, 0, 1, 1, parent), m_grid_view(in_gridview)
{
setAcceptHoverEvents(true);
setAcceptDrops(true);
setPen(Qt::NoPen);
......@@ -186,8 +185,9 @@ void GridGraphicsView::mousePressEvent(QMouseEvent *event)
QGraphicsView::mousePressEvent(event);
}
else
QGraphicsView::mousePressEvent(event);
m_gridview.update_current_mouse_pos(coord);
}
void GridGraphicsView::mouseMoveEvent(QMouseEvent *event)
......@@ -196,6 +196,8 @@ void GridGraphicsView::mouseMoveEvent(QMouseEvent *event)
if (!sceneRect().contains(item_pos) || !sceneRect().contains(mapToScene(m_last_mouse_pos)))
return;
Coord coord = Coord{(int)item_pos.x(), (int)item_pos.y()};
if (!m_gridview.in_toggle_mode() && QGuiApplication::keyboardModifiers() == Qt::NoModifier && event->buttons() == Qt::LeftButton)
{
draw_bresenham(mapToScene(m_last_mouse_pos), item_pos);
......@@ -210,6 +212,7 @@ void GridGraphicsView::mouseMoveEvent(QMouseEvent *event)
QGraphicsView::mouseMoveEvent(event);
m_last_mouse_pos = event->pos();
m_gridview.update_current_mouse_pos(coord);
}
void GridGraphicsView::drawForeground(QPainter *painter, const QRectF &)
......@@ -297,6 +300,8 @@ GridView::GridView(QWidget *parent)
QGridLayout *layout = new QGridLayout;
layout->addWidget(m_view);
m_mouse_pos_label = new QLabel("");
layout->addWidget(m_mouse_pos_label);
layout->addWidget(new QLabel("Clic gauche : éditer; Clic droit : sélectionner", this));
layout->addWidget(new QLabel("Maintenir SHIFT pour déplacer la grille; Molette ou CTRL+/CTRL- pour zoomer", this));
setLayout(layout);
......@@ -316,6 +321,7 @@ GridView::GridView(QWidget *parent)
Alphabet alph(state{stateColor{255, 255, 255}, "Dead"});
alph.newEtat(state{stateColor{0, 0, 255}, "Alive"});
set_alphabet(alph);
update_current_mouse_pos({0, 0});
connect(m_zoom, &detail::Graphics_view_zoom::zoomed, this, [this]
{
......@@ -447,17 +453,20 @@ void GridView::load_grid(const Grid &grid)
{
for (int j = 0; j < (int)m_height; ++j)
{
QColor color = stateColor_to_QColor(m_alph.getState(grid.get_state(Coord{i, j})).getColor());
QColor color = stateColor_to_QColor(m_alph.getState(grid.get_state(Coord{i, j}) % m_alph.taille()).getColor());
m_grid_image.setPixelColor(i, j, color);
m_grid.set_cell(Coord{i, j}, grid.get_state(Coord{i, j}) % m_alph.taille());
}
}
m_grid_pixmap.convertFromImage(m_grid_image);
m_scene->setSceneRect(QRectF(0, 0, m_width, m_height));
m_drag_drop_handler->setRect(QRectF(0, 0, m_width, m_height));
update_current_mouse_pos(m_last_mouse_pos);
}
void GridView::set_cell_state(Coord pos, unsigned state)
{
state %= m_alph.taille();
QColor color = stateColor_to_QColor(m_alph.getState(state).getColor());
m_grid_image.setPixelColor(pos.x, pos.y, color);
m_grid.set_cell(pos, state);
......@@ -553,6 +562,14 @@ void GridView::click_on(Coord coord)
}
}
void GridView::update_current_mouse_pos(Coord coord)
{
m_last_mouse_pos = coord;
auto state_label = m_alph.getState(m_grid.get_state(coord)).getStateLabel();
m_mouse_pos_label->setText(QString("Mouse position : %1,%2 : \"%3\"").arg(coord.x).arg(coord.y).arg(
QString::fromStdString(state_label)));
}
void GridView::paste_structure_at(Coord origin, const Structure &s)
{
push_history();
......
......@@ -401,8 +401,6 @@ void MainWindow::load_model(const QJsonObject &obj)
prop->accept(visit);
}
ui_update_alphabet(alpha);
// On transfère la propriété de ces pointeurs vers Simulation, qui en est désormais propriétaire pour l'exécution de l'automate
simulation.setNeighborhoodRule(m_neighborhood_rule);
simulation.setTransitionRule(m_transition_rule);
......
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