finish of close fiche button and add of start menu
This commit is contained in:
parent
24c4685cb2
commit
22e56df104
@ -12,12 +12,14 @@ SOURCES += \
|
|||||||
character.cpp \
|
character.cpp \
|
||||||
main.cpp \
|
main.cpp \
|
||||||
mainwindow.cpp \
|
mainwindow.cpp \
|
||||||
notepad.cpp
|
notepad.cpp \
|
||||||
|
textformatutils.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
character.h \
|
character.h \
|
||||||
mainwindow.h \
|
mainwindow.h \
|
||||||
notepad.h \
|
notepad.h \
|
||||||
|
textformatutils.h
|
||||||
|
|
||||||
FORMS += \
|
FORMS += \
|
||||||
mainwindow.ui \
|
mainwindow.ui \
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"age": 0,
|
"age": 0,
|
||||||
"backPack": "",
|
"backPack": "fdzsfzf",
|
||||||
"blocNote": "",
|
"blocNote": "egerger",
|
||||||
"classe": "",
|
"classe": "",
|
||||||
"image": "data/images/logo.png",
|
"image": "data/images/logo.png",
|
||||||
"name": "ssfsf",
|
"name": "ssfsf",
|
||||||
|
|||||||
168
mainwindow.cpp
168
mainwindow.cpp
@ -1,5 +1,6 @@
|
|||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "ui_mainwindow.h"
|
#include "ui_mainwindow.h"
|
||||||
|
#include "textFormatUtils.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
@ -9,6 +10,7 @@
|
|||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
#include <QJsonValue>
|
#include <QJsonValue>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@ -18,21 +20,27 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
, ui(new Ui::MainWindow)
|
, ui(new Ui::MainWindow)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
addWindow();
|
|
||||||
notePad = new NotePad();
|
notePad = new NotePad();
|
||||||
connect(notePad, &NotePad::demandeSauvegarde, this, &MainWindow::recevoirSauvegarde);
|
connect(notePad, &NotePad::demandeSauvegarde, this, &MainWindow::recevoirSauvegarde);
|
||||||
Character* c = new Character();
|
|
||||||
currentCharacter = c;
|
|
||||||
characters.append(c);
|
|
||||||
currentFile = QString();
|
|
||||||
files.append(currentFile);
|
|
||||||
ui->ageLineEdit->setValidator(new QIntValidator(0, 999999, ui->ageLineEdit));
|
ui->ageLineEdit->setValidator(new QIntValidator(0, 999999, ui->ageLineEdit));
|
||||||
ui->niveauLineEdit->setValidator(new QIntValidator(0, 999999, ui->niveauLineEdit));
|
ui->niveauLineEdit->setValidator(new QIntValidator(0, 999999, ui->niveauLineEdit));
|
||||||
ui->tailleLineEdit->setValidator(new QDoubleValidator(0.0, 999999.0, 1,ui->tailleLineEdit));
|
ui->tailleLineEdit->setValidator(new QDoubleValidator(0.0, 999999.0, 1,ui->tailleLineEdit));
|
||||||
ui->BackPack->setHidden(true);
|
ui->BackPack->setHidden(true);
|
||||||
loadImage(QString("data/images/logo.png"));
|
ui->Edition->setHidden(true);
|
||||||
ui->Fenetre->setStyleSheet("background-color: #f2f2f2;");
|
ui->Fenetre->setStyleSheet("background-color: #f2f2f2;");
|
||||||
qobject_cast<QPushButton*>(ui->Fenetre->children()[0])->setStyleSheet("background-color: white;");
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -59,14 +67,22 @@ void MainWindow::loadNewCharacter(){
|
|||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
Character* c = new Character(&file);
|
Character* c = new Character(&file);
|
||||||
|
createNewCharacter(c, fileName);
|
||||||
currentCharacter = c;
|
currentCharacter = c;
|
||||||
characters.append(c);
|
characters.append(c);
|
||||||
currentFile = fileName;
|
currentFile = fileName;
|
||||||
files.append(fileName);
|
files.append(fileName);
|
||||||
createNewCharacter(c, fileName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::createNewCharacter(Character* p, QString s) {
|
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);
|
addWindow(s);
|
||||||
notePad->setTexte(p->getTexteBlocNote());
|
notePad->setTexte(p->getTexteBlocNote());
|
||||||
ui->BackPackPlainTextEdit->setPlainText(p->getTexteBlocNote());
|
ui->BackPackPlainTextEdit->setPlainText(p->getTexteBlocNote());
|
||||||
@ -81,7 +97,19 @@ void MainWindow::createNewCharacter(Character* p, QString s) {
|
|||||||
QPushButton* bt = qobject_cast<QPushButton*>(ui->Fenetre->children()[i]);
|
QPushButton* bt = qobject_cast<QPushButton*>(ui->Fenetre->children()[i]);
|
||||||
bt->setStyleSheet("background-color: #f2f2f2;");
|
bt->setStyleSheet("background-color: #f2f2f2;");
|
||||||
}
|
}
|
||||||
qobject_cast<QPushButton*>(ui->Fenetre->children()[ui->Fenetre->children().size()-1])->setStyleSheet("background-color: white;");
|
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -168,7 +196,6 @@ void MainWindow::saveJson(){
|
|||||||
file.close();
|
file.close();
|
||||||
if (button) {
|
if (button) {
|
||||||
if (button->objectName() != currentFile) {
|
if (button->objectName() != currentFile) {
|
||||||
std::cout << "oui" << std::endl;
|
|
||||||
button->setObjectName(currentFile);
|
button->setObjectName(currentFile);
|
||||||
button->setText(extractFileName(currentFile));
|
button->setText(extractFileName(currentFile));
|
||||||
}
|
}
|
||||||
@ -313,6 +340,7 @@ void MainWindow::setUi(Character* p){
|
|||||||
spinBox->setValue(p->getStats()[i]);
|
spinBox->setValue(p->getStats()[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ui->BackPackPlainTextEdit->setPlainText(p->getTexteBackPack());
|
||||||
loadImage(p->getImage());
|
loadImage(p->getImage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -326,9 +354,15 @@ void MainWindow::toogleBackPack(){
|
|||||||
if(ui->BackPack->isHidden()){
|
if(ui->BackPack->isHidden()){
|
||||||
ui->Edition->setHidden(true);
|
ui->Edition->setHidden(true);
|
||||||
ui->BackPack->setHidden(false);
|
ui->BackPack->setHidden(false);
|
||||||
|
for(int i=0; i<ui->menuEdition->actions().size(); i++){
|
||||||
|
ui->menuEdition->actions()[i]->setDisabled(false);
|
||||||
|
}
|
||||||
}else{
|
}else{
|
||||||
ui->BackPack->setHidden(true);
|
ui->BackPack->setHidden(true);
|
||||||
ui->Edition->setHidden(false);
|
ui->Edition->setHidden(false);
|
||||||
|
for(int i=0; i<ui->menuEdition->actions().size(); i++){
|
||||||
|
ui->menuEdition->actions()[i]->setDisabled(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -339,6 +373,19 @@ void MainWindow::on_actionNouvelle_fiche_triggered(){this->createNewCharacter(ne
|
|||||||
void MainWindow::on_actionSauvegarder_triggered(){this->saveJson();}
|
void MainWindow::on_actionSauvegarder_triggered(){this->saveJson();}
|
||||||
void MainWindow::on_actionEnregistrer_sous_triggered(){this->saveAsJson();}
|
void MainWindow::on_actionEnregistrer_sous_triggered(){this->saveAsJson();}
|
||||||
void MainWindow::on_actionFermer_triggered(){QApplication::quit();}
|
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()
|
void MainWindow::on_imagePushButton_clicked()
|
||||||
{
|
{
|
||||||
@ -352,6 +399,19 @@ void MainWindow::on_actionCaract_ristiques_triggered(){this->toogleBackPack();}
|
|||||||
|
|
||||||
void MainWindow::addWindow(const QString& s){
|
void MainWindow::addWindow(const QString& s){
|
||||||
int nb = ui->Fenetre->children().size();
|
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;
|
QPushButton* button;
|
||||||
if(s == ""){
|
if(s == ""){
|
||||||
button = new QPushButton("Sans titre", ui->Fenetre);
|
button = new QPushButton("Sans titre", ui->Fenetre);
|
||||||
@ -360,11 +420,79 @@ void MainWindow::addWindow(const QString& s){
|
|||||||
button = new QPushButton(extractFileName(s), ui->Fenetre);
|
button = new QPushButton(extractFileName(s), ui->Fenetre);
|
||||||
button->setObjectName(s);
|
button->setObjectName(s);
|
||||||
}
|
}
|
||||||
button->setFixedSize(100, 35);
|
button->setGeometry(nb * sizeButtonFiche, 0, sizeButtonFiche, 35);
|
||||||
button->move(nb * 100, 0);
|
|
||||||
button->setProperty("id", idFicheButtonCounter);
|
button->setProperty("id", idFicheButtonCounter);
|
||||||
button->show();
|
button->show();
|
||||||
connect(button, &QPushButton::clicked, this, &MainWindow::changer_fiche_clicked);
|
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++;
|
idFicheButtonCounter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -374,12 +502,10 @@ QString MainWindow::extractFileName(QString s){
|
|||||||
return infoFichier.fileName();
|
return infoFichier.fileName();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::changer_fiche_clicked(){
|
|
||||||
changeCurrentChracter();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::changeCurrentChracter(){
|
|
||||||
|
void MainWindow::changeCurrentCharacter(){
|
||||||
getUi();
|
getUi();
|
||||||
notePad->getUi();
|
notePad->getUi();
|
||||||
currentCharacter->setTexteBlocNote(notePad->getTexte());
|
currentCharacter->setTexteBlocNote(notePad->getTexte());
|
||||||
@ -403,3 +529,11 @@ void MainWindow::changeCurrentChracter(){
|
|||||||
button->setStyleSheet("background-color: white;");
|
button->setStyleSheet("background-color: white;");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MainWindow::toogleStartMenu(){
|
||||||
|
ui->BackPack->setHidden(true);
|
||||||
|
ui->Edition->setHidden(true);
|
||||||
|
ui->StartMenu->setHidden(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
18
mainwindow.h
18
mainwindow.h
@ -5,6 +5,7 @@
|
|||||||
#include "notepad.h"
|
#include "notepad.h"
|
||||||
|
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
|
#include <QPushButton>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
@ -30,7 +31,11 @@ public:
|
|||||||
void toogleBackPack();
|
void toogleBackPack();
|
||||||
void addWindow(const QString& s = QString());
|
void addWindow(const QString& s = QString());
|
||||||
QString extractFileName(QString s);
|
QString extractFileName(QString s);
|
||||||
void changeCurrentChracter();
|
void changeCurrentCharacter();
|
||||||
|
void changeTab(int index);
|
||||||
|
void layoutTabs();
|
||||||
|
void removeTab(int index);
|
||||||
|
void toogleStartMenu();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_actionOuvrir_une_fiche_triggered();
|
void on_actionOuvrir_une_fiche_triggered();
|
||||||
@ -43,6 +48,16 @@ private slots:
|
|||||||
void on_actionBloc_note_triggered();
|
void on_actionBloc_note_triggered();
|
||||||
void on_actionCaract_ristiques_triggered();
|
void on_actionCaract_ristiques_triggered();
|
||||||
void changer_fiche_clicked();
|
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:
|
private:
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
@ -54,5 +69,6 @@ private:
|
|||||||
QList<QString> files;
|
QList<QString> files;
|
||||||
Character* currentCharacter;
|
Character* currentCharacter;
|
||||||
int idFicheButtonCounter = 0;
|
int idFicheButtonCounter = 0;
|
||||||
|
int sizeButtonFiche = 100;
|
||||||
};
|
};
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
|||||||
118
mainwindow.ui
118
mainwindow.ui
@ -1055,9 +1055,48 @@
|
|||||||
<enum>QFrame::Shadow::Raised</enum>
|
<enum>QFrame::Shadow::Raised</enum>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
<zorder>BackPack</zorder>
|
<widget class="QFrame" name="StartMenu">
|
||||||
<zorder>Edition</zorder>
|
<property name="geometry">
|
||||||
<zorder>Fenetre</zorder>
|
<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>
|
||||||
<widget class="QMenuBar" name="menubar">
|
<widget class="QMenuBar" name="menubar">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
@ -1085,8 +1124,22 @@
|
|||||||
<addaction name="actionCaract_ristiques"/>
|
<addaction name="actionCaract_ristiques"/>
|
||||||
<addaction name="actionBloc_note"/>
|
<addaction name="actionBloc_note"/>
|
||||||
</widget>
|
</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="menuFichier"/>
|
||||||
<addaction name="menuAffichage"/>
|
<addaction name="menuAffichage"/>
|
||||||
|
<addaction name="menuEdition"/>
|
||||||
</widget>
|
</widget>
|
||||||
<action name="actionOuvrir_une_fiche">
|
<action name="actionOuvrir_une_fiche">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -1144,6 +1197,65 @@
|
|||||||
<string>Ctrl+,</string>
|
<string>Ctrl+,</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</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>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
|
|||||||
123
notepad.cpp
123
notepad.cpp
@ -1,5 +1,6 @@
|
|||||||
#include "notepad.h"
|
#include "notepad.h"
|
||||||
#include "ui_notepad.h"
|
#include "ui_notepad.h"
|
||||||
|
#include "textFormatUtils.h"
|
||||||
|
|
||||||
#include <QInputDialog>
|
#include <QInputDialog>
|
||||||
#include <QFontDialog>
|
#include <QFontDialog>
|
||||||
@ -14,121 +15,15 @@ NotePad::NotePad(QWidget *parent)
|
|||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
NotePad::~NotePad(){
|
NotePad::~NotePad(){}
|
||||||
|
|
||||||
}
|
void NotePad::on_actionFont_triggered() {TextFormatUtils::changeFont(this);}
|
||||||
|
void NotePad::on_actionFontSize_triggered() {TextFormatUtils::changeFontSize(this);}
|
||||||
void NotePad::on_actionFontSize_triggered(){
|
void NotePad::on_actionFontColor_triggered() {TextFormatUtils::changeFontColor(this);}
|
||||||
QWidget *focused = QApplication::focusWidget();
|
void NotePad::on_actionBold_triggered() {TextFormatUtils::toggleBold();}
|
||||||
QPlainTextEdit* plainTextEdit = qobject_cast<QPlainTextEdit*>(focused);
|
void NotePad::on_actionItalic_triggered() {TextFormatUtils::toggleItalic();}
|
||||||
|
void NotePad::on_actionOverline_triggered() {TextFormatUtils::toggleOverline();}
|
||||||
if (plainTextEdit) {
|
void NotePad::on_actionUnderline_triggered() {TextFormatUtils::toggleUnderline();}
|
||||||
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::setTexte(QString t){
|
void NotePad::setTexte(QString t){
|
||||||
texte = t;
|
texte = t;
|
||||||
|
|||||||
98
textformatutils.cpp
Normal file
98
textformatutils.cpp
Normal 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
textformatutils.h
Normal file
26
textformatutils.h
Normal 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
|
||||||
Loading…
x
Reference in New Issue
Block a user