diff --git a/retroshare-gui/src/gui/chat/ChatWidget.cpp b/retroshare-gui/src/gui/chat/ChatWidget.cpp index 725fcb11b..65b27d6e0 100644 --- a/retroshare-gui/src/gui/chat/ChatWidget.cpp +++ b/retroshare-gui/src/gui/chat/ChatWidget.cpp @@ -21,18 +21,19 @@ ****************************************************************/ #include -#include -#include -#include +#include #include #include +#include +#include #include -#include -#include -#include -#include -#include +#include #include +#include +#include +#include +#include +#include #include "ChatWidget.h" #include "ui_ChatWidget.h" @@ -157,6 +158,8 @@ ChatWidget::ChatWidget(QWidget *parent) : connect(ui->actionQuote, SIGNAL(triggered()), this, SLOT(quote())); connect(ui->actionDropPlacemark, SIGNAL(triggered()), this, SLOT(dropPlacemark())); connect(ui->actionSave_image, SIGNAL(triggered()), this, SLOT(saveImage())); + connect(ui->actionShow_Hidden_Images, SIGNAL(triggered()), ui->textBrowser, SLOT(showImages())); + ui->actionShow_Hidden_Images->setIcon(ui->textBrowser->getBlockedImage()); connect(ui->hashBox, SIGNAL(fileHashingFinished(QList)), this, SLOT(fileHashingFinished(QList))); @@ -196,9 +199,7 @@ ChatWidget::ChatWidget(QWidget *parent) : ui->actionSendAsPlainText->setChecked(Settings->getChatSendAsPlainTextByDef()); - ui->textBrowser->setImageBlockWidget(ui->imageBlockWidget); - ui->textBrowser->resetImagesStatus(Settings->getChatLoadEmbeddedImages());//Need to be called after setImageBlockWidget - ui->imageBlockWidget->setAutoHide(true); + ui->textBrowser->resetImagesStatus(Settings->getChatLoadEmbeddedImages()); ui->textBrowser->installEventFilter(this); ui->textBrowser->viewport()->installEventFilter(this); ui->chatTextEdit->installEventFilter(this); @@ -581,6 +582,12 @@ bool ChatWidget::eventFilter(QObject *obj, QEvent *event) if (!anchors.isEmpty()){ toolTipText = anchors.at(0); } + if (toolTipText.isEmpty() && !ui->textBrowser->getShowImages()){ + QString imageStr; + if (ui->textBrowser->checkImage(helpEvent->pos(), imageStr)) { + toolTipText = imageStr; + } + } } if (!toolTipText.isEmpty()){ QToolTip::showText(helpEvent->globalPos(), toolTipText); @@ -1016,9 +1023,11 @@ void ChatWidget::contextMenuTextBrowser(QPoint point) contextMnu->addAction(ui->actionQuote); contextMnu->addAction(ui->actionDropPlacemark); - QTextCursor cursor = ui->textBrowser->cursorForPosition(point); - if(ImageUtil::checkImage(cursor)) + if(ui->textBrowser->checkImage(point)) { + if (! ui->textBrowser->getShowImages()) + contextMnu->addAction(ui->actionShow_Hidden_Images); + ui->actionSave_image->setData(point); contextMnu->addAction(ui->actionSave_image); } diff --git a/retroshare-gui/src/gui/chat/ChatWidget.ui b/retroshare-gui/src/gui/chat/ChatWidget.ui index 1b9f57b71..fed47f6ce 100644 --- a/retroshare-gui/src/gui/chat/ChatWidget.ui +++ b/retroshare-gui/src/gui/chat/ChatWidget.ui @@ -7,7 +7,7 @@ 0 0 667 - 323 + 334 @@ -206,16 +206,6 @@ border-image: url(:/images/closepressed.png) - - - - - 0 - 0 - - - - @@ -989,6 +979,11 @@ border-image: url(:/images/closepressed.png) Don't replace tag with Emote Icon. + + + Show Hidden Images + + @@ -1017,17 +1012,10 @@ border-image: url(:/images/closepressed.png) QTextEdit
gui/common/MimeTextEdit.h
- - RSImageBlockWidget - QWidget -
gui/common/RSImageBlockWidget.h
- 1 -
- - + diff --git a/retroshare-gui/src/gui/common/RSTextBrowser.cpp b/retroshare-gui/src/gui/common/RSTextBrowser.cpp index cb0634ee6..f57e650a9 100644 --- a/retroshare-gui/src/gui/common/RSTextBrowser.cpp +++ b/retroshare-gui/src/gui/common/RSTextBrowser.cpp @@ -1,8 +1,9 @@ #include -#include #include +#include #include +#include #include "RSTextBrowser.h" #include "RSImageBlockWidget.h" @@ -19,7 +20,7 @@ RSTextBrowser::RSTextBrowser(QWidget *parent) : mImageBlockWidget = NULL; mLinkClickActive = true; - highliter = new RsSyntaxHighlighter(this); + highlighter = new RsSyntaxHighlighter(this); connect(this, SIGNAL(anchorClicked(QUrl)), this, SLOT(linkClicked(QUrl))); } @@ -73,6 +74,23 @@ void RSTextBrowser::paintEvent(QPaintEvent *event) painter.drawText(QRect(QPoint(), vieportWidget->size()), Qt::AlignHCenter | Qt::AlignVCenter | Qt::TextWordWrap, mPlaceholderText); } +#ifdef RSTEXTBROWSER_CHECKIMAGE_DEBUG + QPainter painter(viewport()); + QPen pen = painter.pen(); + pen.setWidth(2); + pen.setColor(QColor(qRgba(255,0,0,128))); + painter.setPen(pen); + painter.drawRect(mCursorRectStart); + pen.setColor(QColor(qRgba(0,255,0,128))); + painter.setPen(pen); + painter.drawRect(mCursorRectLeft); + pen.setColor(QColor(qRgba(0,0,255,128))); + painter.setPen(pen); + painter.drawRect(mCursorRectRight); + pen.setColor(QColor(qRgba(0,0,0,128))); + painter.setPen(pen); + painter.drawRect(mCursorRectEnd); +#endif } QVariant RSTextBrowser::loadResource(int type, const QUrl &name) @@ -103,6 +121,11 @@ QVariant RSTextBrowser::loadResource(int type, const QUrl &name) if (mImageBlockWidget) mImageBlockWidget->show(); + return getBlockedImage(); +} + +QPixmap RSTextBrowser::getBlockedImage() +{ return QPixmap(":/images/imageblocked_24.png"); } @@ -159,3 +182,61 @@ void RSTextBrowser::activateLinkClick(bool active) { mLinkClickActive = active; } + +/** + * @brief RSTextBrowser::checkImage + * @param pos where to check if image is shown in viewport coordinate + * @param imageStr return html source of cursor + * @return True if an image is under cursor + */ +bool RSTextBrowser::checkImage(QPoint pos, QString &imageStr) +{ + //Get text cursor under pos. But if pos is under text browser end line this return last cursor. + QTextCursor cursor = cursorForPosition(pos); + //First get rect of cursor (could be at left or right of image) + QRect cursorRectStart = cursorRect(cursor); + //Second get text + cursor.movePosition(QTextCursor::Left, QTextCursor::MoveAnchor, 1);//To get character just before + QRect cursorRectLeft = cursorRect(cursor); + cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, 2); + QRect cursorRectRight = cursorRect(cursor); + imageStr = cursor.selection().toHtml(); +#ifdef RSTEXTBROWSER_CHECKIMAGE_DEBUG + mCursorRectStart = cursorRectStart; + mCursorRectLeft = cursorRectLeft; + mCursorRectRight = cursorRectRight; + + std::cerr << "cursorRect LTRB :" << cursorRectStart.left() << ";" << cursorRectStart.top() << ";" << cursorRectStart.right() << ";" << cursorRectStart.bottom() << std::endl; + std::cerr << "cursorRectLeft :" << cursorRectLeft.left() << ";" << cursorRectLeft.top() << ";" << cursorRectLeft.right() << ";" << cursorRectLeft.bottom() << std::endl; + std::cerr << "cursorRectRight :" << cursorRectRight.left() << ";" << cursorRectRight.top() << ";" << cursorRectRight.right() << ";" << cursorRectRight.bottom() << std::endl; + std::cerr << "pos XY :" << pos.x() << ";" << pos.y() << std::endl; +#endif + QRect cursorRectEnd = cursorRectStart; + //Finally set left with right of precedent character. + if (cursorRectEnd.top() < cursorRectLeft.bottom()) + { + cursorRectEnd.setLeft(cursorRectLeft.right()); + } else { + //Image on new line + cursorRectEnd.setLeft(0); + } + //And set Right with left of next character. + if (cursorRectEnd.bottom() > cursorRectRight.top()) + { + cursorRectEnd.setRight(cursorRectRight.left()); + } else { + //New line after Image. + } +#ifdef RSTEXTBROWSER_CHECKIMAGE_DEBUG + mCursorRectEnd = cursorRectEnd; + + std::cerr << "final cursorRect:" << cursorRectEnd.left() << ";" << cursorRectEnd.top() << ";" << cursorRectEnd.right() << ";" << cursorRectEnd.bottom() << std::endl; + viewport()->update(); +#endif + //If pos is on text rect + if (cursorRectEnd.contains(pos)) + { + return imageStr.indexOf("base64,") != -1; + } + return false; +} diff --git a/retroshare-gui/src/gui/common/RSTextBrowser.h b/retroshare-gui/src/gui/common/RSTextBrowser.h index f9e218b77..13e520d00 100644 --- a/retroshare-gui/src/gui/common/RSTextBrowser.h +++ b/retroshare-gui/src/gui/common/RSTextBrowser.h @@ -4,6 +4,8 @@ #include #include "util/RsSyntaxHighlighter.h" +//#define RSTEXTBROWSER_CHECKIMAGE_DEBUG 1 + class RSImageBlockWidget; class RSTextBrowser : public QTextBrowser @@ -18,16 +20,20 @@ public: void setPlaceholderText(const QString &text); void setImageBlockWidget(RSImageBlockWidget *widget); void resetImagesStatus(bool load); + QPixmap getBlockedImage(); + bool checkImage(QPoint pos, QString &imageStr); + bool checkImage(QPoint pos) {QString imageStr; return checkImage(pos, imageStr); } void activateLinkClick(bool active); virtual QVariant loadResource(int type, const QUrl &name); - QColor textColorQuote() const { return highliter->textColorQuote();} + QColor textColorQuote() const { return highlighter->textColorQuote();} + bool getShowImages() const { return mShowImages; } public slots: void showImages(); - void setTextColorQuote(QColor textColorQuote) { highliter->setTextColorQuote(textColorQuote);} + void setTextColorQuote(QColor textColorQuote) { highlighter->setTextColorQuote(textColorQuote);} private slots: void linkClicked(const QUrl &url); @@ -41,7 +47,13 @@ private: bool mShowImages; RSImageBlockWidget *mImageBlockWidget; bool mLinkClickActive; - RsSyntaxHighlighter *highliter; + RsSyntaxHighlighter *highlighter; +#ifdef RSTEXTBROWSER_CHECKIMAGE_DEBUG + QRect mCursorRectStart; + QRect mCursorRectLeft; + QRect mCursorRectRight; + QRect mCursorRectEnd; +#endif }; #endif // RSTEXTBROWSER_H diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp index 29033ae09..24c4729cd 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp +++ b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp @@ -517,8 +517,7 @@ void GxsForumThreadWidget::contextMenuTextBrowser(QPoint point) contextMnu->addSeparator(); - QTextCursor cursor = ui->postText->cursorForPosition(point); - if(ImageUtil::checkImage(cursor)) + if(ui->postText->checkImage(point)) { ui->actionSave_image->setData(point); contextMnu->addAction(ui->actionSave_image); diff --git a/retroshare-gui/src/util/imageutil.cpp b/retroshare-gui/src/util/imageutil.cpp index 01f8c4bcb..1a08ffb07 100644 --- a/retroshare-gui/src/util/imageutil.cpp +++ b/retroshare-gui/src/util/imageutil.cpp @@ -1,13 +1,13 @@ #include "imageutil.h" #include "util/misc.h" -#include -#include -#include -#include -#include -#include #include +#include +#include +#include +#include +#include +#include ImageUtil::ImageUtil() {} @@ -42,10 +42,3 @@ void ImageUtil::extractImage(QWidget *window, QTextCursor cursor) } } -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 f8ac9016a..30e6ecb67 100644 --- a/retroshare-gui/src/util/imageutil.h +++ b/retroshare-gui/src/util/imageutil.h @@ -4,14 +4,12 @@ #include #include - class ImageUtil { public: ImageUtil(); static void extractImage(QWidget *window, QTextCursor cursor); - static bool checkImage(QTextCursor cursor); }; #endif // IMAGEUTIL_H