Quilting-lw/sharedviews/debuginfodialog.cpp

231 lines
6.6 KiB
C++
Raw Permalink Normal View History

2026-01-23 08:37:18 +00:00
#include "debuginfodialog.h"
#include "ui_debuginfodialog.h"
DebugInfoDialog::DebugInfoDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::DebugInfoDialog),
m_itemPerPage(12)
{
ui->setupUi(this);
setWindowFlags (Qt::Window | Qt::FramelessWindowHint);
setAttribute(Qt::WA_TranslucentBackground, true);//设置窗体背景透明
setWindowModality(Qt::ApplicationModal);
connect(g_pMachine, SIGNAL(siDebugInfo()), this, SLOT(slotDebugInfo()));
initDialog();
initControl();
}
DebugInfoDialog::~DebugInfoDialog()
{
delete ui;
}
void DebugInfoDialog::initDialog()
{
m_curPages = 1;//当前页数
m_pageNums = 1;//总页数
m_infoList.clear();
}
void DebugInfoDialog::initControl()
{
m_DebugInfoLabelList.append(ui->label1);
m_DebugInfoLabelList.append(ui->label2);
m_DebugInfoLabelList.append(ui->label3);
m_DebugInfoLabelList.append(ui->label4);
m_DebugInfoLabelList.append(ui->label5);
m_DebugInfoLabelList.append(ui->label6);
m_DebugInfoLabelList.append(ui->label7);
m_DebugInfoLabelList.append(ui->label8);
m_DebugInfoLabelList.append(ui->label9);
m_DebugInfoLabelList.append(ui->label10);
m_DebugInfoLabelList.append(ui->label11);
m_DebugInfoLabelList.append(ui->label12);
//根据不同分辨率设置控件的位置和尺寸
initResolution();
initControlStyle();//初始化窗体控件样式
//refreshUi();
}
//初始化窗体控件为任意分辨率
void DebugInfoDialog::initResolution()
{
double factoryX = getFactoryX();
double factoryY = getFactoryY();
this->resize(650*factoryX,513*factoryY);
this->move(101*factoryX+g_mainWidgetPos.x(),36*factoryY+g_mainWidgetPos.y());
ui->frameBack->setGeometry(0*factoryX,0*factoryY,650*factoryX,513*factoryY);
ui->labelMainTitle->setGeometry(10*factoryX,2*factoryY,300*factoryX,28*factoryY);
for(int i = 0; i < m_itemPerPage; i++)
{
m_DebugInfoLabelList[i]->setGeometry(10*factoryX,(34 + i * 35)*factoryY,630*factoryX,32*factoryY);
}
ui->labelPage->setGeometry(10*factoryX,466*factoryY,200*factoryX,40*factoryY);
ui->buttonPgUp->setGeometry(340*factoryX,462*factoryY,90*factoryX,40*factoryY);
ui->buttonPgDn->setGeometry(446*factoryX,462*factoryY,90*factoryX,40*factoryY);
ui->buttonCancel->setGeometry(552*factoryX,462*factoryY,90*factoryX,40*factoryY);
}
//初始化窗体控件样式
void DebugInfoDialog::initControlStyle()
{
SetStyle setControlStyle;
setControlStyle.setUiName(this->objectName());
//背景图
//QString style1 = "background-color: rgb(62, 62, 62);outline:none;border:0px;border-radius:" + borderRadius() + "px;";
QString style1 = "background-color: rgb(246, 242, 239);outline:none;border:0px;border-radius:" + borderRadius() + "px;";
QString style1_1 = "background-color: rgb(240, 245, 249);outline:none;border:0px;border-radius:" + borderRadius() + "px;";
ui->frameBack->setStyleSheet(style1_1);
if(g_emTheme == theme2)
{
ui->frameBack->setStyleSheet(frameBackStyle());
}
ui->labelMainTitle->setFont(fontSize_L());
ui->labelMainTitle->setStyleSheet(classIconTextColour());
//todo 布线机部分缺少相应代码需进行补充完善
for(int i = 0; i < m_DebugInfoLabelList.size(); i++)
{
m_DebugInfoLabelList[i]->setFont(fontSize_M());
}
ui->labelPage->setFont(fontSize_M());
ui->labelPage->setStyleSheet(classIconTextColour());
ui->buttonPgUp->setStyleSheet(confirmIconStyle());
ui->buttonPgUp->setTopImage(setControlStyle.getSharedTopStyleSheet(ui->buttonPgUp->objectName()));
ui->buttonPgDn->setStyleSheet(confirmIconStyle());
ui->buttonPgDn->setTopImage(setControlStyle.getSharedTopStyleSheet(ui->buttonPgDn->objectName()));
ui->buttonCancel->setStyleSheet(confirmIconStyle());
ui->buttonCancel->setTopImage(setControlStyle.getSharedTopStyleSheet(ui->buttonCancel->objectName()));
}
void DebugInfoDialog::addListInfo()
{
// for(int i = 0; i < 100; i++)
// {
// m_infoList.append("1234qfdhdjdnfjdisjdfj");
// }
m_infoList = g_pSettings->readToCsv(TYPE_DEBUGINFO);//读取 QStringList
refreshUi();
}
void DebugInfoDialog::refreshUi()
{
int itemNum;
if (m_infoList.size() <= 0)
{
itemNum = 0;
for (int i = 0; i < m_itemPerPage; i++)
{
m_DebugInfoLabelList.at(i)->hide();
}
ui->labelPage->setText(tr("pageNum: 0/0"));//页数: 0/0
ui->buttonPgUp->setEnabled(false);
ui->buttonPgDn->setEnabled(false);
//ui->buttonOk->setEnabled(false);
return;
}
else
{
itemNum = m_infoList.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_DebugInfoLabelList[i]->setText(m_infoList.at(itemidx));
m_DebugInfoLabelList.at(i)->show();
itemidx++;
}
else
{
m_DebugInfoLabelList.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);
}
void DebugInfoDialog::slotDebugInfo()
{
DebugInfo info;//调试信息
char mDebugInfoStr[1024+1];
info = g_pMachine->getDebugInfo();
memcpy(mDebugInfoStr, info.debugInfoStr, 1024);
mDebugInfoStr[1024] = 0;
QString strDebugInfoStr;
strDebugInfoStr.sprintf("%s", mDebugInfoStr);
QString strCurTime = QDateTime::currentDateTime().toString("yyyy/MM/dd/ hh:mm:ss");//时间
QString strMessage;
strMessage = QString("%1//%2").arg(strCurTime).arg(strDebugInfoStr);//时间,内容
m_infoList.insert(0,strMessage);
//m_infoList = g_pSettings->readToCsv(TYPE_DEBUGINFO);//读取 QStringList
refreshUi();
}
void DebugInfoDialog::on_buttonCancel_clicked()
{
done(0);
}
void DebugInfoDialog::on_buttonPgUp_clicked()
{
m_curPages--;
refreshUi();
}
void DebugInfoDialog::on_buttonPgDn_clicked()
{
m_curPages++;
refreshUi();
}