Compare commits

..

4 Commits

Author SHA1 Message Date
Giovanni-Josserand f08d7c5cbc Merge pull request 'dev' (#2) from dev into main
Reviewed-on: Giovanni-Josserand/FicheJDR#2
2025-07-14 21:32:56 +00:00
Giovanni 22e56df104 finish of close fiche button and add of start menu 2025-07-14 23:31:12 +02:00
Giovanni 24c4685cb2 add of fiche button 2025-07-10 17:53:53 +02:00
Giovanni 646ec2fb0c remove of visualisation and backPackTextEdit functional 2025-06-27 15:19:36 +02:00
68 changed files with 2154 additions and 1107 deletions
+3 -1
View File
@@ -12,12 +12,14 @@ SOURCES += \
character.cpp \
main.cpp \
mainwindow.cpp \
notepad.cpp
notepad.cpp \
textformatutils.cpp
HEADERS += \
character.h \
mainwindow.h \
notepad.h \
textformatutils.h
FORMS += \
mainwindow.ui \
Binary file not shown.
+4 -1
View File
@@ -5,7 +5,9 @@
#include <QJsonArray>
#include <QDebug>
Character::Character(){
Character::Character()
: age(0), niveau(0), taille(0), vie(0)
{
for(int i = 0; i<6; i++){skills.append(0);}
for(int i = 0; i<6; i++){skillsMod.append(0);}
for(int i = 0; i<18; i++){stats.append(0);}
@@ -31,6 +33,7 @@ Character::Character(QFile *file){
race = json["race"].toString();
classe = json["classe"].toString();
niveau = json["niveau"].toInt();
sexe = json["sexe"].toString();
taille = json["taille"].toDouble();
vie = json["vie"].toInt();
+1
View File
@@ -4,6 +4,7 @@
#include <QList>
#include <QFile>
using namespace std;
class Character{
+5 -5
View File
@@ -1,10 +1,10 @@
{
"age": 0,
"backPack": "",
"blocNote": "dghdgdgfgd",
"age": 1,
"backPack": "'(y'eyhrhyrhr",
"blocNote": "'(y'eyhrhyrhr",
"classe": "",
"image": "data/images/logo.png",
"name": "",
"name": "dfh",
"niveau": 0,
"race": "",
"sexe": "",
@@ -45,5 +45,5 @@
0
],
"taille": 0,
"vie": 6619181
"vie": 569
}
+2 -2
View File
@@ -1,10 +1,10 @@
{
"age": 0,
"backPack": "",
"blocNote": "sfsfsffsd",
"blocNote": "",
"classe": "",
"image": "data/images/logo.png",
"name": "Gio",
"name": "dgdfg",
"niveau": 0,
"race": "",
"sexe": "",
+49
View File
@@ -0,0 +1,49 @@
{
"age": 0,
"backPack": "fdzsfzf",
"blocNote": "egerger",
"classe": "",
"image": "data/images/logo.png",
"name": "ssfsf",
"niveau": 0,
"race": "",
"sexe": "",
"skills": [
0,
0,
0,
0,
0,
0
],
"skillsMod": [
0,
0,
0,
0,
0,
0
],
"stats": [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
],
"taille": 0,
"vie": 0
}
+49
View File
@@ -0,0 +1,49 @@
{
"age": 0,
"backPack": "",
"blocNote": "",
"classe": "",
"image": "data/images/logo.png",
"name": "ssfsf",
"niveau": 0,
"race": "",
"sexe": "",
"skills": [
0,
0,
0,
0,
0,
0
],
"skillsMod": [
0,
0,
0,
0,
0,
0
],
"stats": [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
],
"taille": 0,
"vie": 0
}
+2 -2
View File
@@ -1,7 +1,7 @@
{
"age": 0,
"backPack": "",
"blocNote": "ssd",
"blocNote": "",
"classe": "",
"image": "data/images/logo.png",
"name": "",
@@ -45,5 +45,5 @@
0
],
"taille": 0,
"vie": 6619181
"vie": 0
}
+49
View File
@@ -0,0 +1,49 @@
{
"age": 0,
"backPack": "",
"blocNote": "",
"classe": "",
"image": "data/images/logo.png",
"name": "ccc",
"niveau": 0,
"race": "",
"sexe": "",
"skills": [
0,
0,
0,
0,
0,
0
],
"skillsMod": [
0,
0,
0,
0,
0,
0
],
"stats": [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
],
"taille": 0,
"vie": 0
}
+49
View File
@@ -0,0 +1,49 @@
{
"age": 0,
"backPack": "",
"blocNote": "",
"classe": "",
"image": "data/images/logo.png",
"name": "",
"niveau": 0,
"race": "",
"sexe": "",
"skills": [
0,
0,
0,
0,
0,
0
],
"skillsMod": [
0,
0,
0,
0,
0,
0
],
"stats": [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
],
"taille": 0,
"vie": 0
}
+49
View File
@@ -0,0 +1,49 @@
{
"age": 0,
"backPack": "",
"blocNote": "",
"classe": "",
"image": "data/images/logo.png",
"name": "",
"niveau": 0,
"race": "",
"sexe": "",
"skills": [
0,
0,
0,
0,
0,
0
],
"skillsMod": [
0,
0,
0,
0,
0,
0
],
"stats": [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
],
"taille": 0,
"vie": 0
}
+49
View File
@@ -0,0 +1,49 @@
{
"age": 0,
"backPack": "",
"blocNote": "",
"classe": "",
"image": "data/images/logo.png",
"name": "s",
"niveau": 0,
"race": "",
"sexe": "",
"skills": [
0,
0,
0,
0,
0,
0
],
"skillsMod": [
0,
0,
0,
0,
0,
0
],
"stats": [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
],
"taille": 0,
"vie": 0
}
+49
View File
@@ -0,0 +1,49 @@
{
"age": 0,
"backPack": "",
"blocNote": "",
"classe": "",
"image": "data/images/logo.png",
"name": "zhfzui",
"niveau": 0,
"race": "",
"sexe": "",
"skills": [
0,
0,
0,
0,
0,
0
],
"skillsMod": [
0,
0,
0,
0,
0,
0
],
"stats": [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
],
"taille": 0,
"vie": 0
}
+49
View File
@@ -0,0 +1,49 @@
{
"age": 0,
"backPack": "",
"blocNote": "",
"classe": "",
"image": "data/images/logo.png",
"name": "",
"niveau": 0,
"race": "",
"sexe": "",
"skills": [
0,
0,
0,
0,
0,
0
],
"skillsMod": [
0,
0,
0,
0,
0,
0
],
"stats": [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
],
"taille": 0,
"vie": 0
}
+49
View File
@@ -0,0 +1,49 @@
{
"age": 0,
"backPack": "",
"blocNote": "",
"classe": "",
"image": "data/images/logo.png",
"name": "",
"niveau": 0,
"race": "",
"sexe": "",
"skills": [
0,
0,
0,
0,
0,
0
],
"skillsMod": [
0,
0,
0,
0,
0,
0
],
"stats": [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
],
"taille": 0,
"vie": 0
}
+49
View File
@@ -0,0 +1,49 @@
{
"age": 0,
"backPack": "",
"blocNote": "",
"classe": "",
"image": "data/images/logo.png",
"name": "",
"niveau": 0,
"race": "",
"sexe": "",
"skills": [
0,
0,
0,
0,
0,
0
],
"skillsMod": [
0,
0,
0,
0,
0,
0
],
"stats": [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
],
"taille": 0,
"vie": 0
}
+49
View File
@@ -0,0 +1,49 @@
{
"age": 0,
"backPack": "",
"blocNote": "",
"classe": "",
"image": "data/images/logo.png",
"name": "",
"niveau": 0,
"race": "",
"sexe": "",
"skills": [
0,
0,
0,
0,
0,
0
],
"skillsMod": [
0,
0,
0,
0,
0,
0
],
"stats": [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
],
"taille": 0,
"vie": 0
}
+49
View File
@@ -0,0 +1,49 @@
{
"age": 0,
"backPack": "",
"blocNote": "",
"classe": "",
"image": "data/images/logo.png",
"name": "fsfs",
"niveau": 0,
"race": "",
"sexe": "",
"skills": [
0,
0,
0,
0,
0,
0
],
"skillsMod": [
0,
0,
0,
0,
0,
0
],
"stats": [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
],
"taille": 0,
"vie": 0
}
+272 -34
View File
@@ -1,5 +1,6 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "textFormatUtils.h"
#include <iostream>
#include <QFile>
@@ -8,6 +9,9 @@
#include <QJsonObject>
#include <QJsonArray>
#include <QJsonValue>
#include <QPushButton>
#include <QTimer>
using namespace std;
@@ -18,24 +22,35 @@ MainWindow::MainWindow(QWidget *parent)
ui->setupUi(this);
notePad = new NotePad();
connect(notePad, &NotePad::demandeSauvegarde, this, &MainWindow::recevoirSauvegarde);
Character* c = new Character();
currentCharacter = c;
characters.append(c);
ui->ageLineEdit->setValidator(new QIntValidator(0, 999999, ui->ageLineEdit));
ui->niveauLineEdit->setValidator(new QIntValidator(0, 999999, ui->niveauLineEdit));
ui->tailleLineEdit->setValidator(new QDoubleValidator(0.0, 999999.0, 1,ui->tailleLineEdit));
loadImage(QString("data/images/logo.png"));
ui->BackPack->setHidden(true);
ui->Edition->setHidden(true);
ui->Fenetre->setStyleSheet("background-color: #f2f2f2;");
QPushButton* button;
button = new QPushButton("+", ui->Fenetre);
button->setObjectName(QString("addFiche"));
button->setFixedSize(35, 35);
button->move(sizeButtonFiche*idFicheButtonCounter, 0);
qobject_cast<QPushButton*>(ui->Fenetre->children()[0])->setStyleSheet("background-color: transparent;border:none;");
button->show();
connect(button, &QPushButton::clicked, this, &MainWindow::ajouter_fiche_clicked);
for(int i=0; i<ui->menuEdition->actions().size(); i++){
ui->menuEdition->actions()[i]->setDisabled(true);
}
}
MainWindow::~MainWindow()
{
delete ui;
delete notePad;
delete currentCharacter;
for(Character* c : characters) {
delete c;
}
for(Character* c : characters) {delete c;}
}
@@ -52,17 +67,49 @@ void MainWindow::loadNewCharacter(){
file.close();
Character* c = new Character(&file);
createNewCharacter(c, fileName);
currentCharacter = c;
characters.append(c);
createNewCharacter(c);
currentFile = fileName;
files.append(fileName);
}
void MainWindow::createNewCharacter(Character* p) {
void MainWindow::createNewCharacter(Character* p, QString s) {
if(characters.size() == 0){
ui->StartMenu->setHidden(true);
ui->BackPack->setHidden(true);
ui->Edition->setHidden(false);
}
delete ui->Fenetre->children().last();
addWindow(s);
notePad->setTexte(p->getTexteBlocNote());
ui->BackPackPlainTextEdit->setPlainText(p->getTexteBlocNote());
setUi(p);
if(s.toStdString() == ""){
currentCharacter = p;
characters.append(p);
setUi(p);
currentFile = s;
files.append(s);
}
for(int i=0; i<ui->Fenetre->children().size(); i++){
QPushButton* bt = qobject_cast<QPushButton*>(ui->Fenetre->children()[i]);
bt->setStyleSheet("background-color: #f2f2f2;");
}
qobject_cast<QPushButton*>(ui->Fenetre->children().last())->setStyleSheet("background-color: white;");
int nb = ui->Fenetre->children().size();
QPushButton* button;
button = new QPushButton("+", ui->Fenetre);
button->setObjectName(QString("addFiche"));
button->setFixedSize(35, 35);
button->move(nb*sizeButtonFiche, 0);
qobject_cast<QPushButton*>(ui->Fenetre->children().last())->setStyleSheet("background-color: transparent;border:none;");
button->show();
connect(button, &QPushButton::clicked, this, &MainWindow::ajouter_fiche_clicked);
}
@@ -91,7 +138,15 @@ void MainWindow::loadImage(QString fileName) {
void MainWindow::saveJson(){
QString fileName;
if (currentFile.isEmpty()) {
int indice = 0;
for (int i = 0; i < characters.size(); ++i) {
if (characters[i] == currentCharacter) {
indice = i;
}
}
QPushButton* button = qobject_cast<QPushButton*>(ui->Fenetre->children()[indice]);
if (button->objectName().toStdString() == "") {
fileName = QFileDialog::getSaveFileName(this, "Save");
currentFile = fileName;
} else {
@@ -103,9 +158,8 @@ void MainWindow::saveJson(){
return;
}
if(edition){
getUi();
}
notePad->getUi();
currentCharacter->setTexteBlocNote(notePad->getTexte());
QJsonObject json;
@@ -140,6 +194,13 @@ void MainWindow::saveJson(){
QJsonDocument doc(json);
file.write(doc.toJson());
file.close();
if (button) {
if (button->objectName() != currentFile) {
button->setObjectName(currentFile);
button->setText(extractFileName(currentFile));
}
}
}
void MainWindow::saveAsJson(){
@@ -153,9 +214,7 @@ void MainWindow::saveAsJson(){
setWindowTitle(fileName);
currentFile = fileName;
if(edition){
getUi();
}
notePad->getUi();
currentCharacter->setTexteBlocNote(notePad->getTexte());
QJsonObject json;
@@ -190,6 +249,22 @@ void MainWindow::saveAsJson(){
QJsonDocument doc(json);
file.write(doc.toJson());
file.close();
int indice = 0;
for (int i = 0; i < characters.size(); ++i) {
if (characters[i] == currentCharacter) {
indice = i;
}
}
QPushButton* button = qobject_cast<QPushButton*>(ui->Fenetre->children()[indice]);
if (button) {
if (button->objectName() != currentFile) {
button->setObjectName(currentFile);
button->setText(extractFileName(currentFile));
}
}
}
@@ -228,7 +303,7 @@ void MainWindow::getUi(){
}
}
currentCharacter->setStats(stats);
//currentCharacter->setImage();
currentCharacter->setTexteBackPack(ui->BackPackPlainTextEdit->toPlainText());
}
@@ -265,32 +340,32 @@ void MainWindow::setUi(Character* p){
spinBox->setValue(p->getStats()[i]);
}
}
ui->BackPackPlainTextEdit->setPlainText(p->getTexteBackPack());
loadImage(p->getImage());
}
void MainWindow::on_actionEditer_triggered(){
if(edition){
//Mode edition
}else{
//Mode visualisation
}
edition=!edition;
}
void MainWindow::on_actionBlocNote_triggered(){
this->notePad->show();
}
void MainWindow::recevoirSauvegarde(QString contenu){
currentCharacter->setTexteBlocNote(contenu);
saveJson();
}
void MainWindow::toogleBackPack(){
if(ui->BackPack->isHidden()){
ui->Edition->setHidden(true);
ui->BackPack->setHidden(false);
for(int i=0; i<ui->menuEdition->actions().size(); i++){
ui->menuEdition->actions()[i]->setDisabled(false);
}
}else{
ui->BackPack->setHidden(true);
ui->Edition->setHidden(false);
for(int i=0; i<ui->menuEdition->actions().size(); i++){
ui->menuEdition->actions()[i]->setDisabled(true);
}
}
}
void MainWindow::on_actionOuvrir_une_fiche_triggered(){this->loadNewCharacter();}
@@ -298,4 +373,167 @@ void MainWindow::on_actionNouvelle_fiche_triggered(){this->createNewCharacter(ne
void MainWindow::on_actionSauvegarder_triggered(){this->saveJson();}
void MainWindow::on_actionEnregistrer_sous_triggered(){this->saveAsJson();}
void MainWindow::on_actionFermer_triggered(){QApplication::quit();}
void MainWindow::on_pushButtonNewFiche_clicked(){this->createNewCharacter(new Character());}
void MainWindow::on_pushButtonOpenFiche_clicked(){this->loadNewCharacter();}
void MainWindow::on_actionCouleur_triggered(){TextFormatUtils::changeFontColor(this);}
void MainWindow::on_actionPolice_triggered(){TextFormatUtils::changeFont(this);}
void MainWindow::on_actionTaille_triggered(){TextFormatUtils::changeFontSize(this);}
void MainWindow::on_actionGras_triggered(){TextFormatUtils::toggleBold();}
void MainWindow::on_actionItalique_triggered(){TextFormatUtils::toggleItalic();}
void MainWindow::on_actionSouligner_triggered(){TextFormatUtils::toggleUnderline();}
void MainWindow::on_actionSurligner_triggered(){TextFormatUtils::toggleOverline();}
void MainWindow::changer_fiche_clicked(){changeCurrentCharacter();}
void MainWindow::ajouter_fiche_clicked(){this->createNewCharacter(new Character());}
void MainWindow::on_imagePushButton_clicked()
{
QString fileName = QFileDialog::getOpenFileName(this, "Open the file");
if (fileName.isEmpty()) return;
this->loadImage(fileName);
}
void MainWindow::on_actionBloc_note_triggered(){this->notePad->show();}
void MainWindow::on_actionCaract_ristiques_triggered(){this->toogleBackPack();}
void MainWindow::addWindow(const QString& s){
int nb = ui->Fenetre->children().size();
int widthBar = ui->Fenetre->size().width();
if((nb+1)*sizeButtonFiche + 35 > widthBar){
while((nb+1)*sizeButtonFiche + 35 > widthBar){
sizeButtonFiche--;
}
}
for(int i=0; i<nb; i++){
QWidget* widget = qobject_cast<QWidget*>(ui->Fenetre->children()[i]);
widget->setGeometry(i*sizeButtonFiche, 0, sizeButtonFiche, 35);
widget->show();
}
QPushButton* button;
if(s == ""){
button = new QPushButton("Sans titre", ui->Fenetre);
button->setObjectName(QString());
}else{
button = new QPushButton(extractFileName(s), ui->Fenetre);
button->setObjectName(s);
}
button->setGeometry(nb * sizeButtonFiche, 0, sizeButtonFiche, 35);
button->setProperty("id", idFicheButtonCounter);
button->show();
connect(button, &QPushButton::clicked, this, &MainWindow::changer_fiche_clicked);
QPushButton* closeButton = new QPushButton("X", button);
closeButton->setFixedSize(25, 25);
closeButton->move(button->width() - 28, (button->height()-25)/2);
closeButton->setStyleSheet("QPushButton { font-size: 10px; padding: 0px; }");
closeButton->raise();
closeButton->show();
connect(closeButton, &QPushButton::clicked, this, [=]() {
int id = button->property("id").toInt();
button->deleteLater();
QTimer::singleShot(0, this, [=]() {
int newNb = ui->Fenetre->children().size();
for(int i=0; i<newNb; i++){
QWidget* widget = qobject_cast<QWidget*>(ui->Fenetre->children()[i]);
widget->setGeometry(i*sizeButtonFiche, 0, sizeButtonFiche, 35);
widget->show();
}
int indice = 0;
bool supprCurent = false;
for(int i=0; i<characters.size(); i++){
if(id == i){
if(characters[i] == currentCharacter){
supprCurent = true;
indice = i;
if(i+1 != characters.size()){
currentCharacter = characters[i+1];
}else if(i>0){
currentCharacter = characters[i-1];
}
}
delete characters[i];
characters.remove(i);
break;
}
}
if(id == indice){
if(supprCurent){
for(int i=0; i<ui->Fenetre->children().size(); i++){
QPushButton* bt = qobject_cast<QPushButton*>(ui->Fenetre->children()[i]);
bt->setStyleSheet("background-color: #f2f2f2;");
}
if(indice + 1 != files.size()){
currentFile = files[indice+1];
setUi(currentCharacter);
notePad->setUi(currentCharacter->getTexteBlocNote());
qobject_cast<QPushButton*>(ui->Fenetre->children()[indice])->setStyleSheet("background-color: white;");
}else if(indice>0){
currentFile = files[indice-1];
setUi(currentCharacter);
notePad->setUi(currentCharacter->getTexteBlocNote());
qobject_cast<QPushButton*>(ui->Fenetre->children()[indice-1])->setStyleSheet("background-color: white;");
}else{
toogleStartMenu();
}
}
files.remove(indice);
}
idFicheButtonCounter = 0;
for(int i=0; i<ui->Fenetre->children().size()-1; i++){
ui->Fenetre->children()[i]->setProperty("id", idFicheButtonCounter);
idFicheButtonCounter++;
}
});
});
idFicheButtonCounter++;
}
QString MainWindow::extractFileName(QString s){
QFileInfo infoFichier(s);
return infoFichier.fileName();
}
void MainWindow::changeCurrentCharacter(){
getUi();
notePad->getUi();
currentCharacter->setTexteBlocNote(notePad->getTexte());
QPushButton* button = qobject_cast<QPushButton*>(sender());
if (!button) return;
int index = button->property("id").toInt();
if (index >= 0 && index < characters.size()) {
currentCharacter = characters[index];
currentFile = files[index];
setUi(currentCharacter);
notePad->setUi(currentCharacter->getTexteBlocNote());
} else {
qWarning("ID de fiche invalide !");
}
for(int i=0; i<ui->Fenetre->children().size(); i++){
QPushButton* bt = qobject_cast<QPushButton*>(ui->Fenetre->children()[i]);
bt->setStyleSheet("background-color: #f2f2f2;");
}
button->setStyleSheet("background-color: white;");
}
void MainWindow::toogleStartMenu(){
ui->BackPack->setHidden(true);
ui->Edition->setHidden(true);
ui->StartMenu->setHidden(false);
}
+27 -5
View File
@@ -5,6 +5,7 @@
#include "notepad.h"
#include <QMainWindow>
#include <QPushButton>
QT_BEGIN_NAMESPACE
namespace Ui {
@@ -21,32 +22,53 @@ public:
~MainWindow();
void loadImage(QString fileName);
void createNewCharacter(Character* p);
void createNewCharacter(Character* p, QString s = QString());
void loadNewCharacter();
void saveJson();
void saveAsJson();
void getUi();
void setUi(Character* p);
void toogleBackPack();
void addWindow(const QString& s = QString());
QString extractFileName(QString s);
void changeCurrentCharacter();
void changeTab(int index);
void layoutTabs();
void removeTab(int index);
void toogleStartMenu();
private slots:
void on_actionEditer_triggered();
void on_actionBlocNote_triggered();
void on_actionOuvrir_une_fiche_triggered();
void on_actionNouvelle_fiche_triggered();
void on_actionSauvegarder_triggered();
void on_actionEnregistrer_sous_triggered();
void on_actionFermer_triggered();
void on_imagePushButton_clicked();
void recevoirSauvegarde(QString contenu);
void on_actionBloc_note_triggered();
void on_actionCaract_ristiques_triggered();
void changer_fiche_clicked();
void ajouter_fiche_clicked();
void on_actionCouleur_triggered();
void on_actionPolice_triggered();
void on_actionTaille_triggered();
void on_actionGras_triggered();
void on_actionItalique_triggered();
void on_actionSouligner_triggered();
void on_actionSurligner_triggered();
void on_pushButtonNewFiche_clicked();
void on_pushButtonOpenFiche_clicked();
private:
Ui::MainWindow *ui;
NotePad *notePad;
bool edition = true;
bool backPack = false;
QString currentFile;
QList<Character*> characters;
QList<QString> files;
Character* currentCharacter;
int idFicheButtonCounter = 0;
int sizeButtonFiche = 100;
};
#endif // MAINWINDOW_H
+231 -57
View File
@@ -17,11 +17,26 @@
<property name="enabled">
<bool>true</bool>
</property>
<widget class="QFrame" name="Edition">
<property name="geometry">
<rect>
<x>0</x>
<y>35</y>
<width>800</width>
<height>590</height>
</rect>
</property>
<property name="frameShape">
<enum>QFrame::Shape::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Shadow::Raised</enum>
</property>
<widget class="QFrame" name="topFrame">
<property name="geometry">
<rect>
<x>0</x>
<y>2</y>
<y>0</y>
<width>800</width>
<height>278</height>
</rect>
@@ -34,7 +49,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>350</width>
<width>390</width>
<height>278</height>
</rect>
</property>
@@ -44,7 +59,7 @@
<widget class="QLabel" name="ageLabel">
<property name="geometry">
<rect>
<x>150</x>
<x>190</x>
<y>54</y>
<width>63</width>
<height>20</height>
@@ -64,7 +79,7 @@
</rect>
</property>
<property name="text">
<string>Logo</string>
<string/>
</property>
<property name="scaledContents">
<bool>true</bool>
@@ -73,7 +88,7 @@
<widget class="QLabel" name="nomLabel">
<property name="geometry">
<rect>
<x>150</x>
<x>190</x>
<y>17</y>
<width>63</width>
<height>20</height>
@@ -86,7 +101,7 @@
<widget class="QLineEdit" name="nomLineEdit">
<property name="geometry">
<rect>
<x>210</x>
<x>250</x>
<y>17</y>
<width>113</width>
<height>20</height>
@@ -96,7 +111,7 @@
<widget class="QLineEdit" name="ageLineEdit">
<property name="geometry">
<rect>
<x>210</x>
<x>250</x>
<y>54</y>
<width>113</width>
<height>20</height>
@@ -106,7 +121,7 @@
<widget class="QLabel" name="raceLabel">
<property name="geometry">
<rect>
<x>150</x>
<x>190</x>
<y>91</y>
<width>63</width>
<height>20</height>
@@ -119,7 +134,7 @@
<widget class="QLabel" name="niveauLabel">
<property name="geometry">
<rect>
<x>150</x>
<x>190</x>
<y>165</y>
<width>63</width>
<height>20</height>
@@ -132,7 +147,7 @@
<widget class="QLabel" name="classeLabel">
<property name="geometry">
<rect>
<x>150</x>
<x>190</x>
<y>128</y>
<width>63</width>
<height>20</height>
@@ -145,7 +160,7 @@
<widget class="QLabel" name="sexeLabel">
<property name="geometry">
<rect>
<x>150</x>
<x>190</x>
<y>202</y>
<width>63</width>
<height>20</height>
@@ -158,7 +173,7 @@
<widget class="QLabel" name="tailleLabel">
<property name="geometry">
<rect>
<x>150</x>
<x>190</x>
<y>239</y>
<width>63</width>
<height>20</height>
@@ -171,7 +186,7 @@
<widget class="QLineEdit" name="raceLineEdit">
<property name="geometry">
<rect>
<x>210</x>
<x>250</x>
<y>91</y>
<width>113</width>
<height>20</height>
@@ -181,7 +196,7 @@
<widget class="QLineEdit" name="classeLineEdit">
<property name="geometry">
<rect>
<x>210</x>
<x>250</x>
<y>128</y>
<width>113</width>
<height>20</height>
@@ -191,7 +206,7 @@
<widget class="QLineEdit" name="niveauLineEdit">
<property name="geometry">
<rect>
<x>210</x>
<x>250</x>
<y>165</y>
<width>113</width>
<height>20</height>
@@ -201,7 +216,7 @@
<widget class="QLineEdit" name="sexeLineEdit">
<property name="geometry">
<rect>
<x>210</x>
<x>250</x>
<y>202</y>
<width>113</width>
<height>20</height>
@@ -211,20 +226,33 @@
<widget class="QLineEdit" name="tailleLineEdit">
<property name="geometry">
<rect>
<x>210</x>
<x>250</x>
<y>239</y>
<width>113</width>
<height>20</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="imagePushButton">
<property name="geometry">
<rect>
<x>10</x>
<y>200</y>
<width>130</width>
<height>29</height>
</rect>
</property>
<property name="text">
<string>Choisir une image</string>
</property>
</widget>
</widget>
<widget class="QFrame" name="topRightFrame">
<property name="geometry">
<rect>
<x>350</x>
<x>390</x>
<y>0</y>
<width>450</width>
<width>411</width>
<height>278</height>
</rect>
</property>
@@ -494,9 +522,9 @@
<property name="geometry">
<rect>
<x>0</x>
<y>280</y>
<y>278</y>
<width>800</width>
<height>581</height>
<height>312</height>
</rect>
</property>
<property name="frameShape">
@@ -985,6 +1013,91 @@
</widget>
</widget>
</widget>
<widget class="QFrame" name="BackPack">
<property name="geometry">
<rect>
<x>0</x>
<y>35</y>
<width>800</width>
<height>590</height>
</rect>
</property>
<property name="frameShape">
<enum>QFrame::Shape::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Shadow::Raised</enum>
</property>
<widget class="QPlainTextEdit" name="BackPackPlainTextEdit">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>590</height>
</rect>
</property>
</widget>
</widget>
<widget class="QFrame" name="Fenetre">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>35</height>
</rect>
</property>
<property name="frameShape">
<enum>QFrame::Shape::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Shadow::Raised</enum>
</property>
</widget>
<widget class="QFrame" name="StartMenu">
<property name="geometry">
<rect>
<x>0</x>
<y>35</y>
<width>800</width>
<height>590</height>
</rect>
</property>
<property name="frameShape">
<enum>QFrame::Shape::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Shadow::Raised</enum>
</property>
<widget class="QPushButton" name="pushButtonNewFiche">
<property name="geometry">
<rect>
<x>340</x>
<y>216</y>
<width>121</width>
<height>29</height>
</rect>
</property>
<property name="text">
<string>Nouvelle fiche</string>
</property>
</widget>
<widget class="QPushButton" name="pushButtonOpenFiche">
<property name="geometry">
<rect>
<x>340</x>
<y>316</y>
<width>121</width>
<height>29</height>
</rect>
</property>
<property name="text">
<string>Ouvrir une fiche</string>
</property>
</widget>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
@@ -1004,21 +1117,29 @@
<addaction name="actionEnregistrer_sous"/>
<addaction name="actionFermer"/>
</widget>
<addaction name="menuFichier"/>
</widget>
<widget class="QStatusBar" name="statusbar"/>
<widget class="QToolBar" name="toolBar">
<property name="windowTitle">
<string>toolBar</string>
<widget class="QMenu" name="menuAffichage">
<property name="title">
<string>Affichage</string>
</property>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="actionEditer"/>
<addaction name="actionBlocNote"/>
<addaction name="actionCaract_ristiques"/>
<addaction name="actionBloc_note"/>
</widget>
<widget class="QMenu" name="menuEdition">
<property name="title">
<string>Edition</string>
</property>
<addaction name="actionCouleur"/>
<addaction name="actionPolice"/>
<addaction name="actionTaille"/>
<addaction name="separator"/>
<addaction name="actionGras"/>
<addaction name="actionItalique"/>
<addaction name="actionSouligner"/>
<addaction name="actionSurligner"/>
</widget>
<addaction name="menuFichier"/>
<addaction name="menuAffichage"/>
<addaction name="menuEdition"/>
</widget>
<action name="actionOuvrir_une_fiche">
<property name="text">
@@ -1052,28 +1173,6 @@
<string>Ctrl+Q</string>
</property>
</action>
<action name="actionEditer">
<property name="icon">
<iconset theme="QIcon::ThemeIcon::MailMessageNew"/>
</property>
<property name="text">
<string>Editer</string>
</property>
<property name="menuRole">
<enum>QAction::MenuRole::NoRole</enum>
</property>
</action>
<action name="actionBlocNote">
<property name="icon">
<iconset theme="QIcon::ThemeIcon::DocumentPageSetup"/>
</property>
<property name="text">
<string>BlocNote</string>
</property>
<property name="menuRole">
<enum>QAction::MenuRole::NoRole</enum>
</property>
</action>
<action name="actionNouvelle_fiche">
<property name="text">
<string>Nouvelle fiche</string>
@@ -1082,6 +1181,81 @@
<string>Ctrl+N</string>
</property>
</action>
<action name="actionBloc_note">
<property name="text">
<string>Bloc note</string>
</property>
<property name="shortcut">
<string>Ctrl+B</string>
</property>
</action>
<action name="actionCaract_ristiques">
<property name="text">
<string>Caractéristiques / Sac à dos</string>
</property>
<property name="shortcut">
<string>Ctrl+,</string>
</property>
</action>
<action name="actionCouleur">
<property name="checkable">
<bool>false</bool>
</property>
<property name="text">
<string>Couleur</string>
</property>
<property name="shortcut">
<string>Ctrl+J</string>
</property>
</action>
<action name="actionPolice">
<property name="text">
<string>Police</string>
</property>
<property name="shortcut">
<string>Ctrl+P</string>
</property>
</action>
<action name="actionTaille">
<property name="text">
<string>Taille</string>
</property>
<property name="shortcut">
<string>Ctrl+T</string>
</property>
</action>
<action name="actionGras">
<property name="text">
<string>Gras</string>
</property>
<property name="shortcut">
<string>Ctrl+B</string>
</property>
</action>
<action name="actionItalique">
<property name="text">
<string>Italique</string>
</property>
<property name="shortcut">
<string>Ctrl+I</string>
</property>
</action>
<action name="actionSouligner">
<property name="text">
<string>Souligner</string>
</property>
<property name="shortcut">
<string>Ctrl+U</string>
</property>
</action>
<action name="actionSurligner">
<property name="text">
<string>Surligner</string>
</property>
<property name="shortcut">
<string>Ctrl+O</string>
</property>
</action>
</widget>
<resources/>
<connections/>
+9 -114
View File
@@ -1,5 +1,6 @@
#include "notepad.h"
#include "ui_notepad.h"
#include "textFormatUtils.h"
#include <QInputDialog>
#include <QFontDialog>
@@ -14,121 +15,15 @@ NotePad::NotePad(QWidget *parent)
ui->setupUi(this);
}
NotePad::~NotePad(){
NotePad::~NotePad(){}
}
void NotePad::on_actionFontSize_triggered(){
QWidget *focused = QApplication::focusWidget();
QPlainTextEdit* plainTextEdit = qobject_cast<QPlainTextEdit*>(focused);
if (plainTextEdit) {
QTextCursor cursor = plainTextEdit->textCursor();
bool ok;
int size = QInputDialog::getInt(this, "Taille de la police", "Entrez la taille de la police:", cursor.charFormat().font().pointSize(), 1, 100, 1, &ok);
if (ok) {
QTextCharFormat format;
QFont font = cursor.charFormat().font();
font.setPointSize(size);
format.setFont(font);
plainTextEdit->mergeCurrentCharFormat(format);
}
}
}
void NotePad::on_actionFontColor_triggered(){
QWidget *focused = QApplication::focusWidget();
QPlainTextEdit* plainTextEdit = qobject_cast<QPlainTextEdit*>(focused);
if (plainTextEdit) {
QColor color = QColorDialog::getColor(Qt::black, this, "Choisir une couleur");
QTextCursor cursor = plainTextEdit->textCursor();
if (color.isValid()) {
QTextCharFormat format;
format.setForeground(color);
plainTextEdit->mergeCurrentCharFormat(format);
}
}
}
void NotePad::on_actionFont_triggered(){
QWidget *focused = QApplication::focusWidget();
QPlainTextEdit* plainTextEdit = qobject_cast<QPlainTextEdit*>(focused);
if (plainTextEdit) {
QTextCursor cursor = plainTextEdit->textCursor();
bool ok;
QFont font = QFontDialog::getFont(&ok, cursor.charFormat().font(), this, "Choisir une police");
if (ok) {
QTextCharFormat format;
format.setFont(font);
plainTextEdit->mergeCurrentCharFormat(format);
}
}
}
void NotePad::on_actionBold_triggered(){
QWidget *focused = QApplication::focusWidget();
QPlainTextEdit* plainTextEdit = qobject_cast<QPlainTextEdit*>(focused);
if (plainTextEdit) {
QTextCursor cursor = plainTextEdit->textCursor();
QTextCharFormat format;
QFont font = cursor.charFormat().font();
font.setBold(!font.bold());
format.setFont(font);
plainTextEdit->mergeCurrentCharFormat(format);
}
}
void NotePad::on_actionItalic_triggered(){
QWidget *focused = QApplication::focusWidget();
QPlainTextEdit* plainTextEdit = qobject_cast<QPlainTextEdit*>(focused);
if (plainTextEdit) {
QTextCursor cursor = plainTextEdit->textCursor();
QTextCharFormat format;
QFont font = cursor.charFormat().font();
font.setItalic(!font.italic());
format.setFont(font);
plainTextEdit->mergeCurrentCharFormat(format);
}
}
void NotePad::on_actionOverline_triggered(){
QWidget *focused = QApplication::focusWidget();
QPlainTextEdit* plainTextEdit = qobject_cast<QPlainTextEdit*>(focused);
if (plainTextEdit) {
QTextCursor cursor = plainTextEdit->textCursor();
QTextCharFormat format;
QFont font = cursor.charFormat().font();
font.setOverline(!font.overline());
format.setFont(font);
plainTextEdit->mergeCurrentCharFormat(format);
}
}
void NotePad::on_actionUnderline_triggered(){
QWidget *focused = QApplication::focusWidget();
QPlainTextEdit* plainTextEdit = qobject_cast<QPlainTextEdit*>(focused);
if (plainTextEdit) {
QTextCursor cursor = plainTextEdit->textCursor();
QTextCharFormat format;
QFont font = cursor.charFormat().font();
font.setUnderline(!font.underline());
format.setFont(font);
plainTextEdit->mergeCurrentCharFormat(format);
}
}
void NotePad::on_actionFont_triggered() {TextFormatUtils::changeFont(this);}
void NotePad::on_actionFontSize_triggered() {TextFormatUtils::changeFontSize(this);}
void NotePad::on_actionFontColor_triggered() {TextFormatUtils::changeFontColor(this);}
void NotePad::on_actionBold_triggered() {TextFormatUtils::toggleBold();}
void NotePad::on_actionItalic_triggered() {TextFormatUtils::toggleItalic();}
void NotePad::on_actionOverline_triggered() {TextFormatUtils::toggleOverline();}
void NotePad::on_actionUnderline_triggered() {TextFormatUtils::toggleUnderline();}
void NotePad::setTexte(QString t){
texte = t;
+98
View File
@@ -0,0 +1,98 @@
#include "TextFormatUtils.h"
#include <QApplication>
QPlainTextEdit* TextFormatUtils::getFocusedPlainTextEdit() {
QWidget* focused = QApplication::focusWidget();
return qobject_cast<QPlainTextEdit*>(focused);
}
void TextFormatUtils::changeFontSize(QWidget* parent) {
QPlainTextEdit* edit = getFocusedPlainTextEdit();
if (edit) {
QTextCursor cursor = edit->textCursor();
bool ok;
int size = QInputDialog::getInt(parent, "Taille de la police", "Entrez la taille de la police:", cursor.charFormat().font().pointSize(), 1, 100, 1, &ok);
if (ok) {
QTextCharFormat format;
QFont font = cursor.charFormat().font();
font.setPointSize(size);
format.setFont(font);
edit->mergeCurrentCharFormat(format);
}
}
}
void TextFormatUtils::changeFontColor(QWidget* parent) {
QPlainTextEdit* edit = getFocusedPlainTextEdit();
if (edit) {
QColor color = QColorDialog::getColor(Qt::black, parent, "Choisir une couleur");
if (color.isValid()) {
QTextCharFormat format;
format.setForeground(color);
edit->mergeCurrentCharFormat(format);
}
}
}
void TextFormatUtils::changeFont(QWidget* parent) {
QPlainTextEdit* edit = getFocusedPlainTextEdit();
if (edit) {
QTextCursor cursor = edit->textCursor();
bool ok;
QFont font = QFontDialog::getFont(&ok, cursor.charFormat().font(), parent, "Choisir une police");
if (ok) {
QTextCharFormat format;
format.setFont(font);
edit->mergeCurrentCharFormat(format);
}
}
}
void TextFormatUtils::toggleBold() {
QPlainTextEdit* edit = getFocusedPlainTextEdit();
if (edit) {
QTextCursor cursor = edit->textCursor();
QTextCharFormat format;
QFont font = cursor.charFormat().font();
font.setBold(!font.bold());
format.setFont(font);
edit->mergeCurrentCharFormat(format);
}
}
void TextFormatUtils::toggleItalic() {
QPlainTextEdit* edit = getFocusedPlainTextEdit();
if (edit) {
QTextCursor cursor = edit->textCursor();
QTextCharFormat format;
QFont font = cursor.charFormat().font();
font.setItalic(!font.italic());
format.setFont(font);
edit->mergeCurrentCharFormat(format);
}
}
void TextFormatUtils::toggleUnderline() {
QPlainTextEdit* edit = getFocusedPlainTextEdit();
if (edit) {
QTextCursor cursor = edit->textCursor();
QTextCharFormat format;
QFont font = cursor.charFormat().font();
font.setUnderline(!font.underline());
format.setFont(font);
edit->mergeCurrentCharFormat(format);
}
}
void TextFormatUtils::toggleOverline() {
QPlainTextEdit* edit = getFocusedPlainTextEdit();
if (edit) {
QTextCursor cursor = edit->textCursor();
QTextCharFormat format;
QFont font = cursor.charFormat().font();
font.setOverline(!font.overline());
format.setFont(font);
edit->mergeCurrentCharFormat(format);
}
}
+26
View File
@@ -0,0 +1,26 @@
#ifndef TEXTFORMATUTILS_H
#define TEXTFORMATUTILS_H
#include <QWidget>
#include <QPlainTextEdit>
#include <QFontDialog>
#include <QColorDialog>
#include <QInputDialog>
class TextFormatUtils
{
public:
static void changeFontSize(QWidget* parent);
static void changeFontColor(QWidget* parent);
static void changeFont(QWidget* parent);
static void toggleBold();
static void toggleItalic();
static void toggleUnderline();
static void toggleOverline();
private:
static QPlainTextEdit* getFocusedPlainTextEdit();
};
#endif // TEXTFORMATUTILS_H