Commit 6a4ad98a authored by Eugene Pin's avatar Eugene Pin
Browse files

#47 Modification de gridView et interface pour redimensionner la grille...

#47 Modification de gridView et interface pour redimensionner la grille suivant les informations entrées depuis l'interface
parent d307b118
Pipeline #78221 passed with stages
in 16 seconds
......@@ -46,8 +46,7 @@ class GridView : public QFrame
{
Q_OBJECT
public:
GridView(QWidget *parent = nullptr);
GridView(QWidget *parent = nullptr, const Grid *g = nullptr);
public:
void set_alphabet(const Alphabet& alph);
const Alphabet& alphabet() const;
......
......@@ -108,8 +108,8 @@ void GridGraphicsView::mousePressEvent(QMouseEvent *event)
QGraphicsView::mousePressEvent(event);
}
GridView::GridView(QWidget *parent)
: QFrame(parent), m_width(0), m_height(0)
GridView::GridView(QWidget *parent, const Grid *g)
: QFrame(parent), m_width(10), m_height(10)
{
setMouseTracking(true);
......@@ -134,15 +134,58 @@ GridView::GridView(QWidget *parent)
layout->addWidget(new QLabel("Maintenir SHIFT pour déplacer la grille", this));
setLayout(layout);
m_width = m_height = 100;
set_current_pen(0);
// Test Alphabet
Alphabet alph(state{stateColor{255, 255, 255}, "Dead"});
alph.newEtat(state{stateColor{0, 0, 255}, "Alive"});
set_alphabet(alph);
if( g != nullptr ) {
m_height = g->get_rows();
m_width = g->get_col();
for (unsigned i = 0; i < m_width; ++i)
{
for (unsigned j = 0; j < m_height; ++j)
{
Coord pos = {static_cast<int>(i), static_cast<int>(j)};
unsigned state = g->get_state(pos);
//std::cout << "state : " << state << endl;
GridItem *item = new GridItem(stateColor_to_QColor(m_alph.getState(state).getColor()), QString::fromStdString(m_alph.getState(state).getStateLabel()));
//GridItem *item = new GridItem((i ^ j) % 2 ? Qt::blue : Qt::white, QString::fromStdString(m_alph.getState(state).getStateLabel()));
item->setPos(QPointF(i*GridItem::width(), j*GridItem::height()));
item->cell_pos = Coord{(int)i, (int)j};
item->cell_state = state;
m_scene->addItem(item);
}
}
}
else // Initialisation la première fois
{
m_height = 10;
m_width = 10;
for (unsigned i = 0; i < m_width; ++i)
{
for (unsigned j = 0; j < m_height; ++j)
{
unsigned state = 0;
GridItem *item = new GridItem(stateColor_to_QColor(m_alph.getState(state).getColor()), QString::fromStdString(m_alph.getState(state).getStateLabel()));
//GridItem *item = new GridItem((i ^ j) % 2 ? Qt::blue : Qt::white, QString::fromStdString(m_alph.getState(state).getStateLabel()));
item->setPos(QPointF(i*GridItem::width(), j*GridItem::height()));
item->cell_pos = Coord{(int)i, (int)j};
item->cell_state = state;
m_scene->addItem(item);
}
}
}
// Populate scene;
/*
for (unsigned i = 0; i < m_width; ++i)
{
for (unsigned j = 0; j < m_height; ++j)
......@@ -156,7 +199,7 @@ GridView::GridView(QWidget *parent)
item->cell_state = state;
m_scene->addItem(item);
}
}
}*/
}
void GridView::set_alphabet(const Alphabet &alph)
......
......@@ -118,7 +118,35 @@ void MainWindow::afficher_interface_sauvegarde_structure(bool)
void MainWindow::on_validateGridDim_clicked()
{
// Appliquer la dimension à la grille
Grid oldGrid = ui->grid_view->get_grid();
delete ui->grid_view;
unsigned int height = ui->heightSpinBox->value();
unsigned int width = ui->widthSpinBox->value();
Grid newGrid(height, width);
fflush(stdout);
if(oldGrid.get_rows() < height && oldGrid.get_col() < width) {
//std::cout << "superieur\n";
fflush(stdout);
for (int i = 0; i < static_cast<int>(oldGrid.get_rows()) ; i++) {
for (int j = 0; j < static_cast<int>(oldGrid.get_col()) ; j++) {
Coord pos = {i, j};
newGrid.set_cell(pos, oldGrid.get_state(pos));
//std::cout << "oldState : " << oldGrid.get_state(pos) << endl;
}
}
}
ui->grid_view = new GridView(ui->grid, &newGrid);
ui->grid_view->setObjectName(QString::fromUtf8("grid_view"));
ui->grid_view->setFrameShape(QFrame::StyledPanel);
ui->grid_view->setFrameShadow(QFrame::Raised);
ui->gridLayout_2->addWidget(ui->grid_view, 0, 0, 1, 1);
ui->validateGridDim->setEnabled(false);
}
......
Markdown is supported
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