1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 18:56:34 +01:00

SiteInfo: Bring back option to save image

This commit is contained in:
David Rosca 2015-09-30 16:20:31 +02:00
parent bd215a69ed
commit 695475b2e4
3 changed files with 51 additions and 1 deletions

View File

@ -34,6 +34,7 @@
#include <QNetworkDiskCache>
#include <QClipboard>
#include <QTimer>
#include <QGraphicsPixmapItem>
QString SiteInfo::showCertInfo(const QString &string)
{
@ -127,6 +128,7 @@ SiteInfo::SiteInfo(WebView* view)
}
});
connect(ui->saveButton, SIGNAL(clicked(QAbstractButton*)), this, SLOT(saveImage()));
connect(ui->listWidget, SIGNAL(currentRowChanged(int)), ui->stackedWidget, SLOT(setCurrentIndex(int)));
connect(ui->treeImages, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), this, SLOT(showImagePreview(QTreeWidgetItem*)));
connect(ui->treeImages, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(imagesCustomContextMenuRequested(QPoint)));
@ -150,7 +152,7 @@ void SiteInfo::imagesCustomContextMenuRequested(const QPoint &p)
menu.addAction(QIcon::fromTheme("edit-copy"), tr("Copy Image Location"), this, SLOT(copyActionData()))->setData(item->text(1));
menu.addAction(tr("Copy Image Name"), this, SLOT(copyActionData()))->setData(item->text(0));
menu.addSeparator();
menu.addAction(QIcon::fromTheme("document-save"), tr("Save Image to Disk"), this, SLOT(downloadImage()));
menu.addAction(QIcon::fromTheme("document-save"), tr("Save Image to Disk"), this, SLOT(saveImage()));
menu.exec(ui->treeImages->viewport()->mapToGlobal(p));
}
@ -161,6 +163,46 @@ void SiteInfo::copyActionData()
}
}
void SiteInfo::saveImage()
{
QTreeWidgetItem* item = ui->treeImages->currentItem();
if (!item) {
return;
}
if (!ui->mediaPreview->scene() || ui->mediaPreview->scene()->items().isEmpty())
return;
QGraphicsItem *graphicsItem = ui->mediaPreview->scene()->items().first();
QGraphicsPixmapItem *pixmapItem = static_cast<QGraphicsPixmapItem*>(graphicsItem);
if (graphicsItem->type() != QGraphicsPixmapItem::Type || !pixmapItem)
return;
if (!pixmapItem || pixmapItem->pixmap().isNull()) {
QMessageBox::warning(this, tr("Error!"), tr("This preview is not available!"));
return;
}
QString imageFileName = QzTools::getFileNameFromUrl(QUrl(item->text(1)));
int index = imageFileName.lastIndexOf(QLatin1Char('.'));
if (index != -1) {
imageFileName = imageFileName.left(index);
imageFileName.append(QL1S(".png"));
}
QString filePath = QzTools::getSaveFileName("SiteInfo-DownloadImage", this, tr("Save image..."),
QDir::homePath() + QDir::separator() + imageFileName,
QSL("*.png"));
if (filePath.isEmpty()) {
return;
}
if (!pixmapItem->pixmap().save(filePath, "PNG")) {
QMessageBox::critical(this, tr("Error!"), tr("Cannot write to file!"));
return;
}
}
void SiteInfo::showLoadingText()
{
delete ui->mediaPreview->scene();

View File

@ -48,6 +48,7 @@ private slots:
void showImagePreview(QTreeWidgetItem *item);
void imagesCustomContextMenuRequested(const QPoint &p);
void copyActionData();
void saveImage();
private:
void showLoadingText();

View File

@ -249,6 +249,13 @@
</widget>
<widget class="QWidget" name="layoutWidget">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QDialogButtonBox" name="saveButton">
<property name="standardButtons">
<set>QDialogButtonBox::Save</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_5">
<property name="maximumSize">