742 lines
22 KiB
C++
742 lines
22 KiB
C++
#include "creatprintbmp.h"
|
||
|
||
CreatPrintBmp::CreatPrintBmp(QObject *parent) : QObject(parent)
|
||
{
|
||
m_savePath.clear();
|
||
m_workState = PAUSE;
|
||
m_beginPrintFileIdx = -1;
|
||
m_fileBegIdx = -1;
|
||
m_fileEndIdx = -1;
|
||
m_deleteFileIdx = -1;
|
||
m_curFileIdx = -1;//当前生成数据的文件索引
|
||
m_curBmpBlockIdx = -1;//当前生成数据的位图块数索引
|
||
m_mcPrintInfo = NULL;
|
||
m_conpressDir = 1;
|
||
m_printFileDir.clear();
|
||
m_moveFileIdx = -1;//上下移动打印文件索引
|
||
m_moveDir = 0;//-1,上移 1,下移
|
||
}
|
||
|
||
CreatPrintBmp::~CreatPrintBmp()
|
||
{
|
||
if(m_mcPrintInfo != NULL)
|
||
{
|
||
m_mcPrintInfo->clear();
|
||
delete m_mcPrintInfo;
|
||
}
|
||
}
|
||
|
||
int CreatPrintBmp::creatFileListMarker()
|
||
{
|
||
if(m_mcPrintInfo->m_loadFileFinishFlag < 0)
|
||
{
|
||
QString iniName = "MachineNo" + QString::number(m_mcPrintInfo->m_mcNum) + ".ini";
|
||
QDir apppath(qApp->applicationDirPath());
|
||
QString iniPath = apppath.path() + apppath.separator() + iniName;
|
||
QSettings setting(iniPath, QSettings::IniFormat); //QSettings能记录一些程序中的信息,下次再打开时可以读取出来
|
||
QString dirPath = setting.value("AutoPrintDir/fileDir").toString();
|
||
QDir dir(dirPath);
|
||
if(dir.exists())
|
||
{
|
||
QStringList filter;
|
||
filter << QString("*.plt") << QString("*.PLT")
|
||
<< QString("*.png") << QString("*.PNG")
|
||
<< QString("*.bmp") << QString("*.BMP")
|
||
<< QString("*.jpg") << QString("*.JPG");
|
||
QFileInfoList fileList = dir.entryInfoList(filter, QDir::Files | QDir::NoSymLinks);
|
||
|
||
for(int i = 0; i < fileList.size(); i++)
|
||
{
|
||
if(m_workState == WORK_PAUSE)
|
||
{
|
||
return -1;
|
||
}
|
||
|
||
//QCoreApplication::processEvents(QEventLoop::AllEvents);
|
||
|
||
QFileInfo fileInfo(fileList[i]);
|
||
QString filePath = fileInfo.filePath();
|
||
|
||
if(m_mcPrintInfo->m_filesList.size() > i)
|
||
{
|
||
//已经生成数据的跳过
|
||
if(m_mcPrintInfo->m_filesList[i].m_creatDataFlag != 1)
|
||
{
|
||
McFilesInfo curFilesInfo;//当前文件信息
|
||
creatMarkerDat(curFilesInfo,filePath,i);
|
||
long long fileTotalLength = (curFilesInfo.m_fileRect.right() - curFilesInfo.m_fileRect.left())/M_IDPMM;
|
||
m_mcPrintInfo->m_fileNums = i+1;
|
||
m_mcPrintInfo->m_fileTotalLength += fileTotalLength;
|
||
m_mcPrintInfo->m_filesList.append(curFilesInfo);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
McFilesInfo curFilesInfo;//当前文件信息
|
||
creatMarkerDat(curFilesInfo,filePath,i);
|
||
long long fileTotalLength = (curFilesInfo.m_fileRect.right() - curFilesInfo.m_fileRect.left())/M_IDPMM;
|
||
m_mcPrintInfo->m_fileNums = i+1;
|
||
m_mcPrintInfo->m_fileTotalLength += fileTotalLength;
|
||
m_mcPrintInfo->m_filesList.append(curFilesInfo);
|
||
}
|
||
}
|
||
m_mcPrintInfo->m_loadFileFinishFlag = 1;
|
||
}
|
||
}
|
||
|
||
QDir apppath(qApp->applicationDirPath());
|
||
QString printPath = apppath.path() + apppath.separator() + PRINTDIR;
|
||
QDir printDir(printPath);//总的打印目录
|
||
if(!printDir.exists())
|
||
{
|
||
printDir.mkdir(printPath);
|
||
}
|
||
QString mcFile = printPath + printDir.separator() + PRINTMCDIR + QString::number(m_mcPrintInfo->m_mcNum);
|
||
QDir mcDir(mcFile);//对应每台机器打印目录
|
||
if(!mcDir.exists())
|
||
{
|
||
mcDir.mkdir(mcFile);
|
||
}
|
||
|
||
return 0;
|
||
}
|
||
|
||
void CreatPrintBmp::creatMarkerDat(McFilesInfo &curFilesInfo, QString filePath, int fileIdx)
|
||
{
|
||
QFileInfo fileInfo(filePath);
|
||
curFilesInfo.m_marker.Initialize();
|
||
|
||
if(fileInfo.suffix().toUpper() == "PLT")
|
||
{
|
||
ImportHPGL importHPGL;
|
||
curFilesInfo.m_fileType = TYPE_FILE;
|
||
|
||
//判断是否为加密文件
|
||
if (importHPGL.IsSecretFile(filePath) == true)
|
||
{
|
||
// 文件路径
|
||
QString strSecretFile = m_printFileDir + QString::number(fileIdx+1) ;
|
||
|
||
QDir fileDir(strSecretFile);//对应每台机器的每个文件打印目录
|
||
if(!fileDir.exists())
|
||
{
|
||
fileDir.mkdir(strSecretFile);
|
||
}
|
||
strSecretFile = strSecretFile + fileDir.separator() + "Secret.plt";
|
||
//qDebug()<<"strSecretFile"<<strSecretFile;
|
||
|
||
importHPGL.BitMapDtat(filePath,strSecretFile);
|
||
importHPGL.IniPara();
|
||
importHPGL.ReadSecretFile(strSecretFile,&curFilesInfo.m_marker);
|
||
//qDebug()<<"importHPGL.IsSecretFile";
|
||
}
|
||
else
|
||
{
|
||
importHPGL.IniPara();
|
||
importHPGL.Read(filePath,&curFilesInfo.m_marker);
|
||
}
|
||
curFilesInfo.m_fileRect = curFilesInfo.m_marker.GetRect();
|
||
}
|
||
else
|
||
{
|
||
curFilesInfo.m_fileType = TYPE_IMAGE;
|
||
QBitmap pixmap;
|
||
pixmap.load(filePath);
|
||
QRect rect;
|
||
rect.setRect(0,0,pixmap.width()/MMPIXELY*M_IDPMM,pixmap.height()/MMPIXELY*M_IDPMM);
|
||
|
||
curFilesInfo.m_pixmap = pixmap;
|
||
curFilesInfo.m_fileRect = rect;
|
||
}
|
||
|
||
curFilesInfo.m_filePath = filePath;
|
||
curFilesInfo.m_fileName = fileInfo.fileName();
|
||
curFilesInfo.m_printNum = 1;
|
||
curFilesInfo.m_startPoint = 0;
|
||
curFilesInfo.m_printState = tr("Waitting");
|
||
curFilesInfo.m_curPrintBlock = 0;//当前打印块数
|
||
curFilesInfo.m_printedBlockNum = 0;//已打印块数
|
||
curFilesInfo.m_selectBlockNum = 0;//当前选择块数
|
||
curFilesInfo.m_creatDataFlag = 1;
|
||
}
|
||
|
||
QPicture CreatPrintBmp::getPicture(Marker marker, int penWidth)
|
||
{
|
||
QPicture pic;
|
||
CBitmapInfo bitmapInfo;
|
||
QPainterPath painterPath;
|
||
QRect rect = marker.GetRect();
|
||
int minX = rect.left();
|
||
int minY = rect.top();
|
||
int maxY = rect.bottom();
|
||
|
||
int nLineCount = marker.m_listPolyline.size();
|
||
for(int i = 0; i < nLineCount; i++)
|
||
{
|
||
CRPPolyline polyLine = marker.m_listPolyline.at(i);
|
||
int type = polyLine.m_nDrawingType;
|
||
|
||
if(type == 0)//直线
|
||
{
|
||
int nPointCount = polyLine.m_listPoint.size();
|
||
for(int j = 0; j < nPointCount; j++)
|
||
{
|
||
double x = (polyLine.m_listPoint.at(j).x() - minX)/(double)M_IDPMM*MMPIXELY;
|
||
double y = ((0 - (polyLine.m_listPoint.at(j).y() - minY))+(maxY-minY))/(double)M_IDPMM*MMPIXELY;
|
||
QPointF point(x,y);
|
||
|
||
if(j == 0)
|
||
{
|
||
painterPath.moveTo(point);
|
||
}
|
||
else
|
||
{
|
||
painterPath.lineTo(point);
|
||
}
|
||
}
|
||
}
|
||
else if(type == 1)//位图
|
||
{
|
||
bitmapInfo = polyLine.m_bitmapInfo;
|
||
int x = bitmapInfo.m_ptAbPostLU.x();
|
||
int y = bitmapInfo.m_ptAbPostLU.y();
|
||
|
||
int nx = (x - minX)/M_IDPMM*MMPIXELY;
|
||
int ny = ((0 - (y - minY))+(maxY-minY))/M_IDPMM*MMPIXELY;
|
||
|
||
bitmapInfo.m_ptAbPostLU.setX(nx);
|
||
bitmapInfo.m_ptAbPostLU.setY(ny);
|
||
}
|
||
}
|
||
|
||
if(painterPath.isEmpty())
|
||
{
|
||
qDebug()<<"painterPath isEmpty";
|
||
}
|
||
|
||
//将路径画在picture上
|
||
QPen pen;
|
||
pen.setWidth(penWidth);//设置笔号
|
||
pen.setColor(QColor(Qt::black));
|
||
|
||
QPainter painter;
|
||
painter.begin(&pic);
|
||
painter.setPen(pen);
|
||
painter.drawPath(painterPath);
|
||
if(bitmapInfo.m_iBytes > 0)//有位图
|
||
{
|
||
painter.drawPixmap(bitmapInfo.m_ptAbPostLU.x(),bitmapInfo.m_ptAbPostLU.y(),bitmapInfo.m_pBitmap);
|
||
}
|
||
painter.end();
|
||
return pic;
|
||
}
|
||
|
||
int CreatPrintBmp::creatFileListDatAndSend(int idx)
|
||
{
|
||
if(idx >= m_mcPrintInfo->m_filesList.size())
|
||
{
|
||
return 1;
|
||
}
|
||
|
||
McFilesInfo curFilesInfo;
|
||
|
||
if(m_workState == WORK_PAUSE)
|
||
{
|
||
return -1;
|
||
}
|
||
|
||
curFilesInfo = m_mcPrintInfo->m_filesList[idx];
|
||
QString filePath = m_printFileDir + QString::number(idx+1);
|
||
QDir fileDir(filePath);//对应每台机器的每个文件打印目录
|
||
if(!fileDir.exists())
|
||
{
|
||
fileDir.mkdir(filePath);
|
||
}
|
||
filePath = filePath + fileDir.separator();
|
||
|
||
if(curFilesInfo.m_creatDataFlag < 0)
|
||
{
|
||
creatMarkerDat(curFilesInfo,m_mcPrintInfo->m_filesList[idx].m_filePath,idx);
|
||
m_mcPrintInfo->m_filesList[idx] = curFilesInfo;
|
||
}
|
||
|
||
QPicture pic;
|
||
QPen pen;
|
||
pen.setWidth(1);
|
||
pen.setColor(QColor(Qt::black));
|
||
|
||
int oft = 0;//起始打印位置的偏移
|
||
if(curFilesInfo.m_fileType == TYPE_FILE)
|
||
{
|
||
//画笔宽度不为1时重画
|
||
if(PENWIDTH != 1)
|
||
{
|
||
pic = getPicture(curFilesInfo.m_marker,PENWIDTH);
|
||
}
|
||
else
|
||
{
|
||
pic = m_mcPrintInfo->m_filesList[idx].m_pic;
|
||
}
|
||
|
||
oft = (int)(m_mcPrintInfo->m_filesList[idx].m_startPoint*MMPIXELY);
|
||
//将picture保存为多个宽度为PIXMAPWIDTH像素的bmp
|
||
m_mcPrintInfo->m_totalNums = (pic.width() - oft) / PIXMAPWIDTH;
|
||
int lwidth = (pic.width() - oft) % (PIXMAPWIDTH);
|
||
if(lwidth != 0)
|
||
{
|
||
m_mcPrintInfo->m_totalNums += 1;
|
||
}
|
||
}
|
||
else if(curFilesInfo.m_fileType == TYPE_IMAGE)
|
||
{
|
||
//将图片画在picture上
|
||
QPainter painter;
|
||
painter.begin(&pic);
|
||
painter.setPen(pen);
|
||
painter.drawPixmap(0,0,m_mcPrintInfo->m_filesList[idx].m_pixmap);
|
||
painter.end();
|
||
|
||
//将pixmap保存为多个宽度为PIXMAPWIDTH像素的bmp
|
||
m_mcPrintInfo->m_totalNums = curFilesInfo.m_pixmap.width() / PIXMAPWIDTH;
|
||
int lwidth = curFilesInfo.m_pixmap.width() % PIXMAPWIDTH;
|
||
if(lwidth != 0)
|
||
{
|
||
m_mcPrintInfo->m_totalNums += 1;
|
||
}
|
||
}
|
||
m_mcPrintInfo->m_filesList[idx].m_pic = pic;
|
||
m_mcPrintInfo->m_filesList[idx].m_totalBlocks = (pic.width() - oft)/ PIXMAPWIDTH;
|
||
|
||
//发送文件列表数据
|
||
emit siSendFileListDatToMc(idx);
|
||
return 0;
|
||
}
|
||
|
||
int CreatPrintBmp::creatBmpBlockDatAndSend(int idx)
|
||
{
|
||
QPen pen;
|
||
pen.setWidth(1);
|
||
pen.setColor(QColor(Qt::black));
|
||
|
||
int nextNum = idx / m_mcPrintInfo->m_filesList[m_curFileIdx].m_totalBlocks;
|
||
if((idx % m_mcPrintInfo->m_filesList[m_curFileIdx].m_totalBlocks) == 0)
|
||
{
|
||
idx = 0;
|
||
}
|
||
|
||
QPicture pic = m_mcPrintInfo->m_filesList[m_curFileIdx].m_pic;
|
||
int oft = (int)(m_mcPrintInfo->m_filesList[m_curFileIdx].m_startPoint*MMPIXELY);
|
||
|
||
//将picture保存为多个宽度为PIXMAPWIDTH像素的bmp
|
||
int num = (pic.width() - oft) / PIXMAPWIDTH;
|
||
int lwidth = (pic.width() - oft) % PIXMAPWIDTH;
|
||
int height = pic.height();
|
||
int offset = 0 - idx * PIXMAPWIDTH + oft;//将picture画在bmp上每次的偏移量,bmp的最大尺寸为u16
|
||
|
||
if(lwidth != 0)
|
||
{
|
||
num += 1;
|
||
}
|
||
|
||
QBitmap *pixmap = new QBitmap(PIXMAPWIDTH,height);
|
||
QPainter *pixPainter = new QPainter();
|
||
pixPainter->begin(pixmap);
|
||
pixPainter->setPen(pen);
|
||
|
||
QString filePath = m_printFileDir + QString::number(m_curFileIdx+1);
|
||
QDir fileDir(filePath);//对应每台机器的每个文件打印目录
|
||
if(!fileDir.exists())
|
||
{
|
||
fileDir.mkdir(filePath);
|
||
}
|
||
filePath = filePath + fileDir.separator();
|
||
|
||
pixmap->fill(Qt::white);//用白色填充
|
||
pixPainter->drawPicture(offset,0,pic);
|
||
|
||
QString path = filePath+QString::number(idx+nextNum*m_mcPrintInfo->m_filesList[m_curFileIdx].m_totalBlocks+1)+".bmp";
|
||
bool bls = pixmap->save(path);
|
||
while(bls == false)
|
||
{
|
||
bls = pixmap->save(path);
|
||
qDebug()<<"pixmap save failed";
|
||
}
|
||
|
||
//压缩位图
|
||
BWBmp bwBmp;
|
||
int rslt;
|
||
|
||
rslt = bwBmp.LoadBiBmp(path);
|
||
if (rslt != 0)
|
||
{
|
||
qDebug() << "open file error" << path;
|
||
return -1;
|
||
}
|
||
rslt = bwBmp.Compress(m_conpressDir);
|
||
if (rslt != 0)
|
||
{
|
||
qDebug() << "Compress error";
|
||
return -1;
|
||
}
|
||
|
||
rslt = bwBmp.SavePrBmp(path+".prbmp");
|
||
if (rslt != 0)
|
||
{
|
||
qDebug() << "save prbmp error";
|
||
return -1;
|
||
}
|
||
QByteArray dat = bwBmp.getPrBmpDat();
|
||
|
||
//发送文件
|
||
BmpDatInfo bmpInfo;
|
||
memset(&bmpInfo,0,sizeof(BmpDatInfo));
|
||
bmpInfo.blkIdx = idx;
|
||
bmpInfo.biWidth = pixmap->width();
|
||
bmpInfo.biHeight = pixmap->height();
|
||
bmpInfo.begPosY = idx * pixmap->width();
|
||
bmpInfo.endPosY = (idx+1) * pixmap->width();
|
||
if(m_conpressDir == -1)
|
||
{
|
||
bmpInfo.compDir = 0;
|
||
}
|
||
else
|
||
{
|
||
bmpInfo.compDir = 1;
|
||
}
|
||
//qDebug()<<"dat.size()"<<dat.size();
|
||
emit siSendDatToMc(dat, bmpInfo);
|
||
m_mcPrintInfo->m_sendedlNums++;
|
||
|
||
pixPainter->end();
|
||
|
||
bool bla = pixPainter->isActive();
|
||
while(bla == true)
|
||
{
|
||
bla = pixPainter->isActive();
|
||
qDebug()<<"pixPainter isActive";
|
||
}
|
||
|
||
delete pixmap;
|
||
delete pixPainter;
|
||
return 0;
|
||
}
|
||
|
||
void CreatPrintBmp::slotCreatBmp()
|
||
{
|
||
#if(1)
|
||
int val = creatFileListMarker();
|
||
if(val < 0)
|
||
{
|
||
return;
|
||
}
|
||
|
||
val = creatFileListDatAndSend(m_curFileIdx);
|
||
if(val < 0)
|
||
{
|
||
return;
|
||
}
|
||
#else
|
||
QPen pen;
|
||
pen.setWidth(1);
|
||
pen.setColor(QColor(Qt::black));
|
||
|
||
//将picture保存为多个宽度为PIXMAPWIDTH像素的bmp
|
||
int num = m_picture.width() / PIXMAPWIDTH;
|
||
int lwidth = m_picture.width() % PIXMAPWIDTH;
|
||
int height = m_picture.height();
|
||
int offset = 0;
|
||
|
||
if(lwidth != 0)
|
||
{
|
||
num += 1;
|
||
}
|
||
|
||
QBitmap *pixmap = new QBitmap(PIXMAPWIDTH,height);
|
||
QPainter *pixPainter = new QPainter();
|
||
pixPainter->begin(pixmap);
|
||
pixPainter->setPen(pen);
|
||
|
||
for(int i = 0 ; i < num; i++)
|
||
{
|
||
pixmap->fill(Qt::white);//用白色填充
|
||
pixPainter->drawPicture(offset,0,m_picture);
|
||
offset -= PIXMAPWIDTH;
|
||
|
||
QString path = m_savePath+QString::number(i+1)+".bmp";
|
||
bool bls = pixmap->save(path);
|
||
while(bls == false)
|
||
{
|
||
bls = pixmap->save(path);
|
||
qDebug()<<"pixmap save failed";
|
||
}
|
||
|
||
//压缩位图
|
||
BWBmp bwBmp;
|
||
int rslt;
|
||
|
||
rslt = bwBmp.LoadBiBmp(path);
|
||
if (rslt != 0)
|
||
{
|
||
qDebug() << "open file error" << path;
|
||
break;
|
||
}
|
||
rslt = bwBmp.Compress();
|
||
if (rslt != 0)
|
||
{
|
||
qDebug() << "Compress error";
|
||
break;
|
||
}
|
||
|
||
rslt = bwBmp.SavePrBmp(path+".prbmp");
|
||
if (rslt != 0)
|
||
{
|
||
qDebug() << "save prbmp error";
|
||
break;
|
||
}
|
||
QByteArray dat = bwBmp.getPrBmpDat();
|
||
siCreatOneBmpFinished((unsigned char*)dat.data(),dat.size());
|
||
}
|
||
|
||
pixPainter->end();
|
||
|
||
bool bla = pixPainter->isActive();
|
||
while(bla == true)
|
||
{
|
||
bla = pixPainter->isActive();
|
||
qDebug()<<"pixPainter isActive";
|
||
}
|
||
|
||
delete pixmap;
|
||
delete pixPainter;
|
||
#endif
|
||
}
|
||
|
||
void CreatPrintBmp::slotCreatNextBmpBlockDat()
|
||
{
|
||
//非正在打印的文件,正在发送文件时的删除操作
|
||
if(m_deleteFileIdx != m_curFileIdx && m_deleteFileIdx != -1)
|
||
{
|
||
int length = (m_mcPrintInfo->m_filesList[m_deleteFileIdx].m_fileRect.right() - m_mcPrintInfo->m_filesList[m_deleteFileIdx].m_fileRect.left())/M_IDPMM;
|
||
m_mcPrintInfo->m_fileTotalLength -= length;
|
||
m_mcPrintInfo->m_filesList[m_deleteFileIdx].clear();
|
||
m_mcPrintInfo->m_filesList.removeAt(m_deleteFileIdx);
|
||
QString mcFile = m_printFileDir + QString::number(m_deleteFileIdx+1);
|
||
QDir fileDir(mcFile);
|
||
if(fileDir.exists())//理论上无此条件
|
||
{
|
||
//删除位图文件夹
|
||
QFileInfoList fileList = fileDir.entryInfoList(QDir::Files);
|
||
for(int i = 0; i < fileList.size(); i++)
|
||
{
|
||
QString fileStr = fileList[i].filePath();
|
||
QFile::remove(fileStr);
|
||
}
|
||
fileDir.rmdir(mcFile);
|
||
}
|
||
|
||
if(m_deleteFileIdx < m_curFileIdx)//理论上无此条件
|
||
{
|
||
QString oldName = m_printFileDir + QString::number(m_curFileIdx+1);
|
||
QDir dir(oldName);
|
||
m_curFileIdx--;
|
||
QString newName = m_printFileDir + QString::number(m_curFileIdx+1);
|
||
dir.rename(oldName,newName);
|
||
}
|
||
|
||
m_mcPrintInfo->m_fileNums = m_mcPrintInfo->m_filesList.size();
|
||
m_deleteFileIdx = -1;
|
||
emit siDeleteFileFinish();
|
||
}
|
||
|
||
//非正在打印的文件,正在发送文件时的上下移操作
|
||
if(m_moveFileIdx != m_curFileIdx && m_moveFileIdx != -1 && m_moveDir != 0)
|
||
{
|
||
//交换列表
|
||
McFilesInfo info = m_mcPrintInfo->m_filesList[m_moveFileIdx];
|
||
McFilesInfo cInfo;
|
||
cInfo = m_mcPrintInfo->m_filesList[m_moveFileIdx+m_moveDir];
|
||
m_mcPrintInfo->m_filesList[m_moveFileIdx+m_moveDir] = info;
|
||
m_mcPrintInfo->m_filesList[m_moveFileIdx] = cInfo;
|
||
|
||
//更换位图文件夹的名称
|
||
//判断当前交换的文件夹是否存在
|
||
QString mcFile = m_printFileDir + QString::number(m_moveFileIdx+1);
|
||
QDir fileDir(mcFile);
|
||
if(fileDir.exists())//理论上无此条件
|
||
{
|
||
//对当前选中文件夹重命名
|
||
QString oldName = mcFile;
|
||
QString newName = mcFile.left(mcFile.size()-1);
|
||
fileDir.rename(oldName,newName);
|
||
|
||
int cRow = m_moveFileIdx + m_moveDir;
|
||
QString mcFile1 = m_printFileDir + QString::number(cRow+1);
|
||
QDir fileDir1(mcFile1);
|
||
|
||
//对要交换的文件夹重命名
|
||
oldName = mcFile1;
|
||
newName = mcFile;
|
||
fileDir1.rename(oldName,newName);
|
||
|
||
//再对选中的文件夹重命名
|
||
QString mcFile2 = mcFile.left(mcFile.size()-1);
|
||
QDir fileDir2(mcFile1);
|
||
oldName = mcFile2;
|
||
newName = mcFile1;
|
||
fileDir2.rename(oldName,newName);
|
||
}
|
||
|
||
m_moveFileIdx = -1;
|
||
m_moveDir = 0;
|
||
}
|
||
|
||
m_curBmpBlockIdx++;//一个文件可分为若干个位图块,位图块索引++
|
||
if(m_curBmpBlockIdx < 0)
|
||
{
|
||
m_curBmpBlockIdx = 0;
|
||
}
|
||
|
||
if(m_curBmpBlockIdx >= m_mcPrintInfo->m_filesList[m_curFileIdx].m_totalBlocks * m_mcPrintInfo->m_filesList[m_curFileIdx].m_printNum)
|
||
{
|
||
m_curFileIdx++;//文件索引++
|
||
creatFileListDatAndSend(m_curFileIdx);
|
||
m_curBmpBlockIdx = -1;
|
||
return;
|
||
}
|
||
|
||
creatBmpBlockDatAndSend(m_curBmpBlockIdx);
|
||
m_conpressDir *= -1;
|
||
}
|
||
|
||
void CreatPrintBmp::setPicture(QPicture pic)
|
||
{
|
||
m_picture = pic;
|
||
}
|
||
|
||
void CreatPrintBmp::setPicture(QBitmap bitmap)
|
||
{
|
||
//将图片画在picture上
|
||
QPicture pic;
|
||
QPen pen;
|
||
pen.setWidth(1);//设置笔号
|
||
pen.setColor(QColor(Qt::black));
|
||
|
||
QPainter painter;
|
||
painter.begin(&pic);
|
||
painter.setPen(pen);
|
||
painter.drawPixmap(0,0,bitmap);
|
||
painter.end();
|
||
m_picture = pic;
|
||
}
|
||
|
||
void CreatPrintBmp::setSavePath(QString path)
|
||
{
|
||
m_savePath.clear();
|
||
m_savePath = path;
|
||
}
|
||
|
||
QString CreatPrintBmp::getSavePath()
|
||
{
|
||
return m_savePath;
|
||
}
|
||
|
||
void CreatPrintBmp::setMcPrintInfo(int fileIdx, McPrintInfo *printInfo)
|
||
{
|
||
m_mcPrintInfo = printInfo;
|
||
|
||
if(fileIdx < 0)
|
||
{
|
||
m_fileBegIdx = 0;
|
||
}
|
||
else
|
||
{
|
||
m_fileBegIdx = fileIdx;
|
||
}
|
||
|
||
//自动打印
|
||
int autoPrint = 1;
|
||
|
||
if(autoPrint == 1)
|
||
{
|
||
m_fileEndIdx = m_mcPrintInfo->m_filesList.size();
|
||
}
|
||
else
|
||
{
|
||
m_fileEndIdx = m_fileBegIdx + 1;
|
||
}
|
||
|
||
m_curFileIdx = m_fileBegIdx;
|
||
|
||
QDir apppath(qApp->applicationDirPath());
|
||
QString printPath = apppath.path() + apppath.separator() + PRINTDIR;
|
||
QString mcFile = printPath + apppath.separator() + PRINTMCDIR + QString::number(m_mcPrintInfo->m_mcNum);
|
||
m_printFileDir = mcFile + apppath.separator() + PRINTFILEDIR;
|
||
}
|
||
|
||
void CreatPrintBmp::setDeleteFile(int fileIdx)
|
||
{
|
||
if(fileIdx == m_curFileIdx)
|
||
{
|
||
return;
|
||
}
|
||
m_deleteFileIdx = fileIdx;
|
||
//空闲时的删除文件操作
|
||
if(m_mcPrintInfo->m_mcWorkState == NotBusy)
|
||
{
|
||
int length = (m_mcPrintInfo->m_filesList[m_deleteFileIdx].m_fileRect.right() - m_mcPrintInfo->m_filesList[m_deleteFileIdx].m_fileRect.left())/M_IDPMM;
|
||
m_mcPrintInfo->m_fileTotalLength -= length;
|
||
m_mcPrintInfo->m_filesList[m_deleteFileIdx].clear();
|
||
m_mcPrintInfo->m_filesList.removeAt(m_deleteFileIdx);
|
||
QString mcFile = m_printFileDir + QString::number(m_deleteFileIdx+1);
|
||
QDir fileDir(mcFile);
|
||
if(fileDir.exists())
|
||
{
|
||
//删除位图文件夹
|
||
QFileInfoList fileList = fileDir.entryInfoList(QDir::Files);
|
||
for(int i = 0; i < fileList.size(); i++)
|
||
{
|
||
QString fileStr = fileList[i].filePath();
|
||
QFile::remove(fileStr);
|
||
}
|
||
fileDir.rmdir(mcFile);
|
||
}
|
||
|
||
m_mcPrintInfo->m_fileNums = m_mcPrintInfo->m_filesList.size();
|
||
m_deleteFileIdx = -1;
|
||
emit siDeleteFileFinish();
|
||
}
|
||
}
|
||
|
||
void CreatPrintBmp::setMoveFile(int fileIdx, int dir)
|
||
{
|
||
if(fileIdx == m_curFileIdx)
|
||
{
|
||
return;
|
||
}
|
||
m_moveFileIdx = fileIdx;//上下移动打印文件索引
|
||
m_moveDir = dir;//-1,上移 1,下移
|
||
|
||
//空闲时的移动文件操作
|
||
if(m_mcPrintInfo->m_mcWorkState == NotBusy)
|
||
{
|
||
//交换列表
|
||
McFilesInfo info = m_mcPrintInfo->m_filesList[fileIdx];
|
||
McFilesInfo cInfo;
|
||
if(dir == -1)
|
||
{
|
||
cInfo = m_mcPrintInfo->m_filesList[fileIdx-1];
|
||
m_mcPrintInfo->m_filesList[fileIdx-1] = info;
|
||
}
|
||
else
|
||
{
|
||
cInfo = m_mcPrintInfo->m_filesList[fileIdx+1];
|
||
m_mcPrintInfo->m_filesList[fileIdx+1] = info;
|
||
}
|
||
|
||
m_mcPrintInfo->m_filesList[fileIdx] = cInfo;
|
||
|
||
m_moveFileIdx = -1;//上下移动打印文件索引
|
||
m_moveDir = 0;//-1,上移 1,下移
|
||
}
|
||
}
|