@@ -35,30 +35,56 @@ CChatDlg::CChatDlg ( QWidget* parent ) : CBaseDlg ( parent, Qt::Window ) // use
35
35
36
36
txvChatWindow->setAccessibleName ( tr ( " Chat history" ) );
37
37
38
- // input message text
38
+ // single-line input message text
39
39
edtLocalInputText->setWhatsThis ( " <b>" + tr ( " Input Message Text" ) + " :</b> " +
40
40
tr ( " Enter the chat message text in the edit box and press enter to send the "
41
41
" message to the server which distributes the message to all connected "
42
42
" clients. Your message will then show up in the chat window." ) );
43
43
44
44
edtLocalInputText->setAccessibleName ( tr ( " New chat text edit box" ) );
45
45
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
47
55
txvChatWindow->clear ();
48
56
edtLocalInputText->clear ();
57
+ edtLocalInputTextMultiline->clear ();
49
58
50
59
// we do not want to show a cursor in the chat history
51
60
txvChatWindow->setCursorWidth ( 0 );
52
61
53
62
// set a placeholder text to make sure where to type the message in (#384)
54
63
edtLocalInputText->setPlaceholderText ( tr ( " Type a message here" ) );
64
+ edtLocalInputTextMultiline->setPlaceholderText ( tr ( " Type a message here" ) );
65
+
66
+ // hide the multiline input
67
+ edtLocalInputTextMultiline->hide ();
55
68
56
69
// Menu -------------------------------------------------------------------
57
70
QMenuBar* pMenu = new QMenuBar ( this );
71
+ QMenu* pViewMenu = new QMenu ( tr ( " &View" ), this );
58
72
QMenu* pEditMenu = new QMenu ( tr ( " &Edit" ), this );
59
73
74
+ QAction* InputModeAction =
75
+ pViewMenu->addAction ( tr ( " &Multiline Input Mode" ), this , SLOT ( OnInputModeAction () ), QKeySequence ( Qt::CTRL + Qt::Key_M ) );
76
+ InputModeAction->setCheckable ( true );
77
+
60
78
pEditMenu->addAction ( tr ( " Cl&ear Chat History" ), this , SLOT ( OnClearChatHistory () ), QKeySequence ( Qt::CTRL + Qt::Key_E ) );
61
79
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 );
62
88
pMenu->addMenu ( pEditMenu );
63
89
#if defined( Q_OS_IOS )
64
90
QAction* action = pMenu->addAction ( tr ( " &Close" ) );
@@ -71,6 +97,8 @@ CChatDlg::CChatDlg ( QWidget* parent ) : CBaseDlg ( parent, Qt::Window ) // use
71
97
// Connections -------------------------------------------------------------
72
98
QObject::connect ( edtLocalInputText, &QLineEdit::textChanged, this , &CChatDlg::OnLocalInputTextTextChanged );
73
99
100
+ QObject::connect ( edtLocalInputTextMultiline, &QPlainTextEdit::textChanged, this , &CChatDlg::OnLocalInputTextMultilineTextChanged );
101
+
74
102
QObject::connect ( butSend, &QPushButton::clicked, this , &CChatDlg::OnSendText );
75
103
76
104
QObject::connect ( txvChatWindow, &QTextBrowser::anchorClicked, this , &CChatDlg::OnAnchorClicked );
@@ -86,14 +114,68 @@ void CChatDlg::OnLocalInputTextTextChanged ( const QString& strNewText )
86
114
}
87
115
}
88
116
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
+
89
132
void CChatDlg::OnSendText ()
90
133
{
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 () )
93
136
{
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 ();
95
169
edtLocalInputText->clear ();
96
170
}
171
+ else
172
+ {
173
+ // show single-line input only
174
+ edtLocalInputTextMultiline->hide ();
175
+ edtLocalInputText->show ();
176
+ edtLocalInputText->setFocus ();
177
+ edtLocalInputTextMultiline->clear ();
178
+ }
97
179
}
98
180
99
181
void CChatDlg::OnClearChatHistory ()
0 commit comments