diff --git a/src/chatlog/chatmessage.cpp b/src/chatlog/chatmessage.cpp index 3eef85519..7ef043a56 100644 --- a/src/chatlog/chatmessage.cpp +++ b/src/chatlog/chatmessage.cpp @@ -57,7 +57,7 @@ ChatMessage::Ptr ChatMessage::createChatMessage(const QString &sender, const QSt text = detectQuotes(detectAnchors(text), type); //markdown - if (Settings::getInstance().getMarkdownPreference() != 0) + if (Settings::getInstance().getMarkdownPreference() != MarkdownType::NONE) text = detectMarkdown(text); switch(type) @@ -187,7 +187,7 @@ QString ChatMessage::detectMarkdown(const QString &str) // Create regex for certain markdown syntax QRegExp exp("(\\*\\*)([^\\*\\*]{2,})(\\*\\*)" // Bold **text** - "|(\\*)([^\\*]{2,})(\\*)" // Bold *text* + "|(\\*)([^\\*]{2,})(\\*)" // Bold *text* "|(\\_)([^\\_]{2,})(\\_)" // Italics _text_ "|(\\_\\_)([^\\_\\_]{2,})(\\_\\_)" // Italics __text__ "|(\\-)([^\\-]{2,})(\\-)" // Underline -text- diff --git a/src/chatlog/chatmessage.h b/src/chatlog/chatmessage.h index 2de1d668c..0cb133563 100644 --- a/src/chatlog/chatmessage.h +++ b/src/chatlog/chatmessage.h @@ -45,6 +45,13 @@ public: ALERT, }; + enum MarkdownType + { + NONE, + WITH_CHARS, + WITHOUT_CHARS, + }; + ChatMessage(); static ChatMessage::Ptr createChatMessage(const QString& sender, const QString& rawMessage, MessageType type, bool isMe, const QDateTime& date = QDateTime()); diff --git a/src/persistence/settings.cpp b/src/persistence/settings.cpp index 72a7a1ecf..84b9bdc02 100644 --- a/src/persistence/settings.cpp +++ b/src/persistence/settings.cpp @@ -177,7 +177,7 @@ void Settings::loadGlobal() separateWindow = s.value("separateWindow", false).toBool(); dontGroupWindows = s.value("dontGroupWindows", true).toBool(); groupchatPosition = s.value("groupchatPosition", true).toBool(); - markdownPreference = s.value("markdownPreference", 1).toInt(); + markdownPreference = static_cast(s.value("markdownPreference", 1).toInt()); s.endGroup(); s.beginGroup("Advanced"); @@ -396,7 +396,7 @@ void Settings::saveGlobal() s.setValue("groupchatPosition", groupchatPosition); s.setValue("autoSaveEnabled", autoSaveEnabled); s.setValue("globalAutoAcceptDir", globalAutoAcceptDir); - s.setValue("markdownPreference", markdownPreference); + s.setValue("markdownPreference", static_cast(markdownPreference)); s.endGroup(); s.beginGroup("Advanced"); @@ -1030,20 +1030,15 @@ void Settings::setDateFormat(const QString &format) dateFormat = format; } -int Settings::getMarkdownPreference() const +MarkdownType Settings::getMarkdownPreference() const { QMutexLocker locker{&bigLock}; return markdownPreference; } -void Settings::setMarkdownPreference(int newValue) +void Settings::setMarkdownPreference(MarkdownType newValue) { QMutexLocker locker{&bigLock}; - if (newValue < 0) - newValue = 1; - else if (newValue > 2) - newValue = 2; - markdownPreference = newValue; } diff --git a/src/persistence/settings.h b/src/persistence/settings.h index 32709a20c..e0ae85d4f 100644 --- a/src/persistence/settings.h +++ b/src/persistence/settings.h @@ -34,6 +34,8 @@ namespace Db { enum class syncType; } enum ProxyType {ptNone, ptSOCKS5, ptHTTP}; +enum MarkdownType {NONE, WITH_CHARS, WITHOUT_CHARS}; + class Settings : public QObject { Q_OBJECT @@ -175,8 +177,8 @@ public: int getThemeColor() const; void setThemeColor(const int& value); - int getMarkdownPreference() const; - void setMarkdownPreference(int newValue); + MarkdownType getMarkdownPreference() const; + void setMarkdownPreference(MarkdownType newValue); bool isCurstomEmojiFont() const; void setCurstomEmojiFont(bool value); @@ -368,9 +370,9 @@ private: bool showSystemTray; // ChatView + MarkdownType markdownPreference; int firstColumnHandlePos; int secondColumnHandlePosFromRight; - int markdownPreference; QString timestampFormat; QString dateFormat; bool statusChangeNotificationEnabled; diff --git a/src/widget/form/settings/generalform.cpp b/src/widget/form/settings/generalform.cpp index 158b935ad..196c20ce0 100644 --- a/src/widget/form/settings/generalform.cpp +++ b/src/widget/form/settings/generalform.cpp @@ -371,7 +371,7 @@ void GeneralForm::onUseEmoticonsChange() void GeneralForm::onMarkdownUpdated() { - Settings::getInstance().setMarkdownPreference(bodyUI->markdownComboBox->currentIndex()); + Settings::getInstance().setMarkdownPreference(static_cast(bodyUI->markdownComboBox->currentIndex())); } void GeneralForm::onSetStatusChange()