@@ -19,6 +19,7 @@ MainWindow::MainWindow(QWidget *parent) :
19
19
QMainWindow(parent),
20
20
ui(new Ui::MainWindow),
21
21
_io(new client()),
22
+ m_typingItem(NULL ),
22
23
m_dialog()
23
24
{
24
25
ui->setupUi (this );
@@ -39,6 +40,7 @@ MainWindow::MainWindow(QWidget *parent) :
39
40
_io->set_fail_listener (std::bind (&MainWindow::OnFailed,this ));
40
41
41
42
connect (this ,SIGNAL (RequestAddListItem (QListWidgetItem*)),this ,SLOT (AddListItem (QListWidgetItem*)));
43
+ connect (this ,SIGNAL (RequestRemoveListItem (QListWidgetItem*)),this ,SLOT (RemoveListItem (QListWidgetItem*)));
42
44
connect (this ,SIGNAL (RequestToggleInputs (bool )),this ,SLOT (ToggleInputs (bool )));
43
45
}
44
46
@@ -58,7 +60,7 @@ void MainWindow::SendBtnClicked()
58
60
QByteArray bytes = text.toUtf8 ();
59
61
std::string msg (bytes.data (),bytes.length ());
60
62
_io->socket ()->emit (" new message" ,msg);
61
- text.append (" : You" );
63
+ text.append (" : You" );
62
64
QListWidgetItem *item = new QListWidgetItem (text);
63
65
item->setTextAlignment (Qt::AlignRight);
64
66
Q_EMIT RequestAddListItem (item);
@@ -126,6 +128,14 @@ void MainWindow::AddListItem(QListWidgetItem* item)
126
128
this ->findChild <QListWidget*>(" listView" )->addItem (item);
127
129
}
128
130
131
+ void MainWindow::RemoveListItem (QListWidgetItem* item)
132
+ {
133
+ QListWidget* list = this ->findChild <QListWidget*>(" listView" );
134
+ int row = list->row (item);
135
+ delete list->takeItem (row);
136
+ }
137
+
138
+
129
139
void MainWindow::OnNewMessage (std::string const & name,message::ptr const & data,bool hasAck,message::ptr &ack_resp)
130
140
{
131
141
@@ -134,7 +144,7 @@ void MainWindow::OnNewMessage(std::string const& name,message::ptr const& data,b
134
144
std::string msg = data->get_map ()[" message" ]->get_string ();
135
145
std::string username = data->get_map ()[" username" ]->get_string ();
136
146
QString label = QString::fromUtf8 (username.data (),username.length ());
137
- label.append (' : ' );
147
+ label.append (" : " );
138
148
label.append (QString::fromUtf8 (msg.data (),msg.length ()));
139
149
QListWidgetItem *item= new QListWidgetItem (label);
140
150
Q_EMIT RequestAddListItem (item);
@@ -200,12 +210,25 @@ void MainWindow::OnUserLeft(std::string const& name,message::ptr const& data,boo
200
210
201
211
void MainWindow::OnTyping (std::string const & name,message::ptr const & data,bool hasAck,message::ptr &ack_resp)
202
212
{
203
- // Not implemented
213
+ if (m_typingItem == NULL )
214
+ {
215
+ std::string name = data->get_map ()[" username" ]->get_string ();
216
+ QString label = QString::fromUtf8 (name.data (),name.length ());
217
+ label.append (" is typing..." );
218
+ QListWidgetItem *item = new QListWidgetItem (label);
219
+ item->setTextColor (QColor (200 ,200 ,200 ,255 ));
220
+ m_typingItem = item;
221
+ Q_EMIT RequestAddListItem (item);
222
+ }
204
223
}
205
224
206
225
void MainWindow::OnStopTyping (std::string const & name,message::ptr const & data,bool hasAck,message::ptr &ack_resp)
207
226
{
208
- // Not implemented
227
+ if (m_typingItem != NULL )
228
+ {
229
+ Q_EMIT RequestRemoveListItem (m_typingItem);
230
+ m_typingItem = NULL ;
231
+ }
209
232
}
210
233
211
234
void MainWindow::OnLogin (std::string const & name,message::ptr const & data,bool hasAck,message::ptr &ack_resp)
0 commit comments