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 <QMenu>
|
||||
#include <QKeyEvent>
|
||||
#include <QScrollBar>
|
||||
#include <QBuffer>
|
||||
#include <QColorDialog>
|
||||
#include <QFontDialog>
|
||||
#include <QKeyEvent>
|
||||
#include <QMenu>
|
||||
#include <QMessageBox>
|
||||
#include <QTextStream>
|
||||
#include <QTextCodec>
|
||||
#include <QTimer>
|
||||
#include <QTextDocumentFragment>
|
||||
#include <QToolTip>
|
||||
#include <QScrollBar>
|
||||
#include <QStringListModel>
|
||||
#include <QTextCodec>
|
||||
#include <QTextDocumentFragment>
|
||||
#include <QTextStream>
|
||||
#include <QTimer>
|
||||
#include <QToolTip>
|
||||
|
||||
#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<HashedFile>)), this, SLOT(fileHashingFinished(QList<HashedFile>)));
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>667</width>
|
||||
<height>323</height>
|
||||
<height>334</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout">
|
||||
@ -206,16 +206,6 @@ border-image: url(:/images/closepressed.png)
|
||||
</layout>
|
||||
</widget>
|
||||
</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>
|
||||
<widget class="QSplitter" name="chatVSplitter">
|
||||
<property name="orientation">
|
||||
@ -989,6 +979,11 @@ border-image: url(:/images/closepressed.png)
|
||||
<string>Don't replace tag with Emote Icon.</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionShow_Hidden_Images">
|
||||
<property name="text">
|
||||
<string>Show Hidden Images</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
@ -1017,17 +1012,10 @@ border-image: url(:/images/closepressed.png)
|
||||
<extends>QTextEdit</extends>
|
||||
<header location="global">gui/common/MimeTextEdit.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>RSImageBlockWidget</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>gui/common/RSImageBlockWidget.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources>
|
||||
<include location="../emojione.qrc"/>
|
||||
<include location="../images.qrc"/>
|
||||
<include location="../icons.qrc"/>
|
||||
<include location="../images.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
@ -1,8 +1,9 @@
|
||||
#include <iostream>
|
||||
|
||||
#include <QDir>
|
||||
#include <QDesktopServices>
|
||||
#include <QDir>
|
||||
#include <QPainter>
|
||||
#include <QTextDocumentFragment>
|
||||
|
||||
#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;
|
||||
}
|
||||
|
@ -4,6 +4,8 @@
|
||||
#include <QTextBrowser>
|
||||
#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
|
||||
|
@ -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);
|
||||
|
@ -1,13 +1,13 @@
|
||||
#include "imageutil.h"
|
||||
#include "util/misc.h"
|
||||
|
||||
#include <QMessageBox>
|
||||
#include <QTextCursor>
|
||||
#include <QByteArray>
|
||||
#include <QString>
|
||||
#include <QImage>
|
||||
#include <QTextDocumentFragment>
|
||||
#include <QApplication>
|
||||
#include <QByteArray>
|
||||
#include <QImage>
|
||||
#include <QMessageBox>
|
||||
#include <QString>
|
||||
#include <QTextCursor>
|
||||
#include <QTextDocumentFragment>
|
||||
|
||||
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 <QWidget>
|
||||
|
||||
|
||||
class ImageUtil
|
||||
{
|
||||
public:
|
||||
ImageUtil();
|
||||
|
||||
static void extractImage(QWidget *window, QTextCursor cursor);
|
||||
static bool checkImage(QTextCursor cursor);
|
||||
};
|
||||
|
||||
#endif // IMAGEUTIL_H
|
||||
|
Loading…
Reference in New Issue
Block a user