#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QStringList>
#include <QStringListModel>
#include <QFileDialog>

#define RESMAX 100

QStringList fileList;
QStringListModel *model ;
unsigned char rlbByte[16384000+1];//4M
unsigned char resByte[163840+1][RESMAX];//40k
unsigned char headByte[16384+1];//头部
int resId[RESMAX];
int resMax;
QString fileName[RESMAX];

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    model = new QStringListModel(fileList);
    ui->listView->setModel(model);
    resMax = 0;
}

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

void MainWindow::on_action_triggered()
{
    //添加
    QStringList fileNameList = QFileDialog::getOpenFileNames(this,tr("添加资源"),".","*.bmp",0);

    for(int i = 0; i < fileNameList.size(); i++)
    {
        QFileInfo fi;

        fi = QFileInfo(fileNameList[i]);
        fileName[resMax] = fi.fileName();
        QString file_name = QString::number(resMax+1, 10) + "-"+fileName[i];
        QString file_path = fi.absolutePath();

        fileList<<file_name;
        resMax++;
    }

    model = new QStringListModel(fileList);
    ui->listView->setModel(model);
}

void MainWindow::on_action_2_triggered()
{//删除
    model->removeRows(ui->listView->currentIndex().row(),1);
}

void MainWindow::on_action_3_triggered()
{
    //新建
    model->removeRows(0,model->rowCount());
    fileList.clear();
    resMax = 0;
}

void MainWindow::on_action_4_triggered()
{
    //保存
    QString fileName = QFileDialog::getSaveFileName(this,tr("保存"),".","*.rlb");

}

void MainWindow::on_action_5_triggered()
{
    //另存为
    QString fileName = QFileDialog::getSaveFileName(this,tr("另存为"),".","*.rlb");
}

void MainWindow::on_action_7_triggered()
{
    exit(0);
}

void MainWindow::on_action_6_triggered()
{
    fileList<<"NORES";
    fileName[resMax] ="NORES";
    model = new QStringListModel(fileList);
    ui->listView->setModel(model);

    resMax ++;
}
