commit 89f03e1f1cdc0a4174e83cd26bbd6ed7f694a9d2 Author: Jérôme Deuchnord Date: Thu May 22 09:51:50 2014 +0200 Version 0.1 diff --git a/aboutdialog.cpp b/aboutdialog.cpp new file mode 100644 index 0000000..32a9eaf --- /dev/null +++ b/aboutdialog.cpp @@ -0,0 +1,25 @@ +#include "aboutdialog.h" +#include "ui_aboutdialog.h" + +#include + +AboutDialog::AboutDialog(QWidget *parent, QString version) : + QDialog(parent), + ui(new Ui::AboutDialog) +{ + ui->setupUi(this); + ui->version->setText("Version "+version); + ui->btnFermer->setFocus(); +} + +void AboutDialog::on_btnQt_clicked() +{ + QMessageBox::aboutQt(this, "À propos de Qt"); +} + +AboutDialog::~AboutDialog() +{ + delete ui; +} + + diff --git a/aboutdialog.h b/aboutdialog.h new file mode 100644 index 0000000..48f9408 --- /dev/null +++ b/aboutdialog.h @@ -0,0 +1,25 @@ +#ifndef ABOUTDIALOG_H +#define ABOUTDIALOG_H + +#include + +namespace Ui { +class AboutDialog; +} + +class AboutDialog : public QDialog +{ + Q_OBJECT + +public: + explicit AboutDialog(QWidget *parent, QString version); + ~AboutDialog(); + +private slots: + void on_btnQt_clicked(); + +private: + Ui::AboutDialog *ui; +}; + +#endif // ABOUTDIALOG_H diff --git a/aboutdialog.ui b/aboutdialog.ui new file mode 100644 index 0000000..86fbe50 --- /dev/null +++ b/aboutdialog.ui @@ -0,0 +1,123 @@ + + + AboutDialog + + + + 0 + 0 + 283 + 173 + + + + + 0 + 0 + + + + + 283 + 173 + + + + À propos de Hermès + + + + + + + 0 + 0 + + + + <html><head/><body><h1>Deuchnord Hermès</h1></body></html> + + + + + + + Version + + + + + + + + 0 + 0 + + + + <html><head/><body><p>Hermès est un logiciel libre distribué sous la licence <a href="http://www.cecill.info/licences/Licence_CeCILL_V2.1-fr.html"><span style=" text-decoration: underline; color:#0000ff;">CeCILL 2.1</span></a> par Jérôme Deuchnord.</p><p>Basé sur Qt 5.</p></body></html> + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + true + + + true + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + À propos de Qt + + + + + + + Fermer + + + + + + + + + + + btnFermer + clicked() + AboutDialog + accept() + + + 641 + 401 + + + 691 + 379 + + + + + diff --git a/deuchnord-hermes.pro b/deuchnord-hermes.pro new file mode 100644 index 0000000..939486d --- /dev/null +++ b/deuchnord-hermes.pro @@ -0,0 +1,38 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2014-05-07T19:11:58 +# +#------------------------------------------------- + +CONFIG += c++11 + +QT += core gui +QT += xml + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = deuchnord-hermes +TEMPLATE = app + + +SOURCES += main.cpp\ + mainwindow.cpp \ + produititem.cpp \ + infosproduitdialog.cpp \ + gestionmagasinsdialog.cpp \ + aboutdialog.cpp + +HEADERS += mainwindow.h \ + produititem.h \ + infosproduitdialog.h \ + gestionmagasinsdialog.h \ + aboutdialog.h + +FORMS += mainwindow.ui \ + produititem.ui \ + infosproduitdialog.ui \ + gestionmagasinsdialog.ui \ + aboutdialog.ui + +RESOURCES += \ + resources.qrc diff --git a/deuchnord-hermes.pro.user b/deuchnord-hermes.pro.user new file mode 100644 index 0000000..b69a304 --- /dev/null +++ b/deuchnord-hermes.pro.user @@ -0,0 +1,260 @@ + + + + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + true + 1 + true + 0 + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + + ProjectExplorer.Project.Target.0 + + Desktop + Desktop + {8a6bac83-397a-433b-b12b-aaf345693483} + 1 + 0 + 0 + + /home/jerome/Dropbox/Git/Hermes/build-deuchnord-hermes-Desktop-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + true + + false + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + /home/jerome/Dropbox/Git/Hermes/build-deuchnord-hermes-Desktop-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + true + + false + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 2 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy locally + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + deuchnord-hermes + + Qt4ProjectManager.Qt4RunConfiguration:/home/jerome/Dropbox/Git/Hermes/deuchnord-hermes/deuchnord-hermes.pro + + deuchnord-hermes.pro + false + false + + 3768 + true + false + false + false + true + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.EnvironmentId + {44abd538-5b46-4276-b819-6072e04c10d4} + + + ProjectExplorer.Project.Updater.FileVersion + 15 + + diff --git a/deuchnord-hermes.pro.user.81ef902 b/deuchnord-hermes.pro.user.81ef902 new file mode 100644 index 0000000..2ae299e --- /dev/null +++ b/deuchnord-hermes.pro.user.81ef902 @@ -0,0 +1,260 @@ + + + + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + true + 1 + true + 0 + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + + ProjectExplorer.Project.Target.0 + + Desktop + Desktop + {8a6bac83-397a-433b-b12b-aaf345693483} + 0 + 0 + 0 + + /home/jerome/Dropbox/Git/Hermes/build-deuchnord-hermes-Desktop-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + true + + false + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + /home/jerome/Dropbox/Git/Hermes/build-deuchnord-hermes-Desktop-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + true + + false + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 2 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy locally + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + deuchnord-hermes + + Qt4ProjectManager.Qt4RunConfiguration:/home/jerome/Dropbox/Git/Hermes/deuchnord-hermes/deuchnord-hermes.pro + + deuchnord-hermes.pro + false + false + + 3768 + true + false + false + false + true + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.EnvironmentId + {81ef902a-0963-4a87-b37c-5a785cdf71d5} + + + ProjectExplorer.Project.Updater.FileVersion + 15 + + diff --git a/gestionmagasinsdialog.cpp b/gestionmagasinsdialog.cpp new file mode 100644 index 0000000..8450ffa --- /dev/null +++ b/gestionmagasinsdialog.cpp @@ -0,0 +1,86 @@ +#include "gestionmagasinsdialog.h" +#include "ui_gestionmagasinsdialog.h" + +#include +#include +#include +#include + +GestionMagasinsDialog::GestionMagasinsDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::GestionMagasinsDialog) +{ + ui->setupUi(this); + + QFile fichierMagasins(QDir::homePath()+"/.deuchnord-hermes/manufacturers.xml"); + fichierMagasins.open(QFile::ReadOnly); + if(fichierMagasins.isOpen()) + { + QString contenuFichier = fichierMagasins.readAll(); + fichierMagasins.close(); + + QDomDocument dom; + dom.setContent(contenuFichier); + QDomElement root = dom.firstChildElement(); + QDomElement manufacturer; + QDomNode node = root.firstChild(); + + while(!node.isNull()) + { + manufacturer = node.toElement(); + if(manufacturer.tagName() == "manufacturer") + ui->listMagasins->addItem(manufacturer.firstChild().toText().data()); + + node = node.nextSibling(); + } + + fichierMagasins.close(); + } + + ui->listMagasins->setCurrentItem(ui->listMagasins->item(0)); +} + +void GestionMagasinsDialog::on_btnAjoutMagasin_clicked() +{ + ui->listMagasins->addItem(QInputDialog::getText(this, "Ajouter un magasin", "Veuillez entrer le nom du nouveau magasin :")); +} + +void GestionMagasinsDialog::on_btnSupprMagasin_clicked() +{ + delete ui->listMagasins->currentItem(); +} + +void GestionMagasinsDialog::on_listMagasins_currentRowChanged() +{ + ui->btnSupprMagasin->setEnabled(true); +} + +void GestionMagasinsDialog::on_buttonBox_accepted() +{ + QDomDocument dom("manufacturers"); + QDomElement rootElement = dom.createElement("manufacturers"); + dom.appendChild(rootElement); + + for(int i = 0; i < ui->listMagasins->count(); i++) + { + QDomElement manufacturer = dom.createElement("manufacturer"); + rootElement.appendChild(manufacturer); + + QListWidgetItem *item = ui->listMagasins->item(i); + + QDomText nomMagasin = dom.createTextNode(item->text()); + manufacturer.appendChild(nomMagasin); + } + + QFile fileManu(QDir::homePath()+"/.deuchnord-hermes/manufacturers.xml"); + if(fileManu.open(QFile::WriteOnly)) + { + fileManu.write(dom.toString().toUtf8()); + fileManu.close(); + } +} + +GestionMagasinsDialog::~GestionMagasinsDialog() +{ + delete ui; +} diff --git a/gestionmagasinsdialog.h b/gestionmagasinsdialog.h new file mode 100644 index 0000000..aace4ca --- /dev/null +++ b/gestionmagasinsdialog.h @@ -0,0 +1,28 @@ +#ifndef GESTIONMAGASINSDIALOG_H +#define GESTIONMAGASINSDIALOG_H + +#include + +namespace Ui { +class GestionMagasinsDialog; +} + +class GestionMagasinsDialog : public QDialog +{ + Q_OBJECT + +public: + explicit GestionMagasinsDialog(QWidget *parent = 0); + ~GestionMagasinsDialog(); + +public slots: + void on_btnAjoutMagasin_clicked(); + void on_btnSupprMagasin_clicked(); + void on_listMagasins_currentRowChanged(); + void on_buttonBox_accepted(); + +private: + Ui::GestionMagasinsDialog *ui; +}; + +#endif // GESTIONMAGASINSDIALOG_H diff --git a/gestionmagasinsdialog.ui b/gestionmagasinsdialog.ui new file mode 100644 index 0000000..fd64ffb --- /dev/null +++ b/gestionmagasinsdialog.ui @@ -0,0 +1,114 @@ + + + GestionMagasinsDialog + + + + 0 + 0 + 655 + 383 + + + + Gérer les magasins + + + + + + + + + + + 0 + + + + + + + + + + + + + + + false + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + GestionMagasinsDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + GestionMagasinsDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/icon-hermes.png b/icon-hermes.png new file mode 100644 index 0000000..dbba77f Binary files /dev/null and b/icon-hermes.png differ diff --git a/infosproduitdialog.cpp b/infosproduitdialog.cpp new file mode 100644 index 0000000..e90744b --- /dev/null +++ b/infosproduitdialog.cpp @@ -0,0 +1,213 @@ +#include "infosproduitdialog.h" +#include "ui_infosproduitdialog.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +InfosProduitDialog::InfosProduitDialog(QWidget *parent, QString nomProduit, QDate dateAchat, QDate dateFinGarantie, QPixmap image, int indexMagasin, bool enSAV, QHash facturePDF, QHash garantiePDF) : + QDialog(parent), + ui(new Ui::InfosProduitDialog) +{ + ui->setupUi(this); + parentWidget = parent; + + // Récupération de la liste des magasins enregistrés + QFile fichierMagasins(QDir::homePath()+"/.deuchnord-hermes/manufacturers.xml"); + fichierMagasins.open(QFile::ReadOnly); + if(fichierMagasins.isOpen()) + { + QString contenuFichier = fichierMagasins.readAll(); + fichierMagasins.close(); + + QDomDocument dom; + dom.setContent(contenuFichier); + QDomElement root = dom.firstChildElement(); + QDomElement manufacturer; + QDomNode node = root.firstChild(); + + while(!node.isNull()) + { + manufacturer = node.toElement(); + if(manufacturer.tagName() == "manufacturer") + ui->comboMagasin->addItem(manufacturer.firstChild().toText().data()); + + node = node.nextSibling(); + } + } + else + { + QMessageBox::critical(this, "Erreur", "Impossible de récupérer la liste des magasins.\nLes avez-vous enregistrés ?"); + } + + // Remplissage des données + ui->txtNom->setText(nomProduit); + ui->dateAchat->setDate(dateAchat); + ui->dateFinGarantie->setDate(dateFinGarantie); + ui->comboMagasin->setCurrentIndex(indexMagasin); + ui->checkSAV->setChecked(enSAV); + ui->image->setPixmap(image); + this->image = image; + + // Factures & garanties + this->facturePDF = facturePDF; + this->garantiePDF = garantiePDF; + for(QString i : this->facturePDF.keys()) + { + ui->listFactures->addItem(i); + } + for(QString i : this->garantiePDF.keys()) + { + ui->listGaranties->addItem(i); + } + + ui->txtNom->setFocus(); + ui->listFactures->setCurrentItem(ui->listFactures->item(0)); + ui->listGaranties->setCurrentItem(ui->listGaranties->item(0)); +} + +void InfosProduitDialog::on_btnImageParcourir_clicked() +{ + QString filename = QFileDialog::getOpenFileName(this, "Sélectionnez une image", "", "Images supportées (*.bmp *.gif *.jpg *.jpeg *.png *.pbm *.pgm *.ppm *.xbm *.xpm)"); + if(filename != "") + { + image = QPixmap(filename); + image = image.scaled(QSize(128, 128), Qt::KeepAspectRatio); + ui->image->setPixmap(image); + } +} + +void InfosProduitDialog::on_btnImageSupprimer_clicked() +{ + image = QPixmap(":/images/no-picture.jpg"); + ui->image->setPixmap(image); +} + +void InfosProduitDialog::on_btnAjoutFacture_clicked() +{ + QString fileName = QFileDialog::getOpenFileName(this, "Sélectionnez une facture", "", "Fichiers PDF (*.pdf);;Image (*.jpg *.jpeg *.png)"); + if(fileName != "") + { + QFile fichier(fileName); + QFileInfo infoFile(fichier.fileName()); + fichier.open(QFile::ReadOnly); + if(fichier.isReadable()) + { + QByteArray contenuFichier = fichier.readAll(); + fichier.close(); + + facturePDF.insert(infoFile.fileName(), contenuFichier); + ui->listFactures->addItem(infoFile.fileName()); + } + else + QMessageBox::critical(this, "Erreur", "Impossible de lire le fichier "+fichier.fileName()+"\nVérifiez qu'il est bien accessible en lecture et réessayez."); + } +} + +void InfosProduitDialog::on_listFactures_currentRowChanged() +{ + ui->btnSupprFacture->setEnabled(true); +} + +void InfosProduitDialog::on_listFactures_itemDoubleClicked(QListWidgetItem *item) +{ + QByteArray contentFile = facturePDF.value(item->text()); + QFile tempFile(QDir::tempPath()+"/"+item->text()); + tempFile.open(QFile::WriteOnly); + tempFile.write(contentFile); + tempFile.close(); + QDesktopServices::openUrl(QUrl(tempFile.fileName())); +} + +void InfosProduitDialog::on_btnSupprFacture_clicked() +{ + if(QMessageBox::question(this, "Hermès", "Voulez-vous vraiment supprimer cette facture ?\nCette action n'est pas réversible.", QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) + { + QListWidgetItem *item = ui->listFactures->selectedItems().value(0); + facturePDF.remove(item->text()); + delete item; + } + + if(ui->listFactures->count() == 0) + ui->btnSupprFacture->setEnabled(false); +} + +void InfosProduitDialog::on_btnAjoutGarantie_clicked() +{ + QString fileName = QFileDialog::getOpenFileName(this, "Sélectionnez une fiche garantie", "", "Fichiers PDF (*.pdf);;Image (*.jpg *.jpeg *.png)"); + if(fileName != "") + { + QFile fichier(fileName); + QFileInfo infoFile(fichier.fileName()); + fichier.open(QFile::ReadOnly); + if(fichier.isReadable()) + { + QByteArray contenuFichier = fichier.readAll(); + fichier.close(); + + garantiePDF.insert(infoFile.fileName(), contenuFichier); + ui->listGaranties->addItem(infoFile.fileName()); + } + else + QMessageBox::critical(this, "Erreur", "Impossible de lire le fichier "+fichier.fileName()+"\nVérifiez qu'il est bien accessible en lecture et réessayez."); + } +} + +void InfosProduitDialog::on_listGaranties_currentRowChanged() +{ + ui->btnSupprGarantie->setEnabled(true); +} + +void InfosProduitDialog::on_listGaranties_itemDoubleClicked(QListWidgetItem *item) +{ + QByteArray contentFile = garantiePDF.value(item->text()); + QFile tempFile(QDir::tempPath()+"/"+item->text()); + tempFile.open(QFile::WriteOnly); + tempFile.write(contentFile); + tempFile.close(); + QDesktopServices::openUrl(QUrl(tempFile.fileName())); +} + +void InfosProduitDialog::on_btnSupprGarantie_clicked() +{ + if(QMessageBox::question(this, "Hermès", "Voulez-vous vraiment supprimer cette fiche garantie ?\nCette action n'est pas réversible.", QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) + { + QListWidgetItem *item = ui->listGaranties->selectedItems().value(0); + garantiePDF.remove(item->text()); + delete item; + } + + if(ui->listGaranties->count() == 0) + ui->btnSupprGarantie->setEnabled(false); +} + +// Bouton "OK" + +void InfosProduitDialog::on_buttonBox_accepted() +{ + getParentItem()->setNomProduit(ui->txtNom->text()); + getParentItem()->setDateAchat(ui->dateAchat->date()); + getParentItem()->setDateFinGarantie(ui->dateFinGarantie->date()); + getParentItem()->setImage(this->image); + getParentItem()->setMagasin(ui->comboMagasin->currentIndex()); + getParentItem()->setEnSAV(ui->checkSAV->isChecked()); + getParentItem()->setFactures(this->facturePDF); + getParentItem()->setGaranties(this->garantiePDF); +} + +ProduitItem* InfosProduitDialog::getParentItem() +{ + return static_cast(this->parentWidget); +} + +InfosProduitDialog::~InfosProduitDialog() +{ + delete ui; +} diff --git a/infosproduitdialog.h b/infosproduitdialog.h new file mode 100644 index 0000000..39de7f3 --- /dev/null +++ b/infosproduitdialog.h @@ -0,0 +1,51 @@ +#ifndef INFOSPRODUITDIALOG_H +#define INFOSPRODUITDIALOG_H + +#include +#include +#include +#include +#include +#include "produititem.h" + +namespace Ui { +class InfosProduitDialog; +} + +class ProduitItem; + +class InfosProduitDialog : public QDialog +{ + Q_OBJECT + +public: + explicit InfosProduitDialog(QWidget *parent, QString nomProduit = "", QDate dateAchat = QDate::currentDate(), QDate dateFinGarantie = QDate::currentDate().addYears(1), QPixmap image = QPixmap(), int indexMagasin = 0, bool enSAV = false, QHash facturePDF = QHash(), QHash garantiePDF = QHash()); + ~InfosProduitDialog(); + +public slots: + // Image + void on_btnImageParcourir_clicked(); + void on_btnImageSupprimer_clicked(); + // Factures + void on_btnAjoutFacture_clicked(); + void on_listFactures_currentRowChanged(); + void on_listFactures_itemDoubleClicked(QListWidgetItem *item); + void on_btnSupprFacture_clicked(); + // Garanties + void on_btnAjoutGarantie_clicked(); + void on_listGaranties_currentRowChanged(); + void on_listGaranties_itemDoubleClicked(QListWidgetItem *item); + void on_btnSupprGarantie_clicked(); + // Boutons du bas + void on_buttonBox_accepted(); + +private: + QPixmap image; + Ui::InfosProduitDialog *ui; + QHash facturePDF; + QHash garantiePDF; + QWidget *parentWidget; + ProduitItem *getParentItem(); +}; + +#endif // INFOSPRODUITDIALOG_H diff --git a/infosproduitdialog.ui b/infosproduitdialog.ui new file mode 100644 index 0000000..86b944f --- /dev/null +++ b/infosproduitdialog.ui @@ -0,0 +1,338 @@ + + + InfosProduitDialog + + + + 0 + 0 + 694 + 427 + + + + Informations sur le produit + + + + + + 0 + + + + Produit + + + + QFormLayout::AllNonFixedFieldsGrow + + + + + Nom : + + + + + + + + + + Date d'achat : + + + + + + + true + + + + + + + Fin de la garantie : + + + + + + + true + + + + + + + Magasin : + + + + + + + + + + Cochez cette case si vous avez envoyé le produit en SAV. + + + Actuellement en SAV + + + + + + + Image à afficher : + + + + + + + + + + Image + + + Qt::AlignCenter + + + + + + + + + Parcourir... + + + + + + + Supprimer + + + + + + + + + Taille conseillée : 128px de hauteur + + + Qt::AlignCenter + + + + + + + + + + + Factures && garanties + + + + + + Cet onglet permet de conserver des versions numérisées de vos factures et garanties, afin de vous délester de papiers encombrants. Un scanner de bonne qualité est toutefois requis, ces pièces devant être imprimées en cas de retour du produit en SAV. +Vous pouvez ouvrir une facture ou une garantie en double-cliquant dessus. + + + true + + + + + + + Factures + + + + + + + + + 0 + + + + + Ajouter une facture + + + + + + + + + + + + + + + false + + + Supprimer la facture + + + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + Garanties + + + + + + + + + 0 + + + + + Ajouter une garantie + + + + + + + + + + + + + + + false + + + Supprimer la garantie + + + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + InfosProduitDialog + accept() + + + 257 + 417 + + + 157 + 274 + + + + + buttonBox + rejected() + InfosProduitDialog + reject() + + + 325 + 417 + + + 286 + 274 + + + + + diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..b47b2c1 --- /dev/null +++ b/main.cpp @@ -0,0 +1,19 @@ +#include "mainwindow.h" +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + + QString locale = QLocale::system().name().section('_', 0, 0); + QTranslator translator; + translator.load(QString("qt_") + locale, QLibraryInfo::location(QLibraryInfo::TranslationsPath)); + a.installTranslator(&translator); + w.show(); + + return a.exec(); +} diff --git a/mainwindow.cpp b/mainwindow.cpp new file mode 100644 index 0000000..b597fe3 --- /dev/null +++ b/mainwindow.cpp @@ -0,0 +1,159 @@ +#include "mainwindow.h" +#include "produititem.h" +#include "gestionmagasinsdialog.h" +#include "aboutdialog.h" +#include "ui_mainwindow.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +MainWindow::MainWindow(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::MainWindow) +{ + ui->setupUi(this); + + version = "0.1"; + + searchBox = new QLineEdit(this); + searchBox->setPlaceholderText("Rechercher..."); + searchBox->setToolTip("Recherchez un produit à partir de son nom.\nLa casse n'est pas prise en compte."); + searchBox->setClearButtonEnabled(true); + + connect(searchBox, SIGNAL(textChanged(QString)), SLOT(searchProduit(QString))); + + ui->mainToolBar->addSeparator(); + ui->mainToolBar->addWidget(searchBox); + + // Récupération de la configuration + + QFile saveFile(QDir::homePath()+"/hermes.hrms"); + QDataStream content(&saveFile); + content.setVersion(QDataStream::Qt_5_0); + + if(saveFile.open(QFile::ReadOnly)) + { + QList listInfoProd; + content >> listInfoProd; + + //QMessageBox::information(this, "test", QString::number(listInfoProd.count())); + for(ProduitInfo i : listInfoProd) + ajouterProduit(new ProduitItem(i.nomProduit, i.dateAchat, i.dateFinGarantie, i.image, i.indexMagasin, i.enSAV, i.factures, i.garanties)); + } + + ui->actionSupprimerProduit->setEnabled(false); +} + +void MainWindow::searchProduit(QString search) +{ + if(search != "") + { + for(int i = 0; i < ui->listeProduits->count(); i++) + { + ProduitItem* item = (ProduitItem*) ui->listeProduits->itemWidget(ui->listeProduits->item(i)); + ProduitInfo prod = item->getProduitInfo(); + + // On cache les produits qui ne correspondent pas + if(prod.nomProduit.contains(search, Qt::CaseInsensitive)) + ui->listeProduits->item(i)->setHidden(false); + else + ui->listeProduits->item(i)->setHidden(true); + } + } + else + { + // Si la zone de recherche est vide, on affiche tout + for(int i = 0; i < ui->listeProduits->count(); i++) + ui->listeProduits->item(i)->setHidden(false); + } +} + +void MainWindow::on_actionNouveauProduit_triggered() +{ + ProduitItem *prod = new ProduitItem("Nouveau produit", QDate::currentDate(), QDate::currentDate().addYears(1)); + prod->openDialog(); + ajouterProduit(prod); +} + +void MainWindow::on_actionSupprimerProduit_triggered() +{ + if(ui->listeProduits->selectedItems().count() == 1) + { + QListWidgetItem *item = ui->listeProduits->selectedItems()[0]; + if(QMessageBox::question(this, "Supprimer le produit", "Êtes-vous sûr de vouloir supprimer ce produit ?\nCette action n'est pas réversible.", QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) + { + ui->listeProduits->removeItemWidget(item); + delete item; + } + } +} + +void MainWindow::on_actionGererMagasins_triggered() +{ + GestionMagasinsDialog *dialog = new GestionMagasinsDialog(this); + dialog->setModal(true); + dialog->show(); +} + +void MainWindow::ajouterProduit(ProduitItem *produit) +{ + QListWidgetItem *widgetItem = new QListWidgetItem(); + widgetItem->setSizeHint(produit->getImage().size()); + ui->listeProduits->addItem(widgetItem); + ui->listeProduits->setItemWidget(widgetItem, produit); +} + +void MainWindow::on_listeProduits_currentRowChanged() +{ + ui->actionSupprimerProduit->setEnabled(true); +} + +void MainWindow::on_actionAPropos_triggered() +{ + AboutDialog *dialog = new AboutDialog(this, version); + dialog->setModal(true); + dialog->show(); +} + +void MainWindow::on_actionAide_triggered() +{ + QDesktopServices::openUrl(QUrl("http://hermes.deuchnord.tk/help/")); +} + +MainWindow::~MainWindow() +{ + // Enregistrement de la configuration + QFile saveFile(QDir::homePath()+"/hermes.hrms"); + QDataStream content(&saveFile); + content.setVersion(QDataStream::Qt_5_0); + QList listProd; + + if(saveFile.open(QFile::WriteOnly)) + { + for(int i = 0; i < ui->listeProduits->count(); i++) + { + ProduitItem* item = (ProduitItem*) ui->listeProduits->itemWidget(ui->listeProduits->item(i)); + ProduitInfo prod = item->getProduitInfo(); + listProd << prod; + } + } + + content << listProd; + + saveFile.close(); + + delete ui; +} + diff --git a/mainwindow.h b/mainwindow.h new file mode 100644 index 0000000..571cc19 --- /dev/null +++ b/mainwindow.h @@ -0,0 +1,38 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include +#include + +#include "produititem.h" + +namespace Ui { +class MainWindow; +} + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit MainWindow(QWidget *parent = 0); + ~MainWindow(); + +public slots: + void searchProduit(QString search); + void on_actionNouveauProduit_triggered(); + void on_actionSupprimerProduit_triggered(); + void on_actionGererMagasins_triggered(); + void on_listeProduits_currentRowChanged(); + void on_actionAPropos_triggered(); + void on_actionAide_triggered(); + +private: + Ui::MainWindow *ui; + void ajouterProduit(ProduitItem *produit); + QLineEdit *searchBox; + QString version; +}; + +#endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui new file mode 100644 index 0000000..103e090 --- /dev/null +++ b/mainwindow.ui @@ -0,0 +1,113 @@ + + + MainWindow + + + + 0 + 0 + 707 + 471 + + + + Gestionnaire de garanties Hermès + + + + :/images/icon-hermes.png:/images/icon-hermes.png + + + + + + + + + + + + 0 + 0 + 707 + 25 + + + + true + + + + Fichier + + + + + + + + + Aide + + + + + + + + + + TopToolBarArea + + + false + + + + + + + + + Nouveau produit... + + + Ctrl+N + + + + + false + + + Supprimer le produit + + + Ctrl+D + + + + + Gérer les magasins... + + + + + Centre d'aide + + + F1 + + + + + À propos... + + + + + + + + + diff --git a/no-picture.jpg b/no-picture.jpg new file mode 100644 index 0000000..165ba94 Binary files /dev/null and b/no-picture.jpg differ diff --git a/no-picture.xcf b/no-picture.xcf new file mode 100644 index 0000000..c442e42 Binary files /dev/null and b/no-picture.xcf differ diff --git a/produititem.cpp b/produititem.cpp new file mode 100644 index 0000000..fb52cfb --- /dev/null +++ b/produititem.cpp @@ -0,0 +1,170 @@ +#include "produititem.h" +#include "ui_produititem.h" + +#include + +QDataStream &operator <<(QDataStream &out, const ProduitInfo &prod) +{ + out << prod.nomProduit << prod.dateAchat << prod.dateFinGarantie << prod.image << prod.indexMagasin << prod.enSAV << prod.factures << prod.garanties; + + return out; +} + +QDataStream &operator >>(QDataStream &in, ProduitInfo &prod) +{ + in >> prod.nomProduit >> prod.dateAchat >> prod.dateFinGarantie >> prod.image >> prod.indexMagasin >> prod.enSAV >> prod.factures >> prod.garanties; + + return in; +} + +ProduitItem::ProduitItem(QString nomProduit, QDate dateAchat, QDate dateFinGarantie, QPixmap image, int magasin, + bool enSAV, QHash factures, QHash garanties) : + QWidget(), + ui(new Ui::ProduitItem) +{ + ui->setupUi(this); + + this->nomProduit = nomProduit; + this->dateAchat = dateAchat; + this->dateFinGarantie = dateFinGarantie; + this->indexMagasin = magasin; + this->enSAV = enSAV; + this->factures = factures; + this->garanties = garanties; + + ui->nomProduit->setText("

"+nomProduit+"

"); + updateDescription(); + this->image = image; + this->image.scaled(QSize(128, 128), Qt::KeepAspectRatio); + ui->image->setPixmap(this->image); + ui->btnMoreInfo->setToolTip("Ouvre une fenêtre contenant toutes les informations\nsur votre "+nomProduit+"."); +} + +ProduitItem::ProduitItem(ProduitInfo prod) : + QWidget(), + ui(new Ui::ProduitItem) +{ + ProduitItem(prod.nomProduit, prod.dateAchat, prod.dateFinGarantie, prod.image, prod.indexMagasin, prod.enSAV, prod.factures, prod.garanties); + ui->setupUi(this); +} + +void ProduitItem::on_btnMoreInfo_clicked() +{ + InfosProduitDialog *winInfoProd = new InfosProduitDialog(this, nomProduit, dateAchat, dateFinGarantie, image, indexMagasin, enSAV, factures, garanties); + winInfoProd->setModal(true); + winInfoProd->show(); +} + +// Accesseurs +QPixmap ProduitItem::getImage() +{ + return this->image; +} + +void ProduitItem::setNomProduit(QString nomProduit) +{ + this->nomProduit = nomProduit; + ui->nomProduit->setText("

"+nomProduit+"

"); +} + +void ProduitItem::setDateAchat(QDate dateAchat) +{ + this->dateAchat = dateAchat; + updateDescription(); +} + +void ProduitItem::setDateFinGarantie(QDate dateFinGarantie) +{ + this->dateFinGarantie = dateFinGarantie; + updateDescription(); +} + +void ProduitItem::setImage(QPixmap image) +{ + this->image = image; + ui->image->setPixmap(image); +} + +void ProduitItem::setMagasin(int index) +{ + this->indexMagasin = index; +} + +void ProduitItem::setEnSAV(bool y) +{ + this->enSAV = y; + updateDescription(); +} + +void ProduitItem::setFactures(QHash factures) +{ + this->factures = factures; +} + +void ProduitItem::setGaranties(QHash garanties) +{ + this->garanties = garanties; +} + +// Permet de mettre à jour le petit texte en-dessous du nom du produit +void ProduitItem::updateDescription() +{ + QString jourAchat = QString::number(dateAchat.day()); + + if(dateAchat.day() < 10) + jourAchat = "0"+jourAchat; + + QString moisAchat = QString::number(dateAchat.month()); + + if(dateAchat.month() < 10) + moisAchat = "0"+moisAchat; + + descriptionListe = "Acheté le "+jourAchat+"/"+moisAchat+"/"+QString::number(dateAchat.year())+", "; + + QString jourFinGarantie = QString::number(dateFinGarantie.day()); + + if(dateFinGarantie.day() < 10) + jourFinGarantie = "0"+jourFinGarantie; + + QString moisFinGarantie = QString::number(dateFinGarantie.month()); + + if(dateFinGarantie.month() < 10) + moisFinGarantie = "0"+moisFinGarantie; + + if(QDate::currentDate() < dateFinGarantie) + descriptionListe += "fin de la garantie le "+jourFinGarantie+"/"+moisFinGarantie+"/"+QString::number(dateFinGarantie.year()); + else + descriptionListe += "garantie expirée"; + + if(this->enSAV) + descriptionListe += "\nParti en SAV"; + + ui->infosProduit->setText(descriptionListe); +} + +void ProduitItem::openDialog() +{ + ui->btnMoreInfo->click(); +} + +// Pour la sérialisation + +ProduitInfo ProduitItem::getProduitInfo() +{ + ProduitInfo i; + i.nomProduit = this->nomProduit; + i.dateAchat = this->dateAchat; + i.dateFinGarantie = this->dateFinGarantie; + i.image = this->image; + i.indexMagasin = this->indexMagasin; + i.enSAV = this->enSAV; + i.factures = this->factures; + i.garanties = this->garanties; + + return i; +} + +ProduitItem::~ProduitItem() +{ + delete ui; +} diff --git a/produititem.h b/produititem.h new file mode 100644 index 0000000..44ddc06 --- /dev/null +++ b/produititem.h @@ -0,0 +1,86 @@ +#ifndef PRODUITITEM_H +#define PRODUITITEM_H + +#include +#include +#include +#include +#include +#include + +#include "infosproduitdialog.h" + +namespace Ui { +class ProduitItem; +} + +struct ProduitInfo { + QString nomProduit; + QDate dateAchat, dateFinGarantie; + QPixmap image; + qint32 indexMagasin; + bool enSAV; + QHash factures, garanties; +}; + +QDataStream &operator <<(QDataStream &out, const ProduitInfo &prod); +QDataStream &operator >>(QDataStream &in, ProduitInfo &prod); + + +class ProduitItem : public QWidget +{ + Q_OBJECT + +public: + explicit ProduitItem(QString nomProduit, QDate dateAchat, QDate dateFinGarantie, QPixmap image = QPixmap(":/images/no-picture.jpg"), int magasin = 0, + bool enSAV = false, QHash factures = QHash(), QHash garanties = QHash()); + explicit ProduitItem(ProduitInfo prod); + explicit ProduitItem(); + + /*QVector items; + + ProduitInfo info(); + QVector extractInfo(QVector const& v); + static void save(QDataStream & out, QVector const& v); + ProduitItem* create(ProduitInfo const& info); + QVector load(QDataStream & in);*/ + + // Pour la sérialisation + ProduitInfo getProduitInfo(); + + // Getters + QPixmap getImage(); + + // Setters + void setNomProduit(QString nomProduit); + void setDateAchat(QDate dateAchat); + void setDateFinGarantie(QDate dateFinGarantie); + void setImage(QPixmap image); + void setMagasin(int index); // le QString ne sert qu'à l'affichage, c'est l'index qui est utilisé par la boîte de dialogue + void setEnSAV(bool y); + void setFactures(QHash factures); + void setGaranties(QHash garanties); + + void updateDescription(); + void openDialog(); + + // Destructeur + ~ProduitItem(); + +public slots: + void on_btnMoreInfo_clicked(); + +private: + Ui::ProduitItem *ui; + + QString nomProduit; + QDate dateAchat, dateFinGarantie; + QString descriptionListe; + QPixmap image; + int indexMagasin; + bool enSAV; + QHash factures; + QHash garanties; +}; + +#endif // PRODUITITEM_H diff --git a/produititem.ui b/produititem.ui new file mode 100644 index 0000000..81bbf8a --- /dev/null +++ b/produititem.ui @@ -0,0 +1,100 @@ + + + ProduitItem + + + + 0 + 0 + 717 + 195 + + + + + 0 + 0 + + + + Form + + + + + + + 0 + 0 + + + + <img src="~/Images/sw2.jpg" /> + + + + + + + + + 0 + + + + + + 0 + 0 + + + + <h1>Nom produit</h1> + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Plus d'infos... + + + + + + + + + + 0 + 0 + + + + TextLabel + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + + + + + + + diff --git a/resources.qrc b/resources.qrc new file mode 100644 index 0000000..e4a03e0 --- /dev/null +++ b/resources.qrc @@ -0,0 +1,6 @@ + + + icon-hermes.png + no-picture.jpg + +