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); text = detectQuotes(detectAnchors(text), type);
//markdown //markdown
if (Settings::getInstance().getMarkdownPreference() != 0) if (Settings::getInstance().getMarkdownPreference() != MarkdownType::NONE)
text = detectMarkdown(text); text = detectMarkdown(text);
switch(type) switch(type)
@ -187,7 +187,7 @@ QString ChatMessage::detectMarkdown(const QString &str)
// Create regex for certain markdown syntax // Create regex for certain markdown syntax
QRegExp exp("(\\*\\*)([^\\*\\*]{2,})(\\*\\*)" // Bold **text** QRegExp exp("(\\*\\*)([^\\*\\*]{2,})(\\*\\*)" // Bold **text**
"|(\\*)([^\\*]{2,})(\\*)" // Bold *text* "|(\\*)([^\\*]{2,})(\\*)" // Bold *text*
"|(\\_)([^\\_]{2,})(\\_)" // Italics _text_ "|(\\_)([^\\_]{2,})(\\_)" // Italics _text_
"|(\\_\\_)([^\\_\\_]{2,})(\\_\\_)" // Italics __text__ "|(\\_\\_)([^\\_\\_]{2,})(\\_\\_)" // Italics __text__
"|(\\-)([^\\-]{2,})(\\-)" // Underline -text- "|(\\-)([^\\-]{2,})(\\-)" // Underline -text-

View File

@ -45,6 +45,13 @@ public:
ALERT, ALERT,
}; };
enum MarkdownType
{
NONE,
WITH_CHARS,
WITHOUT_CHARS,
};
ChatMessage(); ChatMessage();
static ChatMessage::Ptr createChatMessage(const QString& sender, const QString& rawMessage, MessageType type, bool isMe, const QDateTime& date = QDateTime()); 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(); separateWindow = s.value("separateWindow", false).toBool();
dontGroupWindows = s.value("dontGroupWindows", true).toBool(); dontGroupWindows = s.value("dontGroupWindows", true).toBool();
groupchatPosition = s.value("groupchatPosition", 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.endGroup();
s.beginGroup("Advanced"); s.beginGroup("Advanced");
@ -396,7 +396,7 @@ void Settings::saveGlobal()
s.setValue("groupchatPosition", groupchatPosition); s.setValue("groupchatPosition", groupchatPosition);
s.setValue("autoSaveEnabled", autoSaveEnabled); s.setValue("autoSaveEnabled", autoSaveEnabled);
s.setValue("globalAutoAcceptDir", globalAutoAcceptDir); s.setValue("globalAutoAcceptDir", globalAutoAcceptDir);
s.setValue("markdownPreference", markdownPreference); s.setValue("markdownPreference", static_cast<int>(markdownPreference));
s.endGroup(); s.endGroup();
s.beginGroup("Advanced"); s.beginGroup("Advanced");
@ -1030,20 +1030,15 @@ void Settings::setDateFormat(const QString &format)
dateFormat = format; dateFormat = format;
} }
int Settings::getMarkdownPreference() const MarkdownType Settings::getMarkdownPreference() const
{ {
QMutexLocker locker{&bigLock}; QMutexLocker locker{&bigLock};
return markdownPreference; return markdownPreference;
} }
void Settings::setMarkdownPreference(int newValue) void Settings::setMarkdownPreference(MarkdownType newValue)
{ {
QMutexLocker locker{&bigLock}; QMutexLocker locker{&bigLock};
if (newValue < 0)
newValue = 1;
else if (newValue > 2)
newValue = 2;
markdownPreference = newValue; markdownPreference = newValue;
} }

View File

@ -34,6 +34,8 @@ namespace Db { enum class syncType; }
enum ProxyType {ptNone, ptSOCKS5, ptHTTP}; enum ProxyType {ptNone, ptSOCKS5, ptHTTP};
enum MarkdownType {NONE, WITH_CHARS, WITHOUT_CHARS};
class Settings : public QObject class Settings : public QObject
{ {
Q_OBJECT Q_OBJECT
@ -175,8 +177,8 @@ public:
int getThemeColor() const; int getThemeColor() const;
void setThemeColor(const int& value); void setThemeColor(const int& value);
int getMarkdownPreference() const; MarkdownType getMarkdownPreference() const;
void setMarkdownPreference(int newValue); void setMarkdownPreference(MarkdownType newValue);
bool isCurstomEmojiFont() const; bool isCurstomEmojiFont() const;
void setCurstomEmojiFont(bool value); void setCurstomEmojiFont(bool value);
@ -368,9 +370,9 @@ private:
bool showSystemTray; bool showSystemTray;
// ChatView // ChatView
MarkdownType markdownPreference;
int firstColumnHandlePos; int firstColumnHandlePos;
int secondColumnHandlePosFromRight; int secondColumnHandlePosFromRight;
int markdownPreference;
QString timestampFormat; QString timestampFormat;
QString dateFormat; QString dateFormat;
bool statusChangeNotificationEnabled; bool statusChangeNotificationEnabled;

View File

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