#include "page_main.h"
#include "ui_page_main.h"
#include <QDebug>
page_main::page_main(QWidget *parent) : BaseWindow(parent),
                                        ui(new Ui::page_main)
{
    ui->setupUi(this);
    fun_stacked_page_init();
}

page_main::~page_main()
{
    delete ui;
}

void page_main::on_logout_button_clicked()
{
    MessageDialog md(
        "确认退出", "退出系统后回到页面选择", MESSAGE_LEVEL_WARNING);
    int ret = md.exec();

    if (ret)
    {
        this->hide();
    }
}
// void page_main::closeEvent(QCloseEvent* e)
// {
//     (void)e;
//     MessageDialog md(
//         "确认关闭", "确认关闭系统？", MESSAGE_LEVEL_WARNING);
//     int ret = md.exec();

//     if(ret) {

//         e->accept();
//     }
//     else {
//         e->ignore();
//     }
// }
void page_main::btn_select_(int index)
{
    ui->btn_model_select->setChecked(false);
    ui->btn_chart_file->setChecked(false);
    ui->btn_database->setChecked(false);
    switch (index)
    {
    case 1:
        ui->btn_model_select->setChecked(true);
        break;
    case 2:
        ui->btn_chart_file->setChecked(true);
        break;
    case 3:
        ui->btn_database->setChecked(true);
        break;
    default:
        break;
    }
}

void page_main::fun_stacked_page_init()
{   
    qDebug() << "fun_stacked_page_init";
    page_model_select_ = new model_select();
    page_chart_file_= new chart_file();
    
    ui->fun_stacked_widget->addWidget(page_model_select_);
    ui->fun_stacked_widget->addWidget(page_chart_file_);
}
void page_main::on_btn_model_select_clicked()
{
    select_form_ = 1;
    qDebug() << "on_btn_model_select_clicked";
    qDebug() << "select_form_:" << select_form_;
    btn_select_(select_form_);
    ui->fun_stacked_widget->setCurrentIndex(select_form_-1);
}
void page_main::on_btn_chart_file_clicked()
{
    select_form_ = 2;
    if (page_chart_flag_==0)
    {page_chart_file_->setPointsNum(1);page_chart_flag_=1;}

    qDebug() << "on_btn_chart_file_clicked";
    qDebug() << "select_form_:" << select_form_;
    
    btn_select_(select_form_);
    ui->fun_stacked_widget->setCurrentIndex(select_form_-1);
}
