mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-08-12 00:00:44 -04:00
Added copy image to clipboard feature
This commit is contained in:
parent
8dfa772782
commit
3004505832
4 changed files with 49 additions and 0 deletions
|
@ -25,6 +25,8 @@
|
|||
#include <QApplication>
|
||||
#include <QByteArray>
|
||||
#include <QImage>
|
||||
#include <QClipboard>
|
||||
#include <QMimeData>
|
||||
#include <QMessageBox>
|
||||
#include <QString>
|
||||
#include <QTextCursor>
|
||||
|
@ -68,6 +70,34 @@ void ImageUtil::extractImage(QWidget *window, QTextCursor cursor, QString file)
|
|||
}
|
||||
}
|
||||
|
||||
void ImageUtil::copyImage(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())
|
||||
{
|
||||
success = true;
|
||||
QClipboard *clipboard = QApplication::clipboard();
|
||||
QMimeData *data = new QMimeData;
|
||||
data->setImageData(image);
|
||||
clipboard->setMimeData(data, QClipboard::Clipboard);
|
||||
}
|
||||
}
|
||||
if(!success)
|
||||
{
|
||||
QMessageBox::warning(window, QApplication::translate("ImageUtil", "Copy image"), QApplication::translate("ImageUtil", "Not an image"));
|
||||
}
|
||||
}
|
||||
|
||||
bool ImageUtil::optimizeSizeBytes(QByteArray &bytearray, const QImage &original, QImage &optimized, const char *format, int maxPixels, int maxBytes)
|
||||
{
|
||||
//nothing to do if it fits into the limits
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue