mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
Clang script (#3085)
This commit is contained in:
parent
fcfb2b12b7
commit
35159ef61a
24 changed files with 2098 additions and 2054 deletions
|
|
@ -1,23 +1,28 @@
|
|||
#include <QTextEdit>
|
||||
#include <QDateTime>
|
||||
#include <QScrollBar>
|
||||
#include <QMouseEvent>
|
||||
#include <QDesktopServices>
|
||||
#include <QApplication>
|
||||
#include "chatview.h"
|
||||
#include "user_level.h"
|
||||
#include "../user_context_menu.h"
|
||||
#include "../pixmapgenerator.h"
|
||||
#include "../settingscache.h"
|
||||
#include "../tab_userlists.h"
|
||||
#include "../soundengine.h"
|
||||
#include "../tab_userlists.h"
|
||||
#include "../user_context_menu.h"
|
||||
#include "user_level.h"
|
||||
#include <QApplication>
|
||||
#include <QDateTime>
|
||||
#include <QDesktopServices>
|
||||
#include <QMouseEvent>
|
||||
#include <QScrollBar>
|
||||
#include <QTextEdit>
|
||||
|
||||
const QColor DEFAULT_MENTION_COLOR = QColor(194, 31, 47);
|
||||
const QColor OTHER_USER_COLOR = QColor(0, 65, 255); // dark blue
|
||||
const QString SERVER_MESSAGE_COLOR = "#851515";
|
||||
|
||||
ChatView::ChatView(const TabSupervisor *_tabSupervisor, const UserlistProxy *_userlistProxy, TabGame *_game, bool _showTimestamps, QWidget *parent)
|
||||
: QTextBrowser(parent), tabSupervisor(_tabSupervisor), game(_game), userlistProxy(_userlistProxy), evenNumber(true), showTimestamps(_showTimestamps), hoveredItemType(HoveredNothing)
|
||||
ChatView::ChatView(const TabSupervisor *_tabSupervisor,
|
||||
const UserlistProxy *_userlistProxy,
|
||||
TabGame *_game,
|
||||
bool _showTimestamps,
|
||||
QWidget *parent)
|
||||
: QTextBrowser(parent), tabSupervisor(_tabSupervisor), game(_game), userlistProxy(_userlistProxy), evenNumber(true),
|
||||
showTimestamps(_showTimestamps), hoveredItemType(HoveredNothing)
|
||||
{
|
||||
document()->setDefaultStyleSheet("a { text-decoration: none; color: blue; }");
|
||||
userContextMenu = new UserContextMenu(tabSupervisor, this, game);
|
||||
|
|
@ -47,7 +52,7 @@ void ChatView::retranslateUi()
|
|||
QTextCursor ChatView::prepareBlock(bool same)
|
||||
{
|
||||
lastSender.clear();
|
||||
|
||||
|
||||
QTextCursor cursor(document()->lastBlock());
|
||||
cursor.movePosition(QTextCursor::End);
|
||||
if (same) {
|
||||
|
|
@ -59,7 +64,7 @@ QTextCursor ChatView::prepareBlock(bool same)
|
|||
blockFormat.setBottomMargin(4);
|
||||
cursor.insertBlock(blockFormat);
|
||||
}
|
||||
|
||||
|
||||
return cursor;
|
||||
}
|
||||
|
||||
|
|
@ -75,7 +80,8 @@ void ChatView::appendHtmlServerMessage(const QString &html, bool optionalIsBold,
|
|||
{
|
||||
bool atBottom = verticalScrollBar()->value() >= verticalScrollBar()->maximum();
|
||||
|
||||
QString htmlText = "<font color=" + ((optionalFontColor.size() > 0) ? optionalFontColor : SERVER_MESSAGE_COLOR) + ">" + QDateTime::currentDateTime().toString("[hh:mm:ss] ")+ html + "</font>";
|
||||
QString htmlText = "<font color=" + ((optionalFontColor.size() > 0) ? optionalFontColor : SERVER_MESSAGE_COLOR) +
|
||||
">" + QDateTime::currentDateTime().toString("[hh:mm:ss] ") + html + "</font>";
|
||||
|
||||
if (optionalIsBold)
|
||||
htmlText = "<b>" + htmlText + "</b>";
|
||||
|
|
@ -103,7 +109,7 @@ void ChatView::appendUrlTag(QTextCursor &cursor, QString url)
|
|||
{
|
||||
if (!url.contains("://"))
|
||||
url.prepend("http://");
|
||||
|
||||
|
||||
QTextCharFormat oldFormat = cursor.charFormat();
|
||||
QTextCharFormat anchorFormat = oldFormat;
|
||||
anchorFormat.setForeground(Qt::blue);
|
||||
|
|
@ -111,19 +117,24 @@ void ChatView::appendUrlTag(QTextCursor &cursor, QString url)
|
|||
anchorFormat.setAnchorHref(url);
|
||||
anchorFormat.setUnderlineColor(Qt::blue);
|
||||
anchorFormat.setFontUnderline(true);
|
||||
|
||||
|
||||
cursor.setCharFormat(anchorFormat);
|
||||
cursor.insertText(url);
|
||||
cursor.setCharFormat(oldFormat);
|
||||
}
|
||||
|
||||
void ChatView::appendMessage(QString message, RoomMessageTypeFlags messageType, QString sender, UserLevelFlags userLevel, QString UserPrivLevel, bool playerBold)
|
||||
void ChatView::appendMessage(QString message,
|
||||
RoomMessageTypeFlags messageType,
|
||||
QString sender,
|
||||
UserLevelFlags userLevel,
|
||||
QString UserPrivLevel,
|
||||
bool playerBold)
|
||||
{
|
||||
bool atBottom = verticalScrollBar()->value() >= verticalScrollBar()->maximum();
|
||||
bool sameSender = (sender == lastSender) && !lastSender.isEmpty();
|
||||
QTextCursor cursor = prepareBlock(sameSender);
|
||||
lastSender = sender;
|
||||
|
||||
|
||||
// timestamp
|
||||
if (showTimestamps && (!sameSender || sender.toLower() == "servatrice") && !sender.isEmpty()) {
|
||||
QTextCharFormat timeFormat;
|
||||
|
|
@ -153,7 +164,8 @@ void ChatView::appendMessage(QString message, RoomMessageTypeFlags messageType,
|
|||
if (!sender.isEmpty()) {
|
||||
const int pixelSize = QFontInfo(cursor.charFormat().font()).pixelSize();
|
||||
bool isBuddy = userlistProxy->isUserBuddy(sender);
|
||||
cursor.insertImage(UserLevelPixmapGenerator::generatePixmap(pixelSize, userLevel, isBuddy, UserPrivLevel).toImage());
|
||||
cursor.insertImage(
|
||||
UserLevelPixmapGenerator::generatePixmap(pixelSize, userLevel, isBuddy, UserPrivLevel).toImage());
|
||||
cursor.insertText(" ");
|
||||
}
|
||||
cursor.setCharFormat(senderFormat);
|
||||
|
|
@ -163,7 +175,7 @@ void ChatView::appendMessage(QString message, RoomMessageTypeFlags messageType,
|
|||
}
|
||||
}
|
||||
|
||||
// use different color for server messages
|
||||
// use different color for server messages
|
||||
defaultFormat = QTextCharFormat();
|
||||
if (sender.isEmpty()) {
|
||||
switch (messageType) {
|
||||
|
|
@ -190,16 +202,14 @@ void ChatView::appendMessage(QString message, RoomMessageTypeFlags messageType,
|
|||
highlightedWords = settingsCache->getHighlightWords().split(' ', QString::SkipEmptyParts);
|
||||
|
||||
// parse the message
|
||||
while (message.size())
|
||||
{
|
||||
QChar c = message.at(0);
|
||||
switch(c.toLatin1())
|
||||
{
|
||||
while (message.size()) {
|
||||
QChar c = message.at(0);
|
||||
switch (c.toLatin1()) {
|
||||
case '[':
|
||||
checkTag(cursor, message);
|
||||
break;
|
||||
case '@':
|
||||
if(mentionEnabled) {
|
||||
if (mentionEnabled) {
|
||||
checkMention(cursor, message, sender, userLevel);
|
||||
} else {
|
||||
cursor.insertText(c, defaultFormat);
|
||||
|
|
@ -211,7 +221,7 @@ void ChatView::appendMessage(QString message, RoomMessageTypeFlags messageType,
|
|||
message = message.mid(1);
|
||||
break;
|
||||
default:
|
||||
if(c.isLetterOrNumber()) {
|
||||
if (c.isLetterOrNumber()) {
|
||||
checkWord(cursor, message);
|
||||
} else {
|
||||
cursor.insertText(c, defaultFormat);
|
||||
|
|
@ -225,11 +235,9 @@ void ChatView::appendMessage(QString message, RoomMessageTypeFlags messageType,
|
|||
verticalScrollBar()->setValue(verticalScrollBar()->maximum());
|
||||
}
|
||||
|
||||
|
||||
void ChatView::checkTag(QTextCursor &cursor, QString &message)
|
||||
{
|
||||
if (message.startsWith("[card]"))
|
||||
{
|
||||
if (message.startsWith("[card]")) {
|
||||
message = message.mid(6);
|
||||
int closeTagIndex = message.indexOf("[/card]");
|
||||
QString cardName = message.left(closeTagIndex);
|
||||
|
|
@ -237,13 +245,12 @@ void ChatView::checkTag(QTextCursor &cursor, QString &message)
|
|||
message.clear();
|
||||
else
|
||||
message = message.mid(closeTagIndex + 7);
|
||||
|
||||
|
||||
appendCardTag(cursor, cardName);
|
||||
return;
|
||||
}
|
||||
|
||||
if (message.startsWith("[["))
|
||||
{
|
||||
if (message.startsWith("[[")) {
|
||||
message = message.mid(2);
|
||||
int closeTagIndex = message.indexOf("]]");
|
||||
QString cardName = message.left(closeTagIndex);
|
||||
|
|
@ -251,13 +258,12 @@ void ChatView::checkTag(QTextCursor &cursor, QString &message)
|
|||
message.clear();
|
||||
else
|
||||
message = message.mid(closeTagIndex + 2);
|
||||
|
||||
|
||||
appendCardTag(cursor, cardName);
|
||||
return;
|
||||
}
|
||||
|
||||
if (message.startsWith("[url]"))
|
||||
{
|
||||
if (message.startsWith("[url]")) {
|
||||
message = message.mid(5);
|
||||
int closeTagIndex = message.indexOf("[/url]");
|
||||
QString url = message.left(closeTagIndex);
|
||||
|
|
@ -265,7 +271,7 @@ void ChatView::checkTag(QTextCursor &cursor, QString &message)
|
|||
message.clear();
|
||||
else
|
||||
message = message.mid(closeTagIndex + 6);
|
||||
|
||||
|
||||
appendUrlTag(cursor, url);
|
||||
return;
|
||||
}
|
||||
|
|
@ -282,8 +288,7 @@ void ChatView::checkMention(QTextCursor &cursor, QString &message, QString &send
|
|||
QString fullMentionUpToSpaceOrEnd = (firstSpace == -1) ? message.mid(1) : message.mid(1, firstSpace - 1);
|
||||
QString mentionIntact = fullMentionUpToSpaceOrEnd;
|
||||
|
||||
while (fullMentionUpToSpaceOrEnd.size())
|
||||
{
|
||||
while (fullMentionUpToSpaceOrEnd.size()) {
|
||||
const ServerInfo_User *onlineUser = userlistProxy->getOnlineUser(fullMentionUpToSpaceOrEnd);
|
||||
if (onlineUser) // Is there a user online named this?
|
||||
{
|
||||
|
|
@ -292,13 +297,15 @@ void ChatView::checkMention(QTextCursor &cursor, QString &message, QString &send
|
|||
// You have received a valid mention!!
|
||||
soundEngine->playSound("chat_mention");
|
||||
mentionFormat.setBackground(QBrush(getCustomMentionColor()));
|
||||
mentionFormat.setForeground(settingsCache->getChatMentionForeground() ? QBrush(Qt::white) : QBrush(Qt::black));
|
||||
mentionFormat.setForeground(settingsCache->getChatMentionForeground() ? QBrush(Qt::white)
|
||||
: QBrush(Qt::black));
|
||||
cursor.insertText(mention, mentionFormat);
|
||||
message = message.mid(mention.size());
|
||||
showSystemPopup(sender);
|
||||
} else {
|
||||
QString correctUserName = QString::fromStdString(onlineUser->name());
|
||||
mentionFormatOtherUser.setAnchorHref("user://" + QString::number(onlineUser->user_level()) + "_" + correctUserName);
|
||||
mentionFormatOtherUser.setAnchorHref("user://" + QString::number(onlineUser->user_level()) + "_" +
|
||||
correctUserName);
|
||||
cursor.insertText("@" + correctUserName, mentionFormatOtherUser);
|
||||
|
||||
message = message.mid(correctUserName.size() + 1);
|
||||
|
|
@ -312,7 +319,8 @@ void ChatView::checkMention(QTextCursor &cursor, QString &message, QString &send
|
|||
// Moderator Sending Global Message
|
||||
soundEngine->playSound("all_mention");
|
||||
mentionFormat.setBackground(QBrush(getCustomMentionColor()));
|
||||
mentionFormat.setForeground(settingsCache->getChatMentionForeground() ? QBrush(Qt::white) : QBrush(Qt::black));
|
||||
mentionFormat.setForeground(settingsCache->getChatMentionForeground() ? QBrush(Qt::white)
|
||||
: QBrush(Qt::black));
|
||||
cursor.insertText("@" + fullMentionUpToSpaceOrEnd, mentionFormat);
|
||||
message = message.mid(fullMentionUpToSpaceOrEnd.size() + 1);
|
||||
showSystemPopup(sender);
|
||||
|
|
@ -321,8 +329,8 @@ void ChatView::checkMention(QTextCursor &cursor, QString &message, QString &send
|
|||
return;
|
||||
}
|
||||
|
||||
if (fullMentionUpToSpaceOrEnd.right(1).indexOf(notALetterOrNumber) == -1 || fullMentionUpToSpaceOrEnd.size() < 2)
|
||||
{
|
||||
if (fullMentionUpToSpaceOrEnd.right(1).indexOf(notALetterOrNumber) == -1 ||
|
||||
fullMentionUpToSpaceOrEnd.size() < 2) {
|
||||
cursor.insertText("@" + mentionIntact, defaultFormat);
|
||||
message = message.mid(mentionIntact.size() + 1);
|
||||
cursor.setCharFormat(defaultFormat);
|
||||
|
|
@ -345,11 +353,9 @@ void ChatView::checkWord(QTextCursor &cursor, QString &message)
|
|||
// check urls
|
||||
if (fullWordUpToSpaceOrEnd.startsWith("http://", Qt::CaseInsensitive) ||
|
||||
fullWordUpToSpaceOrEnd.startsWith("https://", Qt::CaseInsensitive) ||
|
||||
fullWordUpToSpaceOrEnd.startsWith("www.", Qt::CaseInsensitive))
|
||||
{
|
||||
fullWordUpToSpaceOrEnd.startsWith("www.", Qt::CaseInsensitive)) {
|
||||
QUrl qUrl(fullWordUpToSpaceOrEnd);
|
||||
if (qUrl.isValid())
|
||||
{
|
||||
if (qUrl.isValid()) {
|
||||
appendUrlTag(cursor, fullWordUpToSpaceOrEnd);
|
||||
cursor.insertText(rest, defaultFormat);
|
||||
return;
|
||||
|
|
@ -357,13 +363,12 @@ void ChatView::checkWord(QTextCursor &cursor, QString &message)
|
|||
}
|
||||
|
||||
// check word mentions
|
||||
foreach (QString word, highlightedWords)
|
||||
{
|
||||
if (fullWordUpToSpaceOrEnd.compare(word, Qt::CaseInsensitive) == 0)
|
||||
{
|
||||
foreach (QString word, highlightedWords) {
|
||||
if (fullWordUpToSpaceOrEnd.compare(word, Qt::CaseInsensitive) == 0) {
|
||||
// You have received a valid mention of custom word!!
|
||||
highlightFormat.setBackground(QBrush(getCustomHighlightColor()));
|
||||
highlightFormat.setForeground(settingsCache->getChatHighlightForeground() ? QBrush(Qt::white) : QBrush(Qt::black));
|
||||
highlightFormat.setForeground(settingsCache->getChatHighlightForeground() ? QBrush(Qt::white)
|
||||
: QBrush(Qt::black));
|
||||
cursor.insertText(fullWordUpToSpaceOrEnd, highlightFormat);
|
||||
cursor.insertText(rest, defaultFormat);
|
||||
QApplication::alert(this);
|
||||
|
|
@ -380,8 +385,7 @@ 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)
|
||||
{
|
||||
if (firstSpace == -1) {
|
||||
word = message;
|
||||
message.clear();
|
||||
} else {
|
||||
|
|
@ -390,10 +394,8 @@ QString ChatView::extractNextWord(QString &message, QString &rest)
|
|||
}
|
||||
|
||||
// remove any punctuation from the end and pass it separately
|
||||
for (int len = word.size() - 1; len >= 0; --len)
|
||||
{
|
||||
if(word.at(len).isLetterOrNumber())
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
|
@ -403,7 +405,6 @@ QString ChatView::extractNextWord(QString &message, QString &rest)
|
|||
return QString();
|
||||
}
|
||||
|
||||
|
||||
bool ChatView::isModeratorSendingGlobal(QFlags<ServerInfo_User::UserLevelFlag> userLevelFlag, QString message)
|
||||
{
|
||||
int userLevel = QString::number(userLevelFlag).toInt();
|
||||
|
|
@ -411,17 +412,17 @@ bool ChatView::isModeratorSendingGlobal(QFlags<ServerInfo_User::UserLevelFlag> u
|
|||
QStringList getAttentionList;
|
||||
getAttentionList << "/all"; // Send a message to all users
|
||||
|
||||
return (getAttentionList.contains(message)
|
||||
&& (userLevel & ServerInfo_User::IsModerator
|
||||
|| userLevel & ServerInfo_User::IsAdmin));
|
||||
|
||||
return (getAttentionList.contains(message) &&
|
||||
(userLevel & ServerInfo_User::IsModerator || userLevel & ServerInfo_User::IsAdmin));
|
||||
}
|
||||
|
||||
void ChatView::actMessageClicked() {
|
||||
void ChatView::actMessageClicked()
|
||||
{
|
||||
emit messageClickedSignal();
|
||||
}
|
||||
|
||||
void ChatView::showSystemPopup(QString &sender) {
|
||||
void ChatView::showSystemPopup(QString &sender)
|
||||
{
|
||||
QApplication::alert(this);
|
||||
if (settingsCache->getShowMentionPopup()) {
|
||||
QString ref = sender.left(sender.length() - 2);
|
||||
|
|
@ -429,19 +430,22 @@ void ChatView::showSystemPopup(QString &sender) {
|
|||
}
|
||||
}
|
||||
|
||||
QColor ChatView::getCustomMentionColor() {
|
||||
QColor ChatView::getCustomMentionColor()
|
||||
{
|
||||
QColor customColor;
|
||||
customColor.setNamedColor("#" + settingsCache->getChatMentionColor());
|
||||
return customColor.isValid() ? customColor : DEFAULT_MENTION_COLOR;
|
||||
}
|
||||
|
||||
QColor ChatView::getCustomHighlightColor() {
|
||||
QColor ChatView::getCustomHighlightColor()
|
||||
{
|
||||
QColor customColor;
|
||||
customColor.setNamedColor("#" + settingsCache->getChatHighlightColor());
|
||||
return customColor.isValid() ? customColor : DEFAULT_MENTION_COLOR;
|
||||
}
|
||||
|
||||
void ChatView::clearChat() {
|
||||
void ChatView::clearChat()
|
||||
{
|
||||
document()->clear();
|
||||
lastSender = "";
|
||||
}
|
||||
|
|
@ -493,7 +497,7 @@ void ChatView::mouseMoveEvent(QMouseEvent *event)
|
|||
hoveredItemType = HoveredNothing;
|
||||
viewport()->setCursor(Qt::IBeamCursor);
|
||||
}
|
||||
|
||||
|
||||
QTextBrowser::mouseMoveEvent(event);
|
||||
}
|
||||
|
||||
|
|
@ -509,21 +513,21 @@ void ChatView::mousePressEvent(QMouseEvent *event)
|
|||
if (event->button() != Qt::MidButton) {
|
||||
const int delimiterIndex = hoveredContent.indexOf("_");
|
||||
const QString userName = hoveredContent.mid(delimiterIndex + 1);
|
||||
switch(event->button()) {
|
||||
case Qt::RightButton :{
|
||||
UserLevelFlags userLevel(hoveredContent.left(delimiterIndex).toInt());
|
||||
userContextMenu->showContextMenu(event->globalPos(), userName, userLevel);
|
||||
break;
|
||||
}
|
||||
case Qt::LeftButton :{
|
||||
if (event->modifiers() == Qt::ControlModifier) {
|
||||
emit openMessageDialog(userName, true);
|
||||
} else
|
||||
emit addMentionTag("@" + userName);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
switch (event->button()) {
|
||||
case Qt::RightButton: {
|
||||
UserLevelFlags userLevel(hoveredContent.left(delimiterIndex).toInt());
|
||||
userContextMenu->showContextMenu(event->globalPos(), userName, userLevel);
|
||||
break;
|
||||
}
|
||||
case Qt::LeftButton: {
|
||||
if (event->modifiers() == Qt::ControlModifier) {
|
||||
emit openMessageDialog(userName, true);
|
||||
} else
|
||||
emit addMentionTag("@" + userName);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
@ -538,7 +542,7 @@ void ChatView::mouseReleaseEvent(QMouseEvent *event)
|
|||
{
|
||||
if ((event->button() == Qt::MidButton) || (event->button() == Qt::LeftButton))
|
||||
emit deleteCardInfoPopup(QString("_"));
|
||||
|
||||
|
||||
QTextBrowser::mouseReleaseEvent(event);
|
||||
}
|
||||
|
||||
|
|
@ -546,6 +550,6 @@ void ChatView::openLink(const QUrl &link)
|
|||
{
|
||||
if ((link.scheme() == "card") || (link.scheme() == "user"))
|
||||
return;
|
||||
|
||||
|
||||
QDesktopServices::openUrl(link);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue