diff --git a/retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.cpp b/retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.cpp index 9155d6761..8626da77e 100644 --- a/retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.cpp +++ b/retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.cpp @@ -35,6 +35,7 @@ #include "util/qtthreadsutils.h" #include "util/HandleRichText.h" #include "gui/Identity/IdDialog.h" +#include "gui/settings/rsharesettings.h" #include "gui/MainWindow.h" #include "util/DateTime.h" #include @@ -236,8 +237,10 @@ void BoardPostDisplayWidgetBase::baseSetup() if (urlOkay) { QString siteurl = url.toEncoded(); + linkColor = Settings->getLinkColor(); - label->setStyleSheet("text-decoration: underline; color:#2255AA;"); + QString colorstring = QString("%1;").arg(linkColor.name()); + label->setStyleSheet("text-decoration: underline; color:" + colorstring ); label->setCursor(QCursor(Qt::PointingHandCursor)); label->setToolTip(siteurl); diff --git a/retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.h b/retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.h index 5c10af55d..fc026f817 100644 --- a/retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.h +++ b/retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.h @@ -109,6 +109,8 @@ signals: protected: RsPostedPost mPost; uint8_t mDisplayFlags; +private: + QColor linkColor; }; class BoardPostDisplayWidget_compact : public BoardPostDisplayWidgetBase @@ -151,6 +153,8 @@ protected: void setup() override; // to be overloaded by the different views private: + QColor linkColor; + /** Qt Designer generated object */ Ui::BoardPostDisplayWidget_compact *ui; }; diff --git a/retroshare-gui/src/gui/Posted/PostedCardView.cpp b/retroshare-gui/src/gui/Posted/PostedCardView.cpp index 1599197d9..704db692e 100644 --- a/retroshare-gui/src/gui/Posted/PostedCardView.cpp +++ b/retroshare-gui/src/gui/Posted/PostedCardView.cpp @@ -230,9 +230,14 @@ void PostedCardView::fill() if (urlOkay) { + linkColor = Settings->getLinkColor(); + QString colorstring = QString("%1;").arg(linkColor.name()); + QString urlstr = QString(" "); + urlstr += QString("\" > "); urlstr += messageName(); urlstr += QString(" "); diff --git a/retroshare-gui/src/gui/Posted/PostedCardView.h b/retroshare-gui/src/gui/Posted/PostedCardView.h index 0f4f5f2ab..aeb0f19b6 100644 --- a/retroshare-gui/src/gui/Posted/PostedCardView.h +++ b/retroshare-gui/src/gui/Posted/PostedCardView.h @@ -57,6 +57,8 @@ protected: void toggleNotes() override; private: + QColor linkColor; + /** Qt Designer generated object */ Ui::PostedCardView *ui; }; diff --git a/retroshare-gui/src/gui/Posted/PostedCreatePostDialog.cpp b/retroshare-gui/src/gui/Posted/PostedCreatePostDialog.cpp index 2c0227cf1..b4ce19448 100644 --- a/retroshare-gui/src/gui/Posted/PostedCreatePostDialog.cpp +++ b/retroshare-gui/src/gui/Posted/PostedCreatePostDialog.cpp @@ -33,6 +33,7 @@ #include "util/misc.h" #include "util/qtthreadsutils.h" #include "util/RichTextEdit.h" +#include "util/HandleRichText.h" #include "gui/feeds/SubFileItem.h" #include "util/rsdir.h" @@ -167,6 +168,7 @@ void PostedCreatePostDialog::createPost() if(!ui->RichTextEditWidget->toPlainText().trimmed().isEmpty()) { QString text; text = ui->RichTextEditWidget->toHtml(); + RsHtml::optimizeHtml(text); post.mNotes = std::string(text.toUtf8()); } diff --git a/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.cpp b/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.cpp index c5ed31892..80c98e4c5 100644 --- a/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.cpp +++ b/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.cpp @@ -920,7 +920,7 @@ void PostedListWidgetWithModel::insertBoardDetails(const RsPostedGroup& group) ui->infoAdministrator->setId(group.mMeta.mAuthorId) ; link = RetroShareLink::createMessage(group.mMeta.mAuthorId, ""); - ui->infoAdministrator->setText(link.toHtml()); + ui->infoAdministrator->setText(link.toHtmlColored()); ui->createdinfolabel->setText(DateTime::formatDateTime(group.mMeta.mPublishTs)); diff --git a/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.ui b/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.ui index 734c4a233..06613c6bf 100644 --- a/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.ui +++ b/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.ui @@ -46,7 +46,7 @@ - + @@ -619,6 +619,11 @@ p, li { white-space: pre-wrap; }
gui/common/RSTabWidget.h
1 + + RSTextBrowser + QTextBrowser +
gui/common/RSTextBrowser.h
+
diff --git a/retroshare-gui/src/gui/RetroShareLink.cpp b/retroshare-gui/src/gui/RetroShareLink.cpp index 35fc3d836..6ef31ea18 100644 --- a/retroshare-gui/src/gui/RetroShareLink.cpp +++ b/retroshare-gui/src/gui/RetroShareLink.cpp @@ -40,6 +40,7 @@ #include "msgs/MessageComposer.h" #include "Posted/PostedDialog.h" #include "util/misc.h" +#include "gui/settings/rsharesettings.h" #include #include @@ -1218,13 +1219,32 @@ QString RetroShareLink::niceName() const QString RetroShareLink::toHtml() const { + QColor linkColor = Settings->getLinkColor(); + QString colorstring = QString("%1;").arg(linkColor.name()); + QString html = "" ; + html += " style=\"color:" + colorstring + "\">" + niceName() + "" ; + + return html; +} + +QString RetroShareLink::toHtmlColored() const +{ + QColor linkColor = Settings->getLinkColor(); + QString colorstring = QString("%1;").arg(linkColor.name()); + + QString html = "" + niceName() + "" ; return html; } diff --git a/retroshare-gui/src/gui/RetroShareLink.h b/retroshare-gui/src/gui/RetroShareLink.h index 2b25e2a2d..957b85161 100644 --- a/retroshare-gui/src/gui/RetroShareLink.h +++ b/retroshare-gui/src/gui/RetroShareLink.h @@ -42,6 +42,7 @@ #include #include #include +#include #include @@ -142,6 +143,8 @@ class RetroShareLink QString toHtmlSize() const ; + QString toHtmlColored() const; + QUrl toUrl() const ; bool operator==(const RetroShareLink& l) const { return _type == l._type && _hash == l._hash ; } @@ -180,6 +183,7 @@ class RetroShareLink time_t _time_stamp ; // time stamp at which the link will expire. QString _radix_group_data; uint32_t _count ; + QColor linkColor; unsigned int _subType; // for general use as sub type for _type (RSLINK_SUBTYPE_...) }; diff --git a/retroshare-gui/src/gui/common/MimeTextEdit.cpp b/retroshare-gui/src/gui/common/MimeTextEdit.cpp index 78ddd00a6..b9a170d19 100644 --- a/retroshare-gui/src/gui/common/MimeTextEdit.cpp +++ b/retroshare-gui/src/gui/common/MimeTextEdit.cpp @@ -30,6 +30,7 @@ #include #include "MimeTextEdit.h" +#include "gui/settings/rsharesettings.h" #include "util/HandleRichText.h" #include "gui/RetroShareLink.h" #include "util/imageutil.h" @@ -329,3 +330,42 @@ void MimeTextEdit::copyImage() QTextCursor cursor = cursorForPosition(point); ImageUtil::copyImage(window(), cursor); } + +void MimeTextEdit::updateLinkColor() +{ + linkColor = Settings->getLinkColor(); + QPalette p = palette(); + p.setColor(QPalette::Link, linkColor); + p.setColor(QPalette::LinkVisited, linkColor); + setPalette(p); + + if (document()) { + document()->setDefaultStyleSheet(QString("a[href] { color: %1; }").arg(linkColor.name())); + } +} + +QString MimeTextEdit::toHtml(const QByteArray &encoding) const +{ + QTextDocument *doc = document(); + QString oldSheet; + if (doc) { + oldSheet = doc->defaultStyleSheet(); + doc->setDefaultStyleSheet(""); + } + QString html; + if (encoding.isEmpty()) { + html = QTextEdit::toHtml(); + } else { +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + // Qt 6: toHtml() takes no arguments + html = doc->toHtml(); +#else + // Qt 5: toHtml() accepts encoding parameter + html = doc->toHtml(encoding); +#endif + } + if (doc) { + doc->setDefaultStyleSheet(oldSheet); + } + return html; +} diff --git a/retroshare-gui/src/gui/common/MimeTextEdit.h b/retroshare-gui/src/gui/common/MimeTextEdit.h index c0bf83892..d46703521 100644 --- a/retroshare-gui/src/gui/common/MimeTextEdit.h +++ b/retroshare-gui/src/gui/common/MimeTextEdit.h @@ -52,12 +52,15 @@ public: QVariant textColorQuotes() const { return highliter->textColorQuotes();} bool onlyPlainText() const {return mOnlyPlainText;} + QString toHtml(const QByteArray &encoding = QByteArray()) const; + void setMaxBytes(int limit) {mMaxBytes = limit;} public slots: void setTextColorQuote(QColor textColorQuote) { highliter->setTextColorQuote(textColorQuote);} void setTextColorQuotes(QVariant textColorQuotes) { highliter->setTextColorQuotes(textColorQuotes);} void setOnlyPlainText(bool bOnlyPlainText) {mOnlyPlainText = bOnlyPlainText;} + void updateLinkColor(); signals: void calculateContextMenuActions(); @@ -91,6 +94,7 @@ private: RsSyntaxHighlighter *highliter; bool mOnlyPlainText; int mMaxBytes = -1; //limit content size, for pasting images + QColor linkColor; }; #endif // MIMETEXTEDIT_H diff --git a/retroshare-gui/src/gui/common/RSTextBrowser.cpp b/retroshare-gui/src/gui/common/RSTextBrowser.cpp index f43a57242..592bc2d73 100644 --- a/retroshare-gui/src/gui/common/RSTextBrowser.cpp +++ b/retroshare-gui/src/gui/common/RSTextBrowser.cpp @@ -19,6 +19,7 @@ *******************************************************************************/ #include "RSTextBrowser.h" +#include "gui/settings/rsharesettings.h" #include "RSImageBlockWidget.h" #include "gui/common/FilesDefs.h" @@ -360,3 +361,53 @@ void RSTextBrowser::copyImage() QTextCursor cursor = cursorForPosition(point); ImageUtil::copyImage(window(), cursor); } + +void RSTextBrowser::showEvent(QShowEvent *event) +{ + if (!event->spontaneous()) { + updateLinkColor(); + } +} + +void RSTextBrowser::updateLinkColor() +{ + linkColor = Settings->getLinkColor(); + QPalette p = palette(); + p.setColor(QPalette::Link, linkColor); + p.setColor(QPalette::LinkVisited, linkColor); + setPalette(p); + + if (document()) { + document()->setDefaultStyleSheet(QString("a[href] { color: %1; }").arg(linkColor.name())); + if (!document()->isEmpty()) { + QString html = document()->toHtml(); + document()->setHtml(html); + } + } +} + +QString RSTextBrowser::toHtml(const QByteArray &encoding) const +{ + QTextDocument *doc = document(); + QString oldSheet; + if (doc) { + oldSheet = doc->defaultStyleSheet(); + doc->setDefaultStyleSheet(""); + } + QString html; + if (encoding.isEmpty()) { + html = QTextBrowser::toHtml(); + } else { +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + // Qt 6: toHtml() takes no arguments + html = doc->toHtml(); +#else + // Qt 5: toHtml() accepts encoding parameter + html = doc->toHtml(encoding); +#endif + } + if (doc) { + doc->setDefaultStyleSheet(oldSheet); + } + return html; +} diff --git a/retroshare-gui/src/gui/common/RSTextBrowser.h b/retroshare-gui/src/gui/common/RSTextBrowser.h index 8ffa398c3..1b1216a2e 100644 --- a/retroshare-gui/src/gui/common/RSTextBrowser.h +++ b/retroshare-gui/src/gui/common/RSTextBrowser.h @@ -58,6 +58,8 @@ public: QVariant textColorQuotes() const { return highlighter->textColorQuotes();} bool getShowImages() const { return mShowImages; } + QString toHtml(const QByteArray &encoding = QByteArray()) const; + QMenu *createStandardContextMenuFromPoint(const QPoint &widgetPos); Q_SIGNALS: @@ -67,6 +69,7 @@ public slots: void showImages(); void setTextColorQuote(QColor textColorQuote) { highlighter->setTextColorQuote(textColorQuote);} void setTextColorQuotes(QVariant textColorQuotes) { highlighter->setTextColorQuotes(textColorQuotes);} + void updateLinkColor(); private slots: void linkClicked(const QUrl &url); @@ -77,6 +80,7 @@ private slots: protected: void paintEvent(QPaintEvent *event); + void showEvent(QShowEvent *event); virtual void contextMenuEvent(QContextMenuEvent *event); private: @@ -90,6 +94,7 @@ private: bool mLinkClickActive; RsSyntaxHighlighter *highlighter; QList mContextMenuActions; + QColor linkColor; #ifdef RSTEXTBROWSER_CHECKIMAGE_DEBUG QRect mCursorRectStart; QRect mCursorRectLeft; diff --git a/retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.cpp b/retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.cpp index bc2f5d960..17ec3b911 100644 --- a/retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.cpp +++ b/retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.cpp @@ -729,6 +729,7 @@ void CreateGxsChannelMsg::sendMsg() QString text; text = RichTextEditWidget->toHtml(); + RsHtml::optimizeHtml(text); std::string msg = std::string(text.toUtf8()); std::list files; diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp index 69df1ce09..62d8e1db1 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp @@ -1440,7 +1440,7 @@ void GxsChannelPostsWidgetWithModel::insertChannelDetails(const RsGxsChannelGrou if(!group.mMeta.mAuthorId.isNull()) { RetroShareLink link = RetroShareLink::createMessage(group.mMeta.mAuthorId, ""); - ui->infoAdministrator->setText(link.toHtml()); + ui->infoAdministrator->setText(link.toHtmlColored()); } else ui->infoAdministrator->setText("[No contact author]"); diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.ui b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.ui index 2740b4654..d88b4ccc8 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.ui +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.ui @@ -397,7 +397,7 @@
- + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> @@ -548,7 +548,7 @@ p, li { white-space: pre-wrap; } - + true @@ -685,6 +685,11 @@ p, li { white-space: pre-wrap; }
gui/gxs/GxsCommentDialog.h
1 + + RSTextBrowser + QTextBrowser +
gui/common/RSTextBrowser.h
+
diff --git a/retroshare-gui/src/gui/msgs/MessageComposer.cpp b/retroshare-gui/src/gui/msgs/MessageComposer.cpp index 176cbbd24..3415ceb6c 100644 --- a/retroshare-gui/src/gui/msgs/MessageComposer.cpp +++ b/retroshare-gui/src/gui/msgs/MessageComposer.cpp @@ -2422,10 +2422,10 @@ bool MessageComposer::fileSave() QTextStream ts(&file); #if QT_VERSION >= QT_VERSION_CHECK (6, 0, 0) ts.setEncoding(QStringConverter::Utf8); - ts << ui.msgText->document()->toHtml(); + ts << ui.msgText->toHtml(); #else ts.setCodec(QTextCodec::codecForName("UTF-8")); - ts << ui.msgText->document()->toHtml("UTF-8"); + ts << ui.msgText->toHtml("UTF-8"); #endif std::cerr << "Setting modified 002 = false" << std::endl; ui.msgText->document()->setModified(false); diff --git a/retroshare-gui/src/gui/msgs/MessageWidget.cpp b/retroshare-gui/src/gui/msgs/MessageWidget.cpp index 540196ab5..81d99d71c 100644 --- a/retroshare-gui/src/gui/msgs/MessageWidget.cpp +++ b/retroshare-gui/src/gui/msgs/MessageWidget.cpp @@ -707,7 +707,7 @@ void MessageWidget::fill(const std::string &msgId) } else { - ui.fromText->setText(link.toHtml()); + ui.fromText->setText(link.toHtmlColored()); ui.fromText->setToolTip(tooltip_string) ; if (toolButtonReply) toolButtonReply->setEnabled(true); } @@ -807,10 +807,10 @@ void MessageWidget::saveAs() QTextStream ts(&file); #if QT_VERSION >= QT_VERSION_CHECK (6, 0, 0) ts.setEncoding(QStringConverter::Utf8); - ts << ui.msgText->document()->toHtml(); + ts << ui.msgText->toHtml(); #else ts.setCodec(QTextCodec::codecForName("UTF-8")); - ts << ui.msgText->document()->toHtml("UTF-8"); + ts << ui.msgText->toHtml("UTF-8"); #endif ui.msgText->document()->setModified(false); } diff --git a/retroshare-gui/src/gui/settings/AppearancePage.cpp b/retroshare-gui/src/gui/settings/AppearancePage.cpp index 17748e05c..95295ad96 100755 --- a/retroshare-gui/src/gui/settings/AppearancePage.cpp +++ b/retroshare-gui/src/gui/settings/AppearancePage.cpp @@ -40,6 +40,7 @@ #include "util/DateTime.h" #include +#include #include #include #include @@ -398,6 +399,11 @@ void AppearancePage::load() whileBlocking(ui.checkBoxShowSystrayOnStatus)->setChecked(Settings->valueFromGroup("StatusBar", "ShowSysTrayOnStatusBar", QVariant(false)).toBool()); whileBlocking(ui.minimumFontSize_SB)->setValue(Settings->getFontSize()); + + rgbLinkColor=Settings->getLinkColor(); + QPixmap colorpix(24, 24); + colorpix.fill(rgbLinkColor); + ui.linkColorButton->setIcon(colorpix); } void AppearancePage::updateFontSize() @@ -415,3 +421,25 @@ void AppearancePage::updateDateFormat() RsGUIEventManager::getInstance()->notifySettingsChanged(); } +void AppearancePage::on_linkColorButton_clicked() +{ + QColor color = QColorDialog::getColor(QColor::fromRgba(rgbLinkColor), window(), "", QColorDialog::ShowAlphaChannel); + if (color.isValid()) { + rgbLinkColor = color.rgba(); + QPixmap pix(24, 24); + pix.fill(color); + ui.linkColorButton->setIcon(pix); + Settings->setLinkColor(rgbLinkColor); + } +} + +void AppearancePage::on_resetButton_clicked() +{ + QRgb color = QString::number(QColor(118, 118, 255).rgba()).toUInt(); + defaultColor = color; + rgbLinkColor = color; + QPixmap pix(24, 24); + pix.fill(color); + ui.linkColorButton->setIcon(pix); + Settings->setLinkColor(defaultColor); +} diff --git a/retroshare-gui/src/gui/settings/AppearancePage.h b/retroshare-gui/src/gui/settings/AppearancePage.h index 5df91fac7..e25f41e51 100755 --- a/retroshare-gui/src/gui/settings/AppearancePage.h +++ b/retroshare-gui/src/gui/settings/AppearancePage.h @@ -74,9 +74,15 @@ private slots: void updateStyle() ; void updateFontSize(); + void on_linkColorButton_clicked(); + void on_resetButton_clicked(); + private: void switch_status(MainWindow::StatusElement s,const QString& key,bool b); + QRgb rgbLinkColor; + QRgb defaultColor; + /** Qt Designer generated object */ Ui::AppearancePage ui; }; diff --git a/retroshare-gui/src/gui/settings/AppearancePage.ui b/retroshare-gui/src/gui/settings/AppearancePage.ui index e4a1014f2..18ab8cc41 100755 --- a/retroshare-gui/src/gui/settings/AppearancePage.ui +++ b/retroshare-gui/src/gui/settings/AppearancePage.ui @@ -109,7 +109,7 @@
- + @@ -336,7 +336,62 @@ - + + + + Link Color + + + + + + + 0 + 0 + + + + Color of the links + + + + + + + + 24 + 24 + + + + + 24 + 24 + + + + Set link color + + + + + + + + + + Reset to default color + + + + :/icons/textedit/undo.png:/icons/textedit/undo.png + + + + + + + Status Bar @@ -445,7 +500,7 @@ - + Qt::Vertical @@ -552,6 +607,8 @@
gui/common/RSComboBox.h
- + + + diff --git a/retroshare-gui/src/gui/settings/rsharesettings.cpp b/retroshare-gui/src/gui/settings/rsharesettings.cpp index d40f6db81..6585982f7 100644 --- a/retroshare-gui/src/gui/settings/rsharesettings.cpp +++ b/retroshare-gui/src/gui/settings/rsharesettings.cpp @@ -1243,6 +1243,15 @@ void RshareSettings::setMessageFontSize(int value) setValueToGroup("Message", "FontSize", value); } +void RshareSettings::setLinkColor(QRgb rgbValue) +{ + setValueToGroup("Chat", "LinkColor", QString::number(rgbValue)); +} +QRgb RshareSettings::getLinkColor() +{ + return valueFromGroup("Chat", "LinkColor", QString::number(QColor(118, 118, 255).rgba())).toUInt(); +} + #ifdef RS_JSONAPI bool RshareSettings::getJsonApiEnabled() { diff --git a/retroshare-gui/src/gui/settings/rsharesettings.h b/retroshare-gui/src/gui/settings/rsharesettings.h index 3dcb54c5b..dad59ce4f 100644 --- a/retroshare-gui/src/gui/settings/rsharesettings.h +++ b/retroshare-gui/src/gui/settings/rsharesettings.h @@ -393,6 +393,9 @@ public: int getMessageFontSize(); void setMessageFontSize(int value); + void setLinkColor(QRgb rgbValue); + QRgb getLinkColor(); + #ifdef RS_JSONAPI bool getJsonApiEnabled(); void setJsonApiEnabled(bool enabled); diff --git a/retroshare-gui/src/util/HandleRichText.cpp b/retroshare-gui/src/util/HandleRichText.cpp index 5a4a166a4..f94bed31d 100644 --- a/retroshare-gui/src/util/HandleRichText.cpp +++ b/retroshare-gui/src/util/HandleRichText.cpp @@ -30,6 +30,8 @@ #include #include "HandleRichText.h" +#include "gui/common/MimeTextEdit.h" +#include "gui/settings/rsharesettings.h" #include "gui/RetroShareLink.h" #include "util/ObjectPainter.h" #include "util/imageutil.h" @@ -407,7 +409,8 @@ void RsHtml::embedHtml(QTextDocument *textDocument, QDomDocument& doc, QDomEleme // skip it } else if (element.tagName().toLower() == "a") { // skip it - if (embedInfos.myType == Ahref) { + if (embedInfos.myType == Ahref && element.hasAttribute("href")) { + element.setAttribute("style", QString("color: %1;").arg(QColor(Settings->getLinkColor()).name())); // but add title if not available if (element.attribute("title").isEmpty()) { RetroShareLink link(element.attribute("href")); @@ -476,6 +479,7 @@ void RsHtml::embedHtml(QTextDocument *textDocument, QDomDocument& doc, QDomEleme { insertedTag = doc.createElement("a"); insertedTag.setAttribute("href", myRE.cap(0)); + insertedTag.setAttribute("style", QString("color: %1;").arg(QColor(Settings->getLinkColor()).name())); insertedTag.appendChild(doc.createTextNode(myRE.cap(0))); RetroShareLink link(myRE.cap(0)); @@ -815,6 +819,66 @@ static void findBestColor(QString &val, qreal bglum, qreal desiredContrast) #endif // QT_VERSION < 0x040600 } +static void stripLinkColorStyle(QDomElement element) +{ + if (element.hasAttribute("style")) { + QString style = element.attribute("style"); + style.remove(QRegularExpression("color\\s*:\\s*[^;]+;?", QRegularExpression::CaseInsensitiveOption)); + if (style.trimmed().isEmpty()) { + element.removeAttribute("style"); + } else { + element.setAttribute("style", style); + } + } + if (element.tagName().toLower() == "font" && element.hasAttribute("color")) { + element.removeAttribute("color"); + } + QDomNodeList children = element.childNodes(); + for (int i = 0; i < children.length(); ++i) { + QDomNode node = children.item(i); + if (node.isElement()) { + stripLinkColorStyle(node.toElement()); + } + } +} + +static void stripThemeColors(QDomElement element, const QString &hexColor) +{ + if (element.hasAttribute("style")) { + QString style = element.attribute("style"); + QRegularExpression re(QString("color\\s*:\\s*%1;?").arg(hexColor), QRegularExpression::CaseInsensitiveOption); + style.remove(re); + if (style.trimmed().isEmpty()) { + element.removeAttribute("style"); + } else { + element.setAttribute("style", style); + } + } + if (element.tagName().toLower() == "font" && element.hasAttribute("color")) { + if (element.attribute("color").compare(hexColor, Qt::CaseInsensitive) == 0) { + element.removeAttribute("color"); + } + } + if (element.tagName().toLower() == "a") { + stripLinkColorStyle(element); + } + + QDomNodeList children = element.childNodes(); + for (int i = 0; i < children.length(); ++i) { + QDomNode node = children.item(i); + if (node.isElement()) { + stripThemeColors(node.toElement(), hexColor); + } + } +} + +static void stripAllLinkColors(QDomElement element) +{ + QColor linkColor = Settings->getLinkColor(); + QString hexColor = linkColor.name(); + stripThemeColors(element, hexColor); +} + /** * @brief optimizeHtml: Optimize HTML Text in DomDocument to reduce size * @param doc: QDomDocument containing Text to optimize @@ -1186,6 +1250,7 @@ void RsHtml::optimizeHtml(QString &text, unsigned int flag /*= 0*/ } QDomElement body = doc.documentElement(); + stripAllLinkColors(body); QHash stylesList; QHash knownStyle;