mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-29 11:01:22 -04:00
Spoiler feature
Select text to hide, then right click --> Spoiler
This commit is contained in:
parent
cdda411c79
commit
5a8f74ce99
4 changed files with 51 additions and 0 deletions
|
@ -231,6 +231,8 @@ void MimeTextEdit::contextMenuEvent(QContextMenuEvent *e)
|
||||||
|
|
||||||
/* Add actions for pasting links */
|
/* Add actions for pasting links */
|
||||||
contextMenu->addAction( tr("Paste as plain text"), this, SLOT(pastePlainText()));
|
contextMenu->addAction( tr("Paste as plain text"), this, SLOT(pastePlainText()));
|
||||||
|
QAction *spoilerAction = contextMenu->addAction(tr("Spoiler"), this, SLOT(spoiler()));
|
||||||
|
spoilerAction->setToolTip(tr("Select text to hide, then push this button"));
|
||||||
contextMenu->addSeparator();
|
contextMenu->addSeparator();
|
||||||
QAction *pasteLinkAction = contextMenu->addAction(QIcon(":/images/pasterslink.png"), tr("Paste RetroShare Link"), this, SLOT(pasteLink()));
|
QAction *pasteLinkAction = contextMenu->addAction(QIcon(":/images/pasterslink.png"), tr("Paste RetroShare Link"), this, SLOT(pasteLink()));
|
||||||
contextMenu->addAction(QIcon(":/images/pasterslink.png"), tr("Paste my certificate link"), this, SLOT(pasteOwnCertificateLink()));
|
contextMenu->addAction(QIcon(":/images/pasterslink.png"), tr("Paste my certificate link"), this, SLOT(pasteOwnCertificateLink()));
|
||||||
|
@ -268,3 +270,8 @@ void MimeTextEdit::pastePlainText()
|
||||||
{
|
{
|
||||||
insertPlainText(QApplication::clipboard()->text());
|
insertPlainText(QApplication::clipboard()->text());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MimeTextEdit::spoiler()
|
||||||
|
{
|
||||||
|
RsHtml::insertSpoilerText(this->textCursor());
|
||||||
|
}
|
||||||
|
|
|
@ -59,6 +59,8 @@ private slots:
|
||||||
void pasteLink();
|
void pasteLink();
|
||||||
void pasteOwnCertificateLink();
|
void pasteOwnCertificateLink();
|
||||||
void pastePlainText();
|
void pastePlainText();
|
||||||
|
void spoiler();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString textUnderCursor() const;
|
QString textUnderCursor() const;
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QTextDocumentFragment>
|
#include <QTextDocumentFragment>
|
||||||
#include <qmath.h>
|
#include <qmath.h>
|
||||||
|
#include <QUrl>
|
||||||
|
|
||||||
#include "HandleRichText.h"
|
#include "HandleRichText.h"
|
||||||
#include "gui/RetroShareLink.h"
|
#include "gui/RetroShareLink.h"
|
||||||
|
@ -643,6 +644,28 @@ static void optimizeHtml(QDomDocument& doc
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//hidden text in a
|
||||||
|
if (element.tagName().toLower() == "a") {
|
||||||
|
if(element.hasAttribute("href")){
|
||||||
|
QString href = element.attribute("href", "");
|
||||||
|
if(href.startsWith("hidden:")){
|
||||||
|
//this text should be hidden and appear in title
|
||||||
|
//we need this trick, because QTextEdit doesn't export the title attribute
|
||||||
|
QString title = href.remove(0, QString("hidden:").length());
|
||||||
|
QString text = element.text();
|
||||||
|
element.setTagName("span");
|
||||||
|
element.removeAttribute("href");
|
||||||
|
QDomNodeList c = element.childNodes();
|
||||||
|
for(int i = 0; i < c.count(); i++){
|
||||||
|
element.removeChild(c.at(i));
|
||||||
|
};
|
||||||
|
element.setAttribute(QString("title"), title);
|
||||||
|
QDomText textnode = doc.createTextNode(text);
|
||||||
|
element.appendChild(textnode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// iterate children
|
// iterate children
|
||||||
optimizeHtml(doc, element, stylesList, knownStyle);
|
optimizeHtml(doc, element, stylesList, knownStyle);
|
||||||
|
|
||||||
|
@ -1004,3 +1027,20 @@ QString RsHtml::makeQuotedText(RSTextBrowser *browser)
|
||||||
text = sl.join("\n>");
|
text = sl.join("\n>");
|
||||||
return QString(">") + text;
|
return QString(">") + text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RsHtml::insertSpoilerText(QTextCursor cursor)
|
||||||
|
{
|
||||||
|
QString hiddentext = cursor.selection().toPlainText();
|
||||||
|
if(hiddentext.isEmpty()) return;
|
||||||
|
QString publictext = "*SPOILER*";
|
||||||
|
|
||||||
|
QString encoded = hiddentext;
|
||||||
|
encoded = encoded.replace(QChar('\"'), QString("""));
|
||||||
|
encoded = encoded.replace(QChar('\''), QString("'"));
|
||||||
|
encoded = encoded.replace(QChar('<'), QString("<"));
|
||||||
|
encoded = encoded.replace(QChar('>'), QString(">"));
|
||||||
|
encoded = encoded.replace(QChar('&'), QString("&"));
|
||||||
|
|
||||||
|
QString html = QString("<a href=\"hidden:%1\" title=\"%1\">%2</a>").arg(encoded, publictext);
|
||||||
|
cursor.insertHtml(html);
|
||||||
|
}
|
||||||
|
|
|
@ -53,6 +53,7 @@ class QDomDocument;
|
||||||
class QDomElement;
|
class QDomElement;
|
||||||
class EmbedInHtml;
|
class EmbedInHtml;
|
||||||
class RetroShareLink;
|
class RetroShareLink;
|
||||||
|
class QTextCursor;
|
||||||
|
|
||||||
class RsHtml
|
class RsHtml
|
||||||
{
|
{
|
||||||
|
@ -75,6 +76,7 @@ public:
|
||||||
static QString plainText(const std::string &text);
|
static QString plainText(const std::string &text);
|
||||||
|
|
||||||
static QString makeQuotedText(RSTextBrowser* browser);
|
static QString makeQuotedText(RSTextBrowser* browser);
|
||||||
|
static void insertSpoilerText(QTextCursor cursor);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void embedHtml(QTextDocument *textDocument, QDomDocument &doc, QDomElement ¤tElement, EmbedInHtml& embedInfos, ulong flag);
|
void embedHtml(QTextDocument *textDocument, QDomDocument &doc, QDomElement ¤tElement, EmbedInHtml& embedInfos, ulong flag);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue