Skip to content
Snippets Groups Projects
Commit 394f7d73 authored by Yann Boucher's avatar Yann Boucher
Browse files
parents cea089f6 0cd9ea6d
No related branches found
No related tags found
No related merge requests found
Pipeline #79265 failed
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include "state.hpp" #include "state.hpp"
#include "stateColor.hpp" #include "stateColor.hpp"
#include "alphabet.hpp" #include "alphabet.hpp"
#include "interface.hpp"
#include <stdlib.h> #include <stdlib.h>
#include <string> #include <string>
#include <QListWidget> #include <QListWidget>
...@@ -14,7 +15,12 @@ ColorLabel::ColorLabel(QWidget *parent) : ...@@ -14,7 +15,12 @@ ColorLabel::ColorLabel(QWidget *parent) :
ui->setupUi(this); 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->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->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() ColorLabel::~ColorLabel()
...@@ -23,10 +29,16 @@ 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){ 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 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)
state* newstate = new state(stateColor(r,g,b),string_name_state); // Création de notre nouvel état throw AlphabetException("Nombre d'états maximal atteint");
a.newEtat(*newstate); // Ajout du nouvel état dans l'alphabet }
ui->state_list->addItem(name_state); // Ajout du nouvel état dans la liste 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){ ...@@ -43,6 +55,7 @@ void ColorLabel::randomGenerator(Alphabet a, QString name_state){
void ColorLabel::daltonianMode(Alphabet a, unsigned int nbStates){ void ColorLabel::daltonianMode(Alphabet a, unsigned int nbStates){
ui->state_list->clear(); // On vide toujours la liste quand on active le mode Daltonien ui->state_list->clear(); // On vide toujours la liste quand on active le mode Daltonien
a.clearAlphabet();
// Création des états à partir du constructeur // Création des états à partir du constructeur
state* black = new state(stateColor(0,0,0),"Black"); state* black = new state(stateColor(0,0,0),"Black");
...@@ -54,24 +67,53 @@ void ColorLabel::daltonianMode(Alphabet a, unsigned int nbStates){ ...@@ -54,24 +67,53 @@ void ColorLabel::daltonianMode(Alphabet a, unsigned int nbStates){
state* orange = new state(stateColor(255,127,0),"Orange"); state* orange = new state(stateColor(255,127,0),"Orange");
state* grey = new state(stateColor(127,127,127),"Grey"); state* grey = new state(stateColor(127,127,127),"Grey");
// Ajout des états dans la liste state* daltonianstates [8];
ui->state_list->addItem(QString::fromStdString(black->getStateLabel())); daltonianstates[0]=black;
ui->state_list->addItem(QString::fromStdString(white->getStateLabel())); daltonianstates[1]=white;
ui->state_list->addItem(QString::fromStdString(blue->getStateLabel())); daltonianstates[2]=blue;
ui->state_list->addItem(QString::fromStdString(pink->getStateLabel())); daltonianstates[3]=pink;
ui->state_list->addItem(QString::fromStdString(red->getStateLabel())); daltonianstates[4]=red;
ui->state_list->addItem(QString::fromStdString(green->getStateLabel())); daltonianstates[5]=green;
ui->state_list->addItem(QString::fromStdString(orange->getStateLabel())); daltonianstates[6]=orange;
ui->state_list->addItem(QString::fromStdString(grey->getStateLabel())); daltonianstates[7]=grey;
// Ajout des états dans l'Alphabet for(unsigned int i=0; i<nbStates ; i++){ // Boucle qui crée le nombre d'états en fonction du nombre désiré
a.newEtat(*black); a.newEtat(*daltonianstates[i]); // Crée et ajoute l'état dans l'alphabet
a.newEtat(*white); ui->state_list->addItem(QString::fromStdString(daltonianstates[i]->getStateLabel())); // Ajoute l'état dans la liste
a.newEtat(*blue); }
a.newEtat(*pink);
a.newEtat(*red); ui->state_id->setMaximum(a.taille()); // Ajout de l'identifiant du nouvel état
a.newEtat(*green);
a.newEtat(*orange);
a.newEtat(*grey); }
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()));
} }
...@@ -23,7 +23,11 @@ public slots: ...@@ -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 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 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: private:
Ui::ColorLabel *ui; Ui::ColorLabel *ui;
......
...@@ -6,131 +6,192 @@ ...@@ -6,131 +6,192 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>470</width> <width>708</width>
<height>232</height> <height>504</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>Form</string> <string>Form</string>
</property> </property>
<widget class="QWidget" name=""> <widget class="QWidget" name="layoutWidget">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>10</x> <x>10</x>
<y>10</y> <y>10</y>
<width>444</width> <width>441</width>
<height>194</height> <height>261</height>
</rect> </rect>
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout_7"> <layout class="QVBoxLayout" name="verticalLayout_3">
<item> <item>
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QHBoxLayout" name="horizontalLayout_7">
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QVBoxLayout" name="verticalLayout_2">
<item> <item>
<widget class="QLabel" name="label"> <layout class="QHBoxLayout" name="horizontalLayout">
<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">
<item> <item>
<widget class="QLabel" name="label_3"> <widget class="QLabel" name="label">
<property name="text"> <property name="text">
<string>Red</string> <string>State name :</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>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLabel" name="red_value"> <widget class="QLineEdit" name="state_label">
<property name="text"> <property name="text">
<string>0</string> <string>Empty_name</string>
</property> </property>
</widget> </widget>
</item> </item>
</layout> </layout>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_3"> <layout class="QHBoxLayout" name="horizontalLayout_9">
<item> <item>
<widget class="QLabel" name="label_4"> <widget class="QLabel" name="label_6">
<property name="text"> <property name="text">
<string>Green</string> <string>State id :</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QSlider" name="green_slider"> <widget class="QSpinBox" name="state_id">
<property name="maximum"> <property name="maximum">
<number>255</number> <number>0</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property> </property>
</widget> </widget>
</item> </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> <item>
<widget class="QLabel" name="green_value"> <layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="text"> <item>
<string>0</string> <widget class="QLabel" name="label_3">
</property> <property name="text">
</widget> <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> </item>
</layout> </layout>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_4"> <layout class="QHBoxLayout" name="horizontalLayout_5">
<item> <item>
<widget class="QLabel" name="label_5"> <widget class="QPushButton" name="generate_button">
<property name="text"> <property name="text">
<string>Blue</string> <string>Create</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QSlider" name="blue_slider"> <widget class="QPushButton" name="random_button">
<property name="maximum"> <property name="text">
<number>255</number> <string>Random</string>
</property> </property>
<property name="orientation"> </widget>
<enum>Qt::Horizontal</enum> </item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QPushButton" name="update_button">
<property name="text">
<string>Update</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLabel" name="blue_value"> <widget class="QPushButton" name="quit_button">
<property name="text"> <property name="text">
<string>0</string> <string>Quit</string>
</property> </property>
</widget> </widget>
</item> </item>
...@@ -139,73 +200,46 @@ ...@@ -139,73 +200,46 @@
</layout> </layout>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_5"> <widget class="QListWidget" name="state_list">
<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">
<item> <item>
<widget class="QPushButton" name="daltonian_button"> <property name="text">
<property name="text"> <string>Nouvel élément</string>
<string>Daltonian Mode</string> </property>
</property>
</widget>
</item> </item>
<item> </widget>
<widget class="QPushButton" name="quit_button">
<property name="text">
<string>Quit</string>
</property>
</widget>
</item>
</layout>
</item> </item>
</layout> </layout>
</item> </item>
<item> <item>
<widget class="QListWidget" name="state_list"> <layout class="QHBoxLayout" name="horizontalLayout_8">
<item> <item>
<property name="text"> <widget class="QPushButton" name="daltonian_button">
<string>Nouvel élément</string> <property name="text">
</property> <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> <item>
<widget class="QPushButton" name="remove_button">
<property name="text">
<string>Remove last state</string>
</property>
</widget>
</item>
</layout>
</item> </item>
</layout> </layout>
</widget> </widget>
</widget> </widget>
<resources/> <resources/>
<connections> <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> <connection>
<sender>green_slider</sender> <sender>green_slider</sender>
<signal>sliderMoved(int)</signal> <signal>sliderMoved(int)</signal>
...@@ -213,12 +247,12 @@ ...@@ -213,12 +247,12 @@
<slot>setNum(int)</slot> <slot>setNum(int)</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>155</x> <x>173</x>
<y>104</y> <y>149</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>187</x> <x>185</x>
<y>107</y> <y>149</y>
</hint> </hint>
</hints> </hints>
</connection> </connection>
...@@ -229,12 +263,12 @@ ...@@ -229,12 +263,12 @@
<slot>setNum(int)</slot> <slot>setNum(int)</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>169</x> <x>173</x>
<y>134</y> <y>172</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>182</x> <x>185</x>
<y>132</y> <y>172</y>
</hint> </hint>
</hints> </hints>
</connection> </connection>
...@@ -245,8 +279,8 @@ ...@@ -245,8 +279,8 @@
<slot>close()</slot> <slot>close()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>150</x> <x>186</x>
<y>186</y> <y>235</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>193</x> <x>193</x>
...@@ -254,5 +288,21 @@ ...@@ -254,5 +288,21 @@
</hint> </hint>
</hints> </hints>
</connection> </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> </connections>
</ui> </ui>
...@@ -60,6 +60,11 @@ public: ...@@ -60,6 +60,11 @@ public:
//! Affecte l'identifiant d'état à un état //! Affecte l'identifiant d'état à un état
void setState(unsigned int i, const state& s); void setState(unsigned int i, const state& s);
void clearAlphabet() {etats.clear();}
void deleleLastState() {etats.pop_back();}
}; };
#endif // ALPHABET_H #endif // ALPHABET_H
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment