diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index ecdbef3..1297e28 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -3,7 +3,7 @@ set(Boost_USE_STATIC_LIBS ON) find_package(Boost 1.62 COMPONENTS date_time REQUIRED) find_package(SQLite3 REQUIRED) #find_package(PkgConfig REQUIRED) -find_package(XLNT REQUIRED) +find_package(XLNT REQUIRED STATIC) find_package(JSONCPP REQUIRED) #pkg_check_modules(XLNT REQUIRED xlnt>=1.3) #pkg_check_modules(JSONCPP REQUIRED jsoncpp) diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 1312dfc..29f4efd 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -9,6 +9,8 @@ #include "sellerdialog.h" #include "settingsdialog.h" +#include + #include #include @@ -58,11 +60,15 @@ MainWindow::MainWindow() marketplace_->clear(); setSaleModel(); }); + + ui_.sellerNoEdit->installEventFilter(this); + ui_.givenSpinBox->installEventFilter(this); + connect(ui_.actionEditSeller, &QAction::triggered, this, &MainWindow::onActionEditSellerTriggered); - connect(ui_.sellerNoEdit, &QLineEdit::returnPressed, this, - &MainWindow::onSellerNoEditCheckSellerNo); connect(ui_.paidButton, &QPushButton::clicked, this, &MainWindow::onPaidButtonTriggered); + connect(ui_.givenSpinBox, QOverload::of(&QDoubleSpinBox::valueChanged), this, + &MainWindow::onGivenSpinBoxValueChanged); connect(ui_.basketView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &MainWindow::onBasketViewSelectionChanged); connect(ui_.cancelArticleButton, &QPushButton::clicked, this, @@ -108,7 +114,6 @@ MainWindow::MainWindow() &MainWindow::onImportSalesJsonActionTriggered); readGeometry(); - ui_.drawbackContainerWidget->setVisible(false); setWindowIcon(QIcon(":/misc/kima2.ico")); } @@ -151,19 +156,61 @@ void MainWindow::onPaidButtonTriggered() dynamic_cast(ui_.basketView->model())->finishSale(); ui_.lastPriceLabel1->setText(lastPrice); ui_.lastPriceLabel2->setText(lastPrice); - ui_.basketSumLabel->setText(" 0,00 €"); + ui_.basketSumLabel->setText(formatCentAsEuroString(0).c_str()); + ui_.drawbackLabel->setText(formatCentAsEuroString(0).c_str()); + ui_.drawbackContainerWidget->setEnabled(false); + ui_.sellerNoEdit->setFocus(); statusBar()->showMessage("Verkaufsvorgang erfolgreich durchgeführt.", STATUSBAR_TIMEOUT); } } -void MainWindow::onSellerNoEditCheckSellerNo() +bool MainWindow::eventFilter(QObject* target, QEvent* event) +{ + if (target == ui_.sellerNoEdit) { + if (event->type() == QEvent::KeyPress) { + QKeyEvent* keyEvent = static_cast(event); + if (keyEvent->key() == Qt::Key::Key_Enter || keyEvent->key() == Qt::Key::Key_Return) { + if (keyEvent->modifiers() == Qt::ControlModifier) { + checkSellerNo(true); + } else { + checkSellerNo(false); + } + + return true; + } + } + } else if (target == ui_.givenSpinBox) { + if (event->type() == QEvent::KeyPress) { + QKeyEvent* keyEvent = static_cast(event); + if (keyEvent->key() == Qt::Key::Key_Enter || keyEvent->key() == Qt::Key::Key_Return) { + if (keyEvent->modifiers() == Qt::ControlModifier) { + onPaidButtonTriggered(); + return true; + } + } else if (keyEvent->key() == Qt::Key::Key_Escape) { + ui_.drawbackLabel->setText(formatCentAsEuroString(0).c_str()); + ui_.drawbackContainerWidget->setEnabled(false); + ui_.sellerNoEdit->setFocus(); + } + } + } + return QMainWindow::eventFilter(target, event); +} + +void MainWindow::checkSellerNo(bool ctrlPressed) { using std::regex, std::regex_match, std::smatch; auto inputText = ui_.sellerNoEdit->text().toStdString(); if (inputText.empty()) { - onPaidButtonTriggered(); + if (ctrlPressed == false) { + onPaidButtonTriggered(); + } else if (marketplace_->getBasket().size() > 0) { + ui_.drawbackContainerWidget->setEnabled(true); + ui_.givenSpinBox->setFocus(); + ui_.givenSpinBox->selectAll(); + } return; } @@ -192,6 +239,14 @@ void MainWindow::onSellerNoEditCheckSellerNo() ui_.sellerNoEdit->clear(); } +void MainWindow::onGivenSpinBoxValueChanged(double value) +{ + int givenInCent = std::round(value * 100); + int basketSumInCent = marketplace_->getBasketSumInCent(); + int drawback = givenInCent - basketSumInCent; + ui_.drawbackLabel->setText(formatCentAsEuroString(drawback).c_str()); +} + void MainWindow::onBasketViewSelectionChanged(const QItemSelection& selected, [[maybe_unused]] const QItemSelection& deselected) { diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index ee99fd7..07cb554 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -29,14 +29,16 @@ class MainWindow : public QMainWindow void onCancelAllArticlesButtonClicked(bool checked); void onAboutQt(); void onAbout(); + virtual bool eventFilter(QObject *target, QEvent *event) override; protected: virtual void closeEvent(QCloseEvent* event) override; private: void onActionEditSellerTriggered(); - void onSellerNoEditCheckSellerNo(); + void checkSellerNo(bool ctrlPressed = false); void onPaidButtonTriggered(); + void onGivenSpinBoxValueChanged(double value); void onImportSellerExcelActionTriggered(); void onImportSellerJsonActionTriggered(); void onExportSellerJsonActionTriggered(); diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index 76efbb2..b215010 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -112,7 +112,7 @@ - + @@ -125,7 +125,7 @@ - + 75