diff --git a/src/chatdlg.cpp b/src/chatdlg.cpp index e248c5c8e5..b40e10f043 100644 --- a/src/chatdlg.cpp +++ b/src/chatdlg.cpp @@ -35,7 +35,7 @@ CChatDlg::CChatDlg ( QWidget* parent ) : CBaseDlg ( parent, Qt::Window ) // use txvChatWindow->setAccessibleName ( tr ( "Chat history" ) ); - // input message text + // single-line input message text edtLocalInputText->setWhatsThis ( "" + tr ( "Input Message Text" ) + ": " + tr ( "Enter the chat message text in the edit box and press enter to send the " "message to the server which distributes the message to all connected " @@ -43,22 +43,48 @@ CChatDlg::CChatDlg ( QWidget* parent ) : CBaseDlg ( parent, Qt::Window ) // use edtLocalInputText->setAccessibleName ( tr ( "New chat text edit box" ) ); - // clear chat window and edit line + // multiline input message text + edtLocalInputTextMultiline->setWhatsThis ( "" + tr ( "Multiline Input Message Text" ) + ": " + + tr ( "Enter the chat message text in the edit box and press ctrl+enter to send the " + "message to the server which distributes the message to all connected " + "clients. Your message will then show up in the chat window." ) ); + + edtLocalInputTextMultiline->setAccessibleName ( tr ( "New multiline chat text edit box" ) ); + + // clear chat window and edit line / multiline edit line txvChatWindow->clear(); edtLocalInputText->clear(); + edtLocalInputTextMultiline->clear(); // we do not want to show a cursor in the chat history txvChatWindow->setCursorWidth ( 0 ); // set a placeholder text to make sure where to type the message in (#384) edtLocalInputText->setPlaceholderText ( tr ( "Type a message here" ) ); + edtLocalInputTextMultiline->setPlaceholderText ( tr ( "Type a message here" ) ); + + // hide the multiline input + edtLocalInputTextMultiline->hide(); // Menu ------------------------------------------------------------------- QMenuBar* pMenu = new QMenuBar ( this ); + QMenu* pViewMenu = new QMenu ( tr ( "&View" ), this ); QMenu* pEditMenu = new QMenu ( tr ( "&Edit" ), this ); + QAction* InputModeAction = + pViewMenu->addAction ( tr ( "&Multiline Input Mode" ), this, SLOT ( OnInputModeAction() ), QKeySequence ( Qt::CTRL + Qt::Key_M ) ); + InputModeAction->setCheckable ( true ); + pEditMenu->addAction ( tr ( "Cl&ear Chat History" ), this, SLOT ( OnClearChatHistory() ), QKeySequence ( Qt::CTRL + Qt::Key_E ) ); + // create action so Ctrl+Return sends a message + QAction* SendAction = new QAction ( this ); + SendAction->setAutoRepeat ( false ); + SendAction->setShortcut ( tr ( "Ctrl+Return" ) ); + connect ( SendAction, SIGNAL ( triggered() ), this, SLOT ( OnSendText() ) ); + this->addAction ( SendAction ); + + pMenu->addMenu ( pViewMenu ); pMenu->addMenu ( pEditMenu ); #if defined( Q_OS_IOS ) QAction* action = pMenu->addAction ( tr ( "&Close" ) ); @@ -71,6 +97,8 @@ CChatDlg::CChatDlg ( QWidget* parent ) : CBaseDlg ( parent, Qt::Window ) // use // Connections ------------------------------------------------------------- QObject::connect ( edtLocalInputText, &QLineEdit::textChanged, this, &CChatDlg::OnLocalInputTextTextChanged ); + QObject::connect ( edtLocalInputTextMultiline, &QPlainTextEdit::textChanged, this, &CChatDlg::OnLocalInputTextMultilineTextChanged ); + QObject::connect ( butSend, &QPushButton::clicked, this, &CChatDlg::OnSendText ); QObject::connect ( txvChatWindow, &QTextBrowser::anchorClicked, this, &CChatDlg::OnAnchorClicked ); @@ -86,14 +114,68 @@ void CChatDlg::OnLocalInputTextTextChanged ( const QString& strNewText ) } } +void CChatDlg::OnLocalInputTextMultilineTextChanged() +{ + // check and correct length + if ( edtLocalInputTextMultiline->toPlainText().length() > MAX_LEN_CHAT_TEXT ) + { + // text is too long, update control with shortened text + edtLocalInputTextMultiline->setPlainText ( edtLocalInputTextMultiline->toPlainText().left ( MAX_LEN_CHAT_TEXT ) ); + + // move cursor to the end + QTextCursor cursor ( edtLocalInputTextMultiline->textCursor() ); + cursor.movePosition ( QTextCursor::End, QTextCursor::MoveAnchor ); + edtLocalInputTextMultiline->setTextCursor ( cursor ); + } +} + void CChatDlg::OnSendText() { - // send new text and clear line afterwards, do not send an empty message - if ( !edtLocalInputText->text().isEmpty() ) + // send new text from whichever input is visible + if ( edtLocalInputText->isVisible() ) { - emit NewLocalInputText ( edtLocalInputText->text() ); + // do not send an empty message + if ( !edtLocalInputText->text().isEmpty() ) + { + // send text and clear line afterwards + emit NewLocalInputText ( edtLocalInputText->text() ); + edtLocalInputText->clear(); + edtLocalInputText->setFocus(); + } + } + else + { + // do not send an empty message + if ( !edtLocalInputTextMultiline->toPlainText().isEmpty() ) + { + // send text and clear multiline input afterwards + emit NewLocalInputText ( edtLocalInputTextMultiline->toPlainText() ); + edtLocalInputTextMultiline->clear(); + edtLocalInputTextMultiline->setFocus(); + } + } +} + +void CChatDlg::OnInputModeAction() +{ + // switch between single-line and multiline input + if ( edtLocalInputText->isVisible() ) + { + // show multiline input only + edtLocalInputText->hide(); + edtLocalInputTextMultiline->setPlainText ( edtLocalInputText->text() ); + edtLocalInputTextMultiline->show(); + edtLocalInputTextMultiline->setFocus(); edtLocalInputText->clear(); } + else + { + // show single-line input only + edtLocalInputTextMultiline->hide(); + edtLocalInputText->show(); + edtLocalInputText->setFocus(); + edtLocalInputTextMultiline->clear(); + } } void CChatDlg::OnClearChatHistory() diff --git a/src/chatdlg.h b/src/chatdlg.h index 19c170640a..7159c7abc5 100644 --- a/src/chatdlg.h +++ b/src/chatdlg.h @@ -51,6 +51,8 @@ class CChatDlg : public CBaseDlg, private Ui_CChatDlgBase public slots: void OnSendText(); void OnLocalInputTextTextChanged ( const QString& strNewText ); + void OnLocalInputTextMultilineTextChanged(); + void OnInputModeAction(); void OnClearChatHistory(); void OnAnchorClicked ( const QUrl& Url ); diff --git a/src/chatdlgbase.ui b/src/chatdlgbase.ui index 7d59db9661..3ce7c4f957 100644 --- a/src/chatdlgbase.ui +++ b/src/chatdlgbase.ui @@ -46,10 +46,35 @@ - + + + + + + + + + 0 + 0 + + + + + Monospace + + + + + + + + 0 + 0 + + &Send diff --git a/src/server.cpp b/src/server.cpp index 21fe46f0b2..3411290e64 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1411,8 +1411,18 @@ void CServer::CreateAndSendChatTextForAllConChannels ( const int iCurChanID, con // use different colors QString sCurColor = vstrChatColors[iCurChanID % vstrChatColors.Size()]; - const QString strActualMessageText = "(" + QTime::currentTime().toString ( "hh:mm:ss AP" ) + ") " + - ChanName.toHtmlEscaped() + " " + strChatText.toHtmlEscaped(); + QString strActualMessageText = + "(" + QTime::currentTime().toString ( "hh:mm:ss AP" ) + ") " + ChanName.toHtmlEscaped() + " "; + + if ( strChatText.contains ( "\n" ) ) + { + // add 'preformatted' tags around multiline strings + strActualMessageText += "
" + strChatText.toHtmlEscaped() + "
"; + } + else + { + strActualMessageText += strChatText.toHtmlEscaped(); + } // Send chat text to all connected clients --------------------------------- for ( int i = 0; i < iMaxNumChannels; i++ )