#include "InfoMainForm.h"
#include "ui_InfoMainForm.h"

InfoMainForm::InfoMainForm(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::InfoMainForm)
{
    ui->setupUi(this);

    initForm();
    initMenuList();
    initSubMenuForms();

    ui->wdgtPage->setCurrentIndex(0);
    ui->listMenu->setCurrentIndex(ui->listMenu->model()->index(0, 0));
}

InfoMainForm::~InfoMainForm()
{
    qDebug() << "~InfoMainForm";
    delete ui;
}

void InfoMainForm::initForm()
{
    // 加载样式表
    QString qssStyle = QssFileUtils::loadQssFileContent(":/qss/infoMain.css");
    if (qssStyle.isEmpty() == false) {
        this->setStyleSheet(qssStyle); // 仅本窗口生效
    }
}
void InfoMainForm::initMenuList()
{
    QStandardItemModel * model = new QStandardItemModel(ui->listMenu);
    QStringList menuLabelList;
    menuLabelList << "实验室任务" << "我的任务" << "新建任务单"
                  << "标准设备管理" << "被检设备管理"
                  << "检定数据管理" << "核查数据管理"
                  << "检定程序管理" << "核查程序管理"
                  << "体系文件" << "现行测试校准检定方法" << "签名管理" << "数据同步";
    int idxLabel = 0;
    for (QString label : menuLabelList) {
        QStandardItem * menu = new QStandardItem(label);
        menu->setData(idxLabel, Qt::UserRole);
        model->appendRow(menu);
        idxLabel++;
    }

    ui->listMenu->setModel(model);
}
void InfoMainForm::initSubMenuForms()
{
    fmMyTask = new MyTaskForm(this);
    fmDeptTask = new DeptTaskForm(this);
    fmNewTask = new NewTaskForm(this);

    ui->wdgtPage->insertWidget(0, fmDeptTask);
    ui->wdgtPage->insertWidget(1, fmMyTask);
    ui->wdgtPage->insertWidget(2, fmNewTask);
}

void InfoMainForm::on_listMenu_clicked(const QModelIndex &index)
{
    ui->wdgtPage->setCurrentIndex(index.data(Qt::UserRole).toInt());
}
