void session::send_message() { QLineEdit *temp = (QLineEdit *)_tabWidget->currentWidget()->layout()->itemAt(1)->widget(); (*_chatVct)[_tabWidget->currentIndex()]->send_message(temp->displayText()); QTextBrowser *tb = (QTextBrowser *)_tabWidget->currentWidget()->layout()->itemAt(0)->widget(); tb->insertPlainText("\t\t\t\t\t"); tb->insertPlainText(temp->displayText() + "\n"); temp->clear(); }
int session::add_tab(QString name,ChatNetWork *chat) { if(chat_in_tab(chat) == -1) return -1; QWidget *widget = new QWidget(this); QVBoxLayout *vLayout = new QVBoxLayout(widget); QTextBrowser *textBrowser = new QTextBrowser(widget); QLineEdit *lineEdit = new QLineEdit(widget); vLayout->addWidget(textBrowser); vLayout->addWidget(lineEdit); QPushButton *sendButton = new QPushButton("send"); QObject::connect(sendButton, &QPushButton::clicked, this, &session::send_message); QPushButton *closeButton = new QPushButton("close"); QObject::connect(closeButton, &QPushButton::clicked, this, &session::close_tab); QHBoxLayout *buttonLayout = new QHBoxLayout(); QWidget *buttonWidget = new QWidget(); buttonLayout->addWidget(sendButton); buttonLayout->addWidget(closeButton); buttonWidget->setLayout(buttonLayout); vLayout->addWidget(buttonWidget); widget->setLayout(vLayout); _tabWidget->addTab(widget, name); _chatVct->push_back(chat); for(QMap<quint32,QString>::iterator it = chat->_messageMap.begin();it != chat->_messageMap.end();it++) { qDebug() << "benlaidexinxi"; textBrowser->insertPlainText(*it+"\n"); } qDebug() << "con display" << chat->_host << chat->_port; connect(chat,&ChatNetWork::display_message,textBrowser,&QTextBrowser::insertPlainText); return 0; }