ishowview.cpp 5.08 KB
#include "ishowview.h"
#include <QVBoxLayout>
#include <QPushButton>
#include "mainwindow.h"
#include "login/widgetLogon.h"
#include "ishowmain.h"
#include "iwebRequest.h"
#include "italkingwidget.h"
#include <QAction>
#include "justtalktest.h"
#include <QMessageBox>

#include <QJsonDocument>
#include <QJsonArray>
#include <QJsonValue>
#include <QJsonParseError>
#include <QJsonObject>


IShowView::IShowView(QWidget *parent, MainWindow *_gui):
    QStackedWidget(parent),
    gui(_gui)
{
    // Create tabs
    QVBoxLayout *vbox = new QVBoxLayout();
    QHBoxLayout *hbox_buttons = new QHBoxLayout();
    QPushButton *exportButton = new QPushButton(tr("&Export"), this);
    exportButton->setToolTip(tr("Export the data in the current tab to a file"));
    hbox_buttons->addStretch();
    hbox_buttons->addWidget(exportButton);
    vbox->addLayout(hbox_buttons);

    overviewPage = new IShowMain(this);//主页面
    this->hide();

    jstest = new JustTalkTest();
    connect(jstest, SIGNAL(justMessage(int)), _gui, SIGNAL(justMessage(int)));
    connect(jstest, SIGNAL(CallIncoming(const QString,const QString,int)), overviewPage, SLOT(showIncomingCall(const QString,const QString,int)));
    connect(jstest, SIGNAL(CallIncoming(const QString,const QString,int)), this, SLOT(showMaincalling()));

    talkingWidget = new ITalkingWidget(this);//通话界面
//    connect(overviewPage, SIGNAL(acceptCalling()), talkingWidget, SLOT(slotClickedBtnAnswer()));
    connect(overviewPage, SIGNAL(acceptCalling()), SLOT(acceptCallAnswer()));
    connect(overviewPage, SIGNAL(repulseCalling()), talkingWidget, SLOT(repulseCurrentCall()));
    connect(talkingWidget, SIGNAL(send_callTimeSec(int)), overviewPage, SLOT(review_create(int)));
//    connect(overviewPage, SIGNAL(repulseCalling()), talkingWidget, SLOT(slotClickedBtnEnd()));
    connect(jstest, SIGNAL(CallOutgoing(QString)), talkingWidget, SLOT(closeTheCurrentCall(QString)));
    connect(jstest, SIGNAL(CallOutgoing(QString)), overviewPage, SLOT(overCallEnd(QString)));
    connect(jstest, SIGNAL(videoReceive(bool)), talkingWidget, SLOT(otherVideoReceive(bool)));
    connect(jstest, SIGNAL(CallUiShow(int)), SLOT(showTalkingPage()));
    connect(jstest, SIGNAL(CallNetStrength(int)), talkingWidget, SLOT(CallNetChanged(int)));

    connect(overviewPage, SIGNAL(hideMain()), this, SLOT(hideMain()));
    connect(talkingWidget, SIGNAL(hideMain()), this, SLOT(hideMain()));
    connect(overviewPage, SIGNAL(showMainMax()), this, SLOT(showMainMaximized()));

    connect(talkingWidget, SIGNAL(stopCalling()), SLOT(hideTalkingPage()));
    //connect(talkingWidget, SIGNAL(stopCalling()), jstest, SIGNAL(closeClient()()));

    connect(jstest, SIGNAL(justLogouted(int)),this, SLOT(lodOut(int)));
    connect(IWebRequest::Instance(),SIGNAL(UseLogOut(int)),this, SLOT(lodOut(int)));

    addWidget(overviewPage);
    addWidget(talkingWidget);
    gotoOverviewPage();
}

IShowView::~IShowView()
{
    delete jstest;
    overviewPage->delgoty();
}
void IShowView::doResponse(int cmd,int,QString,QString)
{

}

void IShowView::lodOut(int flag)
{
    if(flag == 2)
    {
        QMessageBox::warning( this , "warning","Your account has been logged in on your phone." );

        qApp->exit(773);
    }
}

void IShowView::hideMain()
{
//    this->gui->hide();
    this->gui->showMinimized();
}

void IShowView::showMaincalling()
{
    if(this->gui->isMinimized())
    {
        this->gui->showMaximized();
        this->gui->showNormal();
    }
    else if(!this->gui->isVisible())
    {
        this->gui->show();
    }
}

void IShowView::showMainMaximized()
{
    if(this->gui->isMaximized())
    {
        this->gui->showNormal();
    }
    else
    {
        this->gui->showMaximized();
    }
}

void IShowView::setMainGUI(MainWindow *gui)
{
    this->gui = gui;
}

void IShowView::gotoOverviewPage()
{
    if(!overviewPage)
        return;
    gui->getOverviewAction()->setChecked(true);
    setCurrentWidget(overviewPage);
}

void IShowView::acceptCallAnswer()
{
    if(!talkingWidget)
        return;

    talkingWidget->slotClickedBtnAnswer();
    talkingWidget->stopLocalVideo();
    talkingWidget->startLocalVideo();
    talkingWidget->startRemoteVideo();
    if(talkingWidget->pptNmu == 0)
    {
        this->gui->showNormal();
        this->resize(QSize(1200,700));
        talkingWidget->initShowUI();
        setCurrentWidget(talkingWidget);
    }

}

void IShowView::showTalkingPage()
{
    if(!talkingWidget)
        return;
//    talkingWidget->slotClickedBtnAnswer();
    if(talkingWidget->pptNmu > 0)
    {
        this->gui->showNormal();
        this->resize(QSize(1200,700));
        talkingWidget->initShowUI();
        setCurrentWidget(talkingWidget);
    }
}

void IShowView::hideTalkingPage()
{
    talkingWidget->showSessTermed();
    RCallManager::Instance()->rmvSession(RCallManager::Instance()->m_pRSession);
    gotoOverviewPage();
    overviewPage->showStackItem();
    overviewPage->setPushButtonEnabled(true);
    qDebug("CMQ hideTalkingPage...\n");
}

void IShowView::on_pushButtonClose_clicked()
{
//    overviewPage->delgoty();
//    this->gui->close();
//    this->close();
//    qApp->exit();
    this->gui->hide();
}