1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Markdown Preference now uses enumeration type instead of integer.

This commit is contained in:
Andrew Morgan 2016-01-30 21:43:58 -08:00
parent a809897850
commit db84074926
5 changed files with 19 additions and 15 deletions

View File

@ -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-

View File

@ -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());

View File

@ -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()
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)
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;
}

View File

@ -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;

View File

@ -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()