Skip to content
Snippets Groups Projects
Commit ec3c13e6 authored by Arthur Detree's avatar Arthur Detree
Browse files

Implémentation Widget ColorLabel + Version 1 Mode Daltonien

parent 78ea73a0
No related branches found
No related tags found
No related merge requests found
Pipeline #78810 passed
#include "colorlabel.h"
#include "ui_colorlabel.h"
#include "state.hpp"
#include "stateColor.hpp"
#include "alphabet.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,nbStates)));
}
ColorLabel::~ColorLabel()
{
delete ui;
}
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
}
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
// 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");
// 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);
}
#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); // La fonction est pour le moment implémentée pour 8 états fixe, à améliorer avec un nbStates désiré
private:
Ui::ColorLabel *ui;
};
#endif // COLORLABEL_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ColorLabel</class>
<widget class="QWidget" name="ColorLabel">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>470</width>
<height>232</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<widget class="QWidget" name="">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>444</width>
<height>194</height>
</rect>
</property>
<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>
<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="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>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>
<widget class="QPushButton" name="daltonian_button">
<property name="text">
<string>Daltonian Mode</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>
<property name="text">
<string>Nouvel élément</string>
</property>
</item>
</widget>
</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>
<receiver>green_value</receiver>
<slot>setNum(int)</slot>
<hints>
<hint type="sourcelabel">
<x>155</x>
<y>104</y>
</hint>
<hint type="destinationlabel">
<x>187</x>
<y>107</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>169</x>
<y>134</y>
</hint>
<hint type="destinationlabel">
<x>182</x>
<y>132</y>
</hint>
</hints>
</connection>
<connection>
<sender>quit_button</sender>
<signal>clicked()</signal>
<receiver>ColorLabel</receiver>
<slot>close()</slot>
<hints>
<hint type="sourcelabel">
<x>150</x>
<y>186</y>
</hint>
<hint type="destinationlabel">
<x>193</x>
<y>209</y>
</hint>
</hints>
</connection>
</connections>
</ui>
......@@ -12,7 +12,6 @@ Représente les données graphiques associées à un état d'un alphabet.
#define STATE_H
#include <string>
#include "stateColor.hpp"
//! \brief Représente les données cosmétiques associées à un état.
......
......@@ -12,6 +12,7 @@ TEMPLATE = app
INCLUDEPATH += ../include ../include/transition_rules ../include/neighborhood_rules
SOURCES += \
../forms/colorlabel.cpp \
alphabet.cpp \
mathexpr.cpp \
neighborhood_rules/arbitraryneighborhoodrule.cpp \
......@@ -38,6 +39,7 @@ SOURCES += \
HEADERS += \
../forms/colorlabel.h \
../include/automaton.hpp \
../include/coord.hpp \
../include/savingdialog.hpp \
......@@ -69,6 +71,7 @@ HEADERS += \
../include/neighborhoodWidget.hpp
FORMS += \
../forms/colorlabel.ui \
../forms/interface.ui \
../forms/savingdialog.ui \
../forms/structurelibraryview.ui \
......
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