mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-28 00:49:28 -05:00
Spoiler feature
Select text to hide, then right click --> Spoiler
This commit is contained in:
parent
cdda411c79
commit
5a8f74ce99
@ -231,6 +231,8 @@ void MimeTextEdit::contextMenuEvent(QContextMenuEvent *e)
|
||||
|
||||
/* Add actions for pasting links */
|
||||
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();
|
||||
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()));
|
||||
@ -268,3 +270,8 @@ void MimeTextEdit::pastePlainText()
|
||||
{
|
||||
insertPlainText(QApplication::clipboard()->text());
|
||||
}
|
||||
|
||||
void MimeTextEdit::spoiler()
|
||||
{
|
||||
RsHtml::insertSpoilerText(this->textCursor());
|
||||
}
|
||||
|
@ -59,6 +59,8 @@ private slots:
|
||||
void pasteLink();
|
||||
void pasteOwnCertificateLink();
|
||||
void pastePlainText();
|
||||
void spoiler();
|
||||
|
||||
private:
|
||||
QString textUnderCursor() const;
|
||||
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include <QMessageBox>
|
||||
#include <QTextDocumentFragment>
|
||||
#include <qmath.h>
|
||||
#include <QUrl>
|
||||
|
||||
#include "HandleRichText.h"
|
||||
#include "gui/RetroShareLink.h"
|
||||
@ -643,6 +644,28 @@ static void optimizeHtml(QDomDocument& doc
|
||||
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
|
||||
optimizeHtml(doc, element, stylesList, knownStyle);
|
||||
|
||||
@ -1004,3 +1027,20 @@ QString RsHtml::makeQuotedText(RSTextBrowser *browser)
|
||||
text = sl.join("\n>");
|
||||
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 EmbedInHtml;
|
||||
class RetroShareLink;
|
||||
class QTextCursor;
|
||||
|
||||
class RsHtml
|
||||
{
|
||||
@ -75,6 +76,7 @@ public:
|
||||
static QString plainText(const std::string &text);
|
||||
|
||||
static QString makeQuotedText(RSTextBrowser* browser);
|
||||
static void insertSpoilerText(QTextCursor cursor);
|
||||
|
||||
protected:
|
||||
void embedHtml(QTextDocument *textDocument, QDomDocument &doc, QDomElement ¤tElement, EmbedInHtml& embedInfos, ulong flag);
|
||||
|
Loading…
Reference in New Issue
Block a user