Compare commits
4 Commits
04a2663a46
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
| f08d7c5cbc | |||
| 22e56df104 | |||
| 24c4685cb2 | |||
| 646ec2fb0c |
+3
-1
@@ -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 \
|
||||
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
+4
-1
@@ -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();
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <QList>
|
||||
#include <QFile>
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Character{
|
||||
|
||||
+5
-5
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
@@ -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
@@ -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
|
||||
}
|
||||
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
|
||||
}
|
||||
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
|
||||
}
|
||||
+275
-37
@@ -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());
|
||||
currentCharacter = p;
|
||||
characters.append(p);
|
||||
ui->BackPackPlainTextEdit->setPlainText(p->getTexteBlocNote());
|
||||
setUi(p);
|
||||
if(s.toStdString() == ""){
|
||||
currentCharacter = p;
|
||||
characters.append(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();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
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
@@ -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
|
||||
|
||||
+1114
-940
File diff suppressed because it is too large
Load Diff
+9
-114
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user