Show save image option only when it is needed

This commit is contained in:
hunbernd 2015-12-12 22:41:15 +01:00
parent bbebd6a5d7
commit bc4691ceb4
4 changed files with 21 additions and 4 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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;
}

View File

@ -11,6 +11,7 @@ public:
ImageUtil();
static void extractImage(QWidget *window, QTextCursor cursor);
static bool checkImage(QTextCursor cursor);
};
#endif // IMAGEUTIL_H