diff -r ccdc1dbc0ebb -r dc4b659a320b src/Setup.cpp --- a/src/Setup.cpp Wed Mar 02 11:06:07 2022 +0100 +++ b/src/Setup.cpp Sat Mar 05 10:37:09 2022 +0100 @@ -101,7 +101,12 @@ ui->yeastEdit->setCurrentIndex(pos); connect(ui->yeastEdit, &QComboBox::currentTextChanged, this, &Setup::is_changed); - // query.value(2).toString() logo varchar(1024) + /* logo */ + logoByteArray = query.value(2).toByteArray(); + QPixmap outPixmap = QPixmap(); + outPixmap.loadFromData(logoByteArray); + ui->logoLabel->setPixmap(outPixmap); + ui->logoLabel->adjustSize(); } @@ -112,6 +117,65 @@ } +bool Setup::loadFile(const QString &fileName) +{ + 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 false; + } + setImage(newImage); + setWindowFilePath(fileName); + is_changed(); + return true; +} + + +void Setup::setImage(const QImage &newImage) +{ + image = newImage; + + qDebug() << "setImage" << image.width() << image.height() << "size" << image.sizeInBytes(); + + QBuffer buffer(&logoByteArray); + buffer.open(QIODevice::WriteOnly); + image.save(&buffer, "PNG"); // writes image into logoByteArray in PNG format + + ui->logoLabel->setPixmap(QPixmap::fromImage(image)); + scaleFactor = 1.0; + +// ui->logoLabel->resize(scaleFactor * ui->logoLabel->pixmap(Qt::ReturnByValue).size()); + ui->logoLabel->adjustSize(); +} + + +void Setup::on_openButton_clicked() +{ + static bool firstDialog = true; + + qDebug() << "Setup open"; + + QFileDialog dialog(this, tr("Open File")); + + if (firstDialog) { + firstDialog = false; + const QStringList picturesLocations = QStandardPaths::standardLocations(QStandardPaths::PicturesLocation); + dialog.setDirectory(picturesLocations.isEmpty() ? QDir::currentPath() : picturesLocations.last()); + } + + /* Only a few image formats are valid */ + QStringList mimeTypeFilters ({ "image/bmp", "image/gif", "image/jpeg", "image/png", "image/svg+xml" }); + dialog.setMimeTypeFilters(mimeTypeFilters); + dialog.setNameFilter("Images (*.bmp *.BMP *.gif *.GIF *.jpg *.JPG *.png *.PNG *.svg *.SVG)"); + dialog.setAcceptMode(QFileDialog::AcceptOpen); + + while (dialog.exec() == QDialog::Accepted && !loadFile(dialog.selectedFiles().constFirst())) {} +} + + /* * Also called from the Quit button if there are changes to save. */ @@ -131,10 +195,11 @@ /* * Update all other data */ - query.prepare("UPDATE profile_setup SET brewery_name=:brewery, factor_mashhop=:mashhop, factor_fwh=:fwh, factor_pellet=:pellet, " - "factor_plug=:plug, factor_wethop=:wet, factor_cryohop=:cryo, color_method=:color, ibu_method=:ibu, " + query.prepare("UPDATE profile_setup SET brewery_name=:brewery, brewery_logo=:logo, factor_mashhop=:mashhop, factor_fwh=:fwh, " + "factor_pellet=:pellet, factor_plug=:plug, factor_wethop=:wet, factor_cryohop=:cryo, color_method=:color, ibu_method=:ibu, " "brix_correction=:brix, grain_absorbtion=:grain, default_water=:water, my_yeastlab=:yeast WHERE record='1'"); query.bindValue(":brewery", ui->breweryEdit->text()); + query.bindValue(":logo", logoByteArray); query.bindValue(":mashhop", ui->mashhopEdit->value()); query.bindValue(":fwh", ui->fwhEdit->value()); query.bindValue(":pellet", ui->pelletEdit->value());