# HG changeset patch # User Michiel Broek # Date 1674055051 -3600 # Node ID 8fc90936055244f0f9eb07d1faba1a851ef44ae6 # Parent 1fed3ff9a64eb3492e130b4f934e5d98e6c0e433 In EditProduct added tab number 13. When entered, a signal is generated to init this tab so that we can defer loading. Added a AddImage button, we can select an image, give it a type and comment and store it is a separate table. The global settings file now has storage for paths (images, download and beerxml). diff -r 1fed3ff9a64e -r 8fc909360552 src/EditProduct.cpp --- a/src/EditProduct.cpp Mon Jan 16 16:55:41 2023 +0100 +++ b/src/EditProduct.cpp Wed Jan 18 16:17:31 2023 +0100 @@ -575,6 +575,9 @@ qDebug() << "== Start connecting =="; + // Global signals + connect(ui->tabWidget, &QTabWidget::currentChanged, this, &EditProduct::tab_changed); + // All signals from tab "Generic" connect(ui->lockedEdit, &QCheckBox::stateChanged, this, &EditProduct::is_changed); connect(ui->codeEdit, &QLineEdit::textChanged, this, &EditProduct::code_changed); @@ -750,6 +753,9 @@ connect(ui->taste_aftertasteEdit, &QLineEdit::textChanged, this, &EditProduct::taste_aftertaste_changed); connect(ui->taste_notesEdit, SIGNAL(textChanged()), this, SLOT(taste_notes_changed())); + /* All signals from tab Images */ + connect(ui->addImage, SIGNAL(clicked()), this, SLOT(addImage_clicked())); + setStage(); ui->saveButton->setEnabled(false); @@ -768,6 +774,18 @@ } +void EditProduct::tab_changed() +{ + if (ui->tabWidget->currentWidget()->objectName() != "images") + return; + + /* + * Entered the images tab. Load the images for this product. + */ + images_Init(); +} + + void EditProduct::calcSupplies() { if (product->inventory_reduced > PROD_STAGE_PACKAGE) { diff -r 1fed3ff9a64e -r 8fc909360552 src/EditProduct.h --- a/src/EditProduct.h Mon Jan 16 16:55:41 2023 +0100 +++ b/src/EditProduct.h Wed Jan 18 16:17:31 2023 +0100 @@ -56,6 +56,7 @@ void on_exportButton_clicked(); void on_printButton_clicked(); void is_changed(); + void tab_changed(); void code_changed(QString); void name_changed(QString); void notes_changed(); @@ -257,6 +258,8 @@ void taste_aftertaste_changed(QString val); void taste_notes_changed(); + void addImage_clicked(); + /* Modified progress bars */ void ferment_perc_mash_valueChanged(int value); void ferment_perc_sugars_valueChanged(int value); @@ -374,6 +377,8 @@ bool block_misc(int stage, int use_use); bool block_yeast(int stage, int use); void check_waters(); + void images_Init(); + bool images_loadFile(const QString &fileName); }; #endif diff -r 1fed3ff9a64e -r 8fc909360552 src/EditProductTab13.cpp --- a/src/EditProductTab13.cpp Mon Jan 16 16:55:41 2023 +0100 +++ b/src/EditProductTab13.cpp Wed Jan 18 16:17:31 2023 +0100 @@ -17,11 +17,133 @@ * along with this program. If not, see . */ -//void EditProduct::taste_date_changed(QDate val) -//{ -// product->taste_date = ui->taste_dateEdit->nullDate(); -// is_changed(); -// setStage(); -//} +void EditProduct::images_Init() +{ + qDebug() << "images_Init()"; + + // Start spinner + // Clean old picture areas + // Load images data for this product uuid + // Show thumbnails on the left. + // If any, show picture 1 + // Stop spinner +} +void EditProduct::addImage_clicked() +{ + QString fileName; + QByteArray imageByteArray; + QSqlQuery query; + QSettings settings(QSettings::IniFormat, QSettings::UserScope, "mbse", "bmsapp"); + + QFileDialog dialog1(this, tr("Open File")); + dialog1.setDirectory(settings.value("paths/images").toString()); + /* Only a few image formats are valid */ + QStringList mimeTypeFilters ({ "image/bmp", "image/gif", "image/jpeg", "image/png", "image/svg+xml" }); + dialog1.setMimeTypeFilters(mimeTypeFilters); + dialog1.setNameFilter("Images (*.bmp *.BMP *.gif *.GIF *.jpg *.JPG *.png *.PNG *.svg *.SVG)"); + dialog1.setAcceptMode(QFileDialog::AcceptOpen); +// dialog1.setOption(QFileDialog::DontUseNativeDialog); + if (dialog1.exec() != QDialog::Accepted) + return; + + /* + * Save our current path + */ + settings.setValue("paths/images", dialog1.directory().absolutePath()); + + fileName = dialog1.selectedFiles().constFirst(); + QImageReader reader(fileName); + reader.setAutoTransform(true); + const QImage newImage = reader.read(); + if (newImage.isNull()) { + QMessageBox::information(this, QGuiApplication::applicationDisplayName(), tr("Cannot load %1: %2") + .arg(QDir::toNativeSeparators(fileName), reader.errorString())); + return; + } + qDebug() << "Image" << fileName << newImage.width() << newImage.height() << "size" << newImage.sizeInBytes(); + + QBuffer buffer(&imageByteArray); + buffer.open(QIODevice::WriteOnly); + newImage.save(&buffer, "PNG"); + + /* + * Now that we have selected a valid image, create a new dialog so + * we can add extra information for this image and a Save button. + */ + QDialog* dialog = new QDialog(this); + dialog->resize(500, 490); + QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog); + buttonBox->setObjectName(QString::fromUtf8("buttonBox")); + buttonBox->setGeometry(QRect(10, 440, 480, 32)); + buttonBox->setLayoutDirection(Qt::LeftToRight); + buttonBox->setOrientation(Qt::Horizontal); + buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Save); + buttonBox->setCenterButtons(true); + + QLabel *imageLabel = new QLabel(dialog); + imageLabel->setObjectName(QString::fromUtf8("imageLabel")); + imageLabel->setGeometry(QRect(10, 10, 480, 320)); + imageLabel->setAlignment(Qt::AlignCenter); + imageLabel->setText(tr("Image here")); + QPixmap outPixmap = QPixmap(); + outPixmap.loadFromData(imageByteArray); + if (outPixmap.width() > 480 || outPixmap.height() > 320) + imageLabel->setPixmap(outPixmap.scaled(480, 320, Qt::KeepAspectRatio, Qt::SmoothTransformation)); + else + imageLabel->setPixmap(outPixmap); + + QLabel *typeLabel = new QLabel(dialog); + typeLabel->setObjectName(QString::fromUtf8("typeLabel")); + typeLabel->setText(tr("Image type:")); + typeLabel->setGeometry(QRect(10, 360, 141, 20)); + typeLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); + + QComboBox *typeEdit = new QComboBox(dialog); + typeEdit->setObjectName(QString::fromUtf8("typeEdit")); + typeEdit->setGeometry(QRect(160, 360, 161, 23)); + for (int i = 0; i < 7; i++) + typeEdit->addItem(g_prod_pic_types[i]); + typeEdit->setCurrentIndex(0); + + QLabel *commentLabel = new QLabel(dialog); + commentLabel->setObjectName(QString::fromUtf8("commentLabel")); + commentLabel->setText(tr("Image comment:")); + commentLabel->setGeometry(QRect(10, 390, 141, 20)); + commentLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); + + QLineEdit *commentEdit = new QLineEdit(dialog); + commentEdit->setObjectName(QString::fromUtf8("commentEdit")); + commentEdit->setGeometry(QRect(160, 390, 320, 23)); + commentEdit->setToolTip(tr("The comment for this image.")); + + connect(buttonBox, SIGNAL(rejected()), dialog, SLOT(reject())); + connect(buttonBox, SIGNAL(accepted()), dialog, SLOT(accept())); + + dialog->setModal(true); + dialog->exec(); + if (dialog->result() == QDialog::Rejected) { + return; + } + disconnect(buttonBox, nullptr, nullptr, nullptr); + + query.prepare("INSERT INTO products_pics SET uuid=:uuid, pic_type=:pic_type, pic_data=:pic_data, pic_comment=:pic_comment"); + query.bindValue(":uuid", product->uuid); + query.bindValue(":pic_type", g_prod_pic_types[typeEdit->currentIndex()]); + query.bindValue(":pic_data", imageByteArray); + query.bindValue(":pic_comment", commentEdit->text()); + + query.exec(); + if (query.lastError().isValid()) { + qWarning() << "addImage_clicked()" << query.lastError(); + QMessageBox::warning(this, tr("Database error"), tr("MySQL error: %1\n%2\n%3") + .arg(query.lastError().nativeErrorCode()).arg(query.lastError().driverText()).arg(query.lastError().databaseText())); + } else { + qDebug() << "new image Saved"; + } + + //emit refreshAll(); +} + + diff -r 1fed3ff9a64e -r 8fc909360552 src/MainWindow.cpp --- a/src/MainWindow.cpp Mon Jan 16 16:55:41 2023 +0100 +++ b/src/MainWindow.cpp Wed Jan 18 16:17:31 2023 +0100 @@ -355,6 +355,14 @@ } settings.endGroup(); qDebug() << "WS dev" << wsDev.host; + + settings.beginGroup("paths"); + if (settings.value("images").toString().isEmpty()) { + settings.setValue("download", QDir::homePath()); + settings.setValue("images", QDir::homePath()); + settings.setValue("beerxml", QDir::homePath()); + } + settings.endGroup(); } diff -r 1fed3ff9a64e -r 8fc909360552 translations/bmsapp_en.ts --- a/translations/bmsapp_en.ts Mon Jan 16 16:55:41 2023 +0100 +++ b/translations/bmsapp_en.ts Wed Jan 18 16:17:31 2023 +0100 @@ -2857,6 +2857,7 @@ + Add @@ -4097,12 +4098,12 @@ - + Export - + Print @@ -4142,43 +4143,43 @@ - + BMSapp - Add new product - + BMSapp - Edit %1 - %2 - - + + Edit Product - + Name empty or too short. - + No beerstyle selected. - + Delete product - + Product changed - + The product has been modified. Save changes? @@ -4303,7 +4304,7 @@ - + Delete %1 @@ -5223,6 +5224,31 @@ Print checklist + + + Open File + + + + + Cannot load %1: %2 + + + + + Image here + + + + + Image type: + + + + + Image comment: + + EditProfileFerment diff -r 1fed3ff9a64e -r 8fc909360552 translations/bmsapp_nl.ts --- a/translations/bmsapp_nl.ts Mon Jan 16 16:55:41 2023 +0100 +++ b/translations/bmsapp_nl.ts Wed Jan 18 16:17:31 2023 +0100 @@ -3056,6 +3056,7 @@ + Add Nieuw @@ -4537,12 +4538,12 @@ Plaatjes - + Export Exporteer - + Print Print @@ -4562,7 +4563,7 @@ Mout - + BMSapp - Edit %1 - %2 BMSapp - Wijzig %1 - %2 @@ -4627,7 +4628,7 @@ Koken %1 minuten - + BMSapp - Add new product BMSapp - Nieuw product @@ -4636,18 +4637,18 @@ BMSapp - Wijzig product %1 - - + + Edit Product Wijzig Product - + Name empty or too short. De naam is leeg of te kort. - + No beerstyle selected. Geen bierstijl gekozen. @@ -4660,17 +4661,17 @@ %3 - + Delete product Verwijder product - + Product changed Product gewijzigd - + The product has been modified. Save changes? Het product is gewijzigd. Wijzigingen opslaan? @@ -4807,7 +4808,7 @@ - + Delete %1 Verwijder %1 @@ -5823,6 +5824,31 @@ Confirm that the beer tasting is done and the results are filled in. Bevestig dat het proeven gedaan is en opmerkingen ingevuld zijn. + + + Open File + Open bestand + + + + Cannot load %1: %2 + Kan niet laden %1: %2 + + + + Image here + + + + + Image type: + + + + + Image comment: + + EditProfileFerment diff -r 1fed3ff9a64e -r 8fc909360552 ui/EditProduct.ui --- a/ui/EditProduct.ui Mon Jan 16 16:55:41 2023 +0100 +++ b/ui/EditProduct.ui Wed Jan 18 16:17:31 2023 +0100 @@ -12122,11 +12122,28 @@ - 20 - 30 - 1111 - 141 - + 10 + 10 + 181 + 451 + + + + + + + 60 + 470 + 80 + 23 + + + + Add + + + + :/icons/silk/image_add.png:/icons/silk/image_add.png