Browse Source

Markdown Preference now uses enumeration type instead of integer.

pull/2832/head
Andrew Morgan 9 years ago
parent
commit
db84074926
  1. 4
      src/chatlog/chatmessage.cpp
  2. 7
      src/chatlog/chatmessage.h
  3. 13
      src/persistence/settings.cpp
  4. 8
      src/persistence/settings.h
  5. 2
      src/widget/form/settings/generalform.cpp

4
src/chatlog/chatmessage.cpp

@ -57,7 +57,7 @@ ChatMessage::Ptr ChatMessage::createChatMessage(const QString &sender, const QSt @@ -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) @@ -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-

7
src/chatlog/chatmessage.h

@ -45,6 +45,13 @@ public: @@ -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());

13
src/persistence/settings.cpp

@ -177,7 +177,7 @@ void Settings::loadGlobal() @@ -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<MarkdownType>(s.value("markdownPreference", 1).toInt());
s.endGroup();
s.beginGroup("Advanced");
@ -396,7 +396,7 @@ void Settings::saveGlobal() @@ -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<int>(markdownPreference));
s.endGroup();
s.beginGroup("Advanced");
@ -1030,20 +1030,15 @@ void Settings::setDateFormat(const QString &format) @@ -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;
}

8
src/persistence/settings.h

@ -34,6 +34,8 @@ namespace Db { enum class syncType; } @@ -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: @@ -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: @@ -368,9 +370,9 @@ private:
bool showSystemTray;
// ChatView
MarkdownType markdownPreference;
int firstColumnHandlePos;
int secondColumnHandlePosFromRight;
int markdownPreference;
QString timestampFormat;
QString dateFormat;
bool statusChangeNotificationEnabled;

2
src/widget/form/settings/generalform.cpp

@ -371,7 +371,7 @@ void GeneralForm::onUseEmoticonsChange() @@ -371,7 +371,7 @@ void GeneralForm::onUseEmoticonsChange()
void GeneralForm::onMarkdownUpdated()
{
Settings::getInstance().setMarkdownPreference(bodyUI->markdownComboBox->currentIndex());
Settings::getInstance().setMarkdownPreference(static_cast<MarkdownType>(bodyUI->markdownComboBox->currentIndex()));
}
void GeneralForm::onSetStatusChange()

Loading…
Cancel
Save