# HG changeset patch # User Michiel Broek # Date 1674307630 -3600 # Node ID b21da6f583be3be07b224af5ae606024212253b4 # Parent c5f6f3f1b7142878ca4b1707377a3ffefa991ee2 The images tab now looks complete. Made the left side (thumbnails) a bit smaller. The right side of the screen now shows the current image and all data that belongs to that. After a new image is added, reload the images. Implemented delete image. diff -r c5f6f3f1b714 -r b21da6f583be src/EditProduct.cpp --- a/src/EditProduct.cpp Fri Jan 20 16:44:08 2023 +0100 +++ b/src/EditProduct.cpp Sat Jan 21 14:27:10 2023 +0100 @@ -102,10 +102,15 @@ ui->keg_sugarEdit->addItem(query.value(0).toString()); } + for (int i = 0; i < 7; i++) + ui->image_typeEdit->addItem(QCoreApplication::translate("PicType", g_prod_pic_types[i])); + ui->spargeGroup->setId(ui->w1_spButton, 0); ui->spargeGroup->setId(ui->w2_spButton, 1); ui->spargeGroup->setId(ui->wg_spButton, 2); + + if (id >= 0) { if (! DB_product::load(product, this, id)) return; @@ -764,6 +769,7 @@ connect(ui->prevImage, SIGNAL(clicked()), this, SLOT(prevImage_clicked())); connect(ui->downloadImage, SIGNAL(clicked()), this, SLOT(downloadImage_clicked())); connect(ui->printImage, SIGNAL(clicked()), this, SLOT(printImage_clicked())); + connect(ui->filmStrip, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(selectImage_clicked(QListWidgetItem *))); setStage(); diff -r c5f6f3f1b714 -r b21da6f583be src/EditProduct.h --- a/src/EditProduct.h Fri Jan 20 16:44:08 2023 +0100 +++ b/src/EditProduct.h Sat Jan 21 14:27:10 2023 +0100 @@ -18,6 +18,7 @@ #include #include #include +#include #include "global.h" @@ -264,7 +265,7 @@ void prevImage_clicked(); void downloadImage_clicked(); void printImage_clicked(); - void selectImage_clicked(int val); + void selectImage_clicked(QListWidgetItem *); /* Modified progress bars */ void ferment_perc_mash_valueChanged(int value); diff -r c5f6f3f1b714 -r b21da6f583be src/EditProductTab13.cpp --- a/src/EditProductTab13.cpp Fri Jan 20 16:44:08 2023 +0100 +++ b/src/EditProductTab13.cpp Sat Jan 21 14:27:10 2023 +0100 @@ -26,6 +26,13 @@ /* * Clean old picture areas. */ + if (product->images_count < 0 && product->images_list.size()) { + qDebug() << " clean images_list"; + ui->filmStrip->clear(); + product->images_list.clear(); + product->images_count = -1; + product->images_current = -1; + } /* * Load images data for this product uuid. @@ -47,7 +54,8 @@ while (query.next()) { Images i; - qDebug() << product->images_count << query.value("pic_data").toByteArray().size(); + i.record = query.value("record").toInt(); + i.uuid = query.value("uuid").toString(); i.pic_type = query.value("pic_type").toInt(); i.pic_data = query.value("pic_data").toByteArray(); i.pic_comment = query.value("pic_comment").toString(); @@ -79,27 +87,20 @@ */ void EditProduct::images_Thumbnails() { - QList items = ui->filmStrip->selectedItems(); - foreach(QListWidgetItem * item, items) { - delete ui->filmStrip->takeItem(ui->filmStrip->row(item)); - } + ui->filmStrip->clear(); for (int i = 0; i < product->images_list.size(); i++) { QListWidgetItem* newItem = new QListWidgetItem(); QString text = QCoreApplication::translate("PicType", g_prod_pic_types[product->images_list.at(i).pic_type]); - if (product->images_list.at(i).filename != "") - text.append("\n" + product->images_list.at(i).filename); - if (product->images_list.at(i).pic_comment != "") - text.append("\n" + product->images_list.at(i).pic_comment); - // product->images_list.at(i).timestamp newItem->setText(text); newItem->setBackground(QColor(0x45,0x53,0x64)); QPixmap outPixmap = QPixmap(); outPixmap.loadFromData(product->images_list.at(i).pic_data); qDebug() << " " << outPixmap.width() << "x" << outPixmap.height() << "size" << outPixmap.size() << product->images_list.at(i).filename; - if (outPixmap.width() > 320 || outPixmap.height() > 240) - newItem->setIcon(QIcon(outPixmap.scaled(320, 240, Qt::KeepAspectRatio, Qt::SmoothTransformation))); + qDebug() << " " << ui->filmStrip->iconSize(); + if (outPixmap.width() > 240 || outPixmap.height() > 180) + newItem->setIcon(QIcon(outPixmap.scaled(240, 180, Qt::KeepAspectRatio, Qt::SmoothTransformation))); else newItem->setIcon(QIcon(outPixmap)); @@ -117,6 +118,28 @@ ui->downloadImage->setEnabled((product->images_count > 0) ? true:false); ui->printImage->setEnabled((product->images_count > 0) ? true:false); ui->delImage->setEnabled((product->images_count > 0) ? true:false); + + if (product->images_count < 1) { + ui->image_filenameEdit->setText(""); + ui->image_timestampEdit->setText(""); + ui->image_commentEdit->setText(""); + ui->image_typeEdit->setCurrentIndex(0); + //ui->currentImage->setPixmap(); + return; + } + + QPixmap outPixmap = QPixmap(); + outPixmap.loadFromData(product->images_list.at(id).pic_data); + qDebug() << " " << outPixmap.width() << "x" << outPixmap.height() << "size" << outPixmap.size() << product->images_list.at(id).filename; + if (outPixmap.width() > ui->currentImage->width() || outPixmap.height() > ui->currentImage->height()) + ui->currentImage->setPixmap(outPixmap.scaled(ui->currentImage->width(), ui->currentImage->height(), Qt::KeepAspectRatio, Qt::SmoothTransformation)); + else + ui->currentImage->setPixmap(outPixmap); + + ui->image_filenameEdit->setText(product->images_list.at(id).filename); + ui->image_timestampEdit->setText(product->images_list.at(id).timestamp.toString(Qt::RFC2822Date)); + ui->image_commentEdit->setText(product->images_list.at(id).pic_comment); + ui->image_typeEdit->setCurrentIndex(product->images_list.at(id).pic_type); } @@ -194,7 +217,7 @@ 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->addItem(QCoreApplication::translate("PicType", g_prod_pic_types[i])); typeEdit->setCurrentIndex(0); QLabel *commentLabel = new QLabel(dialog); @@ -235,15 +258,36 @@ .arg(query.lastError().nativeErrorCode()).arg(query.lastError().driverText()).arg(query.lastError().databaseText())); } else { qDebug() << "new image Saved"; + product->images_count = -1; // Force reload data + images_Init(); } - - //emit refreshAll(); } void EditProduct::delImage_clicked() { - qDebug() << "delImage_clicked()" << product->images_current << ui->filmStrip->currentRow(); + qDebug() << "delImage_clicked()" << ui->filmStrip->currentRow(); + + int rc = QMessageBox::warning(this, tr("Delete image"), tr("Delete %1").arg(product->images_list.at(ui->filmStrip->currentRow()).filename), + QMessageBox::Yes | QMessageBox::No, QMessageBox::No); + if (rc == QMessageBox::No) + return; + + qDebug() << " delete record" << product->images_list.at(ui->filmStrip->currentRow()).record; + + QSqlQuery query; + query.prepare("DELETE FROM products_pics WHERE record=:record"); + query.bindValue(":record", product->images_list.at(ui->filmStrip->currentRow()).record); + query.exec(); + + if (query.lastError().isValid()) { + qWarning() << "delImage_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())); + } + + product->images_count = -1; // Force reload data + images_Init(); } @@ -287,8 +331,13 @@ } -void EditProduct::selectImage_clicked(int val) +void EditProduct::selectImage_clicked(QListWidgetItem *val) { - qDebug() << "selectImage_clicked()" << val << product->images_current << ui->filmStrip->currentRow(); + qDebug() << "selectImage_clicked()" << ui->filmStrip->currentRow(); + + if (product->images_count > 0) { + product->images_current = ui->filmStrip->currentRow(); + images_Main(product->images_current); + } } diff -r c5f6f3f1b714 -r b21da6f583be src/global.h --- a/src/global.h Fri Jan 20 16:44:08 2023 +0100 +++ b/src/global.h Sat Jan 21 14:27:10 2023 +0100 @@ -239,6 +239,8 @@ struct Images { + int record; + QString uuid; int pic_type; QByteArray pic_data; QString pic_comment; diff -r c5f6f3f1b714 -r b21da6f583be translations/bmsapp_en.ts --- a/translations/bmsapp_en.ts Fri Jan 20 16:44:08 2023 +0100 +++ b/translations/bmsapp_en.ts Sat Jan 21 14:27:10 2023 +0100 @@ -2336,14 +2336,14 @@ - + Save - + @@ -4100,23 +4100,38 @@ - + Previous - + Next - + + Filename: + + + + + Comment: + + + + + Type: + + + + Export - - + + Print @@ -4151,48 +4166,48 @@ - + %1, part %2 of %3 - + 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? @@ -4317,7 +4332,8 @@ - + + Delete %1 @@ -5238,44 +5254,52 @@ - + Open File - + Cannot load %1: %2 - + + Image here - + Image type: - + Image comment: - + The comment for this image. - - + + Delete image + + + + + + Database error - - + + + MySQL error: %1 %2 %3 diff -r c5f6f3f1b714 -r b21da6f583be translations/bmsapp_nl.ts --- a/translations/bmsapp_nl.ts Fri Jan 20 16:44:08 2023 +0100 +++ b/translations/bmsapp_nl.ts Sat Jan 21 14:27:10 2023 +0100 @@ -2636,14 +2636,14 @@ - + Save Bewaar - + @@ -4540,23 +4540,38 @@ Plaatjes - + Previous - + Next - + + Filename: + + + + + Comment: + + + + + Type: + Soort: + + + Export Exporteer - - + + Print Print @@ -4576,7 +4591,7 @@ Mout - + BMSapp - Edit %1 - %2 BMSapp - Wijzig %1 - %2 @@ -4624,8 +4639,9 @@ Zuurstof - - + + + Database error Database fout @@ -4634,7 +4650,7 @@ MySQL fout: record %1 niet gevonden - + %1, part %2 of %3 %1, deel %2 van %3 @@ -4643,7 +4659,7 @@ Koken %1 minuten - + BMSapp - Add new product BMSapp - Nieuw product @@ -4652,24 +4668,25 @@ 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. - - + + + MySQL error: %1 %2 %3 @@ -4678,17 +4695,17 @@ %3 - + Delete product Verwijder product - + Product changed Product gewijzigd - + The product has been modified. Save changes? Het product is gewijzigd. Wijzigingen opslaan? @@ -4825,7 +4842,8 @@ - + + Delete %1 Verwijder %1 @@ -5842,35 +5860,41 @@ 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 Plaatje hier - + Image type: Soort plaatje: - + Image comment: Bijschrift: - + The comment for this image. Het bijschrift of commentaar bij dit plaatje. + + + Delete image + + EditProfileFerment diff -r c5f6f3f1b714 -r b21da6f583be ui/EditProduct.ui --- a/ui/EditProduct.ui Fri Jan 20 16:44:08 2023 +0100 +++ b/ui/EditProduct.ui Sat Jan 21 14:27:10 2023 +0100 @@ -12122,8 +12122,8 @@ - 950 - 470 + 300 + 10 80 23 @@ -12141,7 +12141,7 @@ 10 10 - 346 + 267 491 @@ -12151,6 +12151,9 @@ Qt::ScrollBarAlwaysOff + + QAbstractItemView::NoEditTriggers + true @@ -12159,8 +12162,8 @@ - 330 - 330 + 250 + 200 @@ -12181,12 +12184,18 @@ QListView::IconMode + + true + + + Qt::AlignHCenter + - 1060 - 470 + 300 + 50 80 23 @@ -12202,8 +12211,8 @@ - 390 - 470 + 300 + 330 80 23 @@ -12219,8 +12228,8 @@ - 500 - 470 + 300 + 370 80 23 @@ -12236,8 +12245,8 @@ - 670 - 470 + 300 + 130 80 23 @@ -12253,8 +12262,8 @@ - 780 - 470 + 300 + 170 80 23 @@ -12267,6 +12276,131 @@ :/icons/silk/printer.png:/icons/silk/printer.png + + + + 400 + 10 + 741 + 381 + + + + false + + + QFrame::StyledPanel + + + Image here + + + Qt::AlignCenter + + + + + + 300 + 410 + 131 + 20 + + + + Filename: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 300 + 470 + 131 + 20 + + + + Comment: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 440 + 470 + 661 + 23 + + + + 256 + + + + + + 440 + 410 + 381 + 23 + + + + 256 + + + true + + + + + + 300 + 440 + 131 + 20 + + + + Type: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 440 + 440 + 161 + 23 + + + + + + + 900 + 410 + 201 + 23 + + + + 256 + + + true + +