@@ -35,30 +35,56 @@ CChatDlg::CChatDlg ( QWidget* parent ) : CBaseDlg ( parent, Qt::Window ) // use
3535
3636 txvChatWindow->setAccessibleName ( tr ( " Chat history" ) );
3737
38- // input message text
38+ // single-line input message text
3939 edtLocalInputText->setWhatsThis ( " <b>" + tr ( " Input Message Text" ) + " :</b> " +
4040 tr ( " Enter the chat message text in the edit box and press enter to send the "
4141 " message to the server which distributes the message to all connected "
4242 " clients. Your message will then show up in the chat window." ) );
4343
4444 edtLocalInputText->setAccessibleName ( tr ( " New chat text edit box" ) );
4545
46- // clear chat window and edit line
46+ // multiline input message text
47+ edtLocalInputTextMultiline->setWhatsThis ( " <b>" + tr ( " Multiline Input Message Text" ) + " :</b> " +
48+ tr ( " Enter the chat message text in the edit box and press ctrl+enter to send the "
49+ " message to the server which distributes the message to all connected "
50+ " clients. Your message will then show up in the chat window." ) );
51+
52+ edtLocalInputTextMultiline->setAccessibleName ( tr ( " New multiline chat text edit box" ) );
53+
54+ // clear chat window and edit line / multiline edit line
4755 txvChatWindow->clear ();
4856 edtLocalInputText->clear ();
57+ edtLocalInputTextMultiline->clear ();
4958
5059 // we do not want to show a cursor in the chat history
5160 txvChatWindow->setCursorWidth ( 0 );
5261
5362 // set a placeholder text to make sure where to type the message in (#384)
5463 edtLocalInputText->setPlaceholderText ( tr ( " Type a message here" ) );
64+ edtLocalInputTextMultiline->setPlaceholderText ( tr ( " Type a message here" ) );
65+
66+ // hide the multiline input
67+ edtLocalInputTextMultiline->hide ();
5568
5669 // Menu -------------------------------------------------------------------
5770 QMenuBar* pMenu = new QMenuBar ( this );
71+ QMenu* pViewMenu = new QMenu ( tr ( " &View" ), this );
5872 QMenu* pEditMenu = new QMenu ( tr ( " &Edit" ), this );
5973
74+ QAction* InputModeAction =
75+ pViewMenu->addAction ( tr ( " &Multiline Input Mode" ), this , SLOT ( OnInputModeAction () ), QKeySequence ( Qt::CTRL + Qt::Key_M ) );
76+ InputModeAction->setCheckable ( true );
77+
6078 pEditMenu->addAction ( tr ( " Cl&ear Chat History" ), this , SLOT ( OnClearChatHistory () ), QKeySequence ( Qt::CTRL + Qt::Key_E ) );
6179
80+ // create action so Ctrl+Return sends a message
81+ QAction* SendAction = new QAction ( this );
82+ SendAction->setAutoRepeat ( false );
83+ SendAction->setShortcut ( tr ( " Ctrl+Return" ) );
84+ connect ( SendAction, SIGNAL ( triggered () ), this , SLOT ( OnSendText () ) );
85+ this ->addAction ( SendAction );
86+
87+ pMenu->addMenu ( pViewMenu );
6288 pMenu->addMenu ( pEditMenu );
6389#if defined( Q_OS_IOS )
6490 QAction* action = pMenu->addAction ( tr ( " &Close" ) );
@@ -71,6 +97,8 @@ CChatDlg::CChatDlg ( QWidget* parent ) : CBaseDlg ( parent, Qt::Window ) // use
7197 // Connections -------------------------------------------------------------
7298 QObject::connect ( edtLocalInputText, &QLineEdit::textChanged, this , &CChatDlg::OnLocalInputTextTextChanged );
7399
100+ QObject::connect ( edtLocalInputTextMultiline, &QPlainTextEdit::textChanged, this , &CChatDlg::OnLocalInputTextMultilineTextChanged );
101+
74102 QObject::connect ( butSend, &QPushButton::clicked, this , &CChatDlg::OnSendText );
75103
76104 QObject::connect ( txvChatWindow, &QTextBrowser::anchorClicked, this , &CChatDlg::OnAnchorClicked );
@@ -86,14 +114,68 @@ void CChatDlg::OnLocalInputTextTextChanged ( const QString& strNewText )
86114 }
87115}
88116
117+ void CChatDlg::OnLocalInputTextMultilineTextChanged ()
118+ {
119+ // check and correct length
120+ if ( edtLocalInputTextMultiline->toPlainText ().length () > MAX_LEN_CHAT_TEXT )
121+ {
122+ // text is too long, update control with shortened text
123+ edtLocalInputTextMultiline->setPlainText ( edtLocalInputTextMultiline->toPlainText ().left ( MAX_LEN_CHAT_TEXT ) );
124+
125+ // move cursor to the end
126+ QTextCursor cursor ( edtLocalInputTextMultiline->textCursor () );
127+ cursor.movePosition ( QTextCursor::End, QTextCursor::MoveAnchor );
128+ edtLocalInputTextMultiline->setTextCursor ( cursor );
129+ }
130+ }
131+
89132void CChatDlg::OnSendText ()
90133{
91- // send new text and clear line afterwards, do not send an empty message
92- if ( ! edtLocalInputText->text (). isEmpty () )
134+ // send new text from whichever input is visible
135+ if ( edtLocalInputText->isVisible () )
93136 {
94- emit NewLocalInputText ( edtLocalInputText->text () );
137+ // do not send an empty message
138+ if ( !edtLocalInputText->text ().isEmpty () )
139+ {
140+ // send text and clear line afterwards
141+ emit NewLocalInputText ( edtLocalInputText->text () );
142+ edtLocalInputText->clear ();
143+ edtLocalInputText->setFocus ();
144+ }
145+ }
146+ else
147+ {
148+ // do not send an empty message
149+ if ( !edtLocalInputTextMultiline->toPlainText ().isEmpty () )
150+ {
151+ // send text and clear multiline input afterwards
152+ emit NewLocalInputText ( edtLocalInputTextMultiline->toPlainText () );
153+ edtLocalInputTextMultiline->clear ();
154+ edtLocalInputTextMultiline->setFocus ();
155+ }
156+ }
157+ }
158+
159+ void CChatDlg::OnInputModeAction ()
160+ {
161+ // switch between single-line and multiline input
162+ if ( edtLocalInputText->isVisible () )
163+ {
164+ // show multiline input only
165+ edtLocalInputText->hide ();
166+ edtLocalInputTextMultiline->setPlainText ( edtLocalInputText->text () );
167+ edtLocalInputTextMultiline->show ();
168+ edtLocalInputTextMultiline->setFocus ();
95169 edtLocalInputText->clear ();
96170 }
171+ else
172+ {
173+ // show single-line input only
174+ edtLocalInputTextMultiline->hide ();
175+ edtLocalInputText->show ();
176+ edtLocalInputText->setFocus ();
177+ edtLocalInputTextMultiline->clear ();
178+ }
97179}
98180
99181void CChatDlg::OnClearChatHistory ()
0 commit comments