1590 lines
48 KiB
C++
1590 lines
48 KiB
C++
#include "patternmanagewidget.h"
|
||
#include "ui_patternmanagewidget.h"
|
||
|
||
PatternManageWidget::PatternManageWidget(QWidget *parent) :
|
||
QWidget(parent),
|
||
ui(new Ui::PatternManageWidget),
|
||
m_itemPerPage(22)
|
||
{
|
||
ui->setupUi(this);
|
||
setWindowFlags (Qt::Window | Qt::FramelessWindowHint);
|
||
setWindowModality(Qt::ApplicationModal);
|
||
|
||
m_itemBtnList.clear();
|
||
//左侧
|
||
m_itemBtnList.append(ui->button1);
|
||
m_itemBtnList.append(ui->button2);
|
||
m_itemBtnList.append(ui->button3);
|
||
m_itemBtnList.append(ui->button4);
|
||
m_itemBtnList.append(ui->button5);
|
||
|
||
ui->button6->setVisible(false);//隐藏
|
||
ui->button7->setVisible(false);
|
||
ui->button8->setVisible(false);
|
||
ui->button9->setVisible(false);
|
||
ui->button10->setVisible(false);
|
||
ui->button11->setVisible(false);
|
||
|
||
if(g_emResolut == resolution1910)//1920x1080的分辨率每页左侧显示12个条目
|
||
{
|
||
ui->button6->setVisible(true);
|
||
ui->button7->setVisible(true);
|
||
ui->button8->setVisible(true);
|
||
ui->button9->setVisible(true);
|
||
ui->button10->setVisible(true);
|
||
ui->button11->setVisible(true);
|
||
m_itemBtnList.append(ui->button6);
|
||
m_itemBtnList.append(ui->button7);
|
||
m_itemBtnList.append(ui->button8);
|
||
m_itemBtnList.append(ui->button9);
|
||
m_itemBtnList.append(ui->button10);
|
||
m_itemBtnList.append(ui->button11);
|
||
}
|
||
else if(g_emResolut == resolution1006)//1024x600的分辨率每页显示8个条目
|
||
{
|
||
ui->button6->setVisible(true);//显示
|
||
ui->button7->setVisible(true);
|
||
ui->button8->setVisible(true);
|
||
m_itemBtnList.append(ui->button6);
|
||
m_itemBtnList.append(ui->button7);
|
||
m_itemBtnList.append(ui->button8);
|
||
}
|
||
|
||
//右侧
|
||
m_itemBtnList.append(ui->button12);
|
||
m_itemBtnList.append(ui->button13);
|
||
m_itemBtnList.append(ui->button14);
|
||
m_itemBtnList.append(ui->button15);
|
||
m_itemBtnList.append(ui->button16);
|
||
ui->button17->setVisible(false);//隐藏
|
||
ui->button18->setVisible(false);
|
||
ui->button19->setVisible(false);
|
||
ui->button20->setVisible(false);
|
||
ui->button21->setVisible(false);
|
||
ui->button22->setVisible(false);
|
||
|
||
if(g_emResolut == resolution1910)//1920x1080的分辨率每页右侧显示12个条目
|
||
{
|
||
ui->button17->setVisible(true);
|
||
ui->button18->setVisible(true);
|
||
ui->button19->setVisible(true);
|
||
ui->button20->setVisible(true);
|
||
ui->button21->setVisible(true);
|
||
ui->button22->setVisible(true);
|
||
m_itemBtnList.append(ui->button17);
|
||
m_itemBtnList.append(ui->button18);
|
||
m_itemBtnList.append(ui->button19);
|
||
m_itemBtnList.append(ui->button20);
|
||
m_itemBtnList.append(ui->button21);
|
||
m_itemBtnList.append(ui->button22);
|
||
}
|
||
else if(g_emResolut == resolution1006)//1024x600的分辨率每页显示8个条目
|
||
{
|
||
ui->button17->setVisible(true);
|
||
ui->button18->setVisible(true);
|
||
ui->button19->setVisible(true);
|
||
m_itemBtnList.append(ui->button17);
|
||
m_itemBtnList.append(ui->button18);
|
||
m_itemBtnList.append(ui->button19);
|
||
}
|
||
|
||
initControl();
|
||
initialize();
|
||
}
|
||
|
||
PatternManageWidget::~PatternManageWidget()
|
||
{
|
||
delete ui;
|
||
}
|
||
|
||
//初始化
|
||
void PatternManageWidget::initialize()
|
||
{
|
||
m_curPages = 1;
|
||
m_pageNums = 1;
|
||
m_fileItemList.clear();//文件列表清空
|
||
m_selectFileItemList.clear();
|
||
m_rootPath.clear();//操作屏根路径
|
||
m_curPath.clear();//当前路径
|
||
m_selectAll = -1;
|
||
|
||
QDir apppath(qApp->applicationDirPath());
|
||
QString filePath = apppath.path() + apppath.separator() + PATTERNPATH;
|
||
m_rootPath = QDir(filePath).absolutePath();//为了将"\"变为"/"
|
||
}
|
||
|
||
//初始化窗体控件,包括位置、尺寸、样式
|
||
void PatternManageWidget::initControl()
|
||
{
|
||
//根据不同分辨率设置控件的位置和尺寸
|
||
switch (g_emResolut)
|
||
{
|
||
case resolution1910:
|
||
initResolution1910();
|
||
break;
|
||
case resolution1006:
|
||
initResolution1006();
|
||
break;
|
||
default:
|
||
this->resize(1920,1080);
|
||
break;
|
||
}
|
||
initControlStyle();//初始化窗体控件样式
|
||
}
|
||
|
||
//初始化窗体控件为1920x1080分辨率
|
||
void PatternManageWidget::initResolution1910()
|
||
{
|
||
this->resize(1920,1080);
|
||
ui->frameBack->setGeometry(0,0,1920,1080);
|
||
ui->buttonTypeLogo->setGeometry(128,66,78,78);
|
||
ui->labelMainTitle->setGeometry(226,60,1000,44);
|
||
ui->labelSubTitle->setGeometry(302,112,1000,36);
|
||
ui->labelPage->setGeometry(48,0,200,70);
|
||
ui->labelPage->setAlignment(Qt::AlignLeft);
|
||
|
||
QRect rectImage(0,0,56,56);
|
||
QRect rectName(58,0,592,56);
|
||
for(int i = 0; i < 2; i++)
|
||
{
|
||
s16 num = m_itemBtnList.size()/2;
|
||
for(int j = 0; j < num; j++)
|
||
{
|
||
m_itemBtnList[i*num + j]->setLabelFont(fontNormal_1);
|
||
m_itemBtnList[i*num + j]->setGeometry(82+i*700,211+j*64,642,56);
|
||
m_itemBtnList[i*num + j]->initLeftImageRightName(rectImage,rectName);
|
||
}
|
||
}
|
||
|
||
ui->frameRightUp->setGeometry(1468,92,406,72);
|
||
ui->buttonBackUpDir->setGeometry(340,0,66,66);
|
||
ui->buttonSelectAll->setGeometry(252,0,66,66);
|
||
ui->buttonNewFolder->setGeometry(252,0,66,66);
|
||
ui->labelPatternView->setGeometry(1566,250,242,242);
|
||
|
||
ui->labelNameValue->setGeometry(1538,564,200,32);
|
||
ui->labelX->setGeometry(1538,604,32,32);
|
||
ui->labelXValue->setGeometry(1680,604,174,32);
|
||
ui->labelY->setGeometry(1538,644,32,32);
|
||
ui->labelYValue->setGeometry(1680,644,174,32);
|
||
ui->labelW->setGeometry(1538,684,32,32);
|
||
ui->labelWValue->setGeometry(1680,684,174,32);
|
||
ui->labelH->setGeometry(1538,724,32,32);
|
||
ui->labelHValue->setGeometry(1680,724,174,32);
|
||
ui->labelC->setGeometry(1538,764,32,32);
|
||
ui->labelCValue->setGeometry(1680,764,174,32);
|
||
ui->labelN->setGeometry(1538,804,32,32);
|
||
ui->labelNValue->setGeometry(1680,804,174,32);
|
||
|
||
ui->framePageBtn->setGeometry(1120,990,800,70);
|
||
ui->labelPage->setGeometry(32,1008,400,40);
|
||
ui->buttonPgUp->setGeometry(0,0,168,70);
|
||
ui->buttonPgDn->setGeometry(200,0,168,70);
|
||
ui->buttonOk->setGeometry(400,0,168,70);
|
||
ui->buttonCancel->setGeometry(600,0,168,70);
|
||
}
|
||
|
||
//初始化窗体控件为1024x600分辨率
|
||
void PatternManageWidget::initResolution1006()
|
||
{
|
||
m_itemPerPage = m_itemPerPage - 6;
|
||
this->resize(1024,600);
|
||
ui->frameBack->setGeometry(0,0,1024,600);
|
||
|
||
ui->buttonTypeLogo->setGeometry(25,30,60,60);
|
||
ui->labelMainTitle->setGeometry(100,30,200,24);
|
||
ui->labelSubTitle->setGeometry(130,64,240,21);
|
||
ui->labelPage->setGeometry(48,0,200,70);
|
||
ui->labelPage->setAlignment(Qt::AlignLeft);
|
||
|
||
QRect rectImage(0,5,26,28);
|
||
QRect rectName(30,0,200,36);//花样名称
|
||
for(int i = 0; i < 2; i++)
|
||
{
|
||
s16 num = m_itemBtnList.size()/2;
|
||
for(int j = 0; j < num; j++)
|
||
{
|
||
m_itemBtnList[i*num + j]->setLabelFont(fontNormal_1);
|
||
m_itemBtnList[i*num + j]->setGeometry(44+i*378,138+j*47,337,38);
|
||
m_itemBtnList[i*num + j]->initLeftImageRightName(rectImage,rectName);
|
||
}
|
||
}
|
||
|
||
ui->frameRightUp->setGeometry(800,40,800,61);
|
||
ui->buttonBackUpDir->setGeometry(150,0,50,50);
|
||
ui->buttonSelectAll->setGeometry(93,0,50,50);
|
||
ui->buttonNewFolder->setGeometry(37,0,50,50);
|
||
|
||
ui->labelPatternView->setGeometry(824,132,150,150);
|
||
ui->labelNameValue->setGeometry(816,315,146,22);
|
||
ui->labelX->setGeometry(816,350,141,20);
|
||
ui->labelXValue->setGeometry(895,350,91,20);
|
||
ui->labelY->setGeometry(816,375,91,20);
|
||
ui->labelYValue->setGeometry(895,375,91,20);
|
||
ui->labelW->setGeometry(816,400,91,20);
|
||
ui->labelWValue->setGeometry(895,400,91,20);
|
||
ui->labelH->setGeometry(816,425,91,20);
|
||
ui->labelHValue->setGeometry(895,425,91,20);
|
||
ui->labelC->setGeometry(816,450,91,20);
|
||
ui->labelCValue->setGeometry(895,450,91,20);
|
||
ui->labelN->setGeometry(816,475,91,20);
|
||
ui->labelNValue->setGeometry(895,475,91,20);
|
||
|
||
ui->framePageBtn->setGeometry(595,545,600,45);
|
||
ui->labelPage->setGeometry(20,550,102,45);
|
||
ui->buttonPgUp->setGeometry(0,0,96,40);
|
||
ui->buttonPgDn->setGeometry(106,0,96,40);
|
||
ui->buttonOk->setGeometry(212,0,96,40);
|
||
ui->buttonCancel->setGeometry(318,0,96,40);
|
||
}
|
||
|
||
//初始化窗体控件样式
|
||
void PatternManageWidget::initControlStyle()
|
||
{
|
||
SetControlStyle setControlStyle;
|
||
setControlStyle.setUiName(this->objectName());
|
||
|
||
//背景图
|
||
QString frameBackImgPath = setControlStyle.getStyleSheet1(this->objectName());
|
||
ui->frameBack->setStyleSheet(frameBackImgPath);
|
||
|
||
//label样式
|
||
ui->labelMainTitle->setFont(fontBold_1);
|
||
ui->labelMainTitle->setStyleSheet(LABELWHITESTYLE);
|
||
ui->labelSubTitle->setFont(fontNormal_1);
|
||
ui->labelSubTitle->setStyleSheet(LABELWHITESTYLE);
|
||
ui->labelPage->setFont(fontNormal_1);
|
||
ui->labelPage->setStyleSheet(LABELWHITESTYLE);
|
||
|
||
ui->labelPatternView->setStyleSheet(TRANSPARENTSTYLE);
|
||
ui->labelNameValue->setFont(fontNormal_1);
|
||
ui->labelNameValue->setStyleSheet(LABELWHITESTYLE);
|
||
ui->labelX->setFont(fontNormal_1);
|
||
ui->labelX->setStyleSheet(LABELWHITESTYLE);
|
||
ui->labelXValue->setFont(fontNormal_1);
|
||
ui->labelXValue->setStyleSheet(LABELWHITESTYLE);
|
||
ui->labelY->setFont(fontNormal_1);
|
||
ui->labelY->setStyleSheet(LABELWHITESTYLE);
|
||
ui->labelYValue->setFont(fontNormal_1);
|
||
ui->labelYValue->setStyleSheet(LABELWHITESTYLE);
|
||
ui->labelW->setFont(fontNormal_1);
|
||
ui->labelW->setStyleSheet(LABELWHITESTYLE);
|
||
ui->labelWValue->setFont(fontNormal_1);
|
||
ui->labelWValue->setStyleSheet(LABELWHITESTYLE);
|
||
ui->labelH->setFont(fontNormal_1);
|
||
ui->labelH->setStyleSheet(LABELWHITESTYLE);
|
||
ui->labelHValue->setFont(fontNormal_1);
|
||
ui->labelHValue->setStyleSheet(LABELWHITESTYLE);
|
||
ui->labelC->setFont(fontNormal_1);
|
||
ui->labelC->setStyleSheet(LABELWHITESTYLE);
|
||
ui->labelCValue->setFont(fontNormal_1);
|
||
ui->labelCValue->setStyleSheet(LABELWHITESTYLE);
|
||
ui->labelN->setFont(fontNormal_1);
|
||
ui->labelN->setStyleSheet(LABELWHITESTYLE);
|
||
ui->labelNValue->setFont(fontNormal_1);
|
||
ui->labelNValue->setStyleSheet(LABELWHITESTYLE);
|
||
|
||
ui->framePageBtn->setStyleSheet(TRANSPARENTSTYLE);
|
||
ui->frameRightUp->setStyleSheet(TRANSPARENTSTYLE);
|
||
|
||
ui->buttonSelectAll->setGreenGradientBottomStyle(BORDER_RADIUS1);
|
||
ui->buttonSelectAll->setTopImage(setControlStyle.getTopStyleSheet(ui->buttonSelectAll->objectName()));
|
||
|
||
ui->buttonBackUpDir->setGreenGradientBottomStyle(BORDER_RADIUS1);
|
||
ui->buttonBackUpDir->setTopImage(setControlStyle.getTopStyleSheet(ui->buttonBackUpDir->objectName()));
|
||
|
||
ui->buttonNewFolder->setGreenGradientBottomStyle(BORDER_RADIUS1);
|
||
ui->buttonNewFolder->setTopImage(setControlStyle.getTopStyleSheet(ui->buttonNewFolder->objectName()));
|
||
|
||
//四个按钮样式表一样
|
||
ui->buttonPgUp->setOrangeGradientBottomStyle(BORDER_RADIUS2);
|
||
ui->buttonPgUp->setTopImage(setControlStyle.getSharedTopStyleSheet(ui->buttonPgUp->objectName()),12);
|
||
|
||
ui->buttonPgDn->setOrangeGradientBottomStyle(BORDER_RADIUS2);
|
||
ui->buttonPgDn->setTopImage(setControlStyle.getSharedTopStyleSheet(ui->buttonPgDn->objectName()),12);
|
||
|
||
ui->buttonOk->setOrangeGradientBottomStyle(BORDER_RADIUS2);
|
||
ui->buttonOk->setTopImage(setControlStyle.getSharedTopStyleSheet(ui->buttonOk->objectName()),12);
|
||
|
||
ui->buttonCancel->setOrangeGradientBottomStyle(BORDER_RADIUS2);
|
||
ui->buttonCancel->setTopImage(setControlStyle.getSharedTopStyleSheet(ui->buttonCancel->objectName()),12);
|
||
}
|
||
|
||
//设置类型图标
|
||
void PatternManageWidget::setTypeLogo(QString tStyle)
|
||
{
|
||
ui->buttonTypeLogo->setUnPreBtnLogo(tStyle);
|
||
}
|
||
|
||
//设置主title
|
||
void PatternManageWidget::setMainTitle(QString str)
|
||
{
|
||
ui->labelMainTitle->setText(str);
|
||
}
|
||
|
||
//设置副title
|
||
void PatternManageWidget::setSubTitle(QString str)
|
||
{
|
||
ui->labelSubTitle->setText(str);
|
||
}
|
||
|
||
//初始化当前路径花样(点击选择花样时刷新)
|
||
void PatternManageWidget::initDirPath(QString path)
|
||
{
|
||
int flag = -1;//该路径下是否存在dst文件或dsr文件的扫描标志
|
||
m_curPath = path;
|
||
if(m_curPath == m_usbPath || m_curPath == m_rootPath)//如果当前目录等于优盘目录或操作屏根目录,返回上级按钮不可按
|
||
{
|
||
ui->buttonBackUpDir->setEnabled(false);
|
||
}
|
||
else
|
||
{
|
||
ui->buttonBackUpDir->setEnabled(true);
|
||
}
|
||
|
||
m_fileItemList.clear();//文件列表清空
|
||
QDir dir(m_curPath);
|
||
//打开路径
|
||
if(!dir.exists())
|
||
{
|
||
m_curPages = 0;
|
||
m_pageNums = 0;
|
||
return;
|
||
}
|
||
|
||
FileItem item;
|
||
QString fileName;
|
||
QString filePath;
|
||
QString imagePath;
|
||
|
||
dir.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot); // 设置类型过滤器,只为文件夹和文件格式
|
||
dir.setSorting(QDir::DirsFirst | QDir::IgnoreCase); //设置排序方式,文件夹优先
|
||
|
||
QFileInfoList fileList = dir.entryInfoList();
|
||
int count = fileList.count();
|
||
for(int i = 0; i < count; i++)
|
||
{
|
||
QFileInfo fileInfo = fileList[i];
|
||
|
||
if(fileInfo.isDir())//为文件夹
|
||
{
|
||
filePath = fileInfo.absoluteFilePath();
|
||
fileName = fileInfo.baseName();
|
||
imagePath = ":/images/folder.png";
|
||
item.setFileInfo(filePath,fileName,imagePath);
|
||
m_fileItemList.append(item);
|
||
}
|
||
else//为文件
|
||
{
|
||
QString suffix = fileInfo.suffix().toUpper();
|
||
if(suffix == "DST" || suffix == "DSR")
|
||
{
|
||
filePath = fileInfo.absoluteFilePath();
|
||
fileName = fileInfo.fileName();
|
||
imagePath = ":/images/file.png";
|
||
item.setFileInfo(filePath,fileName,imagePath);
|
||
m_fileItemList.append(item);
|
||
flag = 1;//扫描到dst或dsr
|
||
}
|
||
}
|
||
}
|
||
|
||
if(flag == -1)//未扫描到dst或dsr
|
||
{
|
||
ui->buttonSelectAll->setEnabled(false);
|
||
}
|
||
else//扫描到dst或dsr
|
||
{
|
||
ui->buttonSelectAll->setEnabled(true);
|
||
}
|
||
|
||
refreshUi();
|
||
}
|
||
|
||
void PatternManageWidget::initExecDirPath(QString path)
|
||
{
|
||
m_curPath = path;
|
||
if(m_curPath == m_usbPath || m_curPath == m_rootPath)//如果当前目录等于优盘目录或操作屏根目录,返回上级按钮不可按
|
||
{
|
||
ui->buttonBackUpDir->setEnabled(false);
|
||
}
|
||
else
|
||
{
|
||
ui->buttonBackUpDir->setEnabled(true);
|
||
}
|
||
|
||
m_fileItemList.clear();//文件列表清空
|
||
QDir dir(m_curPath);
|
||
//打开路径
|
||
if(!dir.exists())
|
||
{
|
||
m_curPages = 0;
|
||
m_pageNums = 0;
|
||
return;
|
||
}
|
||
|
||
FileItem item;
|
||
QString fileName;
|
||
QString filePath;
|
||
QString imagePath;
|
||
|
||
dir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot); // 设置类型过滤器,只为文件夹和文件格式
|
||
|
||
QFileInfoList fileList = dir.entryInfoList();
|
||
int count = fileList.count();
|
||
for(int i = 0; i < count; i++)
|
||
{
|
||
QFileInfo fileInfo = fileList[i];
|
||
|
||
if(fileInfo.isDir())//为文件夹
|
||
{
|
||
filePath = fileInfo.absoluteFilePath();
|
||
fileName = fileInfo.baseName();
|
||
imagePath = ":/images/folder.png";
|
||
item.setFileInfo(filePath,fileName,imagePath);
|
||
m_fileItemList.append(item);
|
||
}
|
||
}
|
||
|
||
refreshUi();
|
||
}
|
||
|
||
//刷新界面显示
|
||
void PatternManageWidget::refreshUi()
|
||
{
|
||
if(m_manageMode == MANAGE_IMPORT_EXEC || m_manageMode == MANAGE_EXPORT_EXEC)
|
||
{
|
||
QString path = m_curPath;
|
||
if(m_manageMode == MANAGE_IMPORT_EXEC)
|
||
{
|
||
path = path.remove(m_rootPath);
|
||
}
|
||
if(m_manageMode == MANAGE_EXPORT_EXEC)
|
||
{
|
||
path = path.remove(m_usbPath);
|
||
}
|
||
setSubTitle(path);
|
||
}
|
||
|
||
int itemNum;
|
||
if (m_fileItemList.size() <= 0)
|
||
{
|
||
itemNum = 0;
|
||
|
||
for (int i = 0; i < m_itemPerPage; i++)
|
||
{
|
||
m_itemBtnList.at(i)->hide();
|
||
}
|
||
ui->labelPage->setText("pageNum: 0/0");
|
||
ui->buttonPgUp->setEnabled(false);
|
||
ui->buttonPgDn->setEnabled(false);
|
||
ui->buttonOk->setEnabled(false);
|
||
ui->buttonSelectAll->setEnabled(false);
|
||
|
||
return;
|
||
}
|
||
else
|
||
{
|
||
itemNum = m_fileItemList.size();
|
||
}
|
||
|
||
m_pageNums = (itemNum + m_itemPerPage - 1)/m_itemPerPage;// 计算页数
|
||
if (m_curPages > m_pageNums)// 当前页
|
||
{
|
||
m_curPages = m_pageNums;
|
||
}
|
||
if (m_curPages <= 1 && itemNum != 0)
|
||
{
|
||
m_curPages = 1;
|
||
}
|
||
|
||
int itemidx = (m_curPages - 1) * m_itemPerPage;
|
||
|
||
for (int i = 0; i < m_itemPerPage; i++)
|
||
{
|
||
if (itemidx < itemNum)
|
||
{
|
||
//设置图标和文件名
|
||
m_itemBtnList[i]->setItemLeftIcon(m_fileItemList.at(itemidx).getImagePath());
|
||
m_itemBtnList[i]->setLabelName(m_fileItemList.at(itemidx).getShowInfo());
|
||
m_itemBtnList.at(i)->show();
|
||
|
||
itemidx++;
|
||
}
|
||
else
|
||
{
|
||
m_itemBtnList.at(i)->hide();
|
||
}
|
||
}
|
||
|
||
// 翻页按钮
|
||
if (m_curPages <= 1)
|
||
{
|
||
ui->buttonPgUp->setEnabled(false);
|
||
}
|
||
else
|
||
{
|
||
ui->buttonPgUp->setEnabled(true);
|
||
}
|
||
if (m_curPages >= m_pageNums)
|
||
{
|
||
ui->buttonPgDn->setEnabled(false);
|
||
}
|
||
else
|
||
{
|
||
ui->buttonPgDn->setEnabled(true);
|
||
}
|
||
|
||
// 页信息
|
||
if(m_pageNums == 0)
|
||
{
|
||
m_curPages = 0;
|
||
}
|
||
|
||
QString str = tr("pageNum: ") + QString("%1/%2").arg(m_curPages).arg(m_pageNums);//页数:
|
||
ui->labelPage->setText(str);
|
||
|
||
refreshCheckedPage();
|
||
}
|
||
|
||
QString PatternManageWidget::detectUsb()
|
||
{
|
||
QString usbPath = "";
|
||
|
||
#ifdef Q_OS_LINUX
|
||
QDir dir(LINUXUSBPATH);
|
||
if(!dir.exists())
|
||
{
|
||
usbPath = "";
|
||
}
|
||
else
|
||
{
|
||
usbPath = LINUXUSBPATH;
|
||
}
|
||
#endif
|
||
|
||
#ifdef Q_OS_WIN
|
||
QFileInfoList list = QDir::drives();
|
||
|
||
for(int i = 0; i<list.count(); i++)
|
||
{
|
||
UINT ret = GetDriveType((WCHAR *) list.at(i).filePath().utf16());
|
||
if(ret == DRIVE_REMOVABLE)
|
||
{
|
||
usbPath = list.at(i).filePath();
|
||
break;
|
||
}
|
||
}
|
||
#endif
|
||
return usbPath;
|
||
}
|
||
|
||
void PatternManageWidget::refreshCheckedPage()
|
||
{
|
||
int idx = (m_curPages - 1) * m_itemPerPage;
|
||
|
||
// 刷新页面中被选择的条目
|
||
for(int var = 0; var < m_itemPerPage; var++)
|
||
{
|
||
if((idx + var) < m_fileItemList.size())
|
||
{
|
||
QString name = m_fileItemList.at(idx + var).getFilePath();
|
||
|
||
int index = m_selectFileItemList.indexOf(name);
|
||
if(index != -1)
|
||
{
|
||
// 条目被选中
|
||
m_itemBtnList.at(var)->setCheckable(true);
|
||
m_itemBtnList.at(var)->setChecked(true);
|
||
}
|
||
else
|
||
{
|
||
// 不被选中
|
||
m_itemBtnList.at(var)->setChecked(false);
|
||
m_itemBtnList.at(var)->setCheckable(false);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
//点击某一条目 lxs走到最新的
|
||
void PatternManageWidget::clickItem(int idx)
|
||
{
|
||
//全选时点击条目,全选标志置为非全选
|
||
if(m_selectAll == 1)
|
||
{
|
||
m_selectAll = m_selectAll * -1;
|
||
}
|
||
|
||
if(idx < 0) //都不选中
|
||
{
|
||
m_selectAll = -1;
|
||
m_selectFileItemList.clear();
|
||
// 刷新页面中被选择的条目
|
||
for (int var = 0; var < m_itemPerPage ; var++)
|
||
{
|
||
// 不被选中
|
||
m_itemBtnList[var]->setChecked(false);
|
||
m_itemBtnList[var]->setCheckable(false);
|
||
ui->buttonOk->setEnabled(false);
|
||
}
|
||
//清空图片
|
||
QPixmap pix = QPixmap();
|
||
ui->labelPatternView->setPixmap(pix);
|
||
clearFileInfo();
|
||
}
|
||
else
|
||
{
|
||
// 计算当前选择按钮对应的花版
|
||
int itemidx = (m_curPages - 1) * m_itemPerPage + idx - 1;
|
||
|
||
if (m_fileItemList.size() <= 0)
|
||
{
|
||
itemidx = -1;
|
||
return;
|
||
}
|
||
else
|
||
{
|
||
|
||
if (itemidx >= m_fileItemList.size())
|
||
{
|
||
return;
|
||
}
|
||
}
|
||
|
||
QString filePath = m_fileItemList.at(itemidx).getFilePath();
|
||
QFileInfo fileInfo(filePath);
|
||
|
||
QString fileName = fileInfo.fileName();
|
||
int size = fileName.length();
|
||
if(size > NAMEMAXLENGTH)//花样名称过长时截取
|
||
{
|
||
fileName = fileName.mid(0,NAMEMAXLENGTH) + "~";
|
||
}
|
||
|
||
if(fileInfo.isDir())//为文件夹
|
||
{
|
||
if(m_manageMode == MANAGE_IMPORT_EXEC || m_manageMode == MANAGE_EXPORT_EXEC)
|
||
{
|
||
initExecDirPath(filePath);
|
||
}
|
||
else
|
||
{
|
||
initDirPath(filePath);
|
||
}
|
||
clickItem(-1);
|
||
}
|
||
else
|
||
{
|
||
int retIdx = m_selectFileItemList.indexOf(filePath);
|
||
|
||
if(retIdx == -1)
|
||
{
|
||
// 没有找到相同的文件名
|
||
// 添加条目
|
||
m_selectFileItemList.append(filePath);
|
||
}
|
||
else
|
||
{
|
||
m_selectFileItemList.takeAt(retIdx);
|
||
}
|
||
refreshCheckedPage();
|
||
|
||
if(m_selectFileItemList.size() > 0)
|
||
{
|
||
QFileInfo lfileInfo(m_selectFileItemList.last()); //最后一个选中Item
|
||
QString fileNamePath = lfileInfo.absoluteFilePath();
|
||
QString suffix = lfileInfo.suffix();//后缀
|
||
|
||
QImage image(QSize(ui->labelPatternView->width(), ui->labelPatternView->height()),QImage::Format_ARGB32);
|
||
ui->labelNameValue->setText(lfileInfo.fileName());
|
||
|
||
if(suffix.toUpper() == "DST")
|
||
{
|
||
DataFileDst dst;
|
||
dst.initColor(g_pSettings->getColorRgbArray().size(),(QRgb*)g_pSettings->getColorRgbArray().data());
|
||
dst.initFile(fileNamePath);//最后一个选中Item
|
||
dst.createPreviewImage(&image, 0, PEN_WIDTH, 1);// 生成预览文件,第2个参数为0不保存图片,1为保存图片
|
||
//刷新文件信息
|
||
ui->labelNValue->setText(QString::number(dst.getStitchNums()));
|
||
|
||
double width = dst.getDatWidth()*0.01;
|
||
ui->labelWValue->setText(QString("%1").arg(width));
|
||
|
||
double height = dst.getDatHeight()*0.01;
|
||
ui->labelHValue->setText(QString("%1").arg(height));
|
||
|
||
double xPos = dst.getMaxX()*0.01;
|
||
ui->labelXValue->setText(QString("%1").arg(xPos));
|
||
|
||
double yPos = dst.getMaxY()*0.01;
|
||
ui->labelYValue->setText(QString("%1").arg(yPos));
|
||
}
|
||
else if(suffix.toUpper() == "DSR")
|
||
{
|
||
DataFileDsr dsr;
|
||
dsr.initColor(g_pSettings->getColorRgbArray().size(),(QRgb*)g_pSettings->getColorRgbArray().data());
|
||
dsr.initFile(fileNamePath);//最后一个选中Item
|
||
dsr.convertDataToEmbAbs();
|
||
dsr.createPreviewImage(&image, 0, PEN_WIDTH, 1);// 生成预览文件,第2个参数为0不保存图片,1为保存图片
|
||
//刷新文件信息
|
||
ui->labelNValue->setText(QString::number(dsr.getStitchNums()));
|
||
|
||
double width = dsr.getDatWidth()*0.01;
|
||
ui->labelWValue->setText(QString("%1").arg(width));
|
||
|
||
double height = dsr.getDatHeight()*0.01;
|
||
ui->labelHValue->setText(QString("%1").arg(height));
|
||
|
||
double xPos = dsr.getMaxX()*0.01;
|
||
ui->labelXValue->setText(QString("%1").arg(xPos));
|
||
|
||
double yPos = dsr.getMaxY()*0.01;
|
||
ui->labelYValue->setText(QString("%1").arg(yPos));
|
||
}
|
||
|
||
QPixmap pix = QPixmap::fromImage(image);
|
||
ui->labelPatternView->setPixmap(pix);
|
||
}
|
||
else
|
||
{
|
||
QPixmap pix = QPixmap();
|
||
ui->labelPatternView->setPixmap(pix);
|
||
//清空文件信息
|
||
clearFileInfo();
|
||
}
|
||
}
|
||
}
|
||
|
||
if(m_manageMode == MANAGE_IMPORT_EXEC || m_manageMode == MANAGE_EXPORT_EXEC)
|
||
{
|
||
//清空图片
|
||
QPixmap pix = QPixmap();
|
||
ui->labelPatternView->setPixmap(pix);
|
||
//清空文件信息
|
||
clearFileInfo();
|
||
ui->buttonOk->setEnabled(true); //导入导出文件
|
||
}
|
||
else//选择文件
|
||
{
|
||
if(m_selectFileItemList.size() <= 0)
|
||
{
|
||
ui->buttonOk->setEnabled(false);
|
||
|
||
//清空图片
|
||
QPixmap pix = QPixmap();
|
||
ui->labelPatternView->setPixmap(pix);
|
||
}
|
||
else
|
||
{
|
||
ui->buttonOk->setEnabled(true);
|
||
}
|
||
}
|
||
}
|
||
|
||
void PatternManageWidget::patternImportOrExport(QString mainStr,QString subStr,QString path)
|
||
{
|
||
QDir apppath(qApp->applicationDirPath());
|
||
|
||
if(m_curPath.length() <= 0)
|
||
{
|
||
return;
|
||
}
|
||
|
||
PromptDialog promptDlg(this);
|
||
promptDlg.setRange(0, m_cpSelectFileItemList.size()-1);
|
||
promptDlg.show();
|
||
s16 showFlag = 1;
|
||
|
||
for(int i = 0; i < m_cpSelectFileItemList.size(); i++)
|
||
{
|
||
QFileInfo fileInfo(m_cpSelectFileItemList.at(i));
|
||
QString fileName = fileInfo.fileName();
|
||
QString suffix = fileInfo.suffix();
|
||
QString newFileName = m_curPath + apppath.separator() + fileName;
|
||
|
||
//非5.2和6.3版本的dsr不可导入
|
||
//dst格式错误不可导入
|
||
if(suffix.toUpper() == "DSR" ||
|
||
suffix.toUpper() == "DST")
|
||
{
|
||
int rel = 0;
|
||
if(suffix.toUpper() == "DSR")
|
||
{
|
||
DataFileDsr dsr;
|
||
dsr.initFile(m_cpSelectFileItemList.at(i));
|
||
rel = dsr.checkDsrVersion();
|
||
}
|
||
else if(suffix.toUpper() == "DST")
|
||
{
|
||
DataFileDst dst;
|
||
dst.initFile(m_cpSelectFileItemList.at(i));
|
||
rel = dst.checkDstFile();
|
||
}
|
||
if(rel < 0)
|
||
{
|
||
promptDlg.initDialog(PromptDialog::BTN_OK);
|
||
promptDlg.setTitleStr(tr("Prompt"));
|
||
|
||
QString str;
|
||
if(rel == -2)
|
||
{
|
||
str = fileName + " " + tr("Over 1.28 million stitches, can not be imported!");//针数超过128万,不能导入!
|
||
}
|
||
else
|
||
{
|
||
str = fileName + " " + tr("Format error, can not be imported!");//格式错误,不能导入!
|
||
}
|
||
promptDlg.setContentStr(str);
|
||
promptDlg.exec();
|
||
showFlag = 0;
|
||
continue;
|
||
}
|
||
}
|
||
|
||
qDebug()<<"Pattern ImportOrExport";
|
||
qDebug()<<"fileName"<<fileName;
|
||
qDebug()<<"newFileName"<<newFileName;
|
||
|
||
QFile file(newFileName);
|
||
if(file.exists() == true)//花样导入或导出,存在u盘里或datafiles路径的花版
|
||
{
|
||
promptDlg.initDialog(PromptDialog::BTN_R_R_S);
|
||
promptDlg.setTitleStr(tr("Prompt"));
|
||
|
||
QString str;
|
||
str = fileName + " " + tr("This file already exists!");//此文件已存在!
|
||
promptDlg.setContentStr(str);
|
||
int ret = promptDlg.exec();
|
||
showFlag = 0;
|
||
if(ret == 1)//重命名
|
||
{
|
||
WordsInputDialog wordInputDlg;
|
||
wordInputDlg.clean();
|
||
wordInputDlg.setTitleStr(tr("Rename"));//重命名
|
||
|
||
int size = fileName.length();
|
||
if(size > NAMEMAXLENGTH + 12)//花样名称过长时截取
|
||
{
|
||
fileName = fileName.mid(0,NAMEMAXLENGTH + 12) + "~";
|
||
}
|
||
|
||
wordInputDlg.setOldWordsStr(fileName);
|
||
if(wordInputDlg.exec() == 1)
|
||
{
|
||
if(m_manageMode == MANAGE_IMPORT)//导入文件
|
||
{
|
||
//文件名称
|
||
QString name = wordInputDlg.getInputStr();
|
||
QString newName = m_curPath + apppath.separator() + name + "." + suffix;
|
||
QFile::copy(m_cpSelectFileItemList.at(i), newName);
|
||
QFile::copy(m_cpSelectFileItemList.at(i) + ".fcg", newName + ".fcg");
|
||
}
|
||
else if(m_manageMode == MANAGE_EXPORT)//导出文件
|
||
{
|
||
//文件名称
|
||
QString name = wordInputDlg.getInputStr();//导出文件路径
|
||
QString newName = m_curPath + apppath.separator() + name + "." + suffix;
|
||
QFile::copy(m_cpSelectFileItemList.at(i), newName);
|
||
QFile::copy(m_cpSelectFileItemList.at(i) + ".fcg", newName + ".fcg");
|
||
QFile::copy(m_cpSelectFileItemList.at(i) + ".ds16", newName + ".ds16");
|
||
}
|
||
}
|
||
}
|
||
else if(ret == 2)//替换
|
||
{
|
||
if(m_manageMode == MANAGE_IMPORT)//导入文件
|
||
{
|
||
QFile::remove(newFileName);
|
||
if (g_emMacType != MACHINE_ADHESIVE)
|
||
{
|
||
QFile::remove(newFileName + ".fcg");
|
||
}
|
||
QFile::remove(newFileName + ".ds16");
|
||
QFile::copy(m_cpSelectFileItemList.at(i), newFileName);
|
||
QFile::copy(m_cpSelectFileItemList.at(i) + ".fcg", newFileName + ".fcg");
|
||
emit siReplacePattrn(newFileName);
|
||
//newFileName = D:/work/workQT/XPlatform/Windows/debug/datafiles\0.7盾牌.dst
|
||
}
|
||
else if(m_manageMode == MANAGE_EXPORT)//导出文件
|
||
{
|
||
QFile::remove(newFileName);
|
||
QFile::remove(newFileName + ".fcg");
|
||
QFile::copy(m_cpSelectFileItemList.at(i), newFileName);
|
||
QFile::copy(m_cpSelectFileItemList.at(i) + ".fcg", newFileName + ".fcg");
|
||
QFile::copy(m_cpSelectFileItemList.at(i) + ".ds16", newFileName + ".ds16");
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
promptDlg.initDialog(PromptDialog::BTN_P_NONE);
|
||
promptDlg.setTitleStr(tr("Prompt"));
|
||
|
||
if(m_manageMode == MANAGE_IMPORT)//导入文件
|
||
{
|
||
promptDlg.setContentProcessStr(tr("Importing ") + fileName); //正在导入
|
||
}
|
||
else if(m_manageMode == MANAGE_EXPORT)//导出文件
|
||
{
|
||
promptDlg.setContentProcessStr(tr("Exporting ") + fileName); //正在导出
|
||
}
|
||
|
||
if(showFlag == 0)
|
||
{
|
||
promptDlg.show();
|
||
showFlag = 1;
|
||
}
|
||
if(m_manageMode == MANAGE_IMPORT)//导入文件
|
||
{
|
||
QFile::copy(m_cpSelectFileItemList.at(i),newFileName);
|
||
QFile::copy(m_cpSelectFileItemList.at(i) + ".fcg", newFileName + ".fcg");
|
||
}
|
||
else if(m_manageMode == MANAGE_EXPORT)//导出文件
|
||
{
|
||
QFile::copy(m_cpSelectFileItemList.at(i),newFileName);
|
||
QFile::copy(m_cpSelectFileItemList.at(i) + ".fcg", newFileName + ".fcg");
|
||
QFile::copy(m_cpSelectFileItemList.at(i) + ".ds16", newFileName + ".ds16");
|
||
}
|
||
}
|
||
|
||
qDebug()<<"processEvents before";
|
||
QCoreApplication::processEvents(QEventLoop::AllEvents);
|
||
qDebug()<<"processEvents end";
|
||
|
||
if(m_manageMode == MANAGE_IMPORT)//导入文件
|
||
{
|
||
QImage image(m_imgSize,QImage::Format_ARGB32);
|
||
|
||
if(suffix.toUpper() == "DST")
|
||
{
|
||
DataFileDst dst;
|
||
dst.initColor(g_pSettings->getColorRgbArray().size(),(QRgb*)g_pSettings->getColorRgbArray().data());
|
||
dst.initFile(newFileName);
|
||
dst.createPreviewImage(&image, 1, PEN_WIDTH);// 生成渐进绘制预览图片,第2个参数为0不保存图片,1为保存图片
|
||
|
||
qDebug()<<"dst.createPreviewImage end";
|
||
}
|
||
else if(suffix.toUpper() == "DSR")
|
||
{
|
||
DataFileDsr dsr;
|
||
dsr.initColor(g_pSettings->getColorRgbArray().size(),(QRgb*)g_pSettings->getColorRgbArray().data());
|
||
dsr.initFile(newFileName);
|
||
dsr.convertDataToEmbAbs();
|
||
dsr.createPreviewImage(&image, 1, PEN_WIDTH);// 生成渐进绘制预览图片,第2个参数为0不保存图片,1为保存图片
|
||
}
|
||
}
|
||
|
||
promptDlg.setValue(i);
|
||
}
|
||
|
||
#ifdef Q_OS_LINUX
|
||
system("sync");
|
||
#endif
|
||
if(m_manageMode == MANAGE_IMPORT)//导入文件
|
||
{
|
||
promptDlg.setContentStr(tr("Import complete")); //导入完成
|
||
}
|
||
else if(m_manageMode == MANAGE_EXPORT)//导出文件
|
||
{
|
||
promptDlg.setContentStr(tr("Export complete")); //导出完成
|
||
}
|
||
promptDlg.hide();
|
||
|
||
setMainTitle(mainStr);
|
||
setSubTitle(subStr);
|
||
initialize();
|
||
initDirPath(path);
|
||
clickItem(-1);
|
||
ui->buttonSelectAll->show();
|
||
ui->buttonNewFolder->hide();
|
||
}
|
||
|
||
void PatternManageWidget::patternDelete()
|
||
{
|
||
if(m_selectAll == 1)//全选时删除整个文件夹
|
||
{
|
||
for(int i = 0; i < m_selectFileItemList.size(); i++)
|
||
{
|
||
QFile::remove(m_selectFileItemList.at(i));
|
||
QFile::remove(m_selectFileItemList.at(i)+".fcg");
|
||
QFile::remove(m_selectFileItemList.at(i)+".ds16");
|
||
QFile::remove(m_selectFileItemList.at(i)+".ds8");
|
||
QFile::remove(m_selectFileItemList.at(i)+".preview.png");
|
||
}
|
||
|
||
if(m_curPath != m_rootPath)//非根目录
|
||
{
|
||
//得到上级目录
|
||
QDir upDir(m_curPath);
|
||
upDir.cdUp();
|
||
QString upPath = upDir.absolutePath();
|
||
|
||
QDir remDir(m_curPath);
|
||
if(remDir.exists() == true)
|
||
{
|
||
remDir.rmpath(remDir.absolutePath());//删除整个文件夹
|
||
}
|
||
|
||
initDirPath(upPath);//初始化上级目录
|
||
}
|
||
else
|
||
{
|
||
initDirPath(m_curPath);//初始化当前目录(根目录)
|
||
}
|
||
}
|
||
else
|
||
{
|
||
//所选文件个数等于目录文件总个数时删除整个文件夹
|
||
if(m_selectFileItemList.size() == m_fileItemList.size())
|
||
{
|
||
for(int i = 0; i < m_selectFileItemList.size(); i++)
|
||
{
|
||
QFile::remove(m_selectFileItemList.at(i));
|
||
QFile::remove(m_selectFileItemList.at(i)+".fcg");
|
||
QFile::remove(m_selectFileItemList.at(i)+".ds16");
|
||
QFile::remove(m_selectFileItemList.at(i)+".ds8");
|
||
QFile::remove(m_selectFileItemList.at(i)+".preview.png");
|
||
}
|
||
|
||
if(m_curPath != m_rootPath)//非根目录
|
||
{
|
||
//得到上级目录
|
||
QDir upDir(m_curPath);
|
||
upDir.cdUp();
|
||
QString upPath = upDir.absolutePath();
|
||
|
||
QDir remDir(m_curPath);
|
||
if(remDir.exists() == true)
|
||
{
|
||
remDir.rmpath(remDir.absolutePath());//删除整个文件夹
|
||
}
|
||
|
||
initDirPath(upPath);//初始化上级目录
|
||
}
|
||
else
|
||
{
|
||
initDirPath(m_curPath);//初始化当前目录(根目录)
|
||
}
|
||
}
|
||
else
|
||
{
|
||
//所选文件个数不等于目录文件总个数时删除整个文件夹
|
||
for(int i = 0; i < m_selectFileItemList.size(); i++)
|
||
{
|
||
QFile::remove(m_selectFileItemList.at(i));
|
||
QFile::remove(m_selectFileItemList.at(i)+".fcg");
|
||
QFile::remove(m_selectFileItemList.at(i)+".ds16");
|
||
QFile::remove(m_selectFileItemList.at(i)+".ds8");
|
||
QFile::remove(m_selectFileItemList.at(i)+".preview.png");
|
||
initDirPath(m_curPath);
|
||
}
|
||
}
|
||
}
|
||
clickItem(-1);
|
||
}
|
||
|
||
void PatternManageWidget::clearFileInfo()
|
||
{
|
||
ui->labelNameValue->setText("");
|
||
ui->labelNValue->setText("");
|
||
ui->labelCValue->setText("");
|
||
ui->labelWValue->setText("");
|
||
ui->labelHValue->setText("");
|
||
ui->labelXValue->setText("");
|
||
ui->labelYValue->setText("");
|
||
}
|
||
|
||
//花样导入
|
||
void PatternManageWidget::patternManage(MANAGE_MODE mode)
|
||
{
|
||
initialize();
|
||
if(mode != MANAGE_DELETE)//删除操作不检测优盘
|
||
{
|
||
m_usbPath.clear();
|
||
m_usbPath = detectUsb();
|
||
if(m_usbPath.length() <= 0)
|
||
{
|
||
//优盘不存在
|
||
PromptDialog dlg(this);
|
||
dlg.initDialog(PromptDialog::BTN_OK);
|
||
dlg.setTitleStr(tr("Prompt"));
|
||
|
||
QString str;
|
||
str = tr("USB flash drive is not detected!");//未检测到优盘!
|
||
dlg.setContentStr(str);
|
||
dlg.exec();
|
||
return;
|
||
}
|
||
}
|
||
|
||
if(mode == MANAGE_IMPORT)
|
||
{
|
||
initDirPath(m_usbPath);
|
||
}
|
||
else
|
||
{
|
||
initDirPath(m_rootPath);
|
||
}
|
||
clickItem(-1);
|
||
|
||
m_manageMode = mode;//花样导入、导出、删除
|
||
ui->buttonNewFolder->hide();
|
||
ui->buttonSelectAll->show();
|
||
this->show();
|
||
}
|
||
|
||
void PatternManageWidget::setImportImageSize(QSize imgSize)
|
||
{
|
||
m_imgSize = imgSize;
|
||
}
|
||
|
||
void PatternManageWidget::on_button1_clicked()
|
||
{
|
||
clickItem(1);
|
||
}
|
||
|
||
void PatternManageWidget::on_button2_clicked()
|
||
{
|
||
clickItem(2);
|
||
}
|
||
|
||
void PatternManageWidget::on_button3_clicked()
|
||
{
|
||
clickItem(3);
|
||
}
|
||
|
||
void PatternManageWidget::on_button4_clicked()
|
||
{
|
||
clickItem(4);
|
||
}
|
||
|
||
void PatternManageWidget::on_button5_clicked()
|
||
{
|
||
clickItem(5);
|
||
}
|
||
|
||
void PatternManageWidget::on_button6_clicked()
|
||
{
|
||
clickItem(6);
|
||
}
|
||
|
||
void PatternManageWidget::on_button7_clicked()
|
||
{
|
||
clickItem(7);
|
||
}
|
||
|
||
void PatternManageWidget::on_button8_clicked()
|
||
{
|
||
clickItem(8);
|
||
}
|
||
|
||
void PatternManageWidget::on_button9_clicked()
|
||
{
|
||
clickItem(9);
|
||
}
|
||
|
||
void PatternManageWidget::on_button10_clicked()
|
||
{
|
||
clickItem(10);
|
||
}
|
||
|
||
void PatternManageWidget::on_button11_clicked()
|
||
{
|
||
clickItem(11);
|
||
}
|
||
|
||
void PatternManageWidget::on_button12_clicked()
|
||
{
|
||
//12是右边第一个
|
||
if(g_emResolut == resolution1006)
|
||
{
|
||
clickItem(9);
|
||
}
|
||
else
|
||
{
|
||
clickItem(12);
|
||
}
|
||
}
|
||
|
||
void PatternManageWidget::on_button13_clicked()
|
||
{
|
||
if(g_emResolut == resolution1006)
|
||
{
|
||
clickItem(10);
|
||
}
|
||
else
|
||
{
|
||
clickItem(13);
|
||
}
|
||
}
|
||
|
||
void PatternManageWidget::on_button14_clicked()
|
||
{
|
||
if(g_emResolut == resolution1006)
|
||
{
|
||
clickItem(11);
|
||
}
|
||
else
|
||
{
|
||
clickItem(14);
|
||
}
|
||
}
|
||
|
||
void PatternManageWidget::on_button15_clicked()
|
||
{
|
||
if(g_emResolut == resolution1006)
|
||
{
|
||
clickItem(12);
|
||
}
|
||
else
|
||
{
|
||
clickItem(15);
|
||
}
|
||
}
|
||
|
||
void PatternManageWidget::on_button16_clicked()
|
||
{
|
||
if(g_emResolut == resolution1006)
|
||
{
|
||
clickItem(13);
|
||
}
|
||
else
|
||
{
|
||
clickItem(16);
|
||
}
|
||
}
|
||
|
||
void PatternManageWidget::on_button17_clicked()
|
||
{
|
||
if(g_emResolut == resolution1006)
|
||
{
|
||
clickItem(14);
|
||
}
|
||
else
|
||
{
|
||
clickItem(17);
|
||
}
|
||
}
|
||
|
||
void PatternManageWidget::on_button18_clicked()
|
||
{
|
||
if(g_emResolut == resolution1006)
|
||
{
|
||
clickItem(15);
|
||
}
|
||
else
|
||
{
|
||
clickItem(18);
|
||
}
|
||
}
|
||
|
||
void PatternManageWidget::on_button19_clicked()
|
||
{
|
||
if(g_emResolut == resolution1006)
|
||
{
|
||
clickItem(16);
|
||
}
|
||
else
|
||
{
|
||
clickItem(19);
|
||
}
|
||
}
|
||
|
||
void PatternManageWidget::on_button20_clicked()
|
||
{
|
||
clickItem(20);
|
||
}
|
||
|
||
void PatternManageWidget::on_button21_clicked()
|
||
{
|
||
clickItem(21);
|
||
}
|
||
|
||
void PatternManageWidget::on_button22_clicked()
|
||
{
|
||
clickItem(22);
|
||
}
|
||
|
||
void PatternManageWidget::on_buttonPgUp_clicked()
|
||
{
|
||
m_curPages--;
|
||
refreshUi();
|
||
}
|
||
|
||
void PatternManageWidget::on_buttonPgDn_clicked()
|
||
{
|
||
m_curPages++;
|
||
refreshUi();
|
||
}
|
||
|
||
void PatternManageWidget::on_buttonOk_clicked()
|
||
{
|
||
if(m_manageMode == MANAGE_DELETE)//花样删除
|
||
{
|
||
//是否删除花样的提示
|
||
PromptDialog dlg(this);
|
||
dlg.initDialog(PromptDialog::BTN_OK_CANCEL);
|
||
dlg.setTitleStr(tr("Prompt"));
|
||
|
||
qDebug()<<"import begin 1";
|
||
QString str;
|
||
str = tr("Whether to delete the pattern?");//是否删除花样?
|
||
dlg.setContentStr(str);
|
||
if(dlg.exec() == 1)
|
||
{
|
||
patternDelete();
|
||
emit siDeletePattern();//删除文件后判断当前文件是否被删除
|
||
}
|
||
}
|
||
else
|
||
{
|
||
qDebug()<<"import begin 1.5";
|
||
QString str;
|
||
QString path;
|
||
if(m_manageMode == MANAGE_IMPORT)//花样导入
|
||
{
|
||
qDebug()<<"import begin 2";
|
||
|
||
str = tr("Operation screen");//操作屏
|
||
//导入路径
|
||
path = m_rootPath;
|
||
m_manageMode = MANAGE_IMPORT_EXEC;
|
||
m_cpSelectFileItemList.clear();
|
||
m_cpSelectFileItemList.append(m_selectFileItemList);
|
||
|
||
qDebug()<<"import begin 2.5";
|
||
}
|
||
else if(m_manageMode == MANAGE_EXPORT)//花样导出
|
||
{
|
||
qDebug()<<"import begin XXX";
|
||
|
||
str = tr("USB");//优盘
|
||
//导出路径
|
||
path = m_usbPath;
|
||
m_manageMode = MANAGE_EXPORT_EXEC;
|
||
m_cpSelectFileItemList.clear();
|
||
m_cpSelectFileItemList.append(m_selectFileItemList);
|
||
qDebug()<<"import begin 3.5";
|
||
}
|
||
else if(m_manageMode == MANAGE_IMPORT_EXEC)//花样导入执行
|
||
{
|
||
|
||
qDebug()<<"import begin 4";
|
||
m_manageMode = MANAGE_IMPORT;
|
||
QString mainStr,subStr,path;
|
||
mainStr = tr("Pattern Import");
|
||
subStr = tr("Pattern Import < Pattern setting");
|
||
path = m_usbPath;
|
||
patternImportOrExport(mainStr,subStr,path);
|
||
|
||
return;
|
||
qDebug()<<"import begin 4.5";
|
||
}
|
||
else if(m_manageMode == MANAGE_EXPORT_EXEC)//花样导出执行
|
||
{
|
||
|
||
qDebug()<<"import begin 5";
|
||
m_manageMode = MANAGE_EXPORT;
|
||
QString mainStr,subStr,path;
|
||
mainStr = tr("Pattern Export");
|
||
subStr = tr("Pattern Export < Pattern setting");
|
||
path = m_rootPath;
|
||
patternImportOrExport(mainStr,subStr,path);
|
||
|
||
return;
|
||
qDebug()<<"import begin 5.5";
|
||
}
|
||
|
||
ui->buttonNewFolder->show();
|
||
ui->buttonSelectAll->hide();
|
||
setMainTitle(str);
|
||
setSubTitle(path);
|
||
initialize();
|
||
initExecDirPath(path);
|
||
clickItem(-1);
|
||
}
|
||
}
|
||
|
||
void PatternManageWidget::on_buttonCancel_clicked()
|
||
{
|
||
QString mainStr,subStr,path;
|
||
if(m_manageMode == MANAGE_IMPORT ||
|
||
m_manageMode == MANAGE_EXPORT ||
|
||
m_manageMode == MANAGE_DELETE )//花样导入、花样导出、花样删除
|
||
{
|
||
this->hide();
|
||
return;
|
||
}
|
||
else if(m_manageMode == MANAGE_IMPORT_EXEC)//花样导入执行
|
||
{
|
||
m_manageMode = MANAGE_IMPORT;
|
||
mainStr = tr("Pattern Import");
|
||
subStr = tr("Pattern Import < Pattern setting");
|
||
path = m_usbPath;
|
||
}
|
||
else if(m_manageMode == MANAGE_EXPORT_EXEC)//花样导出执行
|
||
{
|
||
m_manageMode = MANAGE_EXPORT;
|
||
mainStr = tr("Pattern Import");
|
||
subStr = tr("Pattern Import < Pattern setting");
|
||
path = m_rootPath;
|
||
}
|
||
|
||
ui->buttonNewFolder->hide();
|
||
ui->buttonSelectAll->show();
|
||
setMainTitle(mainStr);
|
||
setSubTitle(subStr);
|
||
initialize();
|
||
initDirPath(path);
|
||
clickItem(-1);
|
||
//密码权限,单次有效
|
||
g_emUser = operate;
|
||
}
|
||
|
||
void PatternManageWidget::on_buttonBackUpDir_clicked()
|
||
{
|
||
QDir dir(m_curPath);
|
||
dir.cdUp();//返回上级目录
|
||
QString path = dir.absolutePath();//得到上级目录
|
||
if(m_manageMode == MANAGE_IMPORT_EXEC || m_manageMode == MANAGE_EXPORT_EXEC)
|
||
{
|
||
initExecDirPath(path);
|
||
}
|
||
else
|
||
{
|
||
initDirPath(path);
|
||
}
|
||
clickItem(-1);
|
||
}
|
||
|
||
void PatternManageWidget::on_buttonSelectAll_clicked()
|
||
{
|
||
m_selectAll = m_selectAll * -1;
|
||
if(m_selectAll == 1)//全选
|
||
{
|
||
QDir dir(m_curPath);
|
||
//打开路径
|
||
if(!dir.exists())
|
||
{
|
||
return;
|
||
}
|
||
|
||
QStringList filters;
|
||
filters<<QString("*.dst")<<QString("*.DST")
|
||
<<QString("*.dsr")<<QString("*.DSR");
|
||
dir.setNameFilters(filters); //dst、dsr文件格式
|
||
QFileInfoList fileList = dir.entryInfoList();
|
||
int count = fileList.count();
|
||
for(int i = 0; i < count; i++)
|
||
{
|
||
QFileInfo fileInfo = fileList[i];
|
||
m_selectFileItemList.append(fileInfo.filePath());
|
||
}
|
||
refreshCheckedPage();
|
||
|
||
QFileInfo lfileInfo(m_selectFileItemList.last()); //最后一个选中Item
|
||
QString fileNamePath = lfileInfo.absoluteFilePath();
|
||
QString suffix = lfileInfo.suffix();//后缀
|
||
|
||
QImage image(QSize(ui->labelPatternView->width(), ui->labelPatternView->height()),QImage::Format_ARGB32);
|
||
ui->labelNameValue->setText(lfileInfo.fileName());
|
||
|
||
if(suffix.toUpper() == "DST")
|
||
{
|
||
DataFileDst dst;
|
||
dst.initColor(g_pSettings->getColorRgbArray().size(),(QRgb*)g_pSettings->getColorRgbArray().data());
|
||
dst.initFile(fileNamePath);//最后一个选中Item
|
||
dst.createPreviewImage(&image, 0, PEN_WIDTH, 1);// 生成预览文件,第2个参数为0不保存图片,1为保存图片
|
||
//刷新文件信息
|
||
ui->labelNValue->setText(QString::number(dst.getStitchNums()));
|
||
|
||
double width = dst.getDatWidth()*0.01;
|
||
ui->labelWValue->setText(QString("%1").arg(width));
|
||
|
||
double height = dst.getDatHeight()*0.01;
|
||
ui->labelHValue->setText(QString("%1").arg(height));
|
||
|
||
double xPos = dst.getMaxX()*0.01;
|
||
ui->labelXValue->setText(QString("%1").arg(xPos));
|
||
|
||
double yPos = dst.getMaxY()*0.01;
|
||
ui->labelYValue->setText(QString("%1").arg(yPos));
|
||
}
|
||
else if(suffix.toUpper() == "DSR")
|
||
{
|
||
DataFileDsr dsr;
|
||
dsr.initColor(g_pSettings->getColorRgbArray().size(),(QRgb*)g_pSettings->getColorRgbArray().data());
|
||
dsr.initFile(fileNamePath);//最后一个选中Item
|
||
dsr.convertDataToEmbAbs();
|
||
dsr.createPreviewImage(&image, 0, PEN_WIDTH, 1);// 生成预览文件,第2个参数为0不保存图片,1为保存图片
|
||
//刷新文件信息
|
||
ui->labelNValue->setText(QString::number(dsr.getStitchNums()));
|
||
|
||
double width = dsr.getDatWidth()*0.01;
|
||
ui->labelWValue->setText(QString("%1").arg(width));
|
||
|
||
double height = dsr.getDatHeight()*0.01;
|
||
ui->labelHValue->setText(QString("%1").arg(height));
|
||
|
||
double xPos = dsr.getMaxX()*0.01;
|
||
ui->labelXValue->setText(QString("%1").arg(xPos));
|
||
|
||
double yPos = dsr.getMaxY()*0.01;
|
||
ui->labelYValue->setText(QString("%1").arg(yPos));
|
||
}
|
||
|
||
QPixmap pix = QPixmap::fromImage(image);
|
||
ui->labelPatternView->setPixmap(pix);
|
||
}
|
||
else if(m_selectAll == -1)//全不选
|
||
{
|
||
clickItem(m_selectAll);
|
||
}
|
||
|
||
if(m_selectFileItemList.size() <= 0)
|
||
{
|
||
ui->buttonOk->setEnabled(false);
|
||
}
|
||
else
|
||
{
|
||
ui->buttonOk->setEnabled(true);
|
||
}
|
||
}
|
||
|
||
//新建文件夹
|
||
void PatternManageWidget::on_buttonNewFolder_clicked()
|
||
{
|
||
WordsInputDialog wordInputDlg;
|
||
wordInputDlg.clean();
|
||
wordInputDlg.setTitleStr(tr("new folder"));//新文件夹
|
||
wordInputDlg.setOldWordsStr("");
|
||
if(wordInputDlg.exec() == 1)
|
||
{
|
||
//文件路径
|
||
QString name = wordInputDlg.getInputStr();
|
||
QDir apppath(qApp->applicationDirPath());
|
||
QString newFolderPath = m_curPath + apppath.separator() + name;
|
||
newFolderPath = QDir(newFolderPath).absolutePath();//为了将"\"变为"/"
|
||
|
||
QDir dir(newFolderPath);
|
||
if(dir.exists() == false)
|
||
{
|
||
dir.mkdir(newFolderPath);
|
||
initExecDirPath(m_curPath);
|
||
}
|
||
else
|
||
{
|
||
PromptDialog dlg(this);
|
||
dlg.initDialog(PromptDialog::BTN_OK);
|
||
dlg.setTitleStr(tr("Prompt"));
|
||
|
||
QString str;
|
||
str = tr("This folder already exists!");//此文件夹已经存在!
|
||
dlg.setContentStr(str);
|
||
dlg.exec();
|
||
return;
|
||
}
|
||
}
|
||
}
|