mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Merge pull request #515 from PhenomRetroShare/Add_ContextMenuToShowImageInLobby
Add context menu to show hidden image on lobby.
This commit is contained in:
commit
259181889f
@ -21,18 +21,19 @@
|
|||||||
****************************************************************/
|
****************************************************************/
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QMenu>
|
#include <QBuffer>
|
||||||
#include <QKeyEvent>
|
|
||||||
#include <QScrollBar>
|
|
||||||
#include <QColorDialog>
|
#include <QColorDialog>
|
||||||
#include <QFontDialog>
|
#include <QFontDialog>
|
||||||
|
#include <QKeyEvent>
|
||||||
|
#include <QMenu>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QTextStream>
|
#include <QScrollBar>
|
||||||
#include <QTextCodec>
|
|
||||||
#include <QTimer>
|
|
||||||
#include <QTextDocumentFragment>
|
|
||||||
#include <QToolTip>
|
|
||||||
#include <QStringListModel>
|
#include <QStringListModel>
|
||||||
|
#include <QTextCodec>
|
||||||
|
#include <QTextDocumentFragment>
|
||||||
|
#include <QTextStream>
|
||||||
|
#include <QTimer>
|
||||||
|
#include <QToolTip>
|
||||||
|
|
||||||
#include "ChatWidget.h"
|
#include "ChatWidget.h"
|
||||||
#include "ui_ChatWidget.h"
|
#include "ui_ChatWidget.h"
|
||||||
@ -157,6 +158,8 @@ ChatWidget::ChatWidget(QWidget *parent) :
|
|||||||
connect(ui->actionQuote, SIGNAL(triggered()), this, SLOT(quote()));
|
connect(ui->actionQuote, SIGNAL(triggered()), this, SLOT(quote()));
|
||||||
connect(ui->actionDropPlacemark, SIGNAL(triggered()), this, SLOT(dropPlacemark()));
|
connect(ui->actionDropPlacemark, SIGNAL(triggered()), this, SLOT(dropPlacemark()));
|
||||||
connect(ui->actionSave_image, SIGNAL(triggered()), this, SLOT(saveImage()));
|
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<HashedFile>)), this, SLOT(fileHashingFinished(QList<HashedFile>)));
|
connect(ui->hashBox, SIGNAL(fileHashingFinished(QList<HashedFile>)), this, SLOT(fileHashingFinished(QList<HashedFile>)));
|
||||||
|
|
||||||
@ -196,9 +199,7 @@ ChatWidget::ChatWidget(QWidget *parent) :
|
|||||||
|
|
||||||
ui->actionSendAsPlainText->setChecked(Settings->getChatSendAsPlainTextByDef());
|
ui->actionSendAsPlainText->setChecked(Settings->getChatSendAsPlainTextByDef());
|
||||||
|
|
||||||
ui->textBrowser->setImageBlockWidget(ui->imageBlockWidget);
|
ui->textBrowser->resetImagesStatus(Settings->getChatLoadEmbeddedImages());
|
||||||
ui->textBrowser->resetImagesStatus(Settings->getChatLoadEmbeddedImages());//Need to be called after setImageBlockWidget
|
|
||||||
ui->imageBlockWidget->setAutoHide(true);
|
|
||||||
ui->textBrowser->installEventFilter(this);
|
ui->textBrowser->installEventFilter(this);
|
||||||
ui->textBrowser->viewport()->installEventFilter(this);
|
ui->textBrowser->viewport()->installEventFilter(this);
|
||||||
ui->chatTextEdit->installEventFilter(this);
|
ui->chatTextEdit->installEventFilter(this);
|
||||||
@ -581,6 +582,12 @@ bool ChatWidget::eventFilter(QObject *obj, QEvent *event)
|
|||||||
if (!anchors.isEmpty()){
|
if (!anchors.isEmpty()){
|
||||||
toolTipText = anchors.at(0);
|
toolTipText = anchors.at(0);
|
||||||
}
|
}
|
||||||
|
if (toolTipText.isEmpty() && !ui->textBrowser->getShowImages()){
|
||||||
|
QString imageStr;
|
||||||
|
if (ui->textBrowser->checkImage(helpEvent->pos(), imageStr)) {
|
||||||
|
toolTipText = imageStr;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!toolTipText.isEmpty()){
|
if (!toolTipText.isEmpty()){
|
||||||
QToolTip::showText(helpEvent->globalPos(), toolTipText);
|
QToolTip::showText(helpEvent->globalPos(), toolTipText);
|
||||||
@ -1016,9 +1023,11 @@ void ChatWidget::contextMenuTextBrowser(QPoint point)
|
|||||||
contextMnu->addAction(ui->actionQuote);
|
contextMnu->addAction(ui->actionQuote);
|
||||||
contextMnu->addAction(ui->actionDropPlacemark);
|
contextMnu->addAction(ui->actionDropPlacemark);
|
||||||
|
|
||||||
QTextCursor cursor = ui->textBrowser->cursorForPosition(point);
|
if(ui->textBrowser->checkImage(point))
|
||||||
if(ImageUtil::checkImage(cursor))
|
|
||||||
{
|
{
|
||||||
|
if (! ui->textBrowser->getShowImages())
|
||||||
|
contextMnu->addAction(ui->actionShow_Hidden_Images);
|
||||||
|
|
||||||
ui->actionSave_image->setData(point);
|
ui->actionSave_image->setData(point);
|
||||||
contextMnu->addAction(ui->actionSave_image);
|
contextMnu->addAction(ui->actionSave_image);
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>667</width>
|
<width>667</width>
|
||||||
<height>323</height>
|
<height>334</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout">
|
<layout class="QGridLayout">
|
||||||
@ -206,16 +206,6 @@ border-image: url(:/images/closepressed.png)
|
|||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
|
||||||
<widget class="RSImageBlockWidget" name="imageBlockWidget" native="true">
|
|
||||||
<property name="sizePolicy">
|
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
|
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
<item>
|
||||||
<widget class="QSplitter" name="chatVSplitter">
|
<widget class="QSplitter" name="chatVSplitter">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
@ -989,6 +979,11 @@ border-image: url(:/images/closepressed.png)
|
|||||||
<string>Don't replace tag with Emote Icon.</string>
|
<string>Don't replace tag with Emote Icon.</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="actionShow_Hidden_Images">
|
||||||
|
<property name="text">
|
||||||
|
<string>Show Hidden Images</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
@ -1017,17 +1012,10 @@ border-image: url(:/images/closepressed.png)
|
|||||||
<extends>QTextEdit</extends>
|
<extends>QTextEdit</extends>
|
||||||
<header location="global">gui/common/MimeTextEdit.h</header>
|
<header location="global">gui/common/MimeTextEdit.h</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
<customwidget>
|
|
||||||
<class>RSImageBlockWidget</class>
|
|
||||||
<extends>QWidget</extends>
|
|
||||||
<header>gui/common/RSImageBlockWidget.h</header>
|
|
||||||
<container>1</container>
|
|
||||||
</customwidget>
|
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
<resources>
|
<resources>
|
||||||
<include location="../emojione.qrc"/>
|
|
||||||
<include location="../images.qrc"/>
|
|
||||||
<include location="../icons.qrc"/>
|
<include location="../icons.qrc"/>
|
||||||
|
<include location="../images.qrc"/>
|
||||||
</resources>
|
</resources>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include <QDir>
|
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
|
#include <QDir>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <QTextDocumentFragment>
|
||||||
|
|
||||||
#include "RSTextBrowser.h"
|
#include "RSTextBrowser.h"
|
||||||
#include "RSImageBlockWidget.h"
|
#include "RSImageBlockWidget.h"
|
||||||
@ -19,7 +20,7 @@ RSTextBrowser::RSTextBrowser(QWidget *parent) :
|
|||||||
mImageBlockWidget = NULL;
|
mImageBlockWidget = NULL;
|
||||||
mLinkClickActive = true;
|
mLinkClickActive = true;
|
||||||
|
|
||||||
highliter = new RsSyntaxHighlighter(this);
|
highlighter = new RsSyntaxHighlighter(this);
|
||||||
|
|
||||||
connect(this, SIGNAL(anchorClicked(QUrl)), this, SLOT(linkClicked(QUrl)));
|
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);
|
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)
|
QVariant RSTextBrowser::loadResource(int type, const QUrl &name)
|
||||||
@ -103,6 +121,11 @@ QVariant RSTextBrowser::loadResource(int type, const QUrl &name)
|
|||||||
if (mImageBlockWidget)
|
if (mImageBlockWidget)
|
||||||
mImageBlockWidget->show();
|
mImageBlockWidget->show();
|
||||||
|
|
||||||
|
return getBlockedImage();
|
||||||
|
}
|
||||||
|
|
||||||
|
QPixmap RSTextBrowser::getBlockedImage()
|
||||||
|
{
|
||||||
return QPixmap(":/images/imageblocked_24.png");
|
return QPixmap(":/images/imageblocked_24.png");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,3 +182,61 @@ void RSTextBrowser::activateLinkClick(bool active)
|
|||||||
{
|
{
|
||||||
mLinkClickActive = 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;
|
||||||
|
}
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
#include <QTextBrowser>
|
#include <QTextBrowser>
|
||||||
#include "util/RsSyntaxHighlighter.h"
|
#include "util/RsSyntaxHighlighter.h"
|
||||||
|
|
||||||
|
//#define RSTEXTBROWSER_CHECKIMAGE_DEBUG 1
|
||||||
|
|
||||||
class RSImageBlockWidget;
|
class RSImageBlockWidget;
|
||||||
|
|
||||||
class RSTextBrowser : public QTextBrowser
|
class RSTextBrowser : public QTextBrowser
|
||||||
@ -18,16 +20,20 @@ public:
|
|||||||
void setPlaceholderText(const QString &text);
|
void setPlaceholderText(const QString &text);
|
||||||
void setImageBlockWidget(RSImageBlockWidget *widget);
|
void setImageBlockWidget(RSImageBlockWidget *widget);
|
||||||
void resetImagesStatus(bool load);
|
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);
|
void activateLinkClick(bool active);
|
||||||
|
|
||||||
virtual QVariant loadResource(int type, const QUrl &name);
|
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:
|
public slots:
|
||||||
void showImages();
|
void showImages();
|
||||||
void setTextColorQuote(QColor textColorQuote) { highliter->setTextColorQuote(textColorQuote);}
|
void setTextColorQuote(QColor textColorQuote) { highlighter->setTextColorQuote(textColorQuote);}
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void linkClicked(const QUrl &url);
|
void linkClicked(const QUrl &url);
|
||||||
@ -41,7 +47,13 @@ private:
|
|||||||
bool mShowImages;
|
bool mShowImages;
|
||||||
RSImageBlockWidget *mImageBlockWidget;
|
RSImageBlockWidget *mImageBlockWidget;
|
||||||
bool mLinkClickActive;
|
bool mLinkClickActive;
|
||||||
RsSyntaxHighlighter *highliter;
|
RsSyntaxHighlighter *highlighter;
|
||||||
|
#ifdef RSTEXTBROWSER_CHECKIMAGE_DEBUG
|
||||||
|
QRect mCursorRectStart;
|
||||||
|
QRect mCursorRectLeft;
|
||||||
|
QRect mCursorRectRight;
|
||||||
|
QRect mCursorRectEnd;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // RSTEXTBROWSER_H
|
#endif // RSTEXTBROWSER_H
|
||||||
|
@ -517,8 +517,7 @@ void GxsForumThreadWidget::contextMenuTextBrowser(QPoint point)
|
|||||||
|
|
||||||
contextMnu->addSeparator();
|
contextMnu->addSeparator();
|
||||||
|
|
||||||
QTextCursor cursor = ui->postText->cursorForPosition(point);
|
if(ui->postText->checkImage(point))
|
||||||
if(ImageUtil::checkImage(cursor))
|
|
||||||
{
|
{
|
||||||
ui->actionSave_image->setData(point);
|
ui->actionSave_image->setData(point);
|
||||||
contextMnu->addAction(ui->actionSave_image);
|
contextMnu->addAction(ui->actionSave_image);
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
#include "imageutil.h"
|
#include "imageutil.h"
|
||||||
#include "util/misc.h"
|
#include "util/misc.h"
|
||||||
|
|
||||||
#include <QMessageBox>
|
|
||||||
#include <QTextCursor>
|
|
||||||
#include <QByteArray>
|
|
||||||
#include <QString>
|
|
||||||
#include <QImage>
|
|
||||||
#include <QTextDocumentFragment>
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QByteArray>
|
||||||
|
#include <QImage>
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QString>
|
||||||
|
#include <QTextCursor>
|
||||||
|
#include <QTextDocumentFragment>
|
||||||
|
|
||||||
ImageUtil::ImageUtil() {}
|
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;
|
|
||||||
}
|
|
||||||
|
@ -4,14 +4,12 @@
|
|||||||
#include <QTextCursor>
|
#include <QTextCursor>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
|
|
||||||
class ImageUtil
|
class ImageUtil
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ImageUtil();
|
ImageUtil();
|
||||||
|
|
||||||
static void extractImage(QWidget *window, QTextCursor cursor);
|
static void extractImage(QWidget *window, QTextCursor cursor);
|
||||||
static bool checkImage(QTextCursor cursor);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // IMAGEUTIL_H
|
#endif // IMAGEUTIL_H
|
||||||
|
Loading…
Reference in New Issue
Block a user