diff --git a/retroshare-gui/src/gui/common/RSTextBrowser.cpp b/retroshare-gui/src/gui/common/RSTextBrowser.cpp index 552369a77..7d6776eb1 100644 --- a/retroshare-gui/src/gui/common/RSTextBrowser.cpp +++ b/retroshare-gui/src/gui/common/RSTextBrowser.cpp @@ -18,19 +18,24 @@ * * *******************************************************************************/ -#include - -#include -#include -#include -#include - #include "RSTextBrowser.h" + #include "RSImageBlockWidget.h" #include "gui/common/FilesDefs.h" #include //To get RsAccounts +#include +#include +#include +#include +#include +#include +#include +#include + +#include + RSTextBrowser::RSTextBrowser(QWidget *parent) : QTextBrowser(parent) { @@ -291,3 +296,40 @@ QString RSTextBrowser::anchorForPosition(const QPoint &pos) const } return anchor; } + + +#ifndef QT_NO_CONTEXTMENU +QMenu *RSTextBrowser::createStandardContextMenu() +{ + return createStandardContextMenu(QPoint()); +} +QMenu *RSTextBrowser::createStandardContextMenu(const QPoint &position) +{ + QMenu *menu = QTextBrowser::createStandardContextMenu(position); + + menu->addSeparator(); + QAction *a = menu->addAction(FilesDefs::getIconFromQtResourcePath("://icons/textedit/code.png"), tr("View &Source"), this, SLOT(viewSource())); + a->setEnabled(!this->document()->isEmpty()); + + return menu; +} +#endif // QT_NO_CONTEXTMENU + +void RSTextBrowser::viewSource() +{ + QString text = this->textCursor().selection().toHtml(); + if (text.isEmpty()) + text = this->document()->toHtml(); + + QDialog *dialog = new QDialog(this); + QPlainTextEdit *pte = new QPlainTextEdit(dialog); + pte->setPlainText(text); + QGridLayout *gl = new QGridLayout(dialog); + gl->addWidget(pte,0,0,1,1); + dialog->setWindowTitle(tr("Document source")); + dialog->resize(500, 400); + + dialog->exec(); + + delete dialog; +} diff --git a/retroshare-gui/src/gui/common/RSTextBrowser.h b/retroshare-gui/src/gui/common/RSTextBrowser.h index 1f4cafd52..e06cd31c8 100644 --- a/retroshare-gui/src/gui/common/RSTextBrowser.h +++ b/retroshare-gui/src/gui/common/RSTextBrowser.h @@ -56,6 +56,11 @@ public: QVariant textColorQuotes() const { return highlighter->textColorQuotes();} bool getShowImages() const { return mShowImages; } +#ifndef QT_NO_CONTEXTMENU + QMenu *createStandardContextMenu(); + QMenu *createStandardContextMenu(const QPoint &position); +#endif + public slots: void showImages(); void setTextColorQuote(QColor textColorQuote) { highlighter->setTextColorQuote(textColorQuote);} @@ -64,6 +69,7 @@ public slots: private slots: void linkClicked(const QUrl &url); void destroyImageBlockWidget(); + void viewSource(); protected: void paintEvent(QPaintEvent *event);