Add CommonMark in ChatLobbyDialog

This commit is contained in:
Phenom 2017-08-19 19:18:58 +02:00
parent 82c9084ca4
commit d03ee1c0b0
26 changed files with 318 additions and 58 deletions

View file

@ -34,7 +34,7 @@
#include "gui/FriendsDialog.h"
#include "gui/MainWindow.h"
#include "gui/chat/ChatWidget.h"
#include "gui/common/html.h"
#include "gui/common/rshtml.h"
#include "gui/common/FriendSelectionDialog.h"
#include "gui/common/RSTreeWidgetItem.h"
#include "gui/gxs/GxsIdChooser.h"

View file

@ -72,8 +72,15 @@
* #define CHAT_DEBUG 1
*****/
ChatWidget::ChatWidget(QWidget *parent) :
QWidget(parent), sendingBlocked(false), ui(new Ui::ChatWidget)
ChatWidget::ChatWidget(QWidget *parent)
: QWidget(parent)
, completionPosition(0), newMessages(false), typing(false), peerStatus(0)
, sendingBlocked(false), useCMark(false)
, lastStatusSendTime(0)
, firstShow(true), inChatCharFormatChanged(false), firstSearch(true)
, lastUpdateCursorPos(0), lastUpdateCursorEnd(0)
, completer(NULL), notify(NULL)
, ui(new Ui::ChatWidget)
{
ui->setupUi(this);
@ -84,17 +91,8 @@ ChatWidget::ChatWidget(QWidget *parent) :
int butt_size(iconSize.height() + fmm);
QSize buttonSize = QSize(butt_size, butt_size);
newMessages = false;
typing = false;
peerStatus = 0;
firstShow = true;
firstSearch = true;
inChatCharFormatChanged = false;
completer = NULL;
lastMsgDate = QDate::currentDate();
lastStatusSendTime = 0 ;
//Resize Tool buttons
ui->emoteiconButton->setFixedSize(buttonSize);
ui->emoteiconButton->setIconSize(iconSize);
@ -144,7 +142,6 @@ ChatWidget::ChatWidget(QWidget *parent) :
connect(ui->actionSearchWithoutLimit, SIGNAL(triggered()), this, SLOT(toogle_SeachWithoutLimit()));
connect(ui->searchButton, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuSearchButton(QPoint)));
notify=NULL;
ui->notifyButton->setVisible(false);
ui->markButton->setToolTip(tr("<b>Mark this selected text</b><br><i>Ctrl+M</i>"));
@ -194,6 +191,7 @@ ChatWidget::ChatWidget(QWidget *parent) :
fontmenu->addAction(ui->actionResetFont);
fontmenu->addAction(ui->actionNoEmbed);
fontmenu->addAction(ui->actionSendAsPlainText);
fontmenu->addAction(ui->actionSend_as_CommonMark);
QMenu *menu = new QMenu();
menu->addAction(ui->actionClearChatHistory);
@ -207,6 +205,10 @@ ChatWidget::ChatWidget(QWidget *parent) :
ui->chatTextEdit->setOnlyPlainText(ui->actionSendAsPlainText->isChecked());
connect(ui->actionSendAsPlainText, SIGNAL(toggled(bool)), ui->chatTextEdit, SLOT(setOnlyPlainText(bool)) );
connect(ui->actionSend_as_CommonMark, SIGNAL(toggled(bool)), this, SLOT(setUseCMark(bool)) );
ui->cmPreview->setVisible(false);
connect(ui->chatTextEdit, SIGNAL(textChanged()), this, SLOT(updateCMPreview()) );
ui->textBrowser->resetImagesStatus(Settings->getChatLoadEmbeddedImages());
ui->textBrowser->installEventFilter(this);
ui->textBrowser->viewport()->installEventFilter(this);
@ -981,6 +983,11 @@ void ChatWidget::addChatMsg(bool incoming, const QString &name, const RsGxsId gx
formatTextFlag |= RSHTML_FORMATTEXT_EMBED_SMILEYS;
}
//Use CommonMark
if (message.contains("CMark=\"true\"")) {
formatTextFlag |= RSHTML_FORMATTEXT_USE_CMARK;
}
// Always fix colors
formatTextFlag |= RSHTML_FORMATTEXT_FIX_COLORS;
qreal desiredContrast = Settings->valueFromGroup("Chat", "MinimumContrast", 4.5).toDouble();
@ -1229,7 +1236,9 @@ void ChatWidget::sendChat()
text = chatWidget->toPlainText();
text.replace(QChar(-4),"");//Char used when image on text.
} else {
RsHtml::optimizeHtml(chatWidget, text, (ui->actionNoEmbed->isChecked() ? RSHTML_FORMATTEXT_NO_EMBED : 0));
RsHtml::optimizeHtml(chatWidget, text,
(ui->actionNoEmbed->isChecked() ? RSHTML_FORMATTEXT_NO_EMBED : 0)
+ (ui->actionSend_as_CommonMark->isChecked() ? RSHTML_FORMATTEXT_USE_CMARK : 0) );
}
std::string msg = text.toUtf8().constData();
@ -1823,6 +1832,22 @@ bool ChatWidget::setStyle()
return false;
}
void ChatWidget::setUseCMark(const bool bUseCMark)
{
useCMark = bUseCMark;
ui->cmPreview->setVisible(useCMark);
updateCMPreview();
}
void ChatWidget::updateCMPreview()
{
if (!useCMark) return;
QString message = ui->chatTextEdit->toHtml();
QString formattedMessage = RsHtml().formatText(ui->cmPreview->document(), message, RSHTML_FORMATTEXT_USE_CMARK);
ui->cmPreview->setHtml(formattedMessage);
}
void ChatWidget::quote()
{
QString text = ui->textBrowser->textCursor().selection().toPlainText();

View file

@ -128,6 +128,8 @@ public:
public slots:
void updateStatus(const QString &peer_id, int status);
void setUseCMark(const bool bUseCMark);
void updateCMPreview();
private slots:
//void pasteCreateMsgLink() ;
@ -222,7 +224,8 @@ private:
bool typing;
int peerStatus;
bool sendingBlocked;
bool sendingBlocked;
bool useCMark;
time_t lastStatusSendTime;

View file

@ -268,22 +268,34 @@ border-image: url(:/images/closepressed.png)
</layout>
</item>
<item>
<widget class="MimeTextEdit" name="chatTextEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
<widget class="QSplitter" name="chatTextEditHSplitter">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
</size>
<property name="handleWidth">
<number>2</number>
</property>
<property name="placeholderText" stdset="0">
<string>Type a message here</string>
<property name="childrenCollapsible">
<bool>false</bool>
</property>
<widget class="MimeTextEdit" name="chatTextEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
</size>
</property>
<property name="placeholderText" stdset="0">
<string>Type a message here</string>
</property>
</widget>
<widget class="RSTextBrowser" name="cmPreview"/>
</widget>
</item>
</layout>
@ -915,6 +927,21 @@ border-image: url(:/images/closepressed.png)
<string>Show Hidden Images</string>
</property>
</action>
<action name="actionSend_as_CommonMark">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="../icons.qrc">
<normaloff>:/icons/png/markdown-mark.png</normaloff>:/icons/png/markdown-mark.png</iconset>
</property>
<property name="text">
<string>Send as CommonMark</string>
</property>
<property name="toolTip">
<string>Text will be formatted using CommonMark.</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
@ -945,8 +972,8 @@ border-image: url(:/images/closepressed.png)
</customwidget>
</customwidgets>
<resources>
<include location="../icons.qrc"/>
<include location="../images.qrc"/>
<include location="../icons.qrc"/>
</resources>
<connections/>
</ui>