@@ -19,6 +19,7 @@ MainWindow::MainWindow(QWidget *parent) :
1919 QMainWindow(parent),
2020 ui(new Ui::MainWindow),
2121 _io(new client()),
22+ m_typingItem(NULL ),
2223 m_dialog()
2324{
2425 ui->setupUi (this );
@@ -39,6 +40,7 @@ MainWindow::MainWindow(QWidget *parent) :
3940 _io->set_fail_listener (std::bind (&MainWindow::OnFailed,this ));
4041
4142 connect (this ,SIGNAL (RequestAddListItem (QListWidgetItem*)),this ,SLOT (AddListItem (QListWidgetItem*)));
43+ connect (this ,SIGNAL (RequestRemoveListItem (QListWidgetItem*)),this ,SLOT (RemoveListItem (QListWidgetItem*)));
4244 connect (this ,SIGNAL (RequestToggleInputs (bool )),this ,SLOT (ToggleInputs (bool )));
4345}
4446
@@ -58,7 +60,7 @@ void MainWindow::SendBtnClicked()
5860 QByteArray bytes = text.toUtf8 ();
5961 std::string msg (bytes.data (),bytes.length ());
6062 _io->socket ()->emit (" new message" ,msg);
61- text.append (" : You" );
63+ text.append (" : You" );
6264 QListWidgetItem *item = new QListWidgetItem (text);
6365 item->setTextAlignment (Qt::AlignRight);
6466 Q_EMIT RequestAddListItem (item);
@@ -126,6 +128,14 @@ void MainWindow::AddListItem(QListWidgetItem* item)
126128 this ->findChild <QListWidget*>(" listView" )->addItem (item);
127129}
128130
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+
129139void MainWindow::OnNewMessage (std::string const & name,message::ptr const & data,bool hasAck,message::ptr &ack_resp)
130140{
131141
@@ -134,7 +144,7 @@ void MainWindow::OnNewMessage(std::string const& name,message::ptr const& data,b
134144 std::string msg = data->get_map ()[" message" ]->get_string ();
135145 std::string username = data->get_map ()[" username" ]->get_string ();
136146 QString label = QString::fromUtf8 (username.data (),username.length ());
137- label.append (' : ' );
147+ label.append (" : " );
138148 label.append (QString::fromUtf8 (msg.data (),msg.length ()));
139149 QListWidgetItem *item= new QListWidgetItem (label);
140150 Q_EMIT RequestAddListItem (item);
@@ -200,12 +210,25 @@ void MainWindow::OnUserLeft(std::string const& name,message::ptr const& data,boo
200210
201211void MainWindow::OnTyping (std::string const & name,message::ptr const & data,bool hasAck,message::ptr &ack_resp)
202212{
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+ }
204223}
205224
206225void MainWindow::OnStopTyping (std::string const & name,message::ptr const & data,bool hasAck,message::ptr &ack_resp)
207226{
208- // Not implemented
227+ if (m_typingItem != NULL )
228+ {
229+ Q_EMIT RequestRemoveListItem (m_typingItem);
230+ m_typingItem = NULL ;
231+ }
209232}
210233
211234void MainWindow::OnLogin (std::string const & name,message::ptr const & data,bool hasAck,message::ptr &ack_resp)
0 commit comments