Wed, 18 Jan 2023 16:17:31 +0100
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).
--- 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) {
--- 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
--- 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 <http://www.gnu.org/licenses/>. */ -//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(); +} + +
--- 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(); }
--- 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 @@ <location filename="../ui/EditProduct.ui" line="3222"/> <location filename="../ui/EditProduct.ui" line="4072"/> <location filename="../ui/EditProduct.ui" line="4227"/> + <location filename="../ui/EditProduct.ui" line="12142"/> <location filename="../src/EditProductExport.cpp" line="866"/> <source>Add</source> <translation type="unfinished"></translation> @@ -4097,12 +4098,12 @@ <translation type="unfinished"></translation> </message> <message> - <location filename="../ui/EditProduct.ui" line="12144"/> + <location filename="../ui/EditProduct.ui" line="12161"/> <source>Export</source> <translation type="unfinished"></translation> </message> <message> - <location filename="../ui/EditProduct.ui" line="12161"/> + <location filename="../ui/EditProduct.ui" line="12178"/> <source>Print</source> <translation type="unfinished"></translation> </message> @@ -4142,43 +4143,43 @@ <translation type="unfinished"></translation> </message> <message> - <location filename="../src/EditProduct.cpp" line="814"/> + <location filename="../src/EditProduct.cpp" line="832"/> <source>BMSapp - Add new product</source> <translation type="unfinished"></translation> </message> <message> - <location filename="../src/EditProduct.cpp" line="816"/> + <location filename="../src/EditProduct.cpp" line="834"/> <source>BMSapp - Edit %1 - %2</source> <translation type="unfinished"></translation> </message> <message> - <location filename="../src/EditProduct.cpp" line="832"/> - <location filename="../src/EditProduct.cpp" line="836"/> + <location filename="../src/EditProduct.cpp" line="850"/> + <location filename="../src/EditProduct.cpp" line="854"/> <source>Edit Product</source> <translation type="unfinished"></translation> </message> <message> - <location filename="../src/EditProduct.cpp" line="832"/> + <location filename="../src/EditProduct.cpp" line="850"/> <source>Name empty or too short.</source> <translation type="unfinished"></translation> </message> <message> - <location filename="../src/EditProduct.cpp" line="836"/> + <location filename="../src/EditProduct.cpp" line="854"/> <source>No beerstyle selected.</source> <translation type="unfinished"></translation> </message> <message> - <location filename="../src/EditProduct.cpp" line="875"/> + <location filename="../src/EditProduct.cpp" line="893"/> <source>Delete product</source> <translation type="unfinished"></translation> </message> <message> - <location filename="../src/EditProduct.cpp" line="899"/> + <location filename="../src/EditProduct.cpp" line="917"/> <source>Product changed</source> <translation type="unfinished"></translation> </message> <message> - <location filename="../src/EditProduct.cpp" line="899"/> + <location filename="../src/EditProduct.cpp" line="917"/> <source>The product has been modified. Save changes?</source> <translation type="unfinished"></translation> </message> @@ -4303,7 +4304,7 @@ <location filename="../src/EditProductTab5.cpp" line="399"/> <location filename="../src/EditProductTab6.cpp" line="896"/> <location filename="../src/EditProductTab7.cpp" line="306"/> - <location filename="../src/EditProduct.cpp" line="875"/> + <location filename="../src/EditProduct.cpp" line="893"/> <source>Delete %1</source> <translation type="unfinished"></translation> </message> @@ -5223,6 +5224,31 @@ <source>Print checklist</source> <translation type="unfinished"></translation> </message> + <message> + <location filename="../src/EditProductTab13.cpp" line="41"/> + <source>Open File</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../src/EditProductTab13.cpp" line="61"/> + <source>Cannot load %1: %2</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../src/EditProductTab13.cpp" line="89"/> + <source>Image here</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../src/EditProductTab13.cpp" line="97"/> + <source>Image type:</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../src/EditProductTab13.cpp" line="110"/> + <source>Image comment:</source> + <translation type="unfinished"></translation> + </message> </context> <context> <name>EditProfileFerment</name>
--- 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 @@ <location filename="../ui/EditProduct.ui" line="3222"/> <location filename="../ui/EditProduct.ui" line="4072"/> <location filename="../ui/EditProduct.ui" line="4227"/> + <location filename="../ui/EditProduct.ui" line="12142"/> <location filename="../src/EditProductExport.cpp" line="866"/> <source>Add</source> <translation>Nieuw</translation> @@ -4537,12 +4538,12 @@ <translation>Plaatjes</translation> </message> <message> - <location filename="../ui/EditProduct.ui" line="12144"/> + <location filename="../ui/EditProduct.ui" line="12161"/> <source>Export</source> <translation>Exporteer</translation> </message> <message> - <location filename="../ui/EditProduct.ui" line="12161"/> + <location filename="../ui/EditProduct.ui" line="12178"/> <source>Print</source> <translation>Print</translation> </message> @@ -4562,7 +4563,7 @@ <translation>Mout</translation> </message> <message> - <location filename="../src/EditProduct.cpp" line="816"/> + <location filename="../src/EditProduct.cpp" line="834"/> <source>BMSapp - Edit %1 - %2</source> <translation>BMSapp - Wijzig %1 - %2</translation> </message> @@ -4627,7 +4628,7 @@ <translation type="vanished">Koken %1 minuten</translation> </message> <message> - <location filename="../src/EditProduct.cpp" line="814"/> + <location filename="../src/EditProduct.cpp" line="832"/> <source>BMSapp - Add new product</source> <translation>BMSapp - Nieuw product</translation> </message> @@ -4636,18 +4637,18 @@ <translation type="vanished">BMSapp - Wijzig product %1</translation> </message> <message> - <location filename="../src/EditProduct.cpp" line="832"/> - <location filename="../src/EditProduct.cpp" line="836"/> + <location filename="../src/EditProduct.cpp" line="850"/> + <location filename="../src/EditProduct.cpp" line="854"/> <source>Edit Product</source> <translation>Wijzig Product</translation> </message> <message> - <location filename="../src/EditProduct.cpp" line="832"/> + <location filename="../src/EditProduct.cpp" line="850"/> <source>Name empty or too short.</source> <translation>De naam is leeg of te kort.</translation> </message> <message> - <location filename="../src/EditProduct.cpp" line="836"/> + <location filename="../src/EditProduct.cpp" line="854"/> <source>No beerstyle selected.</source> <translation>Geen bierstijl gekozen.</translation> </message> @@ -4660,17 +4661,17 @@ %3</translation> </message> <message> - <location filename="../src/EditProduct.cpp" line="875"/> + <location filename="../src/EditProduct.cpp" line="893"/> <source>Delete product</source> <translation>Verwijder product</translation> </message> <message> - <location filename="../src/EditProduct.cpp" line="899"/> + <location filename="../src/EditProduct.cpp" line="917"/> <source>Product changed</source> <translation>Product gewijzigd</translation> </message> <message> - <location filename="../src/EditProduct.cpp" line="899"/> + <location filename="../src/EditProduct.cpp" line="917"/> <source>The product has been modified. Save changes?</source> <translation>Het product is gewijzigd. Wijzigingen opslaan?</translation> </message> @@ -4807,7 +4808,7 @@ <location filename="../src/EditProductTab5.cpp" line="399"/> <location filename="../src/EditProductTab6.cpp" line="896"/> <location filename="../src/EditProductTab7.cpp" line="306"/> - <location filename="../src/EditProduct.cpp" line="875"/> + <location filename="../src/EditProduct.cpp" line="893"/> <source>Delete %1</source> <translation>Verwijder %1</translation> </message> @@ -5823,6 +5824,31 @@ <source>Confirm that the beer tasting is done and the results are filled in.</source> <translation>Bevestig dat het proeven gedaan is en opmerkingen ingevuld zijn.</translation> </message> + <message> + <location filename="../src/EditProductTab13.cpp" line="41"/> + <source>Open File</source> + <translation type="unfinished">Open bestand</translation> + </message> + <message> + <location filename="../src/EditProductTab13.cpp" line="61"/> + <source>Cannot load %1: %2</source> + <translation type="unfinished">Kan niet laden %1: %2</translation> + </message> + <message> + <location filename="../src/EditProductTab13.cpp" line="89"/> + <source>Image here</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../src/EditProductTab13.cpp" line="97"/> + <source>Image type:</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../src/EditProductTab13.cpp" line="110"/> + <source>Image comment:</source> + <translation type="unfinished"></translation> + </message> </context> <context> <name>EditProfileFerment</name>
--- 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 @@ <widget class="QListView" name="filmView"> <property name="geometry"> <rect> - <x>20</x> - <y>30</y> - <width>1111</width> - <height>141</height> - </rect> + <x>10</x> + <y>10</y> + <width>181</width> + <height>451</height> + </rect> + </property> + </widget> + <widget class="QPushButton" name="addImage"> + <property name="geometry"> + <rect> + <x>60</x> + <y>470</y> + <width>80</width> + <height>23</height> + </rect> + </property> + <property name="text"> + <string>Add</string> + </property> + <property name="icon"> + <iconset resource="../../../../../../home/mbroek/MyProjects/bmsapp/resources/icons.qrc"> + <normaloff>:/icons/silk/image_add.png</normaloff>:/icons/silk/image_add.png</iconset> </property> </widget> </widget>