17 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
18 */ |
18 */ |
19 |
19 |
20 void EditProduct::images_Init() |
20 void EditProduct::images_Init() |
21 { |
21 { |
22 qDebug() << "images_Init()"; |
22 qDebug() << "images_Init()"; |
23 |
23 |
24 // Start spinner |
24 // Start spinner |
25 // Clean old picture areas |
25 |
26 // Load images data for this product uuid |
26 /* |
27 // Show thumbnails on the left. |
27 * Clean old picture areas. |
|
28 */ |
|
29 |
|
30 /* |
|
31 * Load images data for this product uuid. |
|
32 */ |
|
33 if (product->images_count < 0) { |
|
34 QSqlQuery query; |
|
35 |
|
36 qDebug() << " loading data"; |
|
37 query.prepare("SELECT * FROM products_pics WHERE uuid=:uuid"); |
|
38 query.bindValue(":uuid", product->uuid); |
|
39 query.exec(); |
|
40 |
|
41 if (query.lastError().isValid()) { |
|
42 qWarning() << "images_init()" << query.lastError(); |
|
43 QMessageBox::warning(this, tr("Database error"), tr("MySQL error: %1\n%2\n%3") |
|
44 .arg(query.lastError().nativeErrorCode()).arg(query.lastError().driverText()).arg(query.lastError().databaseText())); |
|
45 } |
|
46 product->images_count = 0; |
|
47 |
|
48 while (query.next()) { |
|
49 Images i; |
|
50 qDebug() << product->images_count << query.value("pic_data").toByteArray().size(); |
|
51 i.pic_type = query.value("pic_type").toInt(); |
|
52 i.pic_data = query.value("pic_data").toByteArray(); |
|
53 i.pic_comment = query.value("pic_comment").toString(); |
|
54 i.filename = query.value("filename").toString(); |
|
55 i.timestamp = query.value("timestamp").toDateTime(); |
|
56 product->images_list.append(i); |
|
57 product->images_count++; |
|
58 } |
|
59 qDebug() << " loaded" << product->images_count << product->images_list.size(); |
|
60 if (product->images_count < 1) |
|
61 product->images_current = -1; |
|
62 else |
|
63 product->images_current = 0; |
|
64 } |
|
65 |
|
66 images_Thumbnails(); |
|
67 if (product->images_current >= 0) { |
|
68 ui->filmStrip->setCurrentRow(product->images_current); |
|
69 } |
|
70 images_Main(product->images_current); |
|
71 |
28 // If any, show picture 1 |
72 // If any, show picture 1 |
29 // Stop spinner |
73 // Stop spinner |
|
74 } |
|
75 |
|
76 |
|
77 /* |
|
78 * Show thumbnails on the left. |
|
79 */ |
|
80 void EditProduct::images_Thumbnails() |
|
81 { |
|
82 QList<QListWidgetItem*> items = ui->filmStrip->selectedItems(); |
|
83 foreach(QListWidgetItem * item, items) { |
|
84 delete ui->filmStrip->takeItem(ui->filmStrip->row(item)); |
|
85 } |
|
86 |
|
87 for (int i = 0; i < product->images_list.size(); i++) { |
|
88 QListWidgetItem* newItem = new QListWidgetItem(); |
|
89 QString text = QCoreApplication::translate("PicType", g_prod_pic_types[product->images_list.at(i).pic_type]); |
|
90 if (product->images_list.at(i).filename != "") |
|
91 text.append("\n" + product->images_list.at(i).filename); |
|
92 if (product->images_list.at(i).pic_comment != "") |
|
93 text.append("\n" + product->images_list.at(i).pic_comment); |
|
94 // product->images_list.at(i).timestamp |
|
95 newItem->setText(text); |
|
96 newItem->setBackground(QColor(0x45,0x53,0x64)); |
|
97 |
|
98 QPixmap outPixmap = QPixmap(); |
|
99 outPixmap.loadFromData(product->images_list.at(i).pic_data); |
|
100 qDebug() << " " << outPixmap.width() << "x" << outPixmap.height() << "size" << outPixmap.size() << product->images_list.at(i).filename; |
|
101 if (outPixmap.width() > 320 || outPixmap.height() > 240) |
|
102 newItem->setIcon(QIcon(outPixmap.scaled(320, 240, Qt::KeepAspectRatio, Qt::SmoothTransformation))); |
|
103 else |
|
104 newItem->setIcon(QIcon(outPixmap)); |
|
105 |
|
106 ui->filmStrip->addItem(newItem); |
|
107 } |
|
108 } |
|
109 |
|
110 |
|
111 void EditProduct::images_Main(int id) |
|
112 { |
|
113 qDebug() << " Main(" << id << ")"; |
|
114 |
|
115 ui->prevImage->setEnabled((product->images_count > 0 && product->images_current > 0) ? true:false); |
|
116 ui->nextImage->setEnabled((product->images_count > 0 && (product->images_current + 1) < product->images_count) ? true:false); |
|
117 ui->downloadImage->setEnabled((product->images_count > 0) ? true:false); |
|
118 ui->printImage->setEnabled((product->images_count > 0) ? true:false); |
|
119 ui->delImage->setEnabled((product->images_count > 0) ? true:false); |
30 } |
120 } |
31 |
121 |
32 |
122 |
33 void EditProduct::addImage_clicked() |
123 void EditProduct::addImage_clicked() |
34 { |
124 { |
40 QFileDialog dialog1(this, tr("Open File")); |
130 QFileDialog dialog1(this, tr("Open File")); |
41 dialog1.setDirectory(settings.value("paths/images").toString()); |
131 dialog1.setDirectory(settings.value("paths/images").toString()); |
42 /* Only a few image formats are valid */ |
132 /* Only a few image formats are valid */ |
43 QStringList mimeTypeFilters ({ "image/bmp", "image/gif", "image/jpeg", "image/png", "image/svg+xml" }); |
133 QStringList mimeTypeFilters ({ "image/bmp", "image/gif", "image/jpeg", "image/png", "image/svg+xml" }); |
44 dialog1.setMimeTypeFilters(mimeTypeFilters); |
134 dialog1.setMimeTypeFilters(mimeTypeFilters); |
45 dialog1.setNameFilter("Images (*.bmp *.BMP *.gif *.GIF *.jpg *.JPG *.png *.PNG *.svg *.SVG)"); |
135 dialog1.setNameFilter("Images (*.bmp *.BMP *.gif *.GIF *.jpg *.JPG *.jpeg *.JPEG *.png *.PNG *.svg *.SVG)"); |
46 dialog1.setAcceptMode(QFileDialog::AcceptOpen); |
136 dialog1.setAcceptMode(QFileDialog::AcceptOpen); |
47 // dialog1.setOption(QFileDialog::DontUseNativeDialog); |
137 // dialog1.setOption(QFileDialog::DontUseNativeDialog); |
48 if (dialog1.exec() != QDialog::Accepted) |
138 if (dialog1.exec() != QDialog::Accepted) |
49 return; |
139 return; |
50 |
140 |
130 |
220 |
131 QFileInfo fi(fileName); |
221 QFileInfo fi(fileName); |
132 query.prepare("INSERT INTO products_pics SET uuid=:uuid, pic_type=:pic_type, pic_data=:pic_data, " |
222 query.prepare("INSERT INTO products_pics SET uuid=:uuid, pic_type=:pic_type, pic_data=:pic_data, " |
133 "pic_comment=:pic_comment, filename=:filename, timestamp=:timestamp"); |
223 "pic_comment=:pic_comment, filename=:filename, timestamp=:timestamp"); |
134 query.bindValue(":uuid", product->uuid); |
224 query.bindValue(":uuid", product->uuid); |
135 query.bindValue(":pic_type", g_prod_pic_types[typeEdit->currentIndex()]); |
225 query.bindValue(":pic_type", typeEdit->currentIndex()); |
136 query.bindValue(":pic_data", imageByteArray); |
226 query.bindValue(":pic_data", imageByteArray); |
137 query.bindValue(":pic_comment", commentEdit->text()); |
227 query.bindValue(":pic_comment", commentEdit->text()); |
138 query.bindValue(":filename", fi.fileName()); |
228 query.bindValue(":filename", fi.completeBaseName() + ".png"); /* The image is converted to .png */ |
139 query.bindValue(":timestamp", fi.lastModified()); |
229 query.bindValue(":timestamp", fi.lastModified()); |
140 |
230 |
141 query.exec(); |
231 query.exec(); |
142 if (query.lastError().isValid()) { |
232 if (query.lastError().isValid()) { |
143 qWarning() << "addImage_clicked()" << query.lastError(); |
233 qWarning() << "addImage_clicked()" << query.lastError(); |
149 |
239 |
150 //emit refreshAll(); |
240 //emit refreshAll(); |
151 } |
241 } |
152 |
242 |
153 |
243 |
|
244 void EditProduct::delImage_clicked() |
|
245 { |
|
246 qDebug() << "delImage_clicked()" << product->images_current << ui->filmStrip->currentRow(); |
|
247 } |
|
248 |
|
249 |
|
250 void EditProduct::nextImage_clicked() |
|
251 { |
|
252 qDebug() << "nextImage_clicked()" << product->images_current << ui->filmStrip->currentRow(); |
|
253 |
|
254 if (product->images_count >= 0) { |
|
255 if ((product->images_current + 1) < product->images_count) { |
|
256 product->images_current++; |
|
257 ui->filmStrip->setCurrentRow(product->images_current); |
|
258 images_Main(product->images_current); |
|
259 } |
|
260 } |
|
261 } |
|
262 |
|
263 |
|
264 void EditProduct::prevImage_clicked() |
|
265 { |
|
266 qDebug() << "prevImage_clicked()" << product->images_current << ui->filmStrip->currentRow(); |
|
267 |
|
268 if (product->images_count >= 0) { |
|
269 if (product->images_current > 0) { |
|
270 product->images_current--; |
|
271 ui->filmStrip->setCurrentRow(product->images_current); |
|
272 images_Main(product->images_current); |
|
273 } |
|
274 } |
|
275 } |
|
276 |
|
277 |
|
278 void EditProduct::downloadImage_clicked() |
|
279 { |
|
280 qDebug() << "downloadImage_clicked()" << product->images_current << ui->filmStrip->currentRow(); |
|
281 } |
|
282 |
|
283 |
|
284 void EditProduct::printImage_clicked() |
|
285 { |
|
286 qDebug() << "printImage_clicked()" << product->images_current << ui->filmStrip->currentRow(); |
|
287 } |
|
288 |
|
289 |
|
290 void EditProduct::selectImage_clicked(int val) |
|
291 { |
|
292 qDebug() << "selectImage_clicked()" << val << product->images_current << ui->filmStrip->currentRow(); |
|
293 } |
|
294 |