petit changement
This commit is contained in:
parent
611f444d86
commit
b42b82465a
@ -6,14 +6,15 @@
|
||||
#include <QApplication>
|
||||
#include <QEvent>
|
||||
#include <QDateTime>
|
||||
#include <QTimer>
|
||||
|
||||
QtView::QtView(QWidget* parent)
|
||||
: QWidget(parent), m_controller(nullptr), m_virtualKeyboard(nullptr), m_stockSelectionLayout(nullptr)
|
||||
: QWidget(parent), m_controller(nullptr), m_virtualKeyboard(nullptr), m_stockSelectionLayout(nullptr), m_stockDisplayWidget(nullptr), m_stockDisplayLayout(nullptr), m_itemTypeDisplayWidget(nullptr), m_itemTypeDisplayLayout(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
QtView::QtView(StockController* controller, QWidget* parent)
|
||||
: QWidget(parent), m_controller(controller), m_virtualKeyboard(nullptr), m_stockSelectionLayout(nullptr)
|
||||
: QWidget(parent), m_controller(controller), m_virtualKeyboard(nullptr), m_stockSelectionLayout(nullptr), m_stockDisplayWidget(nullptr), m_stockDisplayLayout(nullptr), m_itemTypeDisplayWidget(nullptr), m_itemTypeDisplayLayout(nullptr)
|
||||
{
|
||||
setupUI();
|
||||
}
|
||||
@ -124,20 +125,15 @@ void QtView::setController(StockController* controller)
|
||||
|
||||
void QtView::displayStocks(const std::vector<Stock>& stocks)
|
||||
{
|
||||
QString output = "=== LISTE DES STOCKS ===\n";
|
||||
// Créer un écran d'affichage des stocks avec la liste détaillée
|
||||
updateStockDisplayScreen(stocks);
|
||||
|
||||
if (stocks.empty()) {
|
||||
output += "Aucun stock disponible.\n";
|
||||
} else {
|
||||
for (const auto& stock : stocks) {
|
||||
output += QString("📦 %1 (Capacité: %2)\n")
|
||||
.arg(QString::fromStdString(stock.getName()))
|
||||
.arg(stock.getCapacity());
|
||||
}
|
||||
}
|
||||
// Afficher l'écran des stocks
|
||||
showActionScreen(m_showStocksScreen);
|
||||
|
||||
m_outputDisplay->clear();
|
||||
m_outputDisplay->append(output);
|
||||
// Optionnel : afficher aussi un message succinct dans la zone de notifications
|
||||
QString message = QString("📦 %1 stock(s) affiché(s)").arg(stocks.size());
|
||||
m_outputDisplay->append(message);
|
||||
}
|
||||
|
||||
void QtView::displayStockCreate(const Stock& stock)
|
||||
@ -152,22 +148,15 @@ void QtView::displayStockCreate(const Stock& stock)
|
||||
|
||||
void QtView::displayItemTypes(const std::vector<ItemType>& itemTypes)
|
||||
{
|
||||
QString output = "=== LISTE DES TYPES D'ARTICLES ===\n";
|
||||
// Créer un écran d'affichage des types d'articles avec la liste détaillée
|
||||
updateItemTypeDisplayScreen(itemTypes);
|
||||
|
||||
if (itemTypes.empty()) {
|
||||
output += "Aucun type d'article disponible.\n";
|
||||
} else {
|
||||
for (const auto& itemType : itemTypes) {
|
||||
output += QString("🏷️ %1 (ID: %2) - %3 (Taille: %4)\n")
|
||||
.arg(QString::fromStdString(itemType.getName()))
|
||||
.arg(itemType.getId())
|
||||
.arg(QString::fromStdString(itemType.getComment()))
|
||||
.arg(itemType.getSize());
|
||||
}
|
||||
}
|
||||
// Afficher l'écran des types d'articles
|
||||
showActionScreen(m_showItemTypesScreen);
|
||||
|
||||
m_outputDisplay->clear();
|
||||
m_outputDisplay->append(output);
|
||||
// Optionnel : afficher aussi un message succinct dans la zone de notifications
|
||||
QString message = QString("🏷️ %1 type(s) d'article(s) affiché(s)").arg(itemTypes.size());
|
||||
m_outputDisplay->append(message);
|
||||
}
|
||||
|
||||
void QtView::displayItemTypeCreate(const ItemType& itemType)
|
||||
@ -468,8 +457,8 @@ void QtView::setupStockActionScreens()
|
||||
m_createStockScreen = createFormScreen("Créer un Nouveau Stock", createStockLabels, createStockPlaceholders);
|
||||
m_stackedWidget->addWidget(m_createStockScreen);
|
||||
|
||||
// Écran d'affichage des stocks
|
||||
m_showStocksScreen = createTitleAndButtonScreen("Afficher les Stocks", {"🔄 Actualiser la liste"}, {[this]() { onShowStocks(); }});
|
||||
// Écran d'affichage des stocks - Créer un écran personnalisé au lieu d'utiliser createTitleAndButtonScreen
|
||||
m_showStocksScreen = createStockDisplayScreen();
|
||||
m_stackedWidget->addWidget(m_showStocksScreen);
|
||||
|
||||
// Écran de suppression de stock - Sera créé à la demande
|
||||
@ -484,8 +473,8 @@ void QtView::setupItemTypeActionScreens()
|
||||
m_createItemTypeScreen = createFormScreen("Créer un Type d'Article", createTypeLabels, createTypePlaceholders);
|
||||
m_stackedWidget->addWidget(m_createItemTypeScreen);
|
||||
|
||||
// Écran d'affichage des types
|
||||
m_showItemTypesScreen = createTitleAndButtonScreen("Afficher les Types", {"🔄 Actualiser la liste"}, {[this]() { onShowItemTypes(); }});
|
||||
// Écran d'affichage des types - Créer un écran personnalisé au lieu d'utiliser createTitleAndButtonScreen
|
||||
m_showItemTypesScreen = createItemTypeDisplayScreen();
|
||||
m_stackedWidget->addWidget(m_showItemTypesScreen);
|
||||
|
||||
// Écran de suppression de type
|
||||
@ -498,20 +487,20 @@ void QtView::setupItemActionScreens()
|
||||
{
|
||||
// Écran d'ajout d'article
|
||||
QStringList addItemLabels = {"Stock:", "Type d'article:", "Quantité:"};
|
||||
QStringList addItemPlaceholders = {"Sélectionner un stock", "Sélectionner un type", "1"};
|
||||
m_addItemScreen = createFormScreen("Ajouter un Article", addItemLabels, addItemPlaceholders);
|
||||
QStringList addItemFieldTypes = {"stock", "itemtype", "quantity"};
|
||||
m_addItemScreen = createSelectionFormScreen("Ajouter un Article", addItemLabels, addItemFieldTypes);
|
||||
m_stackedWidget->addWidget(m_addItemScreen);
|
||||
|
||||
// Écran de déplacement d'article
|
||||
QStringList moveItemLabels = {"Stock source:", "Stock destination:", "Type d'article:", "Quantité:"};
|
||||
QStringList moveItemPlaceholders = {"Stock source", "Stock destination", "Type d'article", "1"};
|
||||
m_moveItemScreen = createFormScreen("Déplacer un Article", moveItemLabels, moveItemPlaceholders);
|
||||
QStringList moveItemFieldTypes = {"stock", "stock", "itemtype", "quantity"};
|
||||
m_moveItemScreen = createSelectionFormScreen("Déplacer un Article", moveItemLabels, moveItemFieldTypes);
|
||||
m_stackedWidget->addWidget(m_moveItemScreen);
|
||||
|
||||
// Écran de retrait d'article
|
||||
QStringList removeItemLabels = {"Stock:", "Type d'article:", "Quantité:"};
|
||||
QStringList removeItemPlaceholders = {"Sélectionner un stock", "Type d'article", "1"};
|
||||
m_removeItemScreen = createFormScreen("Retirer un Article", removeItemLabels, removeItemPlaceholders);
|
||||
QStringList removeItemFieldTypes = {"stock", "itemtype", "quantity"};
|
||||
m_removeItemScreen = createSelectionFormScreen("Retirer un Article", removeItemLabels, removeItemFieldTypes);
|
||||
m_stackedWidget->addWidget(m_removeItemScreen);
|
||||
}
|
||||
|
||||
@ -674,6 +663,174 @@ QWidget* QtView::createFormScreen(const QString& title, const QStringList& label
|
||||
return screen;
|
||||
}
|
||||
|
||||
QWidget* QtView::createSelectionFormScreen(const QString& title, const QStringList& labels, const QStringList& fieldTypes)
|
||||
{
|
||||
QWidget* screen = new QWidget();
|
||||
QVBoxLayout* layout = new QVBoxLayout(screen);
|
||||
layout->setSpacing(20);
|
||||
layout->setContentsMargins(30, 30, 30, 30);
|
||||
|
||||
// Titre
|
||||
QLabel* titleLabel = new QLabel(title);
|
||||
titleLabel->setStyleSheet("font-size: 28px; font-weight: bold; color: #2c3e50; margin-bottom: 30px;");
|
||||
titleLabel->setAlignment(Qt::AlignCenter);
|
||||
layout->addWidget(titleLabel);
|
||||
|
||||
// Formulaire
|
||||
QWidget* formWidget = new QWidget();
|
||||
QVBoxLayout* formLayout = new QVBoxLayout(formWidget);
|
||||
formLayout->setSpacing(15);
|
||||
|
||||
for (int i = 0; i < labels.size(); ++i) {
|
||||
// Label
|
||||
QLabel* label = new QLabel(labels[i]);
|
||||
label->setStyleSheet("font-size: 16px; font-weight: bold; color: #34495e;");
|
||||
formLayout->addWidget(label);
|
||||
|
||||
QString fieldType = (i < fieldTypes.size()) ? fieldTypes[i] : "text";
|
||||
|
||||
if (fieldType == "stock") {
|
||||
// ComboBox pour sélectionner un stock
|
||||
QComboBox* combo = new QComboBox();
|
||||
combo->setMinimumHeight(50);
|
||||
combo->setStyleSheet(
|
||||
"QComboBox {"
|
||||
" border: 2px solid #bdc3c7;"
|
||||
" border-radius: 8px;"
|
||||
" padding: 10px;"
|
||||
" font-size: 16px;"
|
||||
" background-color: white;"
|
||||
"}"
|
||||
"QComboBox:focus {"
|
||||
" border-color: #3498db;"
|
||||
"}"
|
||||
"QComboBox::drop-down {"
|
||||
" subcontrol-origin: padding;"
|
||||
" subcontrol-position: top right;"
|
||||
" width: 20px;"
|
||||
" border-left-width: 1px;"
|
||||
" border-left-color: #bdc3c7;"
|
||||
" border-left-style: solid;"
|
||||
"}"
|
||||
"QComboBox::down-arrow {"
|
||||
" image: none;"
|
||||
" border: 3px solid #34495e;"
|
||||
" border-radius: 3px;"
|
||||
" margin: 5px;"
|
||||
"}"
|
||||
);
|
||||
|
||||
// Remplir avec les stocks disponibles
|
||||
QStringList stocks = getAvailableStocks();
|
||||
combo->addItems(stocks);
|
||||
|
||||
combo->setObjectName(QString("field_%1").arg(i));
|
||||
formLayout->addWidget(combo);
|
||||
|
||||
} else if (fieldType == "itemtype") {
|
||||
// ComboBox pour sélectionner un type d'article
|
||||
QComboBox* combo = new QComboBox();
|
||||
combo->setMinimumHeight(50);
|
||||
combo->setStyleSheet(
|
||||
"QComboBox {"
|
||||
" border: 2px solid #bdc3c7;"
|
||||
" border-radius: 8px;"
|
||||
" padding: 10px;"
|
||||
" font-size: 16px;"
|
||||
" background-color: white;"
|
||||
"}"
|
||||
"QComboBox:focus {"
|
||||
" border-color: #9b59b6;"
|
||||
"}"
|
||||
"QComboBox::drop-down {"
|
||||
" subcontrol-origin: padding;"
|
||||
" subcontrol-position: top right;"
|
||||
" width: 20px;"
|
||||
" border-left-width: 1px;"
|
||||
" border-left-color: #bdc3c7;"
|
||||
" border-left-style: solid;"
|
||||
"}"
|
||||
"QComboBox::down-arrow {"
|
||||
" image: none;"
|
||||
" border: 3px solid #34495e;"
|
||||
" border-radius: 3px;"
|
||||
" margin: 5px;"
|
||||
"}"
|
||||
);
|
||||
|
||||
// Remplir avec les types d'articles disponibles
|
||||
QStringList itemTypes = getAvailableItemTypes();
|
||||
combo->addItems(itemTypes);
|
||||
|
||||
combo->setObjectName(QString("field_%1").arg(i));
|
||||
formLayout->addWidget(combo);
|
||||
|
||||
} else {
|
||||
// Champ de saisie normal pour la quantité ou autre
|
||||
QLineEdit* field = new QLineEdit();
|
||||
field->setMinimumHeight(50);
|
||||
field->setStyleSheet(
|
||||
"QLineEdit {"
|
||||
" border: 2px solid #bdc3c7;"
|
||||
" border-radius: 8px;"
|
||||
" padding: 10px;"
|
||||
" font-size: 16px;"
|
||||
" background-color: white;"
|
||||
"}"
|
||||
"QLineEdit:focus {"
|
||||
" border-color: #e67e22;"
|
||||
"}"
|
||||
);
|
||||
|
||||
if (fieldType == "quantity") {
|
||||
field->setPlaceholderText("1");
|
||||
// Accepter seulement les nombres
|
||||
field->setValidator(new QIntValidator(1, 999999, this));
|
||||
}
|
||||
|
||||
field->setObjectName(QString("field_%1").arg(i));
|
||||
field->installEventFilter(this);
|
||||
formLayout->addWidget(field);
|
||||
}
|
||||
}
|
||||
|
||||
layout->addWidget(formWidget);
|
||||
|
||||
// Boutons d'action
|
||||
QWidget* buttonWidget = new QWidget();
|
||||
QHBoxLayout* buttonLayout = new QHBoxLayout(buttonWidget);
|
||||
buttonLayout->setSpacing(20);
|
||||
|
||||
QPushButton* executeButton = new QPushButton("✅ Exécuter");
|
||||
QPushButton* cancelButton = new QPushButton("❌ Annuler");
|
||||
|
||||
// Style des boutons
|
||||
executeButton->setMinimumHeight(60);
|
||||
executeButton->setStyleSheet(
|
||||
"QPushButton { background-color: #27ae60; color: white; border: none; border-radius: 8px; font-size: 16px; font-weight: bold; padding: 15px; }"
|
||||
"QPushButton:pressed { background-color: #229954; }"
|
||||
"QPushButton:hover { background-color: #2ecc71; }");
|
||||
|
||||
cancelButton->setMinimumHeight(60);
|
||||
cancelButton->setStyleSheet(
|
||||
"QPushButton { background-color: #e74c3c; color: white; border: none; border-radius: 8px; font-size: 16px; font-weight: bold; padding: 15px; }"
|
||||
"QPushButton:pressed { background-color: #c0392b; }"
|
||||
"QPushButton:hover { background-color: #c0392b; }");
|
||||
|
||||
// Connecter les boutons
|
||||
connect(executeButton, &QPushButton::clicked, [this, screen, title]() {
|
||||
executeFormAction(screen, title);
|
||||
});
|
||||
connect(cancelButton, &QPushButton::clicked, this, &QtView::goBack);
|
||||
|
||||
buttonLayout->addWidget(executeButton);
|
||||
buttonLayout->addWidget(cancelButton);
|
||||
layout->addWidget(buttonWidget);
|
||||
|
||||
layout->addStretch();
|
||||
return screen;
|
||||
}
|
||||
|
||||
QWidget* QtView::createStockSelectionScreen()
|
||||
{
|
||||
QWidget* screen = new QWidget();
|
||||
@ -783,15 +940,22 @@ void QtView::refreshStockSelectionScreen()
|
||||
// Créer un bouton pour chaque stock
|
||||
for (const auto& stock : stocks) {
|
||||
QString stockName = QString::fromStdString(stock.getName());
|
||||
QPushButton* stockButton = new QPushButton(stockName);
|
||||
stockButton->setMinimumHeight(60);
|
||||
|
||||
// Créer des informations détaillées sur le stock
|
||||
QString stockInfo = QString("%1\nCapacité: %2 | Utilisé: %3")
|
||||
.arg(stockName)
|
||||
.arg(stock.getCapacity())
|
||||
.arg(stock.getCurrentSize());
|
||||
|
||||
QPushButton* stockButton = new QPushButton(stockInfo);
|
||||
stockButton->setMinimumHeight(80);
|
||||
stockButton->setStyleSheet(
|
||||
"QPushButton {"
|
||||
" background-color: #e74c3c;"
|
||||
" color: white;"
|
||||
" border: none;"
|
||||
" border-radius: 8px;"
|
||||
" font-size: 18px;"
|
||||
" font-size: 16px;"
|
||||
" font-weight: bold;"
|
||||
" padding: 15px;"
|
||||
" text-align: left;"
|
||||
@ -817,6 +981,346 @@ void QtView::refreshStockSelectionScreen()
|
||||
m_stockSelectionLayout->addStretch();
|
||||
}
|
||||
|
||||
QWidget* QtView::createStockDisplayScreen()
|
||||
{
|
||||
QWidget* screen = new QWidget();
|
||||
QVBoxLayout* layout = new QVBoxLayout(screen);
|
||||
layout->setSpacing(20);
|
||||
layout->setContentsMargins(30, 30, 30, 30);
|
||||
|
||||
// Titre
|
||||
QLabel* titleLabel = new QLabel("📦 Liste des Stocks");
|
||||
titleLabel->setStyleSheet("font-size: 28px; font-weight: bold; color: #2c3e50; margin-bottom: 30px;");
|
||||
titleLabel->setAlignment(Qt::AlignCenter);
|
||||
layout->addWidget(titleLabel);
|
||||
|
||||
// Bouton d'actualisation
|
||||
QPushButton* refreshButton = new QPushButton("🔄 Actualiser la liste");
|
||||
refreshButton->setMinimumHeight(60);
|
||||
refreshButton->setStyleSheet(
|
||||
"QPushButton {"
|
||||
" background-color: #3498db;"
|
||||
" color: white;"
|
||||
" border: none;"
|
||||
" border-radius: 12px;"
|
||||
" font-size: 16px;"
|
||||
" font-weight: bold;"
|
||||
" padding: 15px;"
|
||||
"}"
|
||||
"QPushButton:pressed {"
|
||||
" background-color: #2980b9;"
|
||||
"}"
|
||||
"QPushButton:hover {"
|
||||
" background-color: #5dade2;"
|
||||
"}"
|
||||
);
|
||||
connect(refreshButton, &QPushButton::clicked, [this]() { onShowStocks(); });
|
||||
layout->addWidget(refreshButton);
|
||||
|
||||
// Zone de contenu avec scroll
|
||||
QScrollArea* scrollArea = new QScrollArea();
|
||||
scrollArea->setWidgetResizable(true);
|
||||
scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||
scrollArea->setStyleSheet(
|
||||
"QScrollArea {"
|
||||
" border: 2px solid #bdc3c7;"
|
||||
" border-radius: 8px;"
|
||||
" background-color: white;"
|
||||
"}"
|
||||
);
|
||||
|
||||
// Widget conteneur pour la liste des stocks
|
||||
m_stockDisplayWidget = new QWidget();
|
||||
m_stockDisplayLayout = new QVBoxLayout(m_stockDisplayWidget);
|
||||
m_stockDisplayLayout->setSpacing(10);
|
||||
m_stockDisplayLayout->setContentsMargins(10, 10, 10, 10);
|
||||
|
||||
scrollArea->setWidget(m_stockDisplayWidget);
|
||||
layout->addWidget(scrollArea);
|
||||
|
||||
return screen;
|
||||
}
|
||||
|
||||
void QtView::updateStockDisplayScreen(const std::vector<Stock>& stocks)
|
||||
{
|
||||
if (!m_stockDisplayLayout) return;
|
||||
|
||||
// Supprimer tous les widgets existants
|
||||
QLayoutItem *child;
|
||||
while ((child = m_stockDisplayLayout->takeAt(0)) != nullptr) {
|
||||
delete child->widget();
|
||||
delete child;
|
||||
}
|
||||
|
||||
if (stocks.empty()) {
|
||||
// Afficher un message si aucun stock
|
||||
QLabel* noStockLabel = new QLabel("🚫 Aucun stock disponible");
|
||||
noStockLabel->setStyleSheet(
|
||||
"QLabel {"
|
||||
" font-size: 20px;"
|
||||
" color: #7f8c8d;"
|
||||
" padding: 40px;"
|
||||
" text-align: center;"
|
||||
" background-color: #f8f9fa;"
|
||||
" border-radius: 8px;"
|
||||
" border: 2px dashed #bdc3c7;"
|
||||
"}"
|
||||
);
|
||||
noStockLabel->setAlignment(Qt::AlignCenter);
|
||||
m_stockDisplayLayout->addWidget(noStockLabel);
|
||||
} else {
|
||||
// Créer une carte pour chaque stock
|
||||
for (const auto& stock : stocks) {
|
||||
QWidget* stockCard = new QWidget();
|
||||
stockCard->setStyleSheet(
|
||||
"QWidget {"
|
||||
" background-color: #ffffff;"
|
||||
" border: 2px solid #3498db;"
|
||||
" border-radius: 12px;"
|
||||
" padding: 15px;"
|
||||
" margin: 5px;"
|
||||
"}"
|
||||
"QWidget:hover {"
|
||||
" border-color: #2980b9;"
|
||||
" background-color: #f8f9fa;"
|
||||
"}"
|
||||
);
|
||||
|
||||
QVBoxLayout* cardLayout = new QVBoxLayout(stockCard);
|
||||
cardLayout->setSpacing(8);
|
||||
cardLayout->setContentsMargins(15, 15, 15, 15);
|
||||
|
||||
// Nom du stock
|
||||
QLabel* nameLabel = new QLabel(QString("📦 %1").arg(QString::fromStdString(stock.getName())));
|
||||
nameLabel->setStyleSheet(
|
||||
"QLabel {"
|
||||
" font-size: 20px;"
|
||||
" font-weight: bold;"
|
||||
" color: #2c3e50;"
|
||||
" margin-bottom: 8px;"
|
||||
"}"
|
||||
);
|
||||
cardLayout->addWidget(nameLabel);
|
||||
|
||||
// Capacité
|
||||
QLabel* capacityLabel = new QLabel(QString("📊 Capacité: %1").arg(stock.getCapacity()));
|
||||
capacityLabel->setStyleSheet(
|
||||
"QLabel {"
|
||||
" font-size: 16px;"
|
||||
" color: #7f8c8d;"
|
||||
" margin-bottom: 4px;"
|
||||
"}"
|
||||
);
|
||||
cardLayout->addWidget(capacityLabel);
|
||||
|
||||
// Utilisation actuelle
|
||||
QLabel* usageLabel = new QLabel(QString("📋 Utilisé: %1").arg(stock.getCurrentSize()));
|
||||
usageLabel->setStyleSheet(
|
||||
"QLabel {"
|
||||
" font-size: 16px;"
|
||||
" color: #7f8c8d;"
|
||||
" margin-bottom: 4px;"
|
||||
"}"
|
||||
);
|
||||
cardLayout->addWidget(usageLabel);
|
||||
|
||||
// Barre de progression pour la capacité
|
||||
double percentage = stock.getCapacity() > 0 ? (static_cast<double>(stock.getCurrentSize()) / stock.getCapacity()) * 100 : 0;
|
||||
QString progressBarColor = percentage > 80 ? "#e74c3c" : (percentage > 50 ? "#f39c12" : "#27ae60");
|
||||
|
||||
QLabel* progressBar = new QLabel();
|
||||
progressBar->setFixedHeight(10);
|
||||
progressBar->setStyleSheet(QString(
|
||||
"QLabel {"
|
||||
" background-color: #ecf0f1;"
|
||||
" border-radius: 5px;"
|
||||
" border: 1px solid #bdc3c7;"
|
||||
"}"
|
||||
"QLabel::chunk {"
|
||||
" background-color: %1;"
|
||||
" border-radius: 5px;"
|
||||
" width: %2%;"
|
||||
"}"
|
||||
).arg(progressBarColor).arg(percentage));
|
||||
cardLayout->addWidget(progressBar);
|
||||
|
||||
m_stockDisplayLayout->addWidget(stockCard);
|
||||
}
|
||||
}
|
||||
|
||||
// Ajouter un stretch à la fin
|
||||
m_stockDisplayLayout->addStretch();
|
||||
}
|
||||
|
||||
QWidget* QtView::createItemTypeDisplayScreen()
|
||||
{
|
||||
QWidget* screen = new QWidget();
|
||||
QVBoxLayout* layout = new QVBoxLayout(screen);
|
||||
layout->setSpacing(20);
|
||||
layout->setContentsMargins(30, 30, 30, 30);
|
||||
|
||||
// Titre
|
||||
QLabel* titleLabel = new QLabel("🏷️ Liste des Types d'Articles");
|
||||
titleLabel->setStyleSheet("font-size: 28px; font-weight: bold; color: #2c3e50; margin-bottom: 30px;");
|
||||
titleLabel->setAlignment(Qt::AlignCenter);
|
||||
layout->addWidget(titleLabel);
|
||||
|
||||
// Bouton d'actualisation
|
||||
QPushButton* refreshButton = new QPushButton("🔄 Actualiser la liste");
|
||||
refreshButton->setMinimumHeight(60);
|
||||
refreshButton->setStyleSheet(
|
||||
"QPushButton {"
|
||||
" background-color: #9b59b6;"
|
||||
" color: white;"
|
||||
" border: none;"
|
||||
" border-radius: 12px;"
|
||||
" font-size: 16px;"
|
||||
" font-weight: bold;"
|
||||
" padding: 15px;"
|
||||
"}"
|
||||
"QPushButton:pressed {"
|
||||
" background-color: #8e44ad;"
|
||||
"}"
|
||||
"QPushButton:hover {"
|
||||
" background-color: #bb8fce;"
|
||||
"}"
|
||||
);
|
||||
connect(refreshButton, &QPushButton::clicked, [this]() { onShowItemTypes(); });
|
||||
layout->addWidget(refreshButton);
|
||||
|
||||
// Zone de contenu avec scroll
|
||||
QScrollArea* scrollArea = new QScrollArea();
|
||||
scrollArea->setWidgetResizable(true);
|
||||
scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||
scrollArea->setStyleSheet(
|
||||
"QScrollArea {"
|
||||
" border: 2px solid #bdc3c7;"
|
||||
" border-radius: 8px;"
|
||||
" background-color: white;"
|
||||
"}"
|
||||
);
|
||||
|
||||
// Widget conteneur pour la liste des types d'articles
|
||||
m_itemTypeDisplayWidget = new QWidget();
|
||||
m_itemTypeDisplayLayout = new QVBoxLayout(m_itemTypeDisplayWidget);
|
||||
m_itemTypeDisplayLayout->setSpacing(10);
|
||||
m_itemTypeDisplayLayout->setContentsMargins(10, 10, 10, 10);
|
||||
|
||||
scrollArea->setWidget(m_itemTypeDisplayWidget);
|
||||
layout->addWidget(scrollArea);
|
||||
|
||||
return screen;
|
||||
}
|
||||
|
||||
void QtView::updateItemTypeDisplayScreen(const std::vector<ItemType>& itemTypes)
|
||||
{
|
||||
if (!m_itemTypeDisplayLayout) return;
|
||||
|
||||
// Supprimer tous les widgets existants
|
||||
QLayoutItem *child;
|
||||
while ((child = m_itemTypeDisplayLayout->takeAt(0)) != nullptr) {
|
||||
delete child->widget();
|
||||
delete child;
|
||||
}
|
||||
|
||||
if (itemTypes.empty()) {
|
||||
// Afficher un message si aucun type d'article
|
||||
QLabel* noItemTypeLabel = new QLabel("🚫 Aucun type d'article disponible");
|
||||
noItemTypeLabel->setStyleSheet(
|
||||
"QLabel {"
|
||||
" font-size: 20px;"
|
||||
" color: #7f8c8d;"
|
||||
" padding: 40px;"
|
||||
" text-align: center;"
|
||||
" background-color: #f8f9fa;"
|
||||
" border-radius: 8px;"
|
||||
" border: 2px dashed #bdc3c7;"
|
||||
"}"
|
||||
);
|
||||
noItemTypeLabel->setAlignment(Qt::AlignCenter);
|
||||
m_itemTypeDisplayLayout->addWidget(noItemTypeLabel);
|
||||
} else {
|
||||
// Créer une carte pour chaque type d'article
|
||||
for (const auto& itemType : itemTypes) {
|
||||
QWidget* itemTypeCard = new QWidget();
|
||||
itemTypeCard->setStyleSheet(
|
||||
"QWidget {"
|
||||
" background-color: #ffffff;"
|
||||
" border: 2px solid #9b59b6;"
|
||||
" border-radius: 12px;"
|
||||
" padding: 15px;"
|
||||
" margin: 5px;"
|
||||
"}"
|
||||
"QWidget:hover {"
|
||||
" border-color: #8e44ad;"
|
||||
" background-color: #f8f9fa;"
|
||||
"}"
|
||||
);
|
||||
|
||||
QVBoxLayout* cardLayout = new QVBoxLayout(itemTypeCard);
|
||||
cardLayout->setSpacing(8);
|
||||
cardLayout->setContentsMargins(15, 15, 15, 15);
|
||||
|
||||
// Nom du type d'article
|
||||
QLabel* nameLabel = new QLabel(QString("🏷️ %1").arg(QString::fromStdString(itemType.getName())));
|
||||
nameLabel->setStyleSheet(
|
||||
"QLabel {"
|
||||
" font-size: 20px;"
|
||||
" font-weight: bold;"
|
||||
" color: #2c3e50;"
|
||||
" margin-bottom: 8px;"
|
||||
"}"
|
||||
);
|
||||
cardLayout->addWidget(nameLabel);
|
||||
|
||||
// ID
|
||||
QLabel* idLabel = new QLabel(QString("🔢 ID: %1").arg(itemType.getId()));
|
||||
idLabel->setStyleSheet(
|
||||
"QLabel {"
|
||||
" font-size: 16px;"
|
||||
" color: #7f8c8d;"
|
||||
" margin-bottom: 4px;"
|
||||
"}"
|
||||
);
|
||||
cardLayout->addWidget(idLabel);
|
||||
|
||||
// Commentaire
|
||||
QString comment = QString::fromStdString(itemType.getComment());
|
||||
if (!comment.isEmpty()) {
|
||||
QLabel* commentLabel = new QLabel(QString("💬 %1").arg(comment));
|
||||
commentLabel->setStyleSheet(
|
||||
"QLabel {"
|
||||
" font-size: 14px;"
|
||||
" color: #7f8c8d;"
|
||||
" margin-bottom: 4px;"
|
||||
" font-style: italic;"
|
||||
"}"
|
||||
);
|
||||
commentLabel->setWordWrap(true);
|
||||
cardLayout->addWidget(commentLabel);
|
||||
}
|
||||
|
||||
// Taille
|
||||
QLabel* sizeLabel = new QLabel(QString("📏 Taille: %1").arg(itemType.getSize()));
|
||||
sizeLabel->setStyleSheet(
|
||||
"QLabel {"
|
||||
" font-size: 16px;"
|
||||
" color: #7f8c8d;"
|
||||
" margin-bottom: 4px;"
|
||||
"}"
|
||||
);
|
||||
cardLayout->addWidget(sizeLabel);
|
||||
|
||||
m_itemTypeDisplayLayout->addWidget(itemTypeCard);
|
||||
}
|
||||
}
|
||||
|
||||
// Ajouter un stretch à la fin
|
||||
m_itemTypeDisplayLayout->addStretch();
|
||||
}
|
||||
|
||||
void QtView::confirmStockDeletion(const QString& stockName)
|
||||
{
|
||||
if (!m_controller) {
|
||||
@ -889,14 +1393,14 @@ void QtView::confirmStockDeletion(const QString& stockName)
|
||||
std::vector<std::string> args = {stockName.toStdString()};
|
||||
m_controller->sendCommand(Command::DeleteStock, args);
|
||||
|
||||
// Afficher un message de confirmation
|
||||
showMessage(QString("Stock '%1' supprimé avec succès").arg(stockName));
|
||||
|
||||
// Retourner à l'écran de sélection et actualiser
|
||||
refreshStockSelectionScreen();
|
||||
m_stackedWidget->removeWidget(confirmationScreen);
|
||||
delete confirmationScreen;
|
||||
m_stackedWidget->setCurrentWidget(m_deleteStockScreen);
|
||||
|
||||
// Ajouter un message de succès temporaire dans l'écran
|
||||
addSuccessMessageToStockScreen(QString("Stock '%1' supprimé avec succès").arg(stockName));
|
||||
});
|
||||
|
||||
connect(cancelButton, &QPushButton::clicked, [this, confirmationScreen]() {
|
||||
@ -917,6 +1421,39 @@ void QtView::confirmStockDeletion(const QString& stockName)
|
||||
m_stackedWidget->setCurrentWidget(confirmationScreen);
|
||||
}
|
||||
|
||||
void QtView::addSuccessMessageToStockScreen(const QString& message)
|
||||
{
|
||||
if (!m_stockSelectionLayout) return;
|
||||
|
||||
// Créer un label de succès temporaire
|
||||
QLabel* successLabel = new QLabel(message);
|
||||
successLabel->setStyleSheet(
|
||||
"QLabel {"
|
||||
" background-color: #27ae60;"
|
||||
" color: white;"
|
||||
" border: none;"
|
||||
" border-radius: 8px;"
|
||||
" font-size: 16px;"
|
||||
" font-weight: bold;"
|
||||
" padding: 15px;"
|
||||
" margin: 10px 0;"
|
||||
"}"
|
||||
);
|
||||
successLabel->setAlignment(Qt::AlignCenter);
|
||||
successLabel->setObjectName("successMessage");
|
||||
|
||||
// Insérer le message au début de la liste
|
||||
m_stockSelectionLayout->insertWidget(0, successLabel);
|
||||
|
||||
// Programmer la suppression automatique du message après 3 secondes
|
||||
QTimer::singleShot(3000, [this, successLabel]() {
|
||||
if (successLabel) {
|
||||
m_stockSelectionLayout->removeWidget(successLabel);
|
||||
delete successLabel;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// MÉTHODES DE NAVIGATION
|
||||
// =============================================================================
|
||||
@ -979,11 +1516,31 @@ void QtView::executeFormAction(QWidget* screen, const QString& title)
|
||||
// Cette méthode sera appelée pour traiter les formulaires
|
||||
// Récupérer les valeurs des champs et exécuter l'action correspondante
|
||||
|
||||
QList<QLineEdit*> fields = screen->findChildren<QLineEdit*>();
|
||||
QStringList values;
|
||||
|
||||
for (QLineEdit* field : fields) {
|
||||
values.append(field->text());
|
||||
// Récupérer les valeurs dans l'ordre des champs (field_0, field_1, etc.)
|
||||
int fieldIndex = 0;
|
||||
while (true) {
|
||||
QString fieldName = QString("field_%1").arg(fieldIndex);
|
||||
|
||||
// Chercher d'abord un QComboBox
|
||||
QComboBox* combo = screen->findChild<QComboBox*>(fieldName);
|
||||
if (combo) {
|
||||
values.append(combo->currentText());
|
||||
fieldIndex++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Sinon chercher un QLineEdit
|
||||
QLineEdit* lineEdit = screen->findChild<QLineEdit*>(fieldName);
|
||||
if (lineEdit) {
|
||||
values.append(lineEdit->text());
|
||||
fieldIndex++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Si aucun champ trouvé, on a fini
|
||||
break;
|
||||
}
|
||||
|
||||
// Exécuter l'action en fonction du titre
|
||||
|
@ -99,9 +99,15 @@ private:
|
||||
// Screen creation helpers
|
||||
QWidget* createTitleAndButtonScreen(const QString& title, const QStringList& buttonTexts, const std::vector<std::function<void()>>& callbacks);
|
||||
QWidget* createFormScreen(const QString& title, const QStringList& labels, const QStringList& placeholders = QStringList());
|
||||
QWidget* createSelectionFormScreen(const QString& title, const QStringList& labels, const QStringList& fieldTypes);
|
||||
QWidget* createStockSelectionScreen();
|
||||
QWidget* createStockDisplayScreen();
|
||||
QWidget* createItemTypeDisplayScreen();
|
||||
void refreshStockSelectionScreen();
|
||||
void updateStockDisplayScreen(const std::vector<Stock>& stocks);
|
||||
void updateItemTypeDisplayScreen(const std::vector<ItemType>& itemTypes);
|
||||
void confirmStockDeletion(const QString& stockName);
|
||||
void addSuccessMessageToStockScreen(const QString& message);
|
||||
|
||||
// Form execution methods
|
||||
void executeFormAction(QWidget* screen, const QString& title);
|
||||
@ -162,10 +168,14 @@ private:
|
||||
QWidget* m_showStocksScreen;
|
||||
QWidget* m_deleteStockScreen;
|
||||
QVBoxLayout* m_stockSelectionLayout; // Layout pour les boutons de stock
|
||||
QWidget* m_stockDisplayWidget; // Widget pour l'affichage des stocks
|
||||
QVBoxLayout* m_stockDisplayLayout; // Layout pour l'affichage des stocks
|
||||
|
||||
QWidget* m_createItemTypeScreen;
|
||||
QWidget* m_showItemTypesScreen;
|
||||
QWidget* m_deleteItemTypeScreen;
|
||||
QWidget* m_itemTypeDisplayWidget; // Widget pour l'affichage des types d'articles
|
||||
QVBoxLayout* m_itemTypeDisplayLayout; // Layout pour l'affichage des types d'articles
|
||||
|
||||
QWidget* m_addItemScreen;
|
||||
QWidget* m_moveItemScreen;
|
||||
|
Loading…
x
Reference in New Issue
Block a user