Added copy and save of image to AspectRatioPixmapLabel

This commit is contained in:
thunder2 2023-05-14 22:19:16 +02:00
parent e829292eaf
commit 8422d3fc8c
4 changed files with 95 additions and 8 deletions

View file

@ -115,13 +115,7 @@ void ImageUtil::extractImage(QWidget *window, QTextCursor cursor, QString file)
if(!image.isNull())
{
success = true;
if(!file.isEmpty() || misc::getSaveFileName(window, RshareSettings::LASTDIR_IMAGES, "Save Picture File", "Pictures (*.png *.xpm *.jpg)", file))
{
if(!image.save(file, nullptr, 100))
if(!image.save(file + ".png", nullptr, 100))
QMessageBox::warning(window, QApplication::translate("ImageUtil", "Save image"), QApplication::translate("ImageUtil", "Cannot save the image, invalid filename")
+ "\n" + file);
}
saveImage(window, image, file);
}
}
if(!success)
@ -130,6 +124,26 @@ void ImageUtil::extractImage(QWidget *window, QTextCursor cursor, QString file)
}
}
bool ImageUtil::saveImage(QWidget *window, const QImage &image, QString file)
{
bool result = false;
if (!file.isEmpty() || misc::getSaveFileName(window, RshareSettings::LASTDIR_IMAGES, QApplication::translate("ImageUtil", "Save Picture File"), QApplication::translate("ImageUtil", "Pictures (*.png *.xpm *.jpg)"), file)) {
if (image.save(file, nullptr, 100)) {
result = true;
} else {
if (image.save(file + ".png", nullptr, 100)) {
result = true;
} else {
QMessageBox::warning(window, QApplication::translate("ImageUtil", "Save image"), QApplication::translate("ImageUtil", "Cannot save the image, invalid filename")
+ "\n" + file);
}
}
}
return result;
}
void ImageUtil::copyImage(QWidget *window, QTextCursor cursor)
{
cursor.movePosition(QTextCursor::Left, QTextCursor::MoveAnchor, 1);