mirror of
https://github.com/mumble-voip/mumble.git
synced 2025-10-26 11:19:16 +00:00
Add auto formating capability to chatbar.
This commit is contained in:
parent
75868a323b
commit
a9a5574339
@ -814,7 +814,14 @@ void MainWindow::on_qleChat_returnPressed() {
|
||||
Channel *c = pmModel->getChannel(qtvPlayers->currentIndex());
|
||||
|
||||
MumbleProto::TextMessage mptm;
|
||||
mptm.set_message(u8(qleChat->text()));
|
||||
QString qsText;
|
||||
|
||||
qsText = qleChat->text();
|
||||
if (! Qt::mightBeRichText(qsText)) {
|
||||
qsText = TextMessage::autoFormat(qsText);
|
||||
}
|
||||
|
||||
mptm.set_message(u8(qsText));
|
||||
|
||||
if (p == NULL || p->uiSession == g.uiSession) {
|
||||
// Channel tree message
|
||||
@ -822,16 +829,16 @@ void MainWindow::on_qleChat_returnPressed() {
|
||||
c = ClientPlayer::get(g.uiSession)->cChannel;
|
||||
|
||||
mptm.add_channel_id(c->iId);
|
||||
g.l->log(Log::TextMessage, tr("To %1: %2").arg(c->qsName).arg(qleChat->text()), tr("Message to %1").arg(c->qsName));
|
||||
g.l->log(Log::TextMessage, tr("To channel %1: %2").arg(c->qsName).arg(qsText), tr("Message to channel %1").arg(c->qsName));
|
||||
}
|
||||
else {
|
||||
// Player message
|
||||
mptm.add_session(p->uiSession);
|
||||
g.l->log(Log::TextMessage, tr("To %1: %2").arg(p->qsName).arg(qleChat->text()), tr("Message to %1").arg(p->qsName));
|
||||
g.l->log(Log::TextMessage, tr("To %1: %2").arg(p->qsName).arg(qsText), tr("Message to %1").arg(p->qsName));
|
||||
}
|
||||
|
||||
g.sh->sendMessage(mptm);
|
||||
qleChat->setText(QString());
|
||||
qleChat->clear();
|
||||
}
|
||||
|
||||
void MainWindow::on_qmConfig_aboutToShow() {
|
||||
@ -1073,7 +1080,7 @@ void MainWindow::on_qaChannelSendMessage_triggered() {
|
||||
mptm.add_channel_id(id);
|
||||
mptm.set_message(u8(texm->message()));
|
||||
g.sh->sendMessage(mptm);
|
||||
g.l->log(Log::TextMessage, tr("To tree %1: %2").arg(c->qsName).arg(texm->message()), tr("Message to tree %1").arg(c->qsName));
|
||||
g.l->log(Log::TextMessage, tr("To channel %1: %2").arg(c->qsName).arg(texm->message()), tr("Message to channel %1").arg(c->qsName));
|
||||
}
|
||||
delete texm;
|
||||
}
|
||||
|
||||
@ -41,6 +41,42 @@ void TextMessage::on_qcbRawMessage_stateChanged(int) {
|
||||
on_qteEdit_textChanged();
|
||||
}
|
||||
|
||||
QString TextMessage::autoFormat(QString qsPlain) {
|
||||
QRegExp qr;
|
||||
qr.setMinimal(true);
|
||||
qr.setPatternSyntax(QRegExp::RegExp2);
|
||||
qr.setCaseSensitivity(Qt::CaseInsensitive);
|
||||
|
||||
qr.setPattern(QLatin1String("[\\r\\n]+"));
|
||||
qsPlain.replace(qr, QLatin1String("<br />"));
|
||||
|
||||
qr.setPattern(QLatin1String("\\*(\\w+)\\*"));
|
||||
qsPlain.replace(qr, QLatin1String("<b>\\1</b>"));
|
||||
|
||||
qr.setPattern(QLatin1String("\"([^\"]+)\""));
|
||||
qsPlain.replace(qr, QLatin1String("\"<i>\\1</i>\""));
|
||||
|
||||
qr.setPattern(QLatin1String("[a-z]+://[^ <$]*"));
|
||||
qr.setMinimal(false);
|
||||
|
||||
int idx = 0;
|
||||
do {
|
||||
idx = qr.indexIn(qsPlain, idx);
|
||||
if (idx >= 0) {
|
||||
QString url = qr.capturedTexts().at(0);
|
||||
QUrl u(url);
|
||||
if (u.isValid()) {
|
||||
int len = qr.matchedLength();
|
||||
QString replacement = QString::fromLatin1("<a href=\"%1\">%1</a>").arg(url);
|
||||
qsPlain.replace(idx, len, replacement);
|
||||
idx += replacement.length();
|
||||
} else {
|
||||
idx++;
|
||||
}
|
||||
}
|
||||
} while (idx >= 0);
|
||||
return qsPlain;
|
||||
}
|
||||
void TextMessage::on_qteEdit_textChanged() {
|
||||
qsRep = qteEdit->toPlainText();
|
||||
|
||||
@ -49,39 +85,7 @@ void TextMessage::on_qteEdit_textChanged() {
|
||||
}
|
||||
|
||||
if (! Qt::mightBeRichText(qsRep) && !qcbRawMessage->isChecked()) {
|
||||
QRegExp qr;
|
||||
qr.setMinimal(true);
|
||||
qr.setPatternSyntax(QRegExp::RegExp2);
|
||||
qr.setCaseSensitivity(Qt::CaseInsensitive);
|
||||
|
||||
qr.setPattern(QLatin1String("[\\r\\n]+"));
|
||||
qsRep.replace(qr, QLatin1String("<br />"));
|
||||
|
||||
qr.setPattern(QLatin1String("\\*(\\w+)\\*"));
|
||||
qsRep.replace(qr, QLatin1String("<b>\\1</b>"));
|
||||
|
||||
qr.setPattern(QLatin1String("\"([^\"]+)\""));
|
||||
qsRep.replace(qr, QLatin1String("\"<i>\\1</i>\""));
|
||||
|
||||
qr.setPattern(QLatin1String("[a-z]+://[^ <$]*"));
|
||||
qr.setMinimal(false);
|
||||
|
||||
int idx = 0;
|
||||
do {
|
||||
idx = qr.indexIn(qsRep, idx);
|
||||
if (idx >= 0) {
|
||||
QString url = qr.capturedTexts().at(0);
|
||||
QUrl u(url);
|
||||
if (u.isValid()) {
|
||||
int len = qr.matchedLength();
|
||||
QString replacement = QString::fromLatin1("<a href=\"%1\">%1</a>").arg(url);
|
||||
qsRep.replace(idx, len, replacement);
|
||||
idx += replacement.length();
|
||||
} else {
|
||||
idx++;
|
||||
}
|
||||
}
|
||||
} while (idx >= 0);
|
||||
qsRep = autoFormat(qsRep);
|
||||
}
|
||||
|
||||
qtbPreview->setHtml(qsRep);
|
||||
|
||||
@ -44,6 +44,7 @@ class TextMessage : public QDialog, public Ui::TextMessage {
|
||||
TextMessage(QWidget *parent = NULL);
|
||||
QString message();
|
||||
bool eventFilter(QObject *obj, QEvent *event);
|
||||
static QString autoFormat(QString qsPlain);
|
||||
public slots:
|
||||
void on_qteEdit_textChanged();
|
||||
void on_qcbRawMessage_stateChanged(int);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user