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 398a095..dd624c9 100644 --- a/src/BarcodeWidget.cpp +++ b/src/BarcodeWidget.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -217,20 +218,15 @@ 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)); @@ -243,15 +239,6 @@ BarcodeWidget::BarcodeWidget(QWidget *parent) } 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); @@ -605,6 +586,7 @@ void BarcodeWidget::onGenerateClicked() { int reqHeight; int finalWidth; // 最终目标宽度 int finalHeight; // 最终目标高度 + int targePPI; // 目标PPI用于设置DPM bool useBase64; ZXing::BarcodeFormat format; @@ -638,6 +620,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 +653,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() { 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 个文件,准备处理: - + [待解码] - + [待生成] - + [不确定类型,默认待生成] - - + + 请选择文件 或者键入内容 - - + + 语言