src/EditProductTab13.cpp

changeset 468
b21da6f583be
parent 467
c5f6f3f1b714
child 469
a022701d47f5
equal deleted inserted replaced
467:c5f6f3f1b714 468:b21da6f583be
24 // Start spinner 24 // Start spinner
25 25
26 /* 26 /*
27 * Clean old picture areas. 27 * Clean old picture areas.
28 */ 28 */
29 if (product->images_count < 0 && product->images_list.size()) {
30 qDebug() << " clean images_list";
31 ui->filmStrip->clear();
32 product->images_list.clear();
33 product->images_count = -1;
34 product->images_current = -1;
35 }
29 36
30 /* 37 /*
31 * Load images data for this product uuid. 38 * Load images data for this product uuid.
32 */ 39 */
33 if (product->images_count < 0) { 40 if (product->images_count < 0) {
45 } 52 }
46 product->images_count = 0; 53 product->images_count = 0;
47 54
48 while (query.next()) { 55 while (query.next()) {
49 Images i; 56 Images i;
50 qDebug() << product->images_count << query.value("pic_data").toByteArray().size(); 57 i.record = query.value("record").toInt();
58 i.uuid = query.value("uuid").toString();
51 i.pic_type = query.value("pic_type").toInt(); 59 i.pic_type = query.value("pic_type").toInt();
52 i.pic_data = query.value("pic_data").toByteArray(); 60 i.pic_data = query.value("pic_data").toByteArray();
53 i.pic_comment = query.value("pic_comment").toString(); 61 i.pic_comment = query.value("pic_comment").toString();
54 i.filename = query.value("filename").toString(); 62 i.filename = query.value("filename").toString();
55 i.timestamp = query.value("timestamp").toDateTime(); 63 i.timestamp = query.value("timestamp").toDateTime();
77 /* 85 /*
78 * Show thumbnails on the left. 86 * Show thumbnails on the left.
79 */ 87 */
80 void EditProduct::images_Thumbnails() 88 void EditProduct::images_Thumbnails()
81 { 89 {
82 QList<QListWidgetItem*> items = ui->filmStrip->selectedItems(); 90 ui->filmStrip->clear();
83 foreach(QListWidgetItem * item, items) {
84 delete ui->filmStrip->takeItem(ui->filmStrip->row(item));
85 }
86 91
87 for (int i = 0; i < product->images_list.size(); i++) { 92 for (int i = 0; i < product->images_list.size(); i++) {
88 QListWidgetItem* newItem = new QListWidgetItem(); 93 QListWidgetItem* newItem = new QListWidgetItem();
89 QString text = QCoreApplication::translate("PicType", g_prod_pic_types[product->images_list.at(i).pic_type]); 94 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); 95 newItem->setText(text);
96 newItem->setBackground(QColor(0x45,0x53,0x64)); 96 newItem->setBackground(QColor(0x45,0x53,0x64));
97 97
98 QPixmap outPixmap = QPixmap(); 98 QPixmap outPixmap = QPixmap();
99 outPixmap.loadFromData(product->images_list.at(i).pic_data); 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; 100 qDebug() << " " << outPixmap.width() << "x" << outPixmap.height() << "size" << outPixmap.size() << product->images_list.at(i).filename;
101 if (outPixmap.width() > 320 || outPixmap.height() > 240) 101 qDebug() << " " << ui->filmStrip->iconSize();
102 newItem->setIcon(QIcon(outPixmap.scaled(320, 240, Qt::KeepAspectRatio, Qt::SmoothTransformation))); 102 if (outPixmap.width() > 240 || outPixmap.height() > 180)
103 newItem->setIcon(QIcon(outPixmap.scaled(240, 180, Qt::KeepAspectRatio, Qt::SmoothTransformation)));
103 else 104 else
104 newItem->setIcon(QIcon(outPixmap)); 105 newItem->setIcon(QIcon(outPixmap));
105 106
106 ui->filmStrip->addItem(newItem); 107 ui->filmStrip->addItem(newItem);
107 } 108 }
115 ui->prevImage->setEnabled((product->images_count > 0 && product->images_current > 0) ? true:false); 116 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->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->downloadImage->setEnabled((product->images_count > 0) ? true:false);
118 ui->printImage->setEnabled((product->images_count > 0) ? true:false); 119 ui->printImage->setEnabled((product->images_count > 0) ? true:false);
119 ui->delImage->setEnabled((product->images_count > 0) ? true:false); 120 ui->delImage->setEnabled((product->images_count > 0) ? true:false);
121
122 if (product->images_count < 1) {
123 ui->image_filenameEdit->setText("");
124 ui->image_timestampEdit->setText("");
125 ui->image_commentEdit->setText("");
126 ui->image_typeEdit->setCurrentIndex(0);
127 //ui->currentImage->setPixmap();
128 return;
129 }
130
131 QPixmap outPixmap = QPixmap();
132 outPixmap.loadFromData(product->images_list.at(id).pic_data);
133 qDebug() << " " << outPixmap.width() << "x" << outPixmap.height() << "size" << outPixmap.size() << product->images_list.at(id).filename;
134 if (outPixmap.width() > ui->currentImage->width() || outPixmap.height() > ui->currentImage->height())
135 ui->currentImage->setPixmap(outPixmap.scaled(ui->currentImage->width(), ui->currentImage->height(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
136 else
137 ui->currentImage->setPixmap(outPixmap);
138
139 ui->image_filenameEdit->setText(product->images_list.at(id).filename);
140 ui->image_timestampEdit->setText(product->images_list.at(id).timestamp.toString(Qt::RFC2822Date));
141 ui->image_commentEdit->setText(product->images_list.at(id).pic_comment);
142 ui->image_typeEdit->setCurrentIndex(product->images_list.at(id).pic_type);
120 } 143 }
121 144
122 145
123 void EditProduct::addImage_clicked() 146 void EditProduct::addImage_clicked()
124 { 147 {
192 215
193 QComboBox *typeEdit = new QComboBox(dialog); 216 QComboBox *typeEdit = new QComboBox(dialog);
194 typeEdit->setObjectName(QString::fromUtf8("typeEdit")); 217 typeEdit->setObjectName(QString::fromUtf8("typeEdit"));
195 typeEdit->setGeometry(QRect(160, 360, 161, 23)); 218 typeEdit->setGeometry(QRect(160, 360, 161, 23));
196 for (int i = 0; i < 7; i++) 219 for (int i = 0; i < 7; i++)
197 typeEdit->addItem(g_prod_pic_types[i]); 220 typeEdit->addItem(QCoreApplication::translate("PicType", g_prod_pic_types[i]));
198 typeEdit->setCurrentIndex(0); 221 typeEdit->setCurrentIndex(0);
199 222
200 QLabel *commentLabel = new QLabel(dialog); 223 QLabel *commentLabel = new QLabel(dialog);
201 commentLabel->setObjectName(QString::fromUtf8("commentLabel")); 224 commentLabel->setObjectName(QString::fromUtf8("commentLabel"));
202 commentLabel->setText(tr("Image comment:")); 225 commentLabel->setText(tr("Image comment:"));
233 qWarning() << "addImage_clicked()" << query.lastError(); 256 qWarning() << "addImage_clicked()" << query.lastError();
234 QMessageBox::warning(this, tr("Database error"), tr("MySQL error: %1\n%2\n%3") 257 QMessageBox::warning(this, tr("Database error"), tr("MySQL error: %1\n%2\n%3")
235 .arg(query.lastError().nativeErrorCode()).arg(query.lastError().driverText()).arg(query.lastError().databaseText())); 258 .arg(query.lastError().nativeErrorCode()).arg(query.lastError().driverText()).arg(query.lastError().databaseText()));
236 } else { 259 } else {
237 qDebug() << "new image Saved"; 260 qDebug() << "new image Saved";
238 } 261 product->images_count = -1; // Force reload data
239 262 images_Init();
240 //emit refreshAll(); 263 }
241 } 264 }
242 265
243 266
244 void EditProduct::delImage_clicked() 267 void EditProduct::delImage_clicked()
245 { 268 {
246 qDebug() << "delImage_clicked()" << product->images_current << ui->filmStrip->currentRow(); 269 qDebug() << "delImage_clicked()" << ui->filmStrip->currentRow();
270
271 int rc = QMessageBox::warning(this, tr("Delete image"), tr("Delete %1").arg(product->images_list.at(ui->filmStrip->currentRow()).filename),
272 QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
273 if (rc == QMessageBox::No)
274 return;
275
276 qDebug() << " delete record" << product->images_list.at(ui->filmStrip->currentRow()).record;
277
278 QSqlQuery query;
279 query.prepare("DELETE FROM products_pics WHERE record=:record");
280 query.bindValue(":record", product->images_list.at(ui->filmStrip->currentRow()).record);
281 query.exec();
282
283 if (query.lastError().isValid()) {
284 qWarning() << "delImage_clicked()" << query.lastError();
285 QMessageBox::warning(this, tr("Database error"), tr("MySQL error: %1\n%2\n%3")
286 .arg(query.lastError().nativeErrorCode()).arg(query.lastError().driverText()).arg(query.lastError().databaseText()));
287 }
288
289 product->images_count = -1; // Force reload data
290 images_Init();
247 } 291 }
248 292
249 293
250 void EditProduct::nextImage_clicked() 294 void EditProduct::nextImage_clicked()
251 { 295 {
285 { 329 {
286 qDebug() << "printImage_clicked()" << product->images_current << ui->filmStrip->currentRow(); 330 qDebug() << "printImage_clicked()" << product->images_current << ui->filmStrip->currentRow();
287 } 331 }
288 332
289 333
290 void EditProduct::selectImage_clicked(int val) 334 void EditProduct::selectImage_clicked(QListWidgetItem *val)
291 { 335 {
292 qDebug() << "selectImage_clicked()" << val << product->images_current << ui->filmStrip->currentRow(); 336 qDebug() << "selectImage_clicked()" << ui->filmStrip->currentRow();
293 } 337
294 338 if (product->images_count > 0) {
339 product->images_current = ui->filmStrip->currentRow();
340 images_Main(product->images_current);
341 }
342 }
343

mercurial