diff --git a/forms/colorlabel.cpp b/forms/colorlabel.cpp deleted file mode 100644 index 9d919f6835f01ab9458d145806b23bccdd7bd10c..0000000000000000000000000000000000000000 --- a/forms/colorlabel.cpp +++ /dev/null @@ -1,119 +0,0 @@ -#include "colorlabel.h" -#include "ui_colorlabel.h" -#include "state.hpp" -#include "stateColor.hpp" -#include "alphabet.hpp" -#include "interface.hpp" -#include <stdlib.h> -#include <string> -#include <QListWidget> - -ColorLabel::ColorLabel(QWidget *parent) : - QWidget(parent), - ui(new Ui::ColorLabel) -{ - ui->setupUi(this); - connect(ui->generate_button, SIGNAL(clicked()), this, SLOT(generateState(a,state_label->text(),red_slider->value(),green_slider->value(),blue_slider->value()))); - connect(ui->random_button, SIGNAL(clicked()), this, SLOT(randomGenerator(a,state_label->text()))); - connect(ui->daltonian_button, SIGNAL(clicked()), this, SLOT(daltonianMode(a,ui->nbrStatesComboBox->value()))); // Pas sûr pour cette ligne, mon but ici est d'aller chercher la valeur - // présente dans nbrStatesComboBox, c'est à dire la valeur du nombre d'états que l'on peut modifier sur l'interface interface.ui - connect(ui->reset_button, SIGNAL(clicked()), this, SLOT(resetMode(a))); - connect(ui->remove_button, SIGNAL(clicked()), this, SLOT(removeState(a))); - connect(ui->update_button, SIGNAL(clicked()), this, SLOT(updateState(a))); - connect(ui->state_id, SIGNAL(valueChanged(int current_id)), this, SLOT(idPath(a,current_id))); -} - -ColorLabel::~ColorLabel() -{ - delete ui; -} - -void ColorLabel::generateState(Alphabet a, QString name_state, unsigned int r, unsigned int g, unsigned int b){ - if(a.taille()==ui->nbrStatesComboBox->value()){ // On vérifie qu'il reste encore de la place dans l'alphabet (récupérer la valeur dans nbrStatesComboBox sur l'interface) - throw AlphabetException("Nombre d'états maximal atteint"); - } - else { - std::string string_name_state = name_state.toStdString(); // On passe notre QString en string pour pouvoir utiliser le constructeur - state* newstate = new state(stateColor(r,g,b),string_name_state); // Création de notre nouvel état - a.newEtat(*newstate); // Ajout du nouvel état dans l'alphabet - ui->state_list->addItem(name_state); // Ajout du nouvel état dans la liste - ui->state_id->setMaximum(a.taille()); // Ajout de l'identifiant du nouvel état - } -} - - -void ColorLabel::randomGenerator(Alphabet a, QString name_state){ - std::string string_name_state = name_state.toStdString(); - unsigned int r = rand() % 255; // On génère aléatoirement nos couleurs - unsigned int g = rand() % 255; - unsigned int b = rand() % 255; - state* newstate = new state(stateColor(r,g,b),string_name_state); // Création de notre nouvel état - a.newEtat(*newstate); // Ajout du nouvel état dans l'alphabet - ui->state_list->addItem(name_state); // Ajout du nouvel état dans la liste -} - - -void ColorLabel::daltonianMode(Alphabet a, unsigned int nbStates){ - ui->state_list->clear(); // On vide toujours la liste quand on active le mode Daltonien - a.clearAlphabet(); - - // Création des états à partir du constructeur - state* black = new state(stateColor(0,0,0),"Black"); - state* white = new state(stateColor(255,255,255),"White"); - state* blue = new state(stateColor(0,0,255),"Blue"); - state* pink = new state(stateColor(255,0,255),"Pink"); - state* red = new state(stateColor(255,0,0),"Red"); - state* green = new state(stateColor(0,255,0),"Green"); - state* orange = new state(stateColor(255,127,0),"Orange"); - state* grey = new state(stateColor(127,127,127),"Grey"); - - state* daltonianstates [8]; - daltonianstates[0]=black; - daltonianstates[1]=white; - daltonianstates[2]=blue; - daltonianstates[3]=pink; - daltonianstates[4]=red; - daltonianstates[5]=green; - daltonianstates[6]=orange; - daltonianstates[7]=grey; - - for(unsigned int i=0; i<nbStates ; i++){ // Boucle qui crée le nombre d'états en fonction du nombre désiré - a.newEtat(*daltonianstates[i]); // Crée et ajoute l'état dans l'alphabet - ui->state_list->addItem(QString::fromStdString(daltonianstates[i]->getStateLabel())); // Ajoute l'état dans la liste - } - - ui->state_id->setMaximum(a.taille()); // Ajout de l'identifiant du nouvel état - - -} - -void ColorLabel::resetMode(Alphabet a){ - ui->state_list->clear(); // On vide la liste - a.clearAlphabet(); - a.newEtat(state{stateColor{255, 255, 255}}); //On recrée toujours l'état par défaut - ui->state_id->setValue(0); // Remise de l'id à zéro - ui->state_id->setMaximum(0); // Remise de l'id max à zéro - } - -void ColorLabel::removeState(Alphabet a){ - ui->state_list->takeItem(a.taille()); // On retire le dernier élément ajouté - a.deleleLastState(); - ui->state_id->setValue(0); // Remise du curseur de l'id à zéro (je ne sais pas si cette ligne est utile) - ui->state_id->setMaximum(a.taille()); // Remise de l'id max à la taille de l'alphabet -} - -void ColorLabel::updateState(Alphabet a){ - unsigned int current_id = ui->state_id->value(); // On récupère l'identifiant de state_id - a.setState(current_id, state(stateColor(static_cast<unsigned char>(ui->red_slider->value()), static_cast<unsigned char>(ui->green_slider->value()), static_cast<unsigned char>(ui->blue_slider->value())), ui->state_label->text())); - ui->state_list->item(current_id)=QString::fromStdString(a.getState(current_id).getStateLabel()); -} - -void ColorLabel::idPath(Alphabet a, unsigned int current_id){ - ui->state_label->setText(QString::fromStdString(a.getState(current_id).getStateLabel())); // On modifie le state_label en fonction du nom de l'état - ui->red_slider->setValue(a.getState(current_id).getColor().getRed()); - ui->red_value->setText(QString::number(ui->red_slider->value())); - ui->green_slider->setValue(a.getState(current_id).getColor().getGreen()); - ui->green_value->setText(QString::number(ui->green_slider->value())); - ui->blue_slider->setValue(a.getState(current_id).getColor().getBlue()); - ui->blue_value->setText(QString::number(ui->blue_slider->value())); -} diff --git a/forms/colorlabel.h b/forms/colorlabel.h deleted file mode 100644 index 191b055ba06219de6d8e5e166801530c0e206ebb..0000000000000000000000000000000000000000 --- a/forms/colorlabel.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef COLORLABEL_H -#define COLORLABEL_H - -#include <QWidget> -#include "state.hpp" -#include "stateColor.hpp" -#include "alphabet.hpp" -#include <QListWidget> - -namespace Ui { -class ColorLabel; -} - -class ColorLabel : public QWidget -{ - Q_OBJECT - -public: - explicit ColorLabel(QWidget *parent = nullptr); - ~ColorLabel(); - -public slots: - - void generateState(Alphabet a, QString list, unsigned int r, unsigned int g, unsigned int b); // Génère notre état en cliquant sur le bouton "Generate" - void randomGenerator(Alphabet a, QString name_state); // Génère un état aléatoire - void daltonianMode(Alphabet a, unsigned int nbStates); // Active le Mode Daltonien : Génère autant d'états que spécifié dans l'interface de façon adaptée aux Daltoniens - void resetMode(Alphabet a); // La fonction resetMode permet de remettre la liste et l'alphabet "à zéro" (on garde tout de même l'état par défaut) - void removeState(Alphabet a); // La fonction removeState permet de retirer le dernier état de l'alphabet - void updateState(Alphabet a); // La fonction updateState permet de remplacer un ancien état par un nouveau qui aura été modifié - void idPath(Alphabet a, unsigned int current_id); // La fonction idPath permet de parcourir la liste des états et d'avoir un affiche du nom et de la couleur sur l'interface - -private: - Ui::ColorLabel *ui; -}; - -#endif // COLORLABEL_H diff --git a/forms/colorlabel.ui b/forms/colorlabel.ui index 3a4f63a377aee8021c6f509bd9dc30910f6c5f74..9a3fe6d3b0cb300ed599948c84143d9db38c9876 100644 --- a/forms/colorlabel.ui +++ b/forms/colorlabel.ui @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> <class>ColorLabel</class> - <widget class="QWidget" name="ColorLabel"> + <widget class="QDialog" name="ColorLabel"> <property name="geometry"> <rect> <x>0</x> @@ -11,296 +11,172 @@ </rect> </property> <property name="windowTitle"> - <string>Form</string> + <string>Edit States</string> </property> - <widget class="QWidget" name="layoutWidget"> - <property name="geometry"> - <rect> - <x>10</x> - <y>10</y> - <width>441</width> - <height>261</height> - </rect> - </property> - <layout class="QVBoxLayout" name="verticalLayout_3"> - <item> - <layout class="QHBoxLayout" name="horizontalLayout_7"> - <item> - <layout class="QVBoxLayout" name="verticalLayout_2"> - <item> - <layout class="QHBoxLayout" name="horizontalLayout"> - <item> - <widget class="QLabel" name="label"> - <property name="text"> - <string>State name :</string> - </property> - </widget> - </item> - <item> - <widget class="QLineEdit" name="state_label"> - <property name="text"> - <string>Empty_name</string> - </property> - </widget> - </item> - </layout> - </item> - <item> - <layout class="QHBoxLayout" name="horizontalLayout_9"> - <item> - <widget class="QLabel" name="label_6"> - <property name="text"> - <string>State id :</string> - </property> - </widget> - </item> - <item> - <widget class="QSpinBox" name="state_id"> - <property name="maximum"> - <number>0</number> - </property> - </widget> - </item> - </layout> - </item> - <item> - <widget class="QLabel" name="label_2"> - <property name="text"> - <string>Color repartition :</string> - </property> - </widget> - </item> - <item> - <layout class="QVBoxLayout" name="verticalLayout"> - <item> - <layout class="QHBoxLayout" name="horizontalLayout_2"> - <item> - <widget class="QLabel" name="label_3"> - <property name="text"> - <string>Red</string> - </property> - </widget> - </item> - <item> - <widget class="QSlider" name="red_slider"> - <property name="maximum"> - <number>255</number> - </property> - <property name="value"> - <number>0</number> - </property> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - </widget> - </item> - <item> - <widget class="QLabel" name="red_value"> - <property name="text"> - <string>0</string> - </property> - </widget> - </item> - </layout> - </item> - <item> - <layout class="QHBoxLayout" name="horizontalLayout_3"> - <item> - <widget class="QLabel" name="label_4"> - <property name="text"> - <string>Green</string> - </property> - </widget> - </item> - <item> - <widget class="QSlider" name="green_slider"> - <property name="maximum"> - <number>255</number> - </property> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - </widget> - </item> - <item> - <widget class="QLabel" name="green_value"> - <property name="text"> - <string>0</string> - </property> - </widget> - </item> - </layout> - </item> - <item> - <layout class="QHBoxLayout" name="horizontalLayout_4"> - <item> - <widget class="QLabel" name="label_5"> - <property name="text"> - <string>Blue</string> - </property> - </widget> - </item> - <item> - <widget class="QSlider" name="blue_slider"> - <property name="maximum"> - <number>255</number> - </property> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - </widget> - </item> - <item> - <widget class="QLabel" name="blue_value"> - <property name="text"> - <string>0</string> - </property> - </widget> - </item> - </layout> - </item> - </layout> - </item> - <item> - <layout class="QHBoxLayout" name="horizontalLayout_5"> - <item> - <widget class="QPushButton" name="generate_button"> - <property name="text"> - <string>Create</string> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="random_button"> - <property name="text"> - <string>Random</string> - </property> - </widget> - </item> - </layout> - </item> - <item> - <layout class="QHBoxLayout" name="horizontalLayout_6"> - <item> - <widget class="QPushButton" name="update_button"> - <property name="text"> - <string>Update</string> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="quit_button"> - <property name="text"> - <string>Quit</string> - </property> - </widget> - </item> - </layout> - </item> - </layout> - </item> - <item> - <widget class="QListWidget" name="state_list"> - <item> + <layout class="QVBoxLayout" name="verticalLayout_4"> + <item> + <layout class="QVBoxLayout" name="verticalLayout_3"> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_7" stretch="2,5"> + <item> + <layout class="QVBoxLayout" name="verticalLayout_2" stretch="1,3,0"> + <item> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QLabel" name="label"> + <property name="text"> + <string>State name :</string> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="state_label"> + <property name="text"> + <string/> + </property> + <property name="placeholderText"> + <string>Choose a name</string> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QFormLayout" name="formLayout"> + <property name="sizeConstraint"> + <enum>QLayout::SetDefaultConstraint</enum> + </property> + <item row="0" column="0"> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>Color</string> + </property> + </widget> + </item> + <item row="1" column="0" colspan="2"> + <layout class="QHBoxLayout" name="horizontalLayout_2"> + <item> + <widget class="QPushButton" name="pick_button"> + <property name="text"> + <string>Pick</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="random_button"> + <property name="text"> + <string>Random</string> + </property> + </widget> + </item> + </layout> + </item> + <item row="0" column="1"> + <widget class="QLabel" name="color_label"> + <property name="maximumSize"> + <size> + <width>40</width> + <height>40</height> + </size> + </property> + <property name="layoutDirection"> + <enum>Qt::LeftToRight</enum> + </property> + <property name="text"> + <string/> + </property> + <property name="alignment"> + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_5"> + <item> + <widget class="QPushButton" name="generate_button"> + <property name="text"> + <string>Insert</string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </item> + <item> + <widget class="QListWidget" name="state_list"/> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_8"> + <item> + <widget class="QPushButton" name="daltonian_button"> <property name="text"> - <string>Nouvel élément</string> + <string>Daltonian Mode</string> </property> - </item> - </widget> - </item> - </layout> - </item> - <item> - <layout class="QHBoxLayout" name="horizontalLayout_8"> - <item> - <widget class="QPushButton" name="daltonian_button"> - <property name="text"> - <string>Daltonian Mode</string> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="reset_button"> - <property name="text"> - <string>Reset</string> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="remove_button"> - <property name="text"> - <string>Remove last state</string> - </property> - </widget> - </item> - </layout> - </item> - </layout> - </widget> + </widget> + </item> + <item> + <widget class="QPushButton" name="reset_button"> + <property name="text"> + <string>Reset</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="remove_button"> + <property name="text"> + <string>Remove last state</string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </item> + <item> + <widget class="QDialogButtonBox" name="buttonBox"> + <property name="standardButtons"> + <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> + </property> + </widget> + </item> + </layout> </widget> <resources/> <connections> <connection> - <sender>green_slider</sender> - <signal>sliderMoved(int)</signal> - <receiver>green_value</receiver> - <slot>setNum(int)</slot> - <hints> - <hint type="sourcelabel"> - <x>173</x> - <y>149</y> - </hint> - <hint type="destinationlabel"> - <x>185</x> - <y>149</y> - </hint> - </hints> - </connection> - <connection> - <sender>blue_slider</sender> - <signal>sliderMoved(int)</signal> - <receiver>blue_value</receiver> - <slot>setNum(int)</slot> - <hints> - <hint type="sourcelabel"> - <x>173</x> - <y>172</y> - </hint> - <hint type="destinationlabel"> - <x>185</x> - <y>172</y> - </hint> - </hints> - </connection> - <connection> - <sender>quit_button</sender> - <signal>clicked()</signal> + <sender>buttonBox</sender> + <signal>accepted()</signal> <receiver>ColorLabel</receiver> - <slot>close()</slot> + <slot>accept()</slot> <hints> <hint type="sourcelabel"> - <x>186</x> - <y>235</y> + <x>531</x> + <y>482</y> </hint> <hint type="destinationlabel"> - <x>193</x> - <y>209</y> + <x>487</x> + <y>501</y> </hint> </hints> </connection> <connection> - <sender>red_slider</sender> - <signal>sliderMoved(int)</signal> - <receiver>red_value</receiver> - <slot>setNum(int)</slot> + <sender>buttonBox</sender> + <signal>rejected()</signal> + <receiver>ColorLabel</receiver> + <slot>reject()</slot> <hints> <hint type="sourcelabel"> - <x>114</x> - <y>126</y> + <x>657</x> + <y>479</y> </hint> <hint type="destinationlabel"> - <x>185</x> - <y>126</y> + <x>689</x> + <y>499</y> </hint> </hints> </connection> diff --git a/forms/interface.ui b/forms/interface.ui index a9b785030831af89fad351a64b0cfbb9d0fbf74b..4bcf62af41ea9c23add7fe8c6d85152f2b7ded16 100644 --- a/forms/interface.ui +++ b/forms/interface.ui @@ -444,59 +444,16 @@ pattern recorded :</string> <layout class="QFormLayout" name="formLayout"> <item row="0" column="0" colspan="2"> <layout class="QGridLayout" name="statesNeighborhoodLayout_3"> - <item row="0" column="2"> + <item row="0" column="0"> <widget class="QPushButton" name="statesSettingsButton"> - <property name="text"> - <string>States settings (color...)</string> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> </property> - </widget> - </item> - <item row="0" column="1"> - <widget class="QComboBox" name="nbrStatesComboBox"> - <item> - <property name="text"> - <string>2</string> - </property> - </item> - <item> - <property name="text"> - <string>3</string> - </property> - </item> - <item> - <property name="text"> - <string>4</string> - </property> - </item> - <item> - <property name="text"> - <string>5</string> - </property> - </item> - <item> - <property name="text"> - <string>6</string> - </property> - </item> - <item> - <property name="text"> - <string>7</string> - </property> - </item> - <item> - <property name="text"> - <string>8</string> - </property> - </item> - </widget> - </item> - <item row="0" column="0"> - <widget class="QLabel" name="nbrStatesLabel"> <property name="text"> - <string>Number of states :</string> - </property> - <property name="buddy"> - <cstring>nbrStatesComboBox</cstring> + <string>Alphabet settings</string> </property> </widget> </item> @@ -599,7 +556,7 @@ pattern recorded :</string> <x>0</x> <y>0</y> <width>1068</width> - <height>26</height> + <height>25</height> </rect> </property> <widget class="QMenu" name="menuFichier"> diff --git a/include/alphabet.hpp b/include/alphabet.hpp index a6187d992157de6726bae595867945d489156a78..5245491cefd7082d27e34b6ecc3c98887db1ca3d 100644 --- a/include/alphabet.hpp +++ b/include/alphabet.hpp @@ -60,8 +60,10 @@ public: //! Affecte l'identifiant d'état à un état void setState(unsigned int i, const state& s); + //! \brief Supprime les états de l'alphabet. void clearAlphabet() {etats.clear();} + //! \brief Supprime le dernier élément ajouté. void deleleLastState() {etats.pop_back();} diff --git a/include/colorlabel.h b/include/colorlabel.h new file mode 100644 index 0000000000000000000000000000000000000000..23a60176fc18ad1465674eaa7018598a2659b53a --- /dev/null +++ b/include/colorlabel.h @@ -0,0 +1,43 @@ +#ifndef COLORLABEL_H +#define COLORLABEL_H + +#include <QDialog> +#include "state.hpp" +#include "stateColor.hpp" +#include "alphabet.hpp" +#include <QListWidget> + +namespace Ui { +class ColorLabel; +} + +//! \brief Classe permettant l'édition des états de l'alphabet. +class ColorLabel : public QDialog +{ + Q_OBJECT + +public: + explicit ColorLabel(const Alphabet& a, QWidget *parent = nullptr); + ~ColorLabel(); + +public: + //! \brief Retourne l'alphabet tel qu'édité par l'utilisateur. + Alphabet getAlphabet() const + { return a; } + +private slots: + void generateState(); // Génère notre état en cliquant sur le bouton "Generate" + void randomGenerator(); // Génère un état aléatoire + void daltonianMode(); // Active le Mode Daltonien : Génère autant d'états que spécifié dans l'interface de façon adaptée aux Daltoniens + void resetMode(); // La fonction resetMode permet de remettre la liste et l'alphabet "à zéro" (on garde tout de même l'état par défaut) + void removeState(); // La fonction removeState permet de retirer le dernier état de l'alphabet + void loadStateID(unsigned int); // La fonction idPath permet de parcourir la liste des états et d'avoir un affiche du nom et de la couleur sur l'interface + void pickColor(); + +private: + Ui::ColorLabel *ui; + Alphabet a; + unsigned current_id; +}; + +#endif // COLORLABEL_H diff --git a/src/colorlabel.cpp b/src/colorlabel.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b77792cee23a45af549dbb45c714d593ba47f9f6 --- /dev/null +++ b/src/colorlabel.cpp @@ -0,0 +1,142 @@ +#include "colorlabel.h" +#include "ui_colorlabel.h" +#include "state.hpp" +#include "stateColor.hpp" +#include "alphabet.hpp" +#include "interface.hpp" +#include <stdlib.h> +#include <string> +#include <QListWidget> +#include <QColorDialog> + +#include "constantes.hpp" + +ColorLabel::ColorLabel(const Alphabet &in_a, QWidget *parent) : + QDialog(parent), + ui(new Ui::ColorLabel) +{ + ui->setupUi(this); + + ui->color_label->setAutoFillBackground(true); + + connect(ui->generate_button, SIGNAL(clicked()), this, SLOT(generateState())); + connect(ui->random_button, SIGNAL(clicked()), this, SLOT(randomGenerator())); + connect(ui->daltonian_button, SIGNAL(clicked()), this, SLOT(daltonianMode())); // Pas sûr pour cette ligne, mon but ici est d'aller chercher la valeur + // présente dans nbrStatesComboBox, c'est à dire la valeur du nombre d'états que l'on peut modifier sur l'interface interface.ui + connect(ui->reset_button, SIGNAL(clicked()), this, SLOT(resetMode())); + connect(ui->remove_button, SIGNAL(clicked()), this, SLOT(removeState())); + connect(ui->pick_button, SIGNAL(clicked()), this, SLOT(pickColor())); + connect(ui->state_list, &QListWidget::currentRowChanged, this, [this](int id) + { + current_id = id; + if (id >= 0) + loadStateID(id); + }); + + a = in_a; + current_id = 0; + ui->state_list->clear(); + for (unsigned i = 0; i < a.taille(); ++i) + ui->state_list->addItem(QString::fromStdString(a.getState(i).getStateLabel())); + loadStateID(0); +} + +ColorLabel::~ColorLabel() +{ + delete ui; +} + +void ColorLabel::generateState(){ + if(a.taille() >= MAX_ETATS) // On vérifie qu'il reste encore de la place dans l'alphabet + { + throw AlphabetException("Nombre d'états maximal atteint"); + } + else { + std::string string_name_state = ui->state_label->text().toStdString(); // On passe notre QString en string pour pouvoir utiliser le constructeur + state newstate = state(stateColor(0,0,0),string_name_state); // Création de notre nouvel état + a.newEtat(newstate); // Ajout du nouvel état dans l'alphabet + ui->state_list->addItem(ui->state_label->text()); // Ajout du nouvel état dans la liste + } +} + + +void ColorLabel::randomGenerator(){ + unsigned int r = rand() % 256; // On génère aléatoirement nos couleurs + unsigned int g = rand() % 256; + unsigned int b = rand() % 256; + + a.setState(current_id, state(stateColor(r, g, b), a.getState(current_id).getStateLabel())); + + QPalette pal = ui->color_label->palette(); + pal.setColor(QPalette::Window, QColor(r, g, b)); + ui->color_label->setPalette(pal); +} + + +void ColorLabel::daltonianMode(){ + ui->state_list->clear(); // On vide toujours la liste quand on active le mode Daltonien + a.clearAlphabet(); + + // Création des états à partir du constructeur + state black = state(stateColor(0,0,0),"Black"); + state white = state(stateColor(255,255,255),"White"); + state blue = state(stateColor(0,0,255),"Blue"); + state pink = state(stateColor(255,0,255),"Pink"); + state red = state(stateColor(255,0,0),"Red"); + state green = state(stateColor(0,255,0),"Green"); + state orange = state(stateColor(255,127,0),"Orange"); + state grey = state(stateColor(127,127,127),"Grey"); + + std::vector<state> daltonianstates; + daltonianstates.resize(8, state{stateColor(0, 0, 0)}); + daltonianstates[0]=black; + daltonianstates[1]=white; + daltonianstates[2]=blue; + daltonianstates[3]=pink; + daltonianstates[4]=red; + daltonianstates[5]=green; + daltonianstates[6]=orange; + daltonianstates[7]=grey; + + for(unsigned int i=0; i< daltonianstates.size() ; i++){ // Boucle qui crée le nombre d'états en fonction du nombre désiré + a.newEtat(daltonianstates[i]); // Crée et ajoute l'état dans l'alphabet + ui->state_list->addItem(QString::fromStdString(daltonianstates[i].getStateLabel())); // Ajoute l'état dans la liste + } +} + +void ColorLabel::resetMode(){ + ui->state_list->clear(); // On vide la liste + ui->state_list->addItem("Default state"); + a.clearAlphabet(); + a.newEtat(state{stateColor{255, 255, 255}}); //On recrée toujours l'état par défaut +} + +void ColorLabel::removeState(){ + if (a.taille() > 1) + { + ui->state_list->takeItem(a.taille()-1); // On retire le dernier élément ajouté + a.deleleLastState(); + } +} + +void ColorLabel::loadStateID(unsigned int current_id){ + assert(current_id < a.taille()); + + state state = a.getState(current_id); + ui->state_label->setText(QString::fromStdString(state.getStateLabel())); // On modifie le state_label en fonction du nom de l'état + + QColor color = QColor(state.getColor().getRed(), state.getColor().getGreen(), state.getColor().getBlue()); + QPalette pal = ui->color_label->palette(); + pal.setColor(QPalette::Window, color); + ui->color_label->setPalette(pal); +} + +void ColorLabel::pickColor() +{ + QColor color = QColorDialog::getColor(); + a.setState(current_id, state(stateColor(color.red(), color.green(), color.blue()), a.getState(current_id).getStateLabel())); + + QPalette pal = ui->color_label->palette(); + pal.setColor(QPalette::Window, color); + ui->color_label->setPalette(pal); +} diff --git a/src/gridview.cpp b/src/gridview.cpp index 2ad8a9a391c08348b9a33f4afe7960d1ac309c04..321ab499c50b3571b617c1bae8961640ab1ced6d 100644 --- a/src/gridview.cpp +++ b/src/gridview.cpp @@ -301,12 +301,6 @@ GridView::GridView(QWidget *parent) layout->addWidget(new QLabel("Maintenir SHIFT pour déplacer la grille; Molette ou CTRL+/CTRL- pour zoomer", this)); setLayout(layout); - 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); - m_drag_drop_handler = new DragDropHandlerItem(*this); m_scene->addItem(m_drag_drop_handler); @@ -317,6 +311,12 @@ GridView::GridView(QWidget *parent) Grid default_grid(m_height, m_width); load_grid(default_grid); + 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); + connect(m_zoom, &detail::Graphics_view_zoom::zoomed, this, [this] { emit zoom_changed(cell_screen_size()); @@ -332,6 +332,9 @@ void GridView::set_alphabet(const Alphabet &alph) m_alph = alph; // Default to using the first non-null state as the current pen set_current_pen(1); + // Reload the current grid to update the colors + load_grid(get_grid()); + update_gridview(); } const Alphabet &GridView::alphabet() const diff --git a/src/interface.cpp b/src/interface.cpp index 8919f180a05f32f69c771486ec8e0075ed4e3c6e..099a176cbaf925d199add5d2b024c55d6468503b 100644 --- a/src/interface.cpp +++ b/src/interface.cpp @@ -11,6 +11,7 @@ #include "modelloadingdialog.hpp" #include "configurationloadingdialog.hpp" #include "neighborhoodDialog.hpp" +#include "colorlabel.h" #include <QJsonArray> #include <QDate> @@ -37,6 +38,15 @@ MainWindow::MainWindow(QWidget *parent) connect(ui->action_save_struct, &QAction::triggered, this, &MainWindow::afficher_interface_sauvegarde_structure); connect(ui->struct_library, &StructureLibraryView::structure_copied, this, &MainWindow::copy_structure_clicked); connect(ui->grid_view, &GridView::zoom_changed, ui->struct_library, &StructureLibraryView::update_cell_pixel_size); + connect(ui->statesSettingsButton, &QPushButton::clicked, this, [this] + { + ColorLabel* dialog = new ColorLabel(simulation.getAlphabet(), this); + if (dialog->exec()) + { + simulation.setAlphabet(dialog->getAlphabet()); + ui->grid_view->set_alphabet(dialog->getAlphabet()); + } + }); connect(ui->transition_list, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this](int) { update_transition_settings(); }); connect(ui->action_propos_de_Cellulut, &QAction::triggered, this, [this](bool) @@ -316,7 +326,7 @@ void MainWindow::update_neighborhood_settings() void MainWindow::enable_rule_customization() { - ui->simulation_tab->setEnabled(false); + //ui->simulation_tab->setEnabled(false); ui->customize_button->setText("Cancel customization"); ui->rule_settings->setEnabled(true); m_customizing = true; @@ -324,7 +334,7 @@ void MainWindow::enable_rule_customization() void MainWindow::disable_rule_customization() { - ui->simulation_tab->setEnabled(true); + //ui->simulation_tab->setEnabled(true); ui->customize_button->setEnabled(true); ui->rule_settings->setEnabled(false); ui->customize_button->setText("Customize..."); @@ -396,6 +406,7 @@ void MainWindow::load_model(const QJsonObject &obj) simulation.setNeighborhoodRule(m_neighborhood_rule); simulation.setTransitionRule(m_transition_rule); simulation.setAlphabet(alpha); + ui->grid_view->set_alphabet(alpha); m_loaded_model = obj; } diff --git a/src/src.pro b/src/src.pro index 1de401f2e723c89be433ad9825ff4781780d20f9..ba12326738e8b5482cbb588266ad5bd3a94f690a 100644 --- a/src/src.pro +++ b/src/src.pro @@ -15,7 +15,7 @@ QMAKE_CXXFLAGS += -O3 -g INCLUDEPATH += ../include ../include/transition_rules ../include/neighborhood_rules SOURCES += \ - ../forms/colorlabel.cpp \ + colorlabel.cpp \ alphabet.cpp \ mathexpr.cpp \ neighborhood_rules/arbitraryneighborhoodrule.cpp \ @@ -45,7 +45,7 @@ SOURCES += \ HEADERS += \ - ../forms/colorlabel.h \ + ../include/colorlabel.h \ ../include/automaton.hpp \ ../include/coord.hpp \ ../include/savingdialog.hpp \