Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions setting/styles/barcode_widget.qss
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ QLineEdit#filePathEdit {
border-radius: 5px;
padding: 5px;
background-color: #f9f9f9;
color: #333;
}

/* 浏览按钮 */
Expand Down Expand Up @@ -44,6 +45,7 @@ QWidget#configWidget {
background-color: #fafafa;
border: 1px solid #d9d9d9;
border-radius: 6px;
padding: 5px;
}

/* 配置标签 */
Expand All @@ -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 {
Expand All @@ -72,6 +92,7 @@ QLineEdit#heightInput {
border-radius: 5px;
padding: 5px;
background-color: #f9f9f9;
color: #333;
}

/* 结果容器 */
Expand Down
71 changes: 30 additions & 41 deletions src/BarcodeWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <QFileDialog>
#include <QFont>
#include <QFutureWatcher>
#include <QGridLayout>
#include <QGuiApplication>
#include <QHBoxLayout>
#include <QLabel>
Expand Down Expand Up @@ -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));
Expand All @@ -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));
Expand All @@ -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");
Expand All @@ -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");
Expand All @@ -293,7 +268,7 @@ BarcodeWidget::BarcodeWidget(QWidget *parent)
unitComboBox->addItem(tr("厘米"), static_cast<int>(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");
Expand All @@ -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);

Expand Down Expand Up @@ -605,6 +586,7 @@ void BarcodeWidget::onGenerateClicked() {
int reqHeight;
int finalWidth; // 最终目标宽度
int finalHeight; // 最终目标高度
int targePPI; // 目标PPI用于设置DPM
bool useBase64;
ZXing::BarcodeFormat format;

Expand Down Expand Up @@ -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<int>(ppi / 0.0254);
img.setDotsPerMeterX(dpm);
img.setDotsPerMeterY(dpm);

res.data = img;
} else {
res.data = QString(tr("生成图片失败")).toStdString();
Expand All @@ -664,7 +653,7 @@ void BarcodeWidget::onGenerateClicked() {
watcher, &QFutureWatcher<convert::result_data_entry>::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() {
Expand Down
Loading