mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-12 11:02:30 -04:00
Added save image function into chat
This commit is contained in:
parent
0b92c79eb0
commit
ff44965e2c
6 changed files with 87 additions and 3 deletions
43
retroshare-gui/src/util/imageutil.cpp
Normal file
43
retroshare-gui/src/util/imageutil.cpp
Normal file
|
@ -0,0 +1,43 @@
|
|||
#include "imageutil.h"
|
||||
#include "util/misc.h"
|
||||
|
||||
#include <QMessageBox>
|
||||
#include <QTextCursor>
|
||||
#include <QByteArray>
|
||||
#include <QString>
|
||||
#include <QImage>
|
||||
#include <QTextDocumentFragment>
|
||||
#include <QApplication>
|
||||
|
||||
ImageUtil::ImageUtil() {}
|
||||
|
||||
void ImageUtil::extractImage(QWidget *window, QTextCursor cursor)
|
||||
{
|
||||
cursor.movePosition(QTextCursor::Left, QTextCursor::MoveAnchor, 1);
|
||||
cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, 2);
|
||||
QString imagestr = cursor.selection().toHtml();
|
||||
bool success = false;
|
||||
int start = imagestr.indexOf("base64,") + 7;
|
||||
int stop = imagestr.indexOf("\"", start);
|
||||
int length = stop - start;
|
||||
if((start >= 0) && (length > 0))
|
||||
{
|
||||
QByteArray ba = QByteArray::fromBase64(imagestr.mid(start, length).toLatin1());
|
||||
QImage image = QImage::fromData(ba);
|
||||
if(!image.isNull())
|
||||
{
|
||||
QString file;
|
||||
success = true;
|
||||
if(misc::getSaveFileName(window, RshareSettings::LASTDIR_IMAGES, "Save Picture File", "Pictures (*.png *.xpm *.jpg)", file))
|
||||
{
|
||||
if(!image.save(file, 0, 100))
|
||||
if(!image.save(file + ".png", 0, 100))
|
||||
QMessageBox::warning(window, QApplication::translate("ImageUtil", "Save image"), QApplication::translate("ImageUtil", "Cannot save the image, invalid filename"));
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!success)
|
||||
{
|
||||
QMessageBox::warning(window, QApplication::translate("ImageUtil", "Save image"), QApplication::translate("ImageUtil", "Not an image"));
|
||||
}
|
||||
}
|
16
retroshare-gui/src/util/imageutil.h
Normal file
16
retroshare-gui/src/util/imageutil.h
Normal file
|
@ -0,0 +1,16 @@
|
|||
#ifndef IMAGEUTIL_H
|
||||
#define IMAGEUTIL_H
|
||||
|
||||
#include <QTextCursor>
|
||||
#include <QWidget>
|
||||
|
||||
|
||||
class ImageUtil
|
||||
{
|
||||
public:
|
||||
ImageUtil();
|
||||
|
||||
static void extractImage(QWidget *window, QTextCursor cursor);
|
||||
};
|
||||
|
||||
#endif // IMAGEUTIL_H
|
Loading…
Add table
Add a link
Reference in a new issue