PunchHMI/sharedviews/needlebarsetwidget.cpp

630 lines
21 KiB
C++
Raw Normal View History

2024-02-06 06:58:57 +00:00
#include "needlebarsetwidget.h"
#include "ui_needlebarsetwidget.h"
NeedleBarSetWidget::NeedleBarSetWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::NeedleBarSetWidget),
m_pEmbNeedleBtn(NULL),
m_pColorBtn(NULL)
{
ui->setupUi(this);
setWindowFlags (Qt::Window | Qt::FramelessWindowHint);
setWindowModality(Qt::ApplicationModal);
initWidget();
initControl();
}
NeedleBarSetWidget::~NeedleBarSetWidget()
{
delete ui;
}
void NeedleBarSetWidget::initWidget()
{
m_setType = 1;
QDir apppath(qApp->applicationDirPath());
//配置文件路径
m_configFile = apppath.path() + apppath.separator() + "config.ini";
m_pColorBuf = (QRgb *)(g_pSettings->getColorRgbArray().data());
m_buttonStyle1 = "QPushButton{outline: none;border:0px solid rgb(0,0,0);border-style:inset;border-radius:5px;";
m_buttonStyle2 = "QPushButton:checked{outline: none;border:3px groove rgb(80,80,80);}";
m_embNeedleBtnList.clear();
int embNeedleItem = 32;
for(int i = 0; i < embNeedleItem; i++)
{
MyButton *buttonEmbNeedle = new MyButton(ui->frameEmb);
m_embNeedleBtnList.append(buttonEmbNeedle);
connect(buttonEmbNeedle,
SIGNAL(clicked()),
this,
SLOT(embNeedleBtnClick())
);
}
int colorNumer = BF_SW_ND; //颜色数
m_colorBtnList.clear();
for(int i = 0; i < colorNumer; i++)
{
QPushButton *buttonColor = new QPushButton(ui->frameColor);
m_colorBtnList.append(buttonColor);
connect(buttonColor,
SIGNAL(clicked()),
this,
SLOT(colorBtnClick())
);
}
}
void NeedleBarSetWidget::initControl()
{
//根据不同分辨率设置控件的位置和尺寸
switch (g_emResolut)
{
case resolution1910:
initResolution1910();
break;
case resolution1006:
initResolution1006();
break;
default:
this->resize(1920,1080);
break;
}
initControlStyle();//初始化窗体控件样式
}
void NeedleBarSetWidget::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->frameRightUp->setGeometry(1366,92,582,72);
ui->buttonEmbSet->setGeometry(176,0,66,66);
ui->buttonPunchSet->setGeometry(88,0,66,66);
ui->buttonSewSet->setGeometry(0,0,66,66);
ui->frameEmb->setGeometry(62,217,336,720);
ui->labelEmbNeedleNum->setGeometry(10,0,228,48);
ui->buttonEmbNeedleNum->setGeometry(240,0,94,48);
for(int i = 0; i < 3; i++)
{
int num = 11;
for(int j = 0; j < num; j++)
{
// 颜色显示
QRgb rgb = m_pColorBuf[((i*num+j) % MC_SW_ND)];
rgb |= 0xff000000;
QColor bkcolor(rgb);
QColor tcolor = QColor(255-bkcolor.red(), 255-bkcolor.green(), 255-bkcolor.blue()).lighter(168);
QString cstyle = "outline: none;background-color:" + bkcolor.name() + ";"
+ " color:" + tcolor.name() + ";";
if(i*num+j < m_embNeedleBtnList.size())
{
m_embNeedleBtnList[i*num+j]->setGeometry(10+i*115,69+j*59,94,48);
m_embNeedleBtnList[i*num+j]->setStyleSheet(m_buttonStyle1 + cstyle + "}" + m_buttonStyle2);
m_embNeedleBtnList[i*num+j]->setFont(fontNormal_1);
m_embNeedleBtnList[i*num+j]->setText(QString::number(i*num+j+1));
}
}
}
//右侧
ui->frameColor->setGeometry(422,218,1426,708);
int hColorNum = 24;
int vColorNum = 12;
for(int i = 0; i < vColorNum; i++)
{
for(int j = 0; j < hColorNum; j++)
{
// 颜色显示
QRgb rgb = m_pColorBuf[((i*hColorNum+j) % MC_SW_ND)];
rgb |= 0xff000000;
QColor bkcolor(rgb);
QString cstyle = "outline: none;background-color:" + bkcolor.name() + ";";
m_colorBtnList[i*hColorNum+j]->setGeometry(7+j*59,3+i*59,50,50);
m_colorBtnList[i*hColorNum+j]->setStyleSheet(m_buttonStyle1 + cstyle + "}" + m_buttonStyle2);
}
}
ui->framePageBtn->setGeometry(1120,990,800,70);
ui->buttonOk->setGeometry(600,0,168,70);
}
void NeedleBarSetWidget::initResolution1006()
{
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->frameRightUp->setGeometry(663,40,338,61);
ui->buttonEmbSet->setGeometry(114,0,50,50);
ui->buttonPunchSet->setGeometry(57,0,50,50);
ui->buttonSewSet->setGeometry(0,0,50,50);
ui->frameEmb->setGeometry(30,90,221,441);
ui->labelEmbNeedleNum->setGeometry(6,30,110,20);
ui->buttonEmbNeedleNum->setGeometry(125,30,55,28);
for(int i = 0; i < 3; i++)
{
int num = 11;
for(int j = 0; j < num; j++)
{
// 颜色显示
QRgb rgb = m_pColorBuf[((i*num+j) % MC_SW_ND)];
rgb |= 0xff000000;
QColor bkcolor(rgb);
QColor tcolor = QColor(255-bkcolor.red(), 255-bkcolor.green(), 255-bkcolor.blue()).lighter(168);
QString cstyle = "outline: none;background-color:" + bkcolor.name() + ";"
+ " color:" + tcolor.name() + ";";
if(i*num+j < m_embNeedleBtnList.size())
{
m_embNeedleBtnList[i*num+j]->setGeometry(5+i*63,62+j*34,54,29);//左侧颜色
m_embNeedleBtnList[i*num+j]->setStyleSheet(m_buttonStyle1 + cstyle + "}" + m_buttonStyle2);
m_embNeedleBtnList[i*num+j]->setFont(fontNormal_1);
m_embNeedleBtnList[i*num+j]->setText(QString::number(i*num+j+1));
}
}
}
ui->frameColor->setGeometry(236,125,735,420);
int hColorNum = 24;
int vColorNum = 12;
for(int i = 0; i < vColorNum; i++)
{
for(int j = 0; j < hColorNum; j++)
{
// 颜色显示
QRgb rgb = m_pColorBuf[((i*hColorNum+j) % MC_SW_ND)];
rgb |= 0xff000000;
QColor bkcolor(rgb);
QString cstyle = "outline: none;background-color:" + bkcolor.name() + ";";
m_colorBtnList[i*hColorNum+j]->setGeometry(3+j*32,3+i*32,26,26);
m_colorBtnList[i*hColorNum+j]->setStyleSheet(m_buttonStyle1 + cstyle + "}" + m_buttonStyle2);
}
}
ui->framePageBtn->setGeometry(595,548,600,45);
ui->buttonOk->setGeometry(318,0,96,40);
}
//初始化窗体控件样式
void NeedleBarSetWidget::initControlStyle()
{
SetControlStyle setControlStyle;
setControlStyle.setUiName(this->objectName());
QString frameBackImgPath = setControlStyle.getStyleSheet(this->objectName());
ui->frameBack->setStyleSheet(frameBackImgPath);
ui->frameEmb->setStyleSheet(TRANSPARENTSTYLE);
ui->frameColor->setStyleSheet(TRANSPARENTSTYLE);
ui->labelMainTitle->setFont(fontBold_1);
ui->labelMainTitle->setStyleSheet(LABELWHITESTYLE);
ui->labelSubTitle->setFont(fontNormal_1);
ui->labelSubTitle->setStyleSheet(LABELWHITESTYLE);
//右上方
ui->frameRightUp->setStyleSheet(TRANSPARENTSTYLE);
ui->buttonEmbSet->setGreenGradientBottomStyle(BORDER_RADIUS1);
ui->buttonEmbSet->setTopImage(setControlStyle.getTopStyleSheet(ui->buttonEmbSet->objectName()));
ui->buttonPunchSet->setGreenGradientBottomStyle(BORDER_RADIUS1);
ui->buttonPunchSet->setTopImage(setControlStyle.getTopStyleSheet(ui->buttonPunchSet->objectName()));
ui->buttonSewSet->setGreenGradientBottomStyle(BORDER_RADIUS1);
ui->buttonSewSet->setTopImage(setControlStyle.getTopStyleSheet(ui->buttonSewSet->objectName()));
ui->labelEmbNeedleNum->setFont(fontNormal_1);
ui->labelEmbNeedleNum->setStyleSheet(LABELWHITESTYLE);
ui->buttonEmbNeedleNum->setFont(fontNormal_1);
ui->buttonOk->setOrangeGradientBottomStyle(BORDER_RADIUS2);
ui->buttonOk->setTopImage(setControlStyle.getSharedTopStyleSheet(ui->buttonOk->objectName()),12);
}
void NeedleBarSetWidget::embNeedleBtnClick()
{
m_pEmbNeedleBtn = (QPushButton*) this->sender();
if(m_pEmbNeedleBtn == NULL)
{
return;
}
for(int i = 0; i < m_embNeedleBtnList.size(); i++)
{
m_embNeedleBtnList.at(i)->setChecked(false);
m_embNeedleBtnList.at(i)->setCheckable(false);
}
m_pEmbNeedleBtn->setCheckable(true);
m_pEmbNeedleBtn->setChecked(true);
}
void NeedleBarSetWidget::colorBtnClick()
{
m_pColorBtn = (QPushButton*) this->sender();
if(m_pColorBtn == NULL || m_pEmbNeedleBtn == NULL)
{
return;
}
int idx = 0;
for(int i = 0; i < m_colorBtnList.size(); i++)
{
if(m_pColorBtn == m_colorBtnList.at(i))
{
idx = i;
}
m_colorBtnList.at(i)->setChecked(false);
m_colorBtnList.at(i)->setCheckable(false);
}
m_pColorBtn->setCheckable(true);
m_pColorBtn->setChecked(true);
QRgb rgb = m_pColorBuf[(idx % BF_SW_ND)];
rgb |= 0xff000000;
QColor bkcolor(rgb);
QColor tcolor = QColor(255-bkcolor.red(), 255-bkcolor.green(), 255-bkcolor.blue()).lighter(168);
QString cstyle = "outline: none;background-color:" + bkcolor.name() + ";"
+ " color:" + tcolor.name() + ";";
m_pEmbNeedleBtn->setStyleSheet(m_buttonStyle1 + cstyle + "}" + m_buttonStyle2);
//写入配置
for(int i = 0; i < m_embNeedleBtnList.size(); i++)
{
if(m_pEmbNeedleBtn == m_embNeedleBtnList.at(i))
{
if(m_setType == SET_TYPE_NEEDLE_EMB)
{
g_pSettings->writeToIniFile("EmbNeedle/"+QString::number(i+1)+"_coloridx",QString::number(idx));
g_pCurEmbData->setNeedleColorTable(i,idx);
emit siChangeNeedleColor(i,idx);
}
else if(m_setType == SET_TYPE_NEEDLE_PUNCH)
{
g_pSettings->writeToIniFile("PunchNeedle/"+QString::number(i+1)+"_coloridx",QString::number(idx));
g_pCurEmbData->setNeedleColorTable(i+EMB_NEEDLE_NUM,idx);
emit siChangeNeedleColor(i+EMB_NEEDLE_NUM,idx);
}
else if(m_setType == SET_TYPE_NEEDLE_SEW)
{
g_pSettings->writeToIniFile("SewNeedle/"+QString::number(i+1)+"_coloridx",QString::number(idx));
g_pCurEmbData->setNeedleColorTable(i+EMB_NEEDLE_NUM+PUNCH_NEEDLE_NUM,idx);
emit siChangeNeedleColor(i+EMB_NEEDLE_NUM+PUNCH_NEEDLE_NUM,idx);
}
break;
}
}
}
void NeedleBarSetWidget::setTypeLogo(QString tStyle)
{
ui->buttonTypeLogo->setUnPreBtnLogo(tStyle);
}
void NeedleBarSetWidget::setMainTitle(QString str)
{
ui->labelMainTitle->setText(str);
}
void NeedleBarSetWidget::setSubTitle(QString str)
{
ui->labelSubTitle->setText(str);
}
void NeedleBarSetWidget::initNeedleBar()
{
//标题显示
if(m_setType == SET_TYPE_NEEDLE_EMB)
{
ui->labelEmbNeedleNum->setText(tr("EmbNeedleNum:"));//绣花针杆个数:
}
else if(m_setType == SET_TYPE_NEEDLE_PUNCH)
{
ui->labelEmbNeedleNum->setText(tr("PunchNeedleNum:"));//冲孔针杆个数:
}
else if(m_setType == SET_TYPE_NEEDLE_SEW)
{
ui->labelEmbNeedleNum->setText(tr("SewNeedleNum:"));//缝纫针杆个数:
}
//读入配置
QFile iniFile(m_configFile);
int num,idx;
num = idx = 0;
if(!iniFile.exists())
{
num = 1;
idx = 0;
QRgb rgb = m_pColorBuf[(idx % BF_SW_ND)];
rgb |= 0xff000000;
QColor bkcolor(rgb);
QColor tcolor = QColor(255-bkcolor.red(), 255-bkcolor.green(), 255-bkcolor.blue()).lighter(168);
QString cstyle = "outline: none;background-color:" + bkcolor.name() + ";"
+ " color:" + tcolor.name() + ";";
for(int i = 0; i < m_embNeedleBtnList.size(); i++)
{
if(i < num)
{
m_embNeedleBtnList.at(i)->setStyleSheet(m_buttonStyle1 + cstyle + "}" + m_buttonStyle2);
m_embNeedleBtnList.at(i)->show();
}
else
{
m_embNeedleBtnList.at(i)->hide();
}
}
}
else
{
QRgb rgb = qRgb(0,255,0);
if(m_setType == SET_TYPE_NEEDLE_EMB)
{
num = g_pSettings->readFromIniFile("EmbNeedle/number").toInt();
}
else if(m_setType == SET_TYPE_NEEDLE_PUNCH)
{
num = g_pSettings->readFromIniFile("PunchNeedle/number").toInt();
}
else if(m_setType == SET_TYPE_NEEDLE_SEW)
{
num = g_pSettings->readFromIniFile("SewNeedle/number").toInt();
}
for(int i = 0; i < m_embNeedleBtnList.size(); i++)//32个针杆
{
QString idxStr;
if(m_setType == SET_TYPE_NEEDLE_EMB)
{
idxStr = "EmbNeedle/"+QString::number(i+1)+"_coloridx";
}
else if(m_setType == SET_TYPE_NEEDLE_PUNCH)
{
idxStr = "PunchNeedle/"+QString::number(i+1)+"_coloridx";
}
else if(m_setType == SET_TYPE_NEEDLE_SEW)
{
idxStr = "SewNeedle/"+QString::number(i+1)+"_coloridx";
}
if(g_pSettings->ifKeyExists(idxStr) == true)
{
idx = g_pSettings->readFromIniFile(idxStr).toInt();//第几个针杆的颜色值
rgb = m_pColorBuf[(idx % BF_SW_ND)];
}
else
{
rgb = m_pColorBuf[(i % MC_SW_ND)];
}
rgb |= 0xff000000;
QColor bkcolor(rgb);
QColor tcolor = QColor(255-bkcolor.red(), 255-bkcolor.green(), 255-bkcolor.blue()).lighter(168);
QString cstyle = "outline: none;background-color:" + bkcolor.name() + ";"
+ " color:" + tcolor.name() + ";";
if(i < num)
{
m_embNeedleBtnList.at(i)->setStyleSheet(m_buttonStyle1 + cstyle + "}" + m_buttonStyle2);
m_embNeedleBtnList.at(i)->show();
}
else
{
m_embNeedleBtnList.at(i)->hide();
}
}
}
ui->buttonEmbNeedleNum->setText(QString::number(num));
}
//刷新右上方按钮的显示,包括选中状态
void NeedleBarSetWidget::refreshTypeBtnShow()
{
ui->buttonEmbSet->setChecked(false);//不是选中状态,可见
ui->buttonEmbSet->setVisible(true);
ui->buttonPunchSet->setChecked(false);//不是选中状态,可见
ui->buttonPunchSet->setVisible(true);
ui->buttonSewSet->setChecked(false);//不是选中状态,可见
ui->buttonSewSet->setVisible(true);
if(g_emResolut == resolution1910)
{
ui->buttonEmbSet->setGeometry(176,0,66,66);
ui->buttonPunchSet->setGeometry(88,0,66,66);
ui->buttonSewSet->setGeometry(0,0,66,66);
}
else if(g_emResolut == resolution1006)
{
ui->buttonEmbSet->setGeometry(114,0,50,50);
ui->buttonPunchSet->setGeometry(57,0,50,50);
ui->buttonSewSet->setGeometry(0,0,50,50);
}
if(g_emMacType == MACHINE_PUNCH_SEW) //等于冲缝机
{
m_setType = SET_TYPE_NEEDLE_PUNCH;
ui->labelEmbNeedleNum->setText(tr("PunchNeedleNum:"));//冲孔针杆个数:
ui->buttonPunchSet->setCheckable(true);//设置绣花为默认选中
ui->buttonPunchSet->setChecked(true);
ui->buttonEmbSet->setVisible(false);
}
else if(g_emMacType == MACHINE_PUNCH_SEW_EMB)//等于冲缝绣
{
m_setType = SET_TYPE_NEEDLE_PUNCH;
ui->labelEmbNeedleNum->setText(tr("PunchNeedleNum:"));//冲孔针杆个数:
ui->buttonPunchSet->setCheckable(true);//设置绣花为默认选中
ui->buttonPunchSet->setChecked(true);
ui->buttonEmbSet->setVisible(true);
}
else
{
m_setType = SET_TYPE_NEEDLE_PUNCH;
ui->labelEmbNeedleNum->setText(tr("PunchNeedleNum:"));//冲孔针杆个数:
ui->buttonEmbSet->setVisible(false);
ui->buttonPunchSet->setVisible(false);
ui->buttonSewSet->setVisible(false);
}
}
//刷新针杆数量及颜色
void NeedleBarSetWidget::refreshNeedleColorShow()
{
ui->buttonEmbSet->setChecked(false);
ui->buttonPunchSet->setChecked(false);
ui->buttonSewSet->setChecked(false);
initNeedleBar();
}
void NeedleBarSetWidget::on_buttonEmbNeedleNum_clicked()
{
NumerInputDialog numberInputDlg;
numberInputDlg.setTitleStr(tr("Number set"));//个数设置
numberInputDlg.setUnitStr("");
if(m_setType == SET_TYPE_NEEDLE_EMB)
{
numberInputDlg.setValueAndRange(ui->buttonEmbNeedleNum->text().toInt(), 1, 32, 0);
}
else if(m_setType == SET_TYPE_NEEDLE_PUNCH)
{
numberInputDlg.setValueAndRange(ui->buttonEmbNeedleNum->text().toInt(), 1, 15, 0);
}
else if(m_setType == SET_TYPE_NEEDLE_SEW)
{
numberInputDlg.setValueAndRange(ui->buttonEmbNeedleNum->text().toInt(), 1, 1, 0);
}
//针杆设置的弹窗点击确认按钮就写在配置文件了
if(numberInputDlg.exec() == 1)
{
s32 val = numberInputDlg.getValue();
ui->buttonEmbNeedleNum->setText(QString::number(val));
for(int i = 0; i < m_embNeedleBtnList.size(); i++)
{
if(i < val)
{
m_embNeedleBtnList.at(i)->show();
}
else
{
m_embNeedleBtnList.at(i)->hide();
}
}
//写入配置
if(m_setType == SET_TYPE_NEEDLE_EMB)
{
g_pSettings->writeToIniFile("EmbNeedle/number",val);
}
else if(m_setType == SET_TYPE_NEEDLE_PUNCH)
{
g_pSettings->writeToIniFile("PunchNeedle/number",val);
}
else if(m_setType == SET_TYPE_NEEDLE_SEW)
{
g_pSettings->writeToIniFile("SewNeedle/number",val);
}
}
}
void NeedleBarSetWidget::on_buttonOk_clicked()
{
int embNum = g_pSettings->readFromIniFile("EmbNeedle/number").toInt();
for(int i = 0; i < embNum; i++)
{
QString idxStr = "EmbNeedle/"+QString::number(i+1)+"_coloridx";
if(g_pSettings->ifKeyExists(idxStr) == false)
{
g_pSettings->writeToIniFile("EmbNeedle/"+QString::number(i+1)+"_coloridx",QString::number(i+1));
g_pCurEmbData->setNeedleColorTable(i+1,i+1);
emit siChangeNeedleColor(i,i+1);
}
}
int punchNum = g_pSettings->readFromIniFile("PunchNeedle/number").toInt();
for(int i = 0; i < punchNum; i++)
{
QString idxStr = "PunchNeedle/"+QString::number(i+1)+"_coloridx";
if(g_pSettings->ifKeyExists(idxStr) == false)
{
g_pSettings->writeToIniFile("PunchNeedle/"+QString::number(i+1)+"_coloridx",QString::number(i+1));
g_pCurEmbData->setNeedleColorTable(i+1+EMB_NEEDLE_NUM,i+1);
emit siChangeNeedleColor(i+EMB_NEEDLE_NUM,i+1);
}
}
int sewNum = g_pSettings->readFromIniFile("SewNeedle/number").toInt();
for(int i = 0; i < sewNum; i++)
{
QString idxStr = "SewNeedle/"+QString::number(i+1)+"_coloridx";
if(g_pSettings->ifKeyExists(idxStr) == false)
{
g_pSettings->writeToIniFile("SewNeedle/"+QString::number(i+1)+"_coloridx",QString::number(i+1));
g_pCurEmbData->setNeedleColorTable(i+1+EMB_NEEDLE_NUM+PUNCH_NEEDLE_NUM,i+1);
emit siChangeNeedleColor(i+EMB_NEEDLE_NUM+PUNCH_NEEDLE_NUM,i+1);
}
}
//密码权限,单次有效
g_emUser = operate;
this->hide();
}
//绣花针杆颜色设置
void NeedleBarSetWidget::on_buttonEmbSet_clicked()
{
m_setType = SET_TYPE_NEEDLE_EMB;
refreshNeedleColorShow();
ui->buttonEmbSet->setCheckable(true);
ui->buttonEmbSet->setChecked(true);
ui->buttonPunchSet->setChecked(false);
ui->buttonPunchSet->setCheckable(false);
ui->buttonSewSet->setChecked(false);
ui->buttonSewSet->setCheckable(false);
}
void NeedleBarSetWidget::on_buttonPunchSet_clicked()
{
m_setType = SET_TYPE_NEEDLE_PUNCH;
refreshNeedleColorShow();
ui->buttonPunchSet->setCheckable(true);
ui->buttonPunchSet->setChecked(true);
ui->buttonEmbSet->setChecked(false);
ui->buttonEmbSet->setCheckable(false);
ui->buttonSewSet->setChecked(false);
ui->buttonSewSet->setCheckable(false);
}
void NeedleBarSetWidget::on_buttonSewSet_clicked()
{
m_setType = SET_TYPE_NEEDLE_SEW;
refreshNeedleColorShow();
ui->buttonSewSet->setCheckable(true);
ui->buttonSewSet->setChecked(true);
ui->buttonEmbSet->setChecked(false);
ui->buttonEmbSet->setCheckable(false);
ui->buttonPunchSet->setChecked(false);
ui->buttonPunchSet->setCheckable(false);
}