99 } |
99 } |
100 if (pos >= 0) |
100 if (pos >= 0) |
101 ui->yeastEdit->setCurrentIndex(pos); |
101 ui->yeastEdit->setCurrentIndex(pos); |
102 connect(ui->yeastEdit, &QComboBox::currentTextChanged, this, &Setup::is_changed); |
102 connect(ui->yeastEdit, &QComboBox::currentTextChanged, this, &Setup::is_changed); |
103 |
103 |
104 // query.value(2).toString() logo varchar(1024) |
104 /* logo */ |
|
105 logoByteArray = query.value(2).toByteArray(); |
|
106 QPixmap outPixmap = QPixmap(); |
|
107 outPixmap.loadFromData(logoByteArray); |
|
108 ui->logoLabel->setPixmap(outPixmap); |
|
109 ui->logoLabel->adjustSize(); |
105 } |
110 } |
106 |
111 |
107 |
112 |
108 Setup::~Setup() |
113 Setup::~Setup() |
109 { |
114 { |
110 qDebug() << "Setup done"; |
115 qDebug() << "Setup done"; |
111 delete ui; |
116 delete ui; |
|
117 } |
|
118 |
|
119 |
|
120 bool Setup::loadFile(const QString &fileName) |
|
121 { |
|
122 QImageReader reader(fileName); |
|
123 reader.setAutoTransform(true); |
|
124 const QImage newImage = reader.read(); |
|
125 if (newImage.isNull()) { |
|
126 QMessageBox::information(this, QGuiApplication::applicationDisplayName(), tr("Cannot load %1: %2") |
|
127 .arg(QDir::toNativeSeparators(fileName), reader.errorString())); |
|
128 return false; |
|
129 } |
|
130 setImage(newImage); |
|
131 setWindowFilePath(fileName); |
|
132 is_changed(); |
|
133 return true; |
|
134 } |
|
135 |
|
136 |
|
137 void Setup::setImage(const QImage &newImage) |
|
138 { |
|
139 image = newImage; |
|
140 |
|
141 qDebug() << "setImage" << image.width() << image.height() << "size" << image.sizeInBytes(); |
|
142 |
|
143 QBuffer buffer(&logoByteArray); |
|
144 buffer.open(QIODevice::WriteOnly); |
|
145 image.save(&buffer, "PNG"); // writes image into logoByteArray in PNG format |
|
146 |
|
147 ui->logoLabel->setPixmap(QPixmap::fromImage(image)); |
|
148 scaleFactor = 1.0; |
|
149 |
|
150 // ui->logoLabel->resize(scaleFactor * ui->logoLabel->pixmap(Qt::ReturnByValue).size()); |
|
151 ui->logoLabel->adjustSize(); |
|
152 } |
|
153 |
|
154 |
|
155 void Setup::on_openButton_clicked() |
|
156 { |
|
157 static bool firstDialog = true; |
|
158 |
|
159 qDebug() << "Setup open"; |
|
160 |
|
161 QFileDialog dialog(this, tr("Open File")); |
|
162 |
|
163 if (firstDialog) { |
|
164 firstDialog = false; |
|
165 const QStringList picturesLocations = QStandardPaths::standardLocations(QStandardPaths::PicturesLocation); |
|
166 dialog.setDirectory(picturesLocations.isEmpty() ? QDir::currentPath() : picturesLocations.last()); |
|
167 } |
|
168 |
|
169 /* Only a few image formats are valid */ |
|
170 QStringList mimeTypeFilters ({ "image/bmp", "image/gif", "image/jpeg", "image/png", "image/svg+xml" }); |
|
171 dialog.setMimeTypeFilters(mimeTypeFilters); |
|
172 dialog.setNameFilter("Images (*.bmp *.BMP *.gif *.GIF *.jpg *.JPG *.png *.PNG *.svg *.SVG)"); |
|
173 dialog.setAcceptMode(QFileDialog::AcceptOpen); |
|
174 |
|
175 while (dialog.exec() == QDialog::Accepted && !loadFile(dialog.selectedFiles().constFirst())) {} |
112 } |
176 } |
113 |
177 |
114 |
178 |
115 /* |
179 /* |
116 * Also called from the Quit button if there are changes to save. |
180 * Also called from the Quit button if there are changes to save. |
129 int record = query.value(0).toInt(); |
193 int record = query.value(0).toInt(); |
130 |
194 |
131 /* |
195 /* |
132 * Update all other data |
196 * Update all other data |
133 */ |
197 */ |
134 query.prepare("UPDATE profile_setup SET brewery_name=:brewery, factor_mashhop=:mashhop, factor_fwh=:fwh, factor_pellet=:pellet, " |
198 query.prepare("UPDATE profile_setup SET brewery_name=:brewery, brewery_logo=:logo, factor_mashhop=:mashhop, factor_fwh=:fwh, " |
135 "factor_plug=:plug, factor_wethop=:wet, factor_cryohop=:cryo, color_method=:color, ibu_method=:ibu, " |
199 "factor_pellet=:pellet, factor_plug=:plug, factor_wethop=:wet, factor_cryohop=:cryo, color_method=:color, ibu_method=:ibu, " |
136 "brix_correction=:brix, grain_absorbtion=:grain, default_water=:water, my_yeastlab=:yeast WHERE record='1'"); |
200 "brix_correction=:brix, grain_absorbtion=:grain, default_water=:water, my_yeastlab=:yeast WHERE record='1'"); |
137 query.bindValue(":brewery", ui->breweryEdit->text()); |
201 query.bindValue(":brewery", ui->breweryEdit->text()); |
|
202 query.bindValue(":logo", logoByteArray); |
138 query.bindValue(":mashhop", ui->mashhopEdit->value()); |
203 query.bindValue(":mashhop", ui->mashhopEdit->value()); |
139 query.bindValue(":fwh", ui->fwhEdit->value()); |
204 query.bindValue(":fwh", ui->fwhEdit->value()); |
140 query.bindValue(":pellet", ui->pelletEdit->value()); |
205 query.bindValue(":pellet", ui->pelletEdit->value()); |
141 query.bindValue(":plug", ui->hopplugEdit->value()); |
206 query.bindValue(":plug", ui->hopplugEdit->value()); |
142 query.bindValue(":wet", ui->wethopEdit->value()); |
207 query.bindValue(":wet", ui->wethopEdit->value()); |