Updated with latest changes from #1243

This commit is contained in:
Fabio Bas
2015-07-14 09:19:07 +02:00
parent 87c70466a4
commit 2e3e6c55ff
6 changed files with 116 additions and 29 deletions
+45 -16
View File
@@ -166,6 +166,8 @@ void ChatView::appendMessage(QString message, QString sender, UserLevelFlags use
cursor.setCharFormat(messageFormat);
bool mentionEnabled = settingsCache->getChatMention();
highlightedWords = settingsCache->getHighlightWords().split(' ', QString::SkipEmptyParts);
// parse the message
while (message.size())
{
@@ -318,16 +320,8 @@ void ChatView::checkMention(QTextCursor &cursor, QString &message, QString &send
void ChatView::checkWord(QTextCursor &cursor, QString &message)
{
// extract the first word
int firstSpace = message.indexOf(' ');
QString fullWordUpToSpaceOrEnd;
if(firstSpace == -1)
{
fullWordUpToSpaceOrEnd = message;
message.clear();
} else {
fullWordUpToSpaceOrEnd = message.mid(0, firstSpace);
message = message.mid(firstSpace);
}
QString rest;
QString fullWordUpToSpaceOrEnd = extractNextWord(message, rest);
// check urls
if (fullWordUpToSpaceOrEnd.startsWith("http://", Qt::CaseInsensitive) ||
@@ -338,30 +332,60 @@ void ChatView::checkWord(QTextCursor &cursor, QString &message)
if (qUrl.isValid())
{
appendUrlTag(cursor, fullWordUpToSpaceOrEnd);
cursor.insertText(rest, defaultFormat);
return;
}
}
// check word mentions
const QStringList highlightedWords = settingsCache->getHighlightWords();
foreach (QString word, highlightedWords)
{
if (fullWordUpToSpaceOrEnd.compare(word, Qt::CaseInsensitive) == 0)
{
// You have received a valid mention of custom word!!
mentionFormat.setBackground(QBrush(getCustomMentionColor()));
mentionFormat.setForeground(settingsCache->getChatMentionForeground() ? QBrush(Qt::white) : QBrush(Qt::black));
cursor.insertText(fullWordUpToSpaceOrEnd, mentionFormat);
highlightFormat.setBackground(QBrush(getCustomHighlightColor()));
highlightFormat.setForeground(settingsCache->getChatHighlightForeground() ? QBrush(Qt::white) : QBrush(Qt::black));
cursor.insertText(fullWordUpToSpaceOrEnd, highlightFormat);
cursor.setCharFormat(defaultFormat);
cursor.insertText(rest, defaultFormat);
QApplication::alert(this);
return;
}
}
// not a special word; just print it
cursor.insertText(fullWordUpToSpaceOrEnd, defaultFormat);
cursor.insertText(fullWordUpToSpaceOrEnd + rest, defaultFormat);
}
QString ChatView::extractNextWord(QString &message, QString &rest)
{
// get the first next space and extract the word
QString word;
int firstSpace = message.indexOf(' ');
if(firstSpace == -1)
{
word = message;
message.clear();
} else {
word = message.mid(0, firstSpace);
message = message.mid(firstSpace);
}
// remove any punctution from the end and pass it separately
for (int len = word.size() - 1; len >= 0; --len)
{
if(word.at(len).isLetterOrNumber())
{
rest = word.mid(len + 1);
return word.mid(0, len + 1);
}
}
rest = word;
return QString();
}
bool ChatView::isModeratorSendingGlobal(QFlags<ServerInfo_User::UserLevelFlag> userLevelFlag, QString message)
{
int userLevel = QString::number(userLevelFlag).toInt();
@@ -387,13 +411,18 @@ void ChatView::showSystemPopup(QString &sender) {
emit showMentionPopup(sender);
}
QColor ChatView::getCustomMentionColor() {
QColor customColor;
customColor.setNamedColor("#" + settingsCache->getChatMentionColor());
return customColor.isValid() ? customColor : DEFAULT_MENTION_COLOR;
}
QColor ChatView::getCustomHighlightColor() {
QColor customColor;
customColor.setNamedColor("#" + settingsCache->getChatHighlightColor());
return customColor.isValid() ? customColor : DEFAULT_MENTION_COLOR;
}
/**
Returns the correct case version of the provided username, if no correct casing version
was found then the provided name is not available and will return an empty QString.
+4
View File
@@ -27,8 +27,10 @@ private:
QString userName;
QString mention;
QTextCharFormat mentionFormat;
QTextCharFormat highlightFormat;
QTextCharFormat mentionFormatOtherUser;
QTextCharFormat defaultFormat;
QStringList highlightedWords;
bool evenNumber;
bool showTimestamps;
HoveredItemType hoveredItemType;
@@ -41,12 +43,14 @@ private:
QString getNameFromUserList(QMap<QString, UserListTWI *> &userList, QString &userName);
bool isFullMentionAValidUser(QMap<QString, UserListTWI *> &userList, QString userNameToMatch);
QColor getCustomMentionColor();
QColor getCustomHighlightColor();
bool shouldShowSystemPopup();
void showSystemPopup(QString &sender);
bool isModeratorSendingGlobal(QFlags<ServerInfo_User::UserLevelFlag> userLevelFlag, QString message);
void checkTag(QTextCursor &cursor, QString &message);
void checkMention(QTextCursor &cursor, QString &message, QString &sender, UserLevelFlags userLevel);
void checkWord(QTextCursor &cursor, QString &message);
QString extractNextWord(QString &message, QString &rest);
private slots:
void openLink(const QUrl &link);
void actMessageClicked();
+39 -8
View File
@@ -580,6 +580,9 @@ MessagesSettingsPage::MessagesSettingsPage()
invertMentionForeground.setChecked(settingsCache->getChatMentionForeground());
connect(&invertMentionForeground, SIGNAL(stateChanged(int)), this, SLOT(updateTextColor(int)));
invertHighlightForeground.setChecked(settingsCache->getChatHighlightForeground());
connect(&invertHighlightForeground, SIGNAL(stateChanged(int)), this, SLOT(updateTextHighlightColor(int)));
mentionColor = new QLineEdit();
mentionColor->setText(settingsCache->getChatMentionColor());
updateMentionPreview();
@@ -592,8 +595,8 @@ MessagesSettingsPage::MessagesSettingsPage()
connect(&mentionPopups, SIGNAL(stateChanged(int)), settingsCache, SLOT(setShowMentionPopups(int)));
customAlertString = new QLineEdit();
customAlertString->setPlaceholderText("Word1, Word2, Word3");
customAlertString->setText(settingsCache->getHighlightWords().join(", "));
customAlertString->setPlaceholderText("Word1 Word2 Word3");
customAlertString->setText(settingsCache->getHighlightWords());
connect(customAlertString, SIGNAL(textChanged(QString)), settingsCache, SLOT(setHighlightWords(QString)));
QGridLayout *chatGrid = new QGridLayout;
@@ -608,9 +611,17 @@ MessagesSettingsPage::MessagesSettingsPage()
chatGroupBox = new QGroupBox;
chatGroupBox->setLayout(chatGrid);
highlightColor = new QLineEdit();
highlightColor->setText(settingsCache->getChatHighlightColor());
updateHighlightPreview();
connect(highlightColor, SIGNAL(textChanged(QString)), this, SLOT(updateHighlightColor(QString)));
QGridLayout *highlightNotice = new QGridLayout;
highlightNotice->addWidget(highlightColor, 0, 2);
highlightNotice->addWidget(&invertHighlightForeground, 0, 1);
highlightNotice->addWidget(&hexHighlightLabel, 1, 2);
highlightNotice->addWidget(customAlertString, 0, 0);
highlightNotice->addWidget(&customAlertStringLabel, 1, 0);
highlightNotice->addWidget(&customAlertStringLabel, 1, 0);
highlightGroupBox = new QGroupBox;
highlightGroupBox->setLayout(highlightNotice);
@@ -660,16 +671,35 @@ void MessagesSettingsPage::updateColor(const QString &value) {
}
}
void MessagesSettingsPage::updateHighlightColor(const QString &value) {
QColor colorToSet;
colorToSet.setNamedColor("#" + value);
if (colorToSet.isValid()) {
settingsCache->setChatHighlightColor(value);
updateHighlightPreview();
}
}
void MessagesSettingsPage::updateTextColor(int value) {
settingsCache->setChatMentionForeground(value);
updateMentionPreview();
}
void MessagesSettingsPage::updateTextHighlightColor(int value) {
settingsCache->setChatHighlightForeground(value);
updateHighlightPreview();
}
void MessagesSettingsPage::updateMentionPreview() {
mentionColor->setStyleSheet("QLineEdit{background:#" + settingsCache->getChatMentionColor() +
";color: " + (settingsCache->getChatMentionForeground() ? "white" : "black") + ";}");
}
void MessagesSettingsPage::updateHighlightPreview() {
highlightColor->setStyleSheet("QLineEdit{background:#" + settingsCache->getChatHighlightColor() +
";color: " + (settingsCache->getChatHighlightForeground() ? "white" : "black") + ";}");
}
void MessagesSettingsPage::storeSettings()
{
QSettings settings;
@@ -703,14 +733,15 @@ void MessagesSettingsPage::retranslateUi()
highlightGroupBox->setTitle(tr("Custom alert words"));
chatMentionCheckBox.setText(tr("Enable chat mentions"));
messageShortcuts->setTitle(tr("In-game message macros"));
ignoreUnregUsersMainChat.setText(tr("Ignore unregistered users in main chat"));
ignoreUnregUsersMainChat.setText(tr("Ignore chat room messages sent by unregistered users."));
ignoreUnregUserMessages.setText(tr("Ignore private messages sent by unregistered users."));
ignoreUnregUsersMainChat.setText(tr("Ignore chat room messages sent by unregistered users"));
ignoreUnregUserMessages.setText(tr("Ignore private messages sent by unregistered users"));
invertMentionForeground.setText(tr("Invert text color"));
messagePopups.setText(tr("Enable desktop notifications for private messages."));
invertHighlightForeground.setText(tr("Invert text color"));
messagePopups.setText(tr("Enable desktop notifications for private messages"));
mentionPopups.setText(tr("Enable desktop notification for mentions."));
hexLabel.setText(tr("(Color is hexadecimal)"));
customAlertStringLabel.setText(tr("(Seperate each word with a comma, words are case insensitive)"));
hexHighlightLabel.setText(tr("(Color is hexadecimal)"));
customAlertStringLabel.setText(tr("(Seperate each word with a space, words are case insensitive)"));
}
+6
View File
@@ -160,13 +160,16 @@ private slots:
void actAdd();
void actRemove();
void updateColor(const QString &value);
void updateHighlightColor(const QString &value);
void updateTextColor(int value);
void updateTextHighlightColor(int value);
private:
QListWidget *messageList;
QAction *aAdd;
QAction *aRemove;
QCheckBox chatMentionCheckBox;
QCheckBox invertMentionForeground;
QCheckBox invertHighlightForeground;
QCheckBox ignoreUnregUsersMainChat;
QCheckBox ignoreUnregUserMessages;
QCheckBox messagePopups;
@@ -175,12 +178,15 @@ private:
QGroupBox *highlightGroupBox;
QGroupBox *messageShortcuts;
QLineEdit *mentionColor;
QLineEdit *highlightColor;
QLineEdit *customAlertString;
QLabel hexLabel;
QLabel hexHighlightLabel;
QLabel customAlertStringLabel;
void storeSettings();
void updateMentionPreview();
void updateHighlightPreview();
};
class SoundSettingsPage : public AbstractSettingsPage {
+14 -3
View File
@@ -56,7 +56,9 @@ SettingsCache::SettingsCache()
tapAnimation = settings->value("cards/tapanimation", true).toBool();
chatMention = settings->value("chat/mention", true).toBool();
chatMentionForeground = settings->value("chat/mentionforeground", true).toBool();
chatHighlightForeground = settings->value("chat/highlightforeground", true).toBool();
chatMentionColor = settings->value("chat/mentioncolor", "A6120D").toString();
chatHighlightColor = settings->value("chat/highlightcolor", "A6120D").toString();
zoneViewSortByName = settings->value("zoneview/sortbyname", true).toBool();
zoneViewSortByType = settings->value("zoneview/sortbytype", true).toBool();
@@ -83,7 +85,7 @@ SettingsCache::SettingsCache()
cardInfoViewMode = settings->value("cards/cardinfoviewmode", 0).toInt();
highlightWords = settings->value("personal/highlightWords", QStringList()).toStringList();
highlightWords = settings->value("personal/highlightWords", QString()).toString();
}
void SettingsCache::setCardInfoViewMode(const int _viewMode) {
@@ -92,8 +94,7 @@ void SettingsCache::setCardInfoViewMode(const int _viewMode) {
}
void SettingsCache::setHighlightWords(const QString &_highlightWords) {
// Words are seperated by a comma and you can not use spaces in words
highlightWords = _highlightWords.simplified().replace(" ", "").split(",");
highlightWords = _highlightWords;
settings->setValue("personal/highlightWords", highlightWords);
}
@@ -322,11 +323,21 @@ void SettingsCache::setChatMentionForeground(int _chatMentionForeground) {
settings->setValue("chat/mentionforeground", chatMentionForeground);
}
void SettingsCache::setChatHighlightForeground(int _chatHighlightForeground) {
chatHighlightForeground = _chatHighlightForeground;
settings->setValue("chat/highlightforeground", chatHighlightForeground);
}
void SettingsCache::setChatMentionColor(const QString &_chatMentionColor) {
chatMentionColor = _chatMentionColor;
settings->setValue("chat/mentioncolor", chatMentionColor);
}
void SettingsCache::setChatHighlightColor(const QString &_chatHighlightColor) {
chatHighlightColor = _chatHighlightColor;
settings->setValue("chat/highlightcolor", chatHighlightColor);
}
void SettingsCache::setZoneViewSortByName(int _zoneViewSortByName)
{
zoneViewSortByName = _zoneViewSortByName;
+8 -2
View File
@@ -65,7 +65,9 @@ private:
bool tapAnimation;
bool chatMention;
QString chatMentionColor;
QString chatHighlightColor;
bool chatMentionForeground;
bool chatHighlightForeground;
bool zoneViewSortByName, zoneViewSortByType, zoneViewPileView;
bool soundEnabled;
QString soundPath;
@@ -85,7 +87,7 @@ private:
bool leftJustified;
int masterVolume;
int cardInfoViewMode;
QStringList highlightWords;
QString highlightWords;
public:
SettingsCache();
const QByteArray &getMainWindowGeometry() const { return mainWindowGeometry; }
@@ -101,6 +103,7 @@ public:
QString getPlayerBgPath() const { return playerBgPath; }
QString getCardBackPicturePath() const { return cardBackPicturePath; }
QString getChatMentionColor() const { return chatMentionColor; }
QString getChatHighlightColor() const { return chatHighlightColor; }
bool getPicDownload() const { return picDownload; }
bool getPicDownloadHq() const { return picDownloadHq; }
bool getNotificationsEnabled() const { return notificationsEnabled; }
@@ -118,6 +121,7 @@ public:
bool getTapAnimation() const { return tapAnimation; }
bool getChatMention() const { return chatMention; }
bool getChatMentionForeground() const { return chatMentionForeground; }
bool getChatHighlightForeground() const { return chatHighlightForeground; }
bool getZoneViewSortByName() const { return zoneViewSortByName; }
bool getZoneViewSortByType() const { return zoneViewSortByType; }
/**
@@ -144,7 +148,7 @@ public:
int getMasterVolume() const { return masterVolume; }
int getCardInfoViewMode() const { return cardInfoViewMode; }
QStringList getCountries() const;
QStringList getHighlightWords() const { return highlightWords; }
QString getHighlightWords() const { return highlightWords; }
public slots:
void setMainWindowGeometry(const QByteArray &_mainWindowGeometry);
void setLang(const QString &_lang);
@@ -159,6 +163,7 @@ public slots:
void setPlayerBgPath(const QString &_playerBgPath);
void setCardBackPicturePath(const QString &_cardBackPicturePath);
void setChatMentionColor(const QString &_chatMentionColor);
void setChatHighlightColor(const QString &_chatHighlightColor);
void setPicDownload(int _picDownload);
void setPicDownloadHq(int _picDownloadHq);
void setNotificationsEnabled(int _notificationsEnabled);
@@ -175,6 +180,7 @@ public slots:
void setTapAnimation(int _tapAnimation);
void setChatMention(int _chatMention);
void setChatMentionForeground(int _chatMentionForeground);
void setChatHighlightForeground(int _chatHighlightForeground);
void setZoneViewSortByName(int _zoneViewSortByName);
void setZoneViewSortByType(int _zoneViewSortByType);
void setZoneViewPileView(int _zoneViewPileView);