From c1facf48712d361037223b921829234504e5096d Mon Sep 17 00:00:00 2001 From: puji4810 Date: Wed, 21 Jan 2026 17:09:10 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=A2=9E=E5=BC=BA=20BarcodeWidget=EF=BC=9A?= =?UTF-8?q?=E4=B8=BA=E5=9B=BE=E5=83=8F=20DPI=20=E8=AE=BE=E7=BD=AE=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E7=9B=AE=E6=A0=87=20PPI=20-=20=E5=BC=95=E5=85=A5?= =?UTF-8?q?=E4=BA=86=20targetPPI=20=E5=8F=98=E9=87=8F=E4=BB=A5=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E5=9B=BE=E5=83=8F=20DPI/DPM=20=E5=85=83=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E3=80=82=20-=20=E6=9B=B4=E6=96=B0=E4=BA=86=E5=9B=BE?= =?UTF-8?q?=E5=83=8F=E5=A4=84=E7=90=86=E4=BB=A5=E5=8C=85=E5=90=AB=E7=94=9F?= =?UTF-8?q?=E6=88=90=E6=9D=A1=E5=BD=A2=E7=A0=81=E7=9A=84=20DPI=20=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E3=80=82=20-=20=E8=B0=83=E6=95=B4=E4=BA=86=20worker?= =?UTF-8?q?=20=E5=8F=82=E6=95=B0=E4=BB=A5=E9=80=82=E5=BA=94=E6=96=B0?= =?UTF-8?q?=E7=9A=84=20targetPPI=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BarcodeWidget.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/BarcodeWidget.cpp b/src/BarcodeWidget.cpp index 4eddf0b..4072898 100644 --- a/src/BarcodeWidget.cpp +++ b/src/BarcodeWidget.cpp @@ -605,6 +605,7 @@ void BarcodeWidget::onGenerateClicked() { int reqHeight; int finalWidth; // 最终目标宽度 int finalHeight; // 最终目标高度 + int targePPI; // 目标PPI用于设置DPM bool useBase64; ZXing::BarcodeFormat format; @@ -638,6 +639,13 @@ void BarcodeWidget::onGenerateClicked() { if (!img.isNull()) { // 缩放图像到精确尺寸 img = convert::resizeImageToExactSize(img, finalWidth, finalHeight); + + // 设置图像DPI/DPM元数据 + int ppi = targePPI; + int dpm = static_cast(ppi / 0.0254); + img.setDotsPerMeterX(dpm); + img.setDotsPerMeterY(dpm); + res.data = img; } else { res.data = QString(tr("生成图片失败")).toStdString(); @@ -664,7 +672,7 @@ void BarcodeWidget::onGenerateClicked() { watcher, &QFutureWatcher::finished, [this, watcher] { onBatchFinish(*watcher); }); watcher->setFuture(QtConcurrent::mapped( - filePaths, worker{targetWidth, targetHeight, targetWidth, targetHeight, useBase64, format})); + filePaths, worker{targetWidth, targetHeight, targetWidth, targetHeight, targePPI, useBase64, format})); } void BarcodeWidget::onDecodeToChemFileClicked() { From 1a17c02a431ddc3824087e88ca713fe128b19565 Mon Sep 17 00:00:00 2001 From: puji4810 Date: Wed, 21 Jan 2026 17:32:31 +0800 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20=E5=AE=8C=E5=96=84=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E7=89=A9=E7=90=86=E5=B0=BA=E5=AF=B8=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E4=B8=8E=E7=95=8C=E9=9D=A2=E4=BC=98=E5=8C=96=20-=20=E4=B8=BA?= =?UTF-8?q?=E6=89=80=E6=9C=89=E7=94=9F=E6=88=90=E6=A8=A1=E5=BC=8F=EF=BC=88?= =?UTF-8?q?=E5=8D=95=E6=96=87=E4=BB=B6=E3=80=81=E6=89=B9=E9=87=8F=EF=BC=89?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20DPI/DPM=20=E5=85=83=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=86=99=E5=85=A5=E6=94=AF=E6=8C=81=20-=20=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=20QGridLayout=20=E9=87=8D=E6=9E=84=E5=9B=BE=E7=89=87=E5=B0=BA?= =?UTF-8?q?=E5=AF=B8=E9=85=8D=E7=BD=AE=E5=8C=BA=E5=9F=9F=EF=BC=8C=E4=BD=BF?= =?UTF-8?q?=E5=85=B6=E5=B8=83=E5=B1=80=E6=9B=B4=E7=B4=A7=E5=87=91=E7=BE=8E?= =?UTF-8?q?=E8=A7=82=20-=20=E5=9C=A8=E6=A0=B7=E5=BC=8F=E8=A1=A8=E4=B8=AD?= =?UTF-8?q?=E6=98=BE=E5=BC=8F=E8=AE=BE=E7=BD=AE=E8=BE=93=E5=85=A5=E6=A1=86?= =?UTF-8?q?=E5=92=8C=E4=B8=8B=E6=8B=89=E6=A1=86=E6=96=87=E5=AD=97=E9=A2=9C?= =?UTF-8?q?=E8=89=B2=EF=BC=8C=E4=BF=AE=E5=A4=8D=20Linux=20=E4=B8=8B?= =?UTF-8?q?=E6=96=87=E5=AD=97=E4=B8=8D=E5=8F=AF=E8=A7=81=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setting/styles/barcode_widget.qss | 21 ++++ src/BarcodeWidget.cpp | 63 +++++------- translations/app_en_US.ts | 158 +++++++++++++++--------------- translations/app_zh_CN.ts | 158 +++++++++++++++--------------- 4 files changed, 201 insertions(+), 199 deletions(-) diff --git a/setting/styles/barcode_widget.qss b/setting/styles/barcode_widget.qss index 78cd9ba..9cf9c74 100644 --- a/setting/styles/barcode_widget.qss +++ b/setting/styles/barcode_widget.qss @@ -6,6 +6,7 @@ QLineEdit#filePathEdit { border-radius: 5px; padding: 5px; background-color: #f9f9f9; + color: #333; } /* 浏览按钮 */ @@ -44,6 +45,7 @@ QWidget#configWidget { background-color: #fafafa; border: 1px solid #d9d9d9; border-radius: 6px; + padding: 5px; } /* 配置标签 */ @@ -52,12 +54,30 @@ QLabel#configLabel { font-weight: 500; } +/* 下拉框 */ +QComboBox { + color: #333; + background-color: white; +} + +QComboBox::drop-down { + border: none; +} + +QComboBox QAbstractItemView { + color: #333; + background-color: white; + selection-background-color: #4CAF50; + selection-color: white; +} + /* 配置输入框 */ QLineEdit#configInput { border: 1px solid #d9d9d9; border-radius: 4px; padding: 5px 8px; background-color: white; + color: #333; } QLineEdit#configInput:focus { @@ -72,6 +92,7 @@ QLineEdit#heightInput { border-radius: 5px; padding: 5px; background-color: #f9f9f9; + color: #333; } /* 结果容器 */ diff --git a/src/BarcodeWidget.cpp b/src/BarcodeWidget.cpp index 4072898..ecba624 100644 --- a/src/BarcodeWidget.cpp +++ b/src/BarcodeWidget.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -217,41 +218,27 @@ BarcodeWidget::BarcodeWidget(QWidget *parent) scrollArea->setMinimumHeight(320); mainLayout->addWidget(scrollArea); - // 创建参数配置区域容器 QWidget *configWidget = new QWidget(this); configWidget->setObjectName("configWidget"); - QVBoxLayout *configMainLayout = new QVBoxLayout(configWidget); - configMainLayout->setContentsMargins(20, 12, 20, 12); - configMainLayout->setSpacing(10); + QGridLayout *configMainLayout = new QGridLayout(configWidget); + configMainLayout->setContentsMargins(15, 10, 15, 10); + configMainLayout->setHorizontalSpacing(15); + configMainLayout->setVerticalSpacing(8); - // 加载图像尺寸配置 imageSizeConfig = ImageSizeConfig::loadFromConfig("./setting/config.json"); - // 第一行:条码类型 - auto *formatLayout = new QHBoxLayout(); - formatLayout->setSpacing(10); - formatLabel = new QLabel(tr("选择条码类型:"), this); formatLabel->setObjectName("configLabel"); formatLabel->setFont(Ui::getAppFont(12)); QComboBox *formatComboBox = new QComboBox(this); formatComboBox->setFont(Ui::getAppFont(11)); - formatComboBox->setFixedWidth(100); + formatComboBox->setFixedWidth(120); for (const auto &item : qAsConst(barcodeFormats)) { formatComboBox->addItem(item); } formatComboBox->setCurrentText("QRCode"); - formatLayout->addWidget(formatLabel); - formatLayout->addWidget(formatComboBox); - formatLayout->addStretch(); - configMainLayout->addLayout(formatLayout); - - // 第二行:宽度和高度 - auto *row2Layout = new QHBoxLayout(); - row2Layout->setSpacing(10); - widthLabel = new QLabel(tr("宽度:"), this); widthLabel->setObjectName("configLabel"); widthLabel->setFont(Ui::getAppFont(12)); @@ -260,7 +247,7 @@ BarcodeWidget::BarcodeWidget(QWidget *parent) widthInput->setObjectName("configInput"); widthInput->setText(QString::number(imageSizeConfig.width)); widthInput->setFont(Ui::getAppFont(11)); - widthInput->setFixedWidth(70); + widthInput->setFixedWidth(80); heightLabel = new QLabel(tr("高度:"), this); heightLabel->setObjectName("configLabel"); @@ -270,19 +257,7 @@ BarcodeWidget::BarcodeWidget(QWidget *parent) heightInput->setObjectName("configInput"); heightInput->setText(QString::number(imageSizeConfig.height)); heightInput->setFont(Ui::getAppFont(11)); - heightInput->setFixedWidth(70); - - row2Layout->addWidget(widthLabel); - row2Layout->addWidget(widthInput); - row2Layout->addStretch(); - row2Layout->addWidget(heightLabel); - row2Layout->addWidget(heightInput); - - configMainLayout->addLayout(row2Layout); - - // 第三行:单位和PPI - auto *row3Layout = new QHBoxLayout(); - row3Layout->setSpacing(10); + heightInput->setFixedWidth(80); unitLabel = new QLabel(tr("单位:"), this); unitLabel->setObjectName("configLabel"); @@ -293,7 +268,7 @@ BarcodeWidget::BarcodeWidget(QWidget *parent) unitComboBox->addItem(tr("厘米"), static_cast(SizeUnit::Centimeter)); unitComboBox->setCurrentIndex(imageSizeConfig.unit == SizeUnit::Pixel ? 0 : 1); unitComboBox->setFont(Ui::getAppFont(11)); - unitComboBox->setFixedWidth(70); + unitComboBox->setFixedWidth(80); ppiLabel = new QLabel(tr("PPI:"), this); ppiLabel->setObjectName("configLabel"); @@ -303,16 +278,22 @@ BarcodeWidget::BarcodeWidget(QWidget *parent) ppiInput->setObjectName("configInput"); ppiInput->setText(QString::number(imageSizeConfig.ppi)); ppiInput->setFont(Ui::getAppFont(11)); - ppiInput->setFixedWidth(70); + ppiInput->setFixedWidth(80); ppiInput->setToolTip(tr("每英寸像素数(用于厘米到像素的转换)")); - row3Layout->addWidget(unitLabel); - row3Layout->addWidget(unitComboBox); - row3Layout->addStretch(); - row3Layout->addWidget(ppiLabel); - row3Layout->addWidget(ppiInput); + configMainLayout->addWidget(formatLabel, 0, 0, Qt::AlignRight); + configMainLayout->addWidget(formatComboBox, 0, 1); + configMainLayout->addWidget(widthLabel, 0, 2, Qt::AlignRight); + configMainLayout->addWidget(widthInput, 0, 3); + configMainLayout->addWidget(heightLabel, 0, 4, Qt::AlignRight); + configMainLayout->addWidget(heightInput, 0, 5); + + configMainLayout->addWidget(unitLabel, 1, 0, Qt::AlignRight); + configMainLayout->addWidget(unitComboBox, 1, 1); + configMainLayout->addWidget(ppiLabel, 1, 2, Qt::AlignRight); + configMainLayout->addWidget(ppiInput, 1, 3); - configMainLayout->addLayout(row3Layout); + configMainLayout->setColumnStretch(6, 1); mainLayout->addWidget(configWidget); diff --git a/translations/app_en_US.ts b/translations/app_en_US.ts index 3b1c66b..32ef5d0 100644 --- a/translations/app_en_US.ts +++ b/translations/app_en_US.ts @@ -77,223 +77,223 @@ BarcodeWidget - - + + 帮助 help - - + + 工具 tool - - + + 设置 settings - - + + 关于软件 About the software - - + + MQTT实时消息监控窗口 MQTT Real-time Message Monitoring Window - - + + 打开摄像头扫码 Open the camera to scan the code - - + + Base64 Base64 - - + + 文本输入 Text input - - - + + + 选择一个文件或图片 Select a file or image - - + + 浏览 Browse - - + + 生成 generate - - + + 解码 decode - - + + 保存 save - - + + 请选择任意文件来生成条码 Please select any file to generate the barcode - - + + 可以解码PNG图片中的条码 It can decode barcodes in PNG images - - + + 选择条码类型: Barcode Type: - - + + 宽度: width: - - + + 高度: height: - - + + 单位: Unit: - + 像素 PX - + 厘米 CM - - + + PPI: PPI: - - + + 每英寸像素数(用于厘米到像素的转换) Pixels Per Inch (for cm to px conversion) - + 输入要转换的文字 Enter the text to be converted - + 选择需要转换的文件或图片 Select the file or image you want to convert - - + + 生成图片失败 Failed to generate image - - - + + + 警告 Warning - - + + 无可处理文件 No files to process - + 无法打开文件: Unable to open the file: - + 无法加载图片文件: %1 Unable to load image file: %1 - + 无法识别条码或条码格式不正确 Unable to recognise the barcode or the barcode format is incorrect - + 没有可保存的内容。 There is no content available to save. - + 保存图片 Save the image - + 保存文件 Save the file - + 请选择保存文件夹 Please select a folder to save the file - + 数据为空或无效 The data is empty or invalid - + 写入失败 Failed to write - + 未知错误 Unknown error - + 操作完成。 总计处理: %1 成功: %2 @@ -304,7 +304,7 @@ Successful: %2 Failed: %3 - + [保存失败的文件]: @@ -315,17 +315,17 @@ Failed: %3 - + ...以及其他 %1 个文件 ...and %1 other files - + 保存结果 - 包含错误 Save results - including errors - + [文件列表]: @@ -336,48 +336,48 @@ Failed: %3 - + 保存成功 Saved successfully - + 当前模式:直接文本生成 请输入内容并点击生成 Current mode: Direct text generation. Please enter the content and click Generate - + 已选择 %1 个文件,准备处理: %1 files selected, ready for processing: - + [待解码] [Pending Decoding] - + [待生成] [Pending Generation] - + [不确定类型,默认待生成] [Uncertain type, pending generation] - - + + 请选择文件 或者键入内容 Please select a file or enter content - - + + 语言 language diff --git a/translations/app_zh_CN.ts b/translations/app_zh_CN.ts index d5d9871..c26ea03 100644 --- a/translations/app_zh_CN.ts +++ b/translations/app_zh_CN.ts @@ -77,223 +77,223 @@ BarcodeWidget - - + + 帮助 - - + + 工具 - - + + 设置 - - + + 关于软件 - - + + MQTT实时消息监控窗口 - - + + 打开摄像头扫码 - - + + Base64 - - + + 文本输入 - - - + + + 选择一个文件或图片 - - + + 浏览 - - + + 生成 - - + + 解码 - - + + 保存 - - + + 请选择任意文件来生成条码 - - + + 可以解码PNG图片中的条码 - - + + 选择条码类型: - - + + 宽度: - - + + 高度: - - + + 单位: - + 像素 - + 厘米 - - + + PPI: - - + + 每英寸像素数(用于厘米到像素的转换) - + 输入要转换的文字 - + 选择需要转换的文件或图片 - - + + 生成图片失败 - - - + + + 警告 - - + + 无可处理文件 - + 无法打开文件: - + 无法加载图片文件: %1 - + 无法识别条码或条码格式不正确 - + 没有可保存的内容。 - + 保存图片 - + 保存文件 - + 请选择保存文件夹 - + 数据为空或无效 - + 写入失败 - + 未知错误 - + 操作完成。 总计处理: %1 成功: %2 @@ -301,7 +301,7 @@ - + [保存失败的文件]: @@ -309,17 +309,17 @@ - + ...以及其他 %1 个文件 - + 保存结果 - 包含错误 - + [文件列表]: @@ -327,46 +327,46 @@ - + 保存成功 - + 当前模式:直接文本生成 请输入内容并点击生成 - + 已选择 %1 个文件,准备处理: - + [待解码] - + [待生成] - + [不确定类型,默认待生成] - - + + 请选择文件 或者键入内容 - - + + 语言