diff --git a/retroshare-gui/src/gui/chat/ChatWidget.cpp b/retroshare-gui/src/gui/chat/ChatWidget.cpp index e40f43c34..92e736f59 100644 --- a/retroshare-gui/src/gui/chat/ChatWidget.cpp +++ b/retroshare-gui/src/gui/chat/ChatWidget.cpp @@ -51,6 +51,7 @@ #include "util/HandleRichText.h" #include "gui/chat/ChatUserNotify.h"//For BradCast #include "util/DateTime.h" +#include "util/imageutil.h" #include #include @@ -126,6 +127,7 @@ ChatWidget::ChatWidget(QWidget *parent) : connect(ui->actionChooseColor, SIGNAL(triggered()), this, SLOT(chooseColor())); connect(ui->actionResetFont, SIGNAL(triggered()), this, SLOT(resetFont())); connect(ui->actionQuote, SIGNAL(triggered()), this, SLOT(quote())); + connect(ui->actionSave_image, SIGNAL(triggered()), this, SLOT(saveImage())); connect(ui->hashBox, SIGNAL(fileHashingFinished(QList)), this, SLOT(fileHashingFinished(QList))); @@ -977,6 +979,9 @@ void ChatWidget::contextMenuTextBrowser(QPoint point) contextMnu->addAction(ui->actionClearChatHistory); contextMnu->addAction(ui->actionQuote); + ui->actionSave_image->setData(point); + contextMnu->addAction(ui->actionSave_image); + contextMnu->exec(ui->textBrowser->viewport()->mapToGlobal(point)); delete(contextMnu); } @@ -1674,3 +1679,10 @@ void ChatWidget::quote() emit ui->chatTextEdit->append(QString(">") + text); } } + +void ChatWidget::saveImage() +{ + QPoint point = ui->actionSave_image->data().toPoint(); + QTextCursor cursor = ui->textBrowser->cursorForPosition(point); + ImageUtil::extractImage(window(), cursor); +} diff --git a/retroshare-gui/src/gui/chat/ChatWidget.h b/retroshare-gui/src/gui/chat/ChatWidget.h index 4679fb0b3..1b3c518e8 100644 --- a/retroshare-gui/src/gui/chat/ChatWidget.h +++ b/retroshare-gui/src/gui/chat/ChatWidget.h @@ -133,7 +133,6 @@ private slots: void messageHistory(); void resetStatusBar() ; void searchHistory(); - void quote(); signals: @@ -186,6 +185,9 @@ private slots: bool fileSave(); bool fileSaveAs(); + void quote(); + void saveImage(); + private: bool findText(const QString& qsStringToFind); bool findText(const QString& qsStringToFind, bool bBackWard, bool bForceMove); diff --git a/retroshare-gui/src/gui/chat/ChatWidget.ui b/retroshare-gui/src/gui/chat/ChatWidget.ui index ab9c0442d..e3bab5679 100644 --- a/retroshare-gui/src/gui/chat/ChatWidget.ui +++ b/retroshare-gui/src/gui/chat/ChatWidget.ui @@ -979,6 +979,15 @@ border-image: url(:/images/closepressed.png) Quotes the selected text + + + + + :/images/document_save.png:/images/document_save.png + + + Save image + diff --git a/retroshare-gui/src/retroshare-gui.pro b/retroshare-gui/src/retroshare-gui.pro index 5f421702d..96aff5aa9 100644 --- a/retroshare-gui/src/retroshare-gui.pro +++ b/retroshare-gui/src/retroshare-gui.pro @@ -524,7 +524,8 @@ HEADERS += rshare.h \ gui/GetStartedDialog.h \ gui/settings/WebuiPage.h \ gui/statistics/BWGraph.h \ - util/RsSyntaxHighlighter.h + util/RsSyntaxHighlighter.h \ + util/imageutil.h # gui/ForumsDialog.h \ # gui/forums/ForumDetails.h \ @@ -873,7 +874,8 @@ SOURCES += main.cpp \ gui/statistics/BwCtrlWindow.cpp \ gui/statistics/RttStatistics.cpp \ gui/statistics/BWGraph.cpp \ - util/RsSyntaxHighlighter.cpp + util/RsSyntaxHighlighter.cpp \ + util/imageutil.cpp # gui/ForumsDialog.cpp \ # gui/forums/ForumDetails.cpp \ diff --git a/retroshare-gui/src/util/imageutil.cpp b/retroshare-gui/src/util/imageutil.cpp new file mode 100644 index 000000000..c3f3e4f6f --- /dev/null +++ b/retroshare-gui/src/util/imageutil.cpp @@ -0,0 +1,43 @@ +#include "imageutil.h" +#include "util/misc.h" + +#include +#include +#include +#include +#include +#include +#include + +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")); + } +} diff --git a/retroshare-gui/src/util/imageutil.h b/retroshare-gui/src/util/imageutil.h new file mode 100644 index 000000000..f958ae8e7 --- /dev/null +++ b/retroshare-gui/src/util/imageutil.h @@ -0,0 +1,16 @@ +#ifndef IMAGEUTIL_H +#define IMAGEUTIL_H + +#include +#include + + +class ImageUtil +{ +public: + ImageUtil(); + + static void extractImage(QWidget *window, QTextCursor cursor); +}; + +#endif // IMAGEUTIL_H