#include "ishowmain.h" #include "ui_main.h" #include "ui_incomingcall.h" #include "ui_homecenter.h" #include "iwebrequest.h" #include #include #include #include "isettingwidget.h" #include #include #include #include #include #include "userinfotip.h" #include "downloadfile.h" #include #include "mywidget.h" #include "GlobalSetting.h" #include "gotyecpp/gotyemsg.h" IShowMain::IShowMain(QWidget *parent) : QWidget(parent) ,ui(new Ui::IShowMain) ,uiHome(new Ui::HomeCenterWidget), uiIncoming(new Ui::IncomingCallWidget) { userInfoTip = NULL; ui->setupUi(this); connect(ui->pushButtonMin, SIGNAL(clicked()), this, SIGNAL(hideMain())); connect(ui->pushButtonClose, SIGNAL(clicked()), parent, SLOT(on_pushButtonClose_clicked())); connect(ui->pushButtonMax, SIGNAL(clicked()), this, SIGNAL(showMainMax())); connect(ui->pushButtonMenuHome, SIGNAL(clicked()), SLOT(showHome())); connect(ui->pushButtonCourses, SIGNAL(clicked()), SLOT(showCourses())); connect(ui->pushButtonCourses, SIGNAL(clicked()), this, SLOT(buttonChecked())); // ui->pushButtonCourses->hide(); connect(ui->pushButtonMenuHome, SIGNAL(clicked()), this, SLOT(buttonChecked())); connect(ui->pushButtonMenuMessage, SIGNAL(clicked()), this, SLOT(buttonChecked())); // connect(ui->pushButtonMenuMessage, SIGNAL(clicked()), this, SLOT(showIncomingCall())); //界面置顶切换需要的配置 //InitAPIVar(); ui->pushButtonMenuHome->setChecked(true); currentButton = ui->pushButtonMenuHome; QWidget *centerHome = new QWidget(); uiHome->setupUi(centerHome); QWidget *centerCalling = new QWidget(); uiIncoming->setupUi(centerCalling); ishowCourses = new IshowCourses(this); uiChatArea = new Ui::msgChatArea(); centerChatArea = new QWidget(); uiChatArea->setupUi(centerChatArea); QFile source(":Images/style/styleMsg.html"); // QFile source("D:/QTest/jquery-lightbox-0.5/styletest.html"); source.open(QIODevice::ReadOnly); uiChatArea->webView->setHtml(QString::fromUtf8(source.readAll().constData())); source.close(); uiChatArea->textEdit->installEventFilter(this); uiChatArea->pushButton->setFocusPolicy(Qt::NoFocus); uiChatArea->webView->setFocusPolicy(Qt::NoFocus); uiChatArea->listWidget->setFocusPolicy(Qt::NoFocus); GotyeMsg::Instance()->setUpdataUserList(uiChatArea->listWidget); centerChatArea->setStyleSheet("background-color:rgba(255,255,255);"); connect(uiChatArea->listWidget,SIGNAL(itemCliLeftChanged()),this,SLOT(showNowChat())); //msgChatAreaInit(); nowUser.name = "0"; connect(uiChatArea->pushButton_picture, SIGNAL(clicked()), SLOT(on_pushButton_picture_clicked())); connect(uiChatArea->pushButton, SIGNAL(clicked()), SLOT(on_pushButton_clicked())); connect(ui->pushButtonMenuMessage, SIGNAL(clicked()), SLOT(showChatArea())); connect(uiChatArea->listWidget, SIGNAL(deleteItem(QListWidgetItem *)), SLOT(delItemChat(QListWidgetItem *))); stack = new QStackedWidget(this); stack->insertWidget(ISTACK_HOME, centerHome); stack->insertWidget(ISTACK_INCOMING, centerCalling); stack->insertWidget(ISTACK_MESSAGE, centerChatArea); stack->insertWidget(ISTACK_COURSE, ishowCourses); stack->setCurrentIndex(ISTACK_HOME); StackItemNum = ISTACK_HOME; connect(uiIncoming->pushButtonAccept, SIGNAL(clicked()), this, SIGNAL(acceptCalling())); connect(uiIncoming->pushButtonDecline, SIGNAL(clicked()), this, SIGNAL(repulseCalling())); setting = new ISettingWidget(); connect(ui->pushButtonSetting, SIGNAL(clicked()), this, SLOT(showSetting())); //上线 connect(uiHome->pushButtonOnline2, SIGNAL(clicked()), SLOT(on_pushButtonOnline_clicked())); ui->verticalLayoutCenter->addWidget(stack); IWebRequest *webrequest = IWebRequest::Instance(); connect(webrequest, SIGNAL(response(int,int,QString,QString)), this, SLOT(doResponse(int,int,QString,QString))); onlineButton = new QPushButton(ui->widgetLeft); onlineButton->setGeometry(58, 68, 12, 12); onlineButton->setStyleSheet("border-image:url(:Images/Home/img_status_offline.png); background: transparent;"); hideTipTimer = new QTimer(this); userInfoTip = new UserInfoTip(); connect(ui->label_header_img, SIGNAL(mouseIn()), this, SLOT(showUserTip())); connect(ui->label_header_img, SIGNAL(mousePress()), this, SLOT(showUserTip())); connect(ui->label_header_img, SIGNAL(mouseOut()), this, SLOT(hideUserTip())); connect(hideTipTimer, SIGNAL(timeout()), userInfoTip, SLOT(hide())); hideTipTimer->setInterval(500); connect(userInfoTip, SIGNAL(mouseIn()), this, SLOT(showUserTip())); connect(userInfoTip, SIGNAL(mouseOut()), this, SLOT(hideUserTip())); //未读信息 newMsg = new QLabel(ui->widgetLeft); newMsg->setGeometry(50,155,20,20); newMsg->hide(); GotyeMsg::Instance()->setShowMsgNum(newMsg); //loading loadTimer = new QTimer(this); loadTimer->setSingleShot(true); loadTimer->setInterval(30*1000); connect(loadTimer, SIGNAL(timeout()), this, SLOT(loginLoading())); } #include "GlobalSetting.h" void IShowMain::initUserInfo() { QStringList params; IWebRequest::Instance()->sendRequestToServer(REQ_USER_GET, params); } void IShowMain::showUserTip() { hideTipTimer->stop(); if(!userInfoTip) { userInfoTip = new UserInfoTip(); } userInfoTip->setVisible(true); // QString headerImg = QCoreApplication::applicationDirPath()+"/img/"+_GlobalSetting.userHeadImg.file_name +_GlobalSetting.userHeadImg.ext; // userInfoTip->setHeaderImg(headerImg); QPoint point = mapToGlobal(ui->label_header_img->pos()+QPoint(ui->label_header_img->size().width()/2, ui->label_header_img->size().height()/2)); userInfoTip->move(point); // WId id = userInfoTip->winId(); // showWindowFront(id); } void IShowMain::hideUserTip() { hideTipTimer->start(); } void IShowMain::loginLoading() { QMessageBox::warning( this , "Failed","Please check if the network is normal!" ); uiHome->label_LogBig->setStyleSheet("border-image:url(:Images/Home/home_img_offline.png);"); uiHome->pushButtonOnline2->setEnabled(true); uiHome->pushButtonOnline2->setText("Go Online"); onlineButton->setStyleSheet("border-image:url(:Images/Home/img_status_offline.png); background: transparent;"); } void IShowMain::doResponse(int cmd,int code,QString ,QString result) { switch(cmd) { case REQ_USER_ONLINE: { if(loadTimer->isActive()) loadTimer->stop(); uiHome->label_LogBig->setStyleSheet("border-image:url(:Images/Home/home_img_online.png);"); uiHome->pushButtonOnline2->setEnabled(true); uiHome->pushButtonOnline2->setText("Go Offline"); onlineButton->setStyleSheet("border-image:url(:Images/Home/img_status_online.png); background: transparent;"); break; } case REQ_USER_OFFLINE: { if(loadTimer->isActive()) loadTimer->stop(); uiHome->label_LogBig->setStyleSheet("border-image:url(:Images/Home/home_img_offline.png);"); uiHome->pushButtonOnline2->setEnabled(true); uiHome->pushButtonOnline2->setText("Go Online"); onlineButton->setStyleSheet("border-image:url(:Images/Home/img_status_offline.png); background: transparent;"); break; } case REQ_LOGOUT: { uiHome->label_LogBig->setStyleSheet("border-image:url(:Images/Home/home_img_offline.png);"); uiHome->pushButtonOnline2->setEnabled(true); uiHome->pushButtonOnline2->setText("Go Online"); onlineButton->setStyleSheet("border-image:url(:Images/Home/img_status_offline.png); background: transparent;"); break; } case REQ_USER_GET: { qDebug() << "void IShowMain::doResponse(int cmd,int code,QString ,QString)"; if(!GotyeMsg::Instance()->isLogin) GotyeMsg::Instance()->login(QString("%1").arg(_GlobalSetting.userInfo.uid)); //获取课程列表 QStringList params; params.append(QString("1")); params.append(QString("1")); IWebRequest::Instance()->sendRequestToServer(REQ_USER_COURSE_LIST_GET, params); headerImg = QCoreApplication::applicationDirPath()+"/img/"+_GlobalSetting.userHeadImg.file_name +_GlobalSetting.userHeadImg.ext; GotyeMsg::Instance()->setMyHeadImg(headerImg); GotyeMsg::Instance()->setMyUid(_GlobalSetting.userInfo.uid); qDebug() << "CMQ:show headerImg = "< 1 && file.exists()/* && file.size() == _GlobalSetting.userHeadImg.size*/) { ui->label_header_img->setPixmap(QPixmap(headerImg).scaled(54,54)); if(userInfoTip) userInfoTip->setHeaderImg(headerImg); } else { qDebug() << "CMQ:not found headerImg..."; IDownloadFile *downfile = IDownloadFile::Instance(); downfile->downloadFile(_GlobalSetting.userHeadImg.s_url, headerImg, _GlobalSetting.userHeadImg.file_id); } if(userInfoTip) { float evaluation_total = _GlobalSetting.teacher.evaluation_total/1.0; QString balance; balance.sprintf("%.2f", _GlobalSetting.credits.credits); uiHome->labelBalanceValue->setText(balance); userInfoTip->setName(_GlobalSetting.userInfo.user_name.section(' ', 0, 0)); if(evaluation_total > 0.001) userInfoTip->setEvaluation(evaluation_total/_GlobalSetting.teacher.evaluation_times); userInfoTip->setCallTime( _GlobalSetting.userInfo.call_time); qDebug("_GlobalSetting.userInfo.call_time %d...evaluation_total = %f\n",_GlobalSetting.userInfo.call_time,evaluation_total); } break; } //通话课程 case REQ_USER_COURSE_CALL_GET: { QJsonParseError jsonErr; QJsonDocument myjsonDoc1 = QJsonDocument::fromJson(result.toLatin1(),&jsonErr); QJsonArray pptarray = myjsonDoc1.object().find("result").value().toObject().find("ppt").value().toArray(); QJsonObject courseInfo = myjsonDoc1.object().find("result").value().toObject().find("courseInfo").value().toObject(); uiIncoming->course->show(); uiIncoming->course->setText(courseInfo.find("content").value().toString()); qDebug()<<"course: "<widgetLeft->hide(); stack->setCurrentIndex(ISTACK_INCOMING); break; } case REQ_USER_REMARK_GET: { QJsonParseError jsonErr; QJsonDocument myjsonDoc1 = QJsonDocument::fromJson(result.toLatin1(),&jsonErr); QJsonObject remark = myjsonDoc1.object().find("result").value().toObject().find("remark").value().toObject(); QString name = QString(""); if(remark.size()) name = myjsonDoc1.object().find("result").value().toObject().find("remark").value().\ toObject().find("remark_name").value().toString(); else name = myjsonDoc1.object().find("result").value().toObject().find("userInfo").value().\ toObject().find("user_name").value().toString(); qDebug()<<"result: "<label_name->setText(name); break; } case REQ_USER_ORDER_GET: { QJsonParseError jsonErr; QJsonDocument myjsonDoc1 = QJsonDocument::fromJson(result.toLatin1(),&jsonErr); QJsonObject order = myjsonDoc1.object().find("result").value().toObject().find("orderInfo").value().toObject(); theOrderRank.setOrder(order.find("money").value().toDouble()); theOrderRank.setHeaderImg(headerImg); } case REQ_USER_ORDER_EARNING_RANK: { QJsonParseError jsonErr; QJsonDocument myjsonDoc1 = QJsonDocument::fromJson(result.toLatin1(),&jsonErr); QJsonArray order = myjsonDoc1.object().find("result").value().toObject().find("lists").value().toArray(); theOrderRank.setEarningsRank(order); } default: break; } } void IShowMain::on_pushButtonOnline_clicked() { QStringList params; if(uiHome->pushButtonOnline2->text().contains("Online")) { //1:在线 2:忙碌 3:离线 params << "1"; IWebRequest::Instance()->sendRequestToServer(REQ_USER_ONLINE, params); } else { //1:在线 2:忙碌 3:离线 params << "3"; IWebRequest::Instance()->sendRequestToServer(REQ_USER_OFFLINE, params); } loadTimer->start(); uiHome->pushButtonOnline2->setText("Loading..."); uiHome->pushButtonOnline2->setEnabled(false); qDebug()<< "void IShowMain::on_pushButtonOnline_clicked()"; } void IShowMain::buttonChecked() { changeCurrentButton((QPushButton*)sender()); } void IShowMain::showSetting() { setting->show(); //WId id = setting->winId(); //showWindowFront(id); } void IShowMain::showWindowFront(WId id) { // bool ret = InitAPIVar() ; // if(ret) // { // AttachThreadInput(GetWindowThreadProcessId(GetForegroundWindow(), NULL), GetCurrentThreadId(), true) ; // SetForegroundWindow(id); // SetFocus(id) ; // AttachThreadInput(GetWindowThreadProcessId(GetForegroundWindow(), NULL), GetCurrentThreadId(), false) ; // } } void IShowMain::changeCurrentButton(QPushButton* button) { if(currentButton != NULL && button != NULL) { if(button != currentButton) { currentButton->setChecked(false); currentButton = button; } } currentButton->setChecked(true); } void IShowMain::showIncomingCall(const QString uid,const QString img,int course_id) { QString ortherheaderImg = QCoreApplication::applicationDirPath()+"/img/"+ QString(uid.toLatin1().data()) + ".jpg"; QFile file(ortherheaderImg); if(img.length() > 6 && !file.exists()) { IDownloadFile *downfile = IDownloadFile::Instance(); downfile->downloadFile(QUrl(img), ortherheaderImg, _GlobalSetting.userHeadImg.file_id); } uiIncoming->label_header->setPixmap(QPixmap(ortherheaderImg).scaled(140,140)); // uiIncoming->label_name->setText(name); QStringList getRemark; getRemark.append(uid); IWebRequest::Instance()->sendRequestToServer(REQ_USER_REMARK_GET, getRemark); if(course_id > 0) { QStringList params; params.append(QString("%1").arg(course_id)); IWebRequest::Instance()->sendRequestToServer(REQ_USER_COURSE_CALL_GET, params); qDebug()<<"CoursesId = "<widgetLeft->hide(); stack->setCurrentIndex(ISTACK_INCOMING); uiIncoming->course->hide(); } qDebug("CMQ fileName = %s filePath = %s course_id = %d",uid.toLatin1().data(),img.toLatin1().data(),course_id); } void IShowMain::overCallEnd(QString callId) { if(callId > 0) { m_callId = callId; QTimer::singleShot(3*1000,this,SLOT(getOrderEarningRank())); } qDebug()<<"overCallEnd callId = "<sendRequestToServer(REQ_USER_ORDER_GET, params); QStringList paramsRank; IWebRequest::Instance()->sendRequestToServer(REQ_USER_ORDER_EARNING_RANK, paramsRank); } void IShowMain::showHome() { stack->setCurrentIndex(ISTACK_HOME); StackItemNum = ISTACK_HOME; GotyeMsg::Instance()->setIsUpdata(false); } void IShowMain::showCourses() { stack->setCurrentIndex(ISTACK_COURSE); StackItemNum = ISTACK_COURSE; GotyeMsg::Instance()->setIsUpdata(false); ishowCourses->go_now_courses(); } void IShowMain::showStackItem() { ui->widgetLeft->show(); if(StackItemNum == ISTACK_HOME) showHome(); else if(StackItemNum == ISTACK_MESSAGE) showChatArea(); else if(StackItemNum == ISTACK_COURSE) showCourses(); } void IShowMain::delItemChat(QListWidgetItem *item) { GotyeMsg::Instance()->delItemChat(item); } void IShowMain::showChatArea() { stack->setCurrentIndex(ISTACK_MESSAGE); StackItemNum = ISTACK_MESSAGE; uiChatArea->textEdit->clear(); uiChatArea->textEdit->activateWindow(); uiChatArea->textEdit->setFocus(); GotyeMsg::Instance()->setShowMsgWebviwe(uiChatArea->webView); GotyeMsg::Instance()->setUpdataUserList(uiChatArea->listWidget); GotyeMsg::Instance()->setShowUserName(uiChatArea->label); GotyeMsg::Instance()->setIsUpdata(true); // if(atoi(nowUser.name.data()) > 0) GotyeMsg::Instance()->showLastChatArea(nowUser); GotyeMsg::Instance()->msgChatAreaInit(); qDebug("CMQ showChatArea...\n"); } void IShowMain::on_pushButtonDecline_clicked() { showStackItem(); emit repulseCalling();//拒绝来电 qDebug("CMQ repulseCalling...\n"); } void IShowMain::showNowChat() { nowUser = GotyeMsg::Instance()->setChooseUser(uiChatArea->listWidget->currentRow()); } void IShowMain::delgoty() { GotyeMsg::Instance()->apiist_exit(); } void IShowMain::on_pushButton_clicked() { // analysisJson(); if(GotyeMsg::Instance()->getNowUserName().toInt() == 0) return; if( uiChatArea->textEdit->toPlainText() == NULL ) { QMessageBox::warning( this , "warning","Message to be sent cannot be empty!" ); return; } //自己发送的消息 GotyeMsg::Instance()->sendMessage(QString(nowUser.name.data()),uiChatArea->textEdit->toPlainText(),GotyeMessageTypeText); // msgChatAreaInit();//刷新聊天列表 uiChatArea->textEdit->clear(); uiChatArea->textEdit->activateWindow(); uiChatArea->textEdit->setFocus(); } void IShowMain::on_pushButton_picture_clicked() { if(GotyeMsg::Instance()->getNowUserName().toInt() == 0) return; QFileDialog::Options options; //if (!native->isChecked()) options |= QFileDialog::DontUseNativeDialog; QString selectedFilter,openFilesPath; QStringList files = QFileDialog::getOpenFileNames( this, tr("QFileDialog::getOpenFileNames()"), openFilesPath, tr("Images (*.png *.bmp *.jpg)"), &selectedFilter, options); if (files.count()) { for(int i = 0;i < files.count();i++) { GotyeMsg::Instance()->sendMessage(QString("%1").arg(nowUser.name.data()), files[i],GotyeMessageTypeImage); qDebug("CMQ openFile = %s...\n",files[i].toLatin1().data()); // SendImageShow(files[i],Myhead); } } } bool IShowMain::eventFilter(QObject *obj, QEvent *e) { // Q_ASSERT(obj == inputTextEdit); if (e->type() == QEvent::KeyPress) { QKeyEvent *event = static_cast(e); if ((event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) && (event->modifiers() & Qt::ControlModifier)) { uiChatArea->textEdit->append(""); // on_pushButton_clicked(); //发送消息的槽 return true; } else if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) { on_pushButton_clicked(); //发送消息的槽 return true; } } return false; }