From bc4691ceb44275714477705240cd8f79c17efac6 Mon Sep 17 00:00:00 2001 From: hunbernd Date: Sat, 12 Dec 2015 22:41:15 +0100 Subject: [PATCH] Show save image option only when it is needed --- retroshare-gui/src/gui/chat/ChatWidget.cpp | 8 ++++++-- retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp | 8 ++++++-- retroshare-gui/src/util/imageutil.cpp | 8 ++++++++ retroshare-gui/src/util/imageutil.h | 1 + 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/retroshare-gui/src/gui/chat/ChatWidget.cpp b/retroshare-gui/src/gui/chat/ChatWidget.cpp index 92e736f59..7b58bcaaa 100644 --- a/retroshare-gui/src/gui/chat/ChatWidget.cpp +++ b/retroshare-gui/src/gui/chat/ChatWidget.cpp @@ -979,8 +979,12 @@ void ChatWidget::contextMenuTextBrowser(QPoint point) contextMnu->addAction(ui->actionClearChatHistory); contextMnu->addAction(ui->actionQuote); - ui->actionSave_image->setData(point); - contextMnu->addAction(ui->actionSave_image); + QTextCursor cursor = ui->textBrowser->cursorForPosition(point); + if(ImageUtil::checkImage(cursor)) + { + ui->actionSave_image->setData(point); + contextMnu->addAction(ui->actionSave_image); + } contextMnu->exec(ui->textBrowser->viewport()->mapToGlobal(point)); delete(contextMnu); diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp index 1e42cce64..050582bc3 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp +++ b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp @@ -514,8 +514,12 @@ void GxsForumThreadWidget::contextMenuTextBrowser(QPoint point) contextMnu->addSeparator(); - ui->actionSave_image->setData(point); - contextMnu->addAction(ui->actionSave_image); + QTextCursor cursor = ui->postText->cursorForPosition(point); + if(ImageUtil::checkImage(cursor)) + { + ui->actionSave_image->setData(point); + contextMnu->addAction(ui->actionSave_image); + } contextMnu->exec(ui->postText->viewport()->mapToGlobal(point)); delete(contextMnu); diff --git a/retroshare-gui/src/util/imageutil.cpp b/retroshare-gui/src/util/imageutil.cpp index c3f3e4f6f..01f8c4bcb 100644 --- a/retroshare-gui/src/util/imageutil.cpp +++ b/retroshare-gui/src/util/imageutil.cpp @@ -41,3 +41,11 @@ void ImageUtil::extractImage(QWidget *window, QTextCursor cursor) QMessageBox::warning(window, QApplication::translate("ImageUtil", "Save image"), QApplication::translate("ImageUtil", "Not an image")); } } + +bool ImageUtil::checkImage(QTextCursor cursor) +{ + cursor.movePosition(QTextCursor::Left, QTextCursor::MoveAnchor, 1); + cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, 2); + QString imagestr = cursor.selection().toHtml(); + return imagestr.indexOf("base64,") != -1; +} diff --git a/retroshare-gui/src/util/imageutil.h b/retroshare-gui/src/util/imageutil.h index f958ae8e7..f8ac9016a 100644 --- a/retroshare-gui/src/util/imageutil.h +++ b/retroshare-gui/src/util/imageutil.h @@ -11,6 +11,7 @@ public: ImageUtil(); static void extractImage(QWidget *window, QTextCursor cursor); + static bool checkImage(QTextCursor cursor); }; #endif // IMAGEUTIL_H