diff --git a/forms/colorlabel.cpp b/forms/colorlabel.cpp index 219c0a7e3c2dc67e35aaa5b43ad8791e941bc861..9d919f6835f01ab9458d145806b23bccdd7bd10c 100644 --- a/forms/colorlabel.cpp +++ b/forms/colorlabel.cpp @@ -3,6 +3,7 @@ #include "state.hpp" #include "stateColor.hpp" #include "alphabet.hpp" +#include "interface.hpp" #include <stdlib.h> #include <string> #include <QListWidget> @@ -14,7 +15,12 @@ ColorLabel::ColorLabel(QWidget *parent) : 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,nbStates))); + 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() @@ -23,10 +29,16 @@ ColorLabel::~ColorLabel() } void ColorLabel::generateState(Alphabet a, QString name_state, unsigned int r, unsigned int g, unsigned int b){ - 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 + 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 + } } @@ -43,6 +55,7 @@ void ColorLabel::randomGenerator(Alphabet a, QString name_state){ 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"); @@ -54,24 +67,53 @@ void ColorLabel::daltonianMode(Alphabet a, unsigned int nbStates){ state* orange = new state(stateColor(255,127,0),"Orange"); state* grey = new state(stateColor(127,127,127),"Grey"); - // Ajout des états dans la liste - ui->state_list->addItem(QString::fromStdString(black->getStateLabel())); - ui->state_list->addItem(QString::fromStdString(white->getStateLabel())); - ui->state_list->addItem(QString::fromStdString(blue->getStateLabel())); - ui->state_list->addItem(QString::fromStdString(pink->getStateLabel())); - ui->state_list->addItem(QString::fromStdString(red->getStateLabel())); - ui->state_list->addItem(QString::fromStdString(green->getStateLabel())); - ui->state_list->addItem(QString::fromStdString(orange->getStateLabel())); - ui->state_list->addItem(QString::fromStdString(grey->getStateLabel())); - - // Ajout des états dans l'Alphabet - a.newEtat(*black); - a.newEtat(*white); - a.newEtat(*blue); - a.newEtat(*pink); - a.newEtat(*red); - a.newEtat(*green); - a.newEtat(*orange); - a.newEtat(*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 index e118ac5993044b90a8db0e38a5568242d411b0b1..191b055ba06219de6d8e5e166801530c0e206ebb 100644 --- a/forms/colorlabel.h +++ b/forms/colorlabel.h @@ -23,7 +23,11 @@ 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); // La fonction est pour le moment implémentée pour 8 états fixe, à améliorer avec un nbStates désiré + 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; diff --git a/forms/colorlabel.ui b/forms/colorlabel.ui index 6c234f4283254021ac8adeee1263e50e9385cfd3..3a4f63a377aee8021c6f509bd9dc30910f6c5f74 100644 --- a/forms/colorlabel.ui +++ b/forms/colorlabel.ui @@ -6,131 +6,192 @@ <rect> <x>0</x> <y>0</y> - <width>470</width> - <height>232</height> + <width>708</width> + <height>504</height> </rect> </property> <property name="windowTitle"> <string>Form</string> </property> - <widget class="QWidget" name=""> + <widget class="QWidget" name="layoutWidget"> <property name="geometry"> <rect> <x>10</x> <y>10</y> - <width>444</width> - <height>194</height> + <width>441</width> + <height>261</height> </rect> </property> - <layout class="QHBoxLayout" name="horizontalLayout_7"> + <layout class="QVBoxLayout" name="verticalLayout_3"> <item> - <layout class="QVBoxLayout" name="verticalLayout_2"> + <layout class="QHBoxLayout" name="horizontalLayout_7"> <item> - <layout class="QHBoxLayout" name="horizontalLayout"> + <layout class="QVBoxLayout" name="verticalLayout_2"> <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> - <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"> + <layout class="QHBoxLayout" name="horizontalLayout"> <item> - <widget class="QLabel" name="label_3"> + <widget class="QLabel" name="label"> <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="orientation"> - <enum>Qt::Horizontal</enum> + <string>State name :</string> </property> </widget> </item> <item> - <widget class="QLabel" name="red_value"> + <widget class="QLineEdit" name="state_label"> <property name="text"> - <string>0</string> + <string>Empty_name</string> </property> </widget> </item> </layout> </item> <item> - <layout class="QHBoxLayout" name="horizontalLayout_3"> + <layout class="QHBoxLayout" name="horizontalLayout_9"> <item> - <widget class="QLabel" name="label_4"> + <widget class="QLabel" name="label_6"> <property name="text"> - <string>Green</string> + <string>State id :</string> </property> </widget> </item> <item> - <widget class="QSlider" name="green_slider"> + <widget class="QSpinBox" name="state_id"> <property name="maximum"> - <number>255</number> - </property> - <property name="orientation"> - <enum>Qt::Horizontal</enum> + <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> - <widget class="QLabel" name="green_value"> - <property name="text"> - <string>0</string> - </property> - </widget> + <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_4"> + <layout class="QHBoxLayout" name="horizontalLayout_5"> <item> - <widget class="QLabel" name="label_5"> + <widget class="QPushButton" name="generate_button"> <property name="text"> - <string>Blue</string> + <string>Create</string> </property> </widget> </item> <item> - <widget class="QSlider" name="blue_slider"> - <property name="maximum"> - <number>255</number> + <widget class="QPushButton" name="random_button"> + <property name="text"> + <string>Random</string> </property> - <property name="orientation"> - <enum>Qt::Horizontal</enum> + </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="QLabel" name="blue_value"> + <widget class="QPushButton" name="quit_button"> <property name="text"> - <string>0</string> + <string>Quit</string> </property> </widget> </item> @@ -139,73 +200,46 @@ </layout> </item> <item> - <layout class="QHBoxLayout" name="horizontalLayout_5"> - <item> - <widget class="QPushButton" name="generate_button"> - <property name="text"> - <string>Generate</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"> + <widget class="QListWidget" name="state_list"> <item> - <widget class="QPushButton" name="daltonian_button"> - <property name="text"> - <string>Daltonian Mode</string> - </property> - </widget> + <property name="text"> + <string>Nouvel élément</string> + </property> </item> - <item> - <widget class="QPushButton" name="quit_button"> - <property name="text"> - <string>Quit</string> - </property> - </widget> - </item> - </layout> + </widget> </item> </layout> </item> <item> - <widget class="QListWidget" name="state_list"> + <layout class="QHBoxLayout" name="horizontalLayout_8"> <item> - <property name="text"> - <string>Nouvel élément</string> - </property> + <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> - </widget> + <item> + <widget class="QPushButton" name="remove_button"> + <property name="text"> + <string>Remove last state</string> + </property> + </widget> + </item> + </layout> </item> </layout> </widget> </widget> <resources/> <connections> - <connection> - <sender>red_slider</sender> - <signal>sliderMoved(int)</signal> - <receiver>red_value</receiver> - <slot>setNum(int)</slot> - <hints> - <hint type="sourcelabel"> - <x>84</x> - <y>82</y> - </hint> - <hint type="destinationlabel"> - <x>185</x> - <y>82</y> - </hint> - </hints> - </connection> <connection> <sender>green_slider</sender> <signal>sliderMoved(int)</signal> @@ -213,12 +247,12 @@ <slot>setNum(int)</slot> <hints> <hint type="sourcelabel"> - <x>155</x> - <y>104</y> + <x>173</x> + <y>149</y> </hint> <hint type="destinationlabel"> - <x>187</x> - <y>107</y> + <x>185</x> + <y>149</y> </hint> </hints> </connection> @@ -229,12 +263,12 @@ <slot>setNum(int)</slot> <hints> <hint type="sourcelabel"> - <x>169</x> - <y>134</y> + <x>173</x> + <y>172</y> </hint> <hint type="destinationlabel"> - <x>182</x> - <y>132</y> + <x>185</x> + <y>172</y> </hint> </hints> </connection> @@ -245,8 +279,8 @@ <slot>close()</slot> <hints> <hint type="sourcelabel"> - <x>150</x> - <y>186</y> + <x>186</x> + <y>235</y> </hint> <hint type="destinationlabel"> <x>193</x> @@ -254,5 +288,21 @@ </hint> </hints> </connection> + <connection> + <sender>red_slider</sender> + <signal>sliderMoved(int)</signal> + <receiver>red_value</receiver> + <slot>setNum(int)</slot> + <hints> + <hint type="sourcelabel"> + <x>114</x> + <y>126</y> + </hint> + <hint type="destinationlabel"> + <x>185</x> + <y>126</y> + </hint> + </hints> + </connection> </connections> </ui> diff --git a/include/alphabet.hpp b/include/alphabet.hpp index e534d6b33ad56b6e5c465f78345e14163f40268e..a6187d992157de6726bae595867945d489156a78 100644 --- a/include/alphabet.hpp +++ b/include/alphabet.hpp @@ -60,6 +60,11 @@ public: //! Affecte l'identifiant d'état à un état void setState(unsigned int i, const state& s); + void clearAlphabet() {etats.clear();} + + void deleleLastState() {etats.pop_back();} + + }; #endif // ALPHABET_H