diff --git a/InstructorsAndTrainees/instructors/viewerinstructors.cpp b/InstructorsAndTrainees/instructors/viewerinstructors.cpp index 2415f5d..4e612fc 100644 --- a/InstructorsAndTrainees/instructors/viewerinstructors.cpp +++ b/InstructorsAndTrainees/instructors/viewerinstructors.cpp @@ -9,9 +9,11 @@ ViewerInstructors::ViewerInstructors(ConnectorToServer* connectorToServer, QWidg { ui->setupUi(this); + connect(treeWidget, &QTreeWidget::currentItemChanged, this, &ViewerInstructors::on_treeWidget_currentItemChanged); + ui->horizontalLayout_1->addWidget(treeWidget); - treeWidget->setSelectionMode(QAbstractItemView::NoSelection); + //treeWidget->setSelectionMode(QAbstractItemView::NoSelection); preparationTreeWidget(); setNotLoggedInVisible(true); @@ -69,6 +71,28 @@ void ViewerInstructors::on_btnEditorInstructors_clicked() Q_EMIT signal_BlockAutorization(false); } +void ViewerInstructors::on_treeWidget_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous) +{ + if(current == nullptr) + return; + + //if(current->childCount() == 0) + {//Выбран обучаемый + QString login = current->text(ColumnsTreeInsructors::clmn_Login); + //if(login != "") + { + int newCurrentID = connectorToServer->getIdInstructorByLogin(login); + + if(newCurrentID == lastCurrentID) + return; + + lastCurrentID = newCurrentID; + + Q_EMIT signal_instructorSelected(login); + } + } +} + void ViewerInstructors::updateButtons() { if(adminMode && authComplited) diff --git a/InstructorsAndTrainees/instructors/viewerinstructors.h b/InstructorsAndTrainees/instructors/viewerinstructors.h index 0451222..0582c71 100644 --- a/InstructorsAndTrainees/instructors/viewerinstructors.h +++ b/InstructorsAndTrainees/instructors/viewerinstructors.h @@ -32,6 +32,13 @@ Q_SIGNALS: public Q_SLOTS: void on_btnEditorInstructors_clicked(); +public slots: + void on_treeWidget_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous); + +Q_SIGNALS: + //сигнал о выборе инструктора + void signal_instructorSelected(QString login); + private: void updateButtons() override; diff --git a/InstructorsAndTrainees/instructorsandtraineeswidget.cpp b/InstructorsAndTrainees/instructorsandtraineeswidget.cpp index 8d8bd1c..c925f70 100644 --- a/InstructorsAndTrainees/instructorsandtraineeswidget.cpp +++ b/InstructorsAndTrainees/instructorsandtraineeswidget.cpp @@ -52,6 +52,7 @@ InstructorsAndTraineesWidget::InstructorsAndTraineesWidget(QWidget *parent) : connect(connectorToServer,&ConnectorToServer::signal_ConnectedToServer,this,&InstructorsAndTraineesWidget::slot_ConnectedToServer); connect(viewerTrainees, &ViewerTrainees::signal_traineeSelected, this, &InstructorsAndTraineesWidget::slot_traineeSelected); + connect(viewerInstructors, &ViewerInstructors::signal_instructorSelected, this, &InstructorsAndTraineesWidget::slot_instructorSelected); //Размещение ui->verticalLayout_Trainees->addWidget(viewerTrainees); @@ -263,6 +264,18 @@ void InstructorsAndTraineesWidget::slot_traineeSelected(QString login) } } +void InstructorsAndTraineesWidget::slot_instructorSelected(QString login) +{ + /* Messanger*/ + messangerController->deleteWidget(messangerWidget); + if(login != "") + { + Instructor instructor = connectorToServer->getInstructor(connectorToServer->getIdInstructorByLogin(login)); + if(instructor.getID()) + messangerWidget = messangerController->newWidget(this, &instructor, ui->verticalLayout_Messenger); + } +} + bool InstructorsAndTraineesWidget::authorizationInstructorDialog(QWidget* parent) { DialogAuthorizationInstructor dlg(parent); diff --git a/InstructorsAndTrainees/instructorsandtraineeswidget.h b/InstructorsAndTrainees/instructorsandtraineeswidget.h index 83bae2c..96dcab0 100644 --- a/InstructorsAndTrainees/instructorsandtraineeswidget.h +++ b/InstructorsAndTrainees/instructorsandtraineeswidget.h @@ -49,6 +49,7 @@ public Q_SLOTS: void slot_ConnectedToServer(bool state); void slot_traineeSelected(QString login); + void slot_instructorSelected(QString login); Q_SIGNALS: //сигнал смены языка