This commit is contained in:
retrop00h 2026-08-29 15:51:48 +05:30 committed by GitHub
commit bd4e386617
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 18 additions and 13 deletions

View File

@ -268,6 +268,7 @@ static QString getStyle(const QDir &styleDir, const QString &styleVariant, enumG
QString ChatStyle::formatMessage(enumFormatMessage type
, const QString &name
, const QString &gxsid
, const QDateTime &timestamp
, const QString &message
, unsigned int flag
@ -356,10 +357,10 @@ QString ChatStyle::formatMessage(enumFormatMessage type
if (flag & CHAT_FORMATMSG_SYSTEM) {
color = Qt::darkBlue;
} else {
// Calculate color from the name
// Calculate color from the id
uint hash = 0;
for (int i = 0; i < name.length(); ++i) {
hash = (((hash << 1) + (hash >> 14)) ^ ((int) name[i].toLatin1())) & 0x3fff;
for (int i = 0; i < gxsid.length(); ++i) {
hash = (((hash << 1) + (hash >> 14)) ^ ((int) gxsid[i].toLatin1())) & 0x3fff;
}
color.setHsv(hash, 255, 150);

View File

@ -83,7 +83,7 @@ public:
bool setStylePath(const QString &stylePath, const QString &styleVariant);
bool setStyleFromSettings(enumStyleType styleType);
QString formatMessage(enumFormatMessage type, const QString &name, const QDateTime &timestamp, const QString &message, unsigned int flag = 0, const QColor &backgroundColor = Qt::white);
QString formatMessage(enumFormatMessage type, const QString &name, const QString &gxsid, const QDateTime &timestamp, const QString &message, unsigned int flag = 0, const QColor &backgroundColor = Qt::white);
static bool getAvailableStyles(enumStyleType styleType, QList<ChatStyleInfo> &styles);
static bool getAvailableVariants(const QString &stylePath, QStringList &variants);

View File

@ -1104,7 +1104,11 @@ void ChatWidget::addChatMsg(bool incoming, const QString &name, const RsGxsId gx
QString formattedMessage = RsHtml().formatText(ui->textBrowser->document(), message, formatTextFlag, backgroundColor, desiredContrast, desiredMinimumFontSize);
QDateTime dtTimestamp=incoming ? sendTime : recvTime;
QString formatMsg = chatStyle.formatMessage(type, name, dtTimestamp, formattedMessage, formatFlag, backgroundColor);
QString strGxsId = "";
if (!gxsId.isNull())
strGxsId = QString::fromStdString(gxsId.toStdString());
QString formatMsg = chatStyle.formatMessage(type, name, strGxsId, dtTimestamp, formattedMessage, formatFlag, backgroundColor);
QString timeStamp = DateTime::formatDateTime(dtTimestamp);
//replace Date and Time anchors

View File

@ -307,7 +307,7 @@ void ImHistoryBrowser::fillItem(QListWidgetItem *itemWidget, HistoryMsg& msg)
}
QColor backgroundColor = ui.listWidget->palette().base().color();
QString formatMsg = style.formatMessage(type, name, DateTime::DateTimeFromTime_t(msg.sendTime), messageText, 0, backgroundColor);
QString formatMsg = style.formatMessage(type, name, name, QDateTime::fromTime_t(msg.sendTime), messageText, 0, backgroundColor);
itemWidget->setData(Qt::DisplayRole, QVariant::fromValue(IMHistoryItemPainter(formatMsg)));
itemWidget->setData(ROLE_MSGID, msg.msgId);

View File

@ -550,13 +550,13 @@ void ChatPage::setPreviewMessages(QString &stylePath, QString styleVariant, QTex
QDateTime timestmp = DateTime::DateTimeFromTime_t(time(NULL));
QColor backgroundColor = textBrowser->palette().base().color();
textBrowser->append(style.formatMessage(ChatStyle::FORMATMSG_HINCOMING, nameIncoming, timestmp, tr("Incoming message in history"), 0, backgroundColor));
textBrowser->append(style.formatMessage(ChatStyle::FORMATMSG_HOUTGOING, nameOutgoing, timestmp, tr("Outgoing message in history"), 0, backgroundColor));
textBrowser->append(style.formatMessage(ChatStyle::FORMATMSG_INCOMING, nameIncoming, timestmp, tr("Incoming message"), 0, backgroundColor));
textBrowser->append(style.formatMessage(ChatStyle::FORMATMSG_OUTGOING, nameOutgoing, timestmp, tr("Outgoing message"), 0, backgroundColor));
textBrowser->append(style.formatMessage(ChatStyle::FORMATMSG_OOUTGOING, nameOutgoing, timestmp, tr("Outgoing offline message"), 0, backgroundColor));
textBrowser->append(style.formatMessage(ChatStyle::FORMATMSG_SYSTEM, tr("System"), timestmp, tr("System message"), 0, backgroundColor));
textBrowser->append(style.formatMessage(ChatStyle::FORMATMSG_OUTGOING, tr("UserName"), timestmp, tr("/me is sending a message with /me"), 0, backgroundColor));
textBrowser->append(style.formatMessage(ChatStyle::FORMATMSG_HINCOMING, nameIncoming, nameIncoming, timestmp, tr("Incoming message in history"), 0, backgroundColor));
textBrowser->append(style.formatMessage(ChatStyle::FORMATMSG_HOUTGOING, nameOutgoing, nameOutgoing, timestmp, tr("Outgoing message in history"), 0, backgroundColor));
textBrowser->append(style.formatMessage(ChatStyle::FORMATMSG_INCOMING, nameIncoming, nameIncoming, timestmp, tr("Incoming message"), 0, backgroundColor));
textBrowser->append(style.formatMessage(ChatStyle::FORMATMSG_OUTGOING, nameOutgoing, nameOutgoing, timestmp, tr("Outgoing message"), 0, backgroundColor));
textBrowser->append(style.formatMessage(ChatStyle::FORMATMSG_OOUTGOING, nameOutgoing, nameOutgoing, timestmp, tr("Outgoing offline message"), 0, backgroundColor));
textBrowser->append(style.formatMessage(ChatStyle::FORMATMSG_SYSTEM, tr("System"), tr("System"), timestmp, tr("System message"), 0, backgroundColor));
textBrowser->append(style.formatMessage(ChatStyle::FORMATMSG_OUTGOING, tr("UserName"), tr("UserName"), timestmp, tr("/me is sending a message with /me"), 0, backgroundColor));
}
void ChatPage::fillPreview(QComboBox *listWidget, QComboBox *comboBox, QTextBrowser *textBrowser)