新二维码/条形码编辑逻辑

This commit is contained in:
2026-05-06 10:34:48 +08:00
parent a06c926162
commit a9e99f4425
76 changed files with 12679 additions and 12744 deletions
+66 -43
View File
@@ -191,6 +191,11 @@ TestPrintWidget::TestPrintWidget(QWidget* parent)
emit sig_showEditCounter(vm);
});
connect(ui.btnBarcode, &QPushButton::clicked, [this](){
pPicScene->clearSelection();
showBarcodeEditor();
});
// X,Y label connection
connect(pPicScene, &PicScene::focusedItemPosChanged, this, &TestPrintWidget::onSceneFocusedItemPosChanged);
@@ -214,6 +219,8 @@ TestPrintWidget::TestPrintWidget(QWidget* parent)
itemEditor = new ItemEditor();
connect(itemEditor, &ItemEditor::accepted, this, &TestPrintWidget::onItemEditorAccepted);
connect(&m_barcodeEditor, &BarcodeEditor::accepted, this, &TestPrintWidget::slt_BarCodeItemDone);
initSelecteCodeDlg();
// 网络通信,暂时屏蔽
@@ -252,6 +259,7 @@ QPixmap TestPrintWidget::loadIcon(const QString& iconName, const QSize& size)
void TestPrintWidget::on_openfileButton_pressed()
{
pPicScene->clearSelection();
pPicScene->clearFocus();
dialogFileOperation->refreshListView(editMode);
dialogFileOperation->exec();
}
@@ -1219,39 +1227,41 @@ void TestPrintWidget::onCreateSceneImage(QString filePath)
void TestPrintWidget::on_KeyUp_clicked()
{
pViewer->setFocus();
#ifndef Q_OS_WIN32
//QWSServer::sendKeyEvent(0,Qt::Key_Up,Qt::NoModifier,true,false); //向系统发送键盘事件
MyInputMethod::sendEvent(Qt::Key_Up,Qt::NoModifier);
#endif
moveSelectedItem(Qt::Key_Up);
}
void TestPrintWidget::on_KeyLeft_clicked()
{
pViewer->setFocus();
#ifndef Q_OS_WIN32
//QWSServer::sendKeyEvent(0,Qt::Key_Left,Qt::NoModifier,true,false); //向系统发送键盘事件
MyInputMethod::sendEvent(Qt::Key_Left,Qt::NoModifier);
#endif
moveSelectedItem(Qt::Key_Left);
}
void TestPrintWidget::on_KeyRight_clicked()
{
pViewer->setFocus();
#ifndef Q_OS_WIN32
//QWSServer::sendKeyEvent(0,Qt::Key_Right,Qt::NoModifier,true,false); //向系统发送键盘事件
MyInputMethod::sendEvent(Qt::Key_Right,Qt::NoModifier);
#endif
moveSelectedItem(Qt::Key_Right);
}
void TestPrintWidget::on_KeyDown_clicked()
{
pViewer->setFocus();
#ifndef Q_OS_WIN32
//QWSServer::sendKeyEvent(0,Qt::Key_Down,Qt::NoModifier,true,false); //向系统发送键盘事件
MyInputMethod::sendEvent(Qt::Key_Down,Qt::NoModifier);
#endif
moveSelectedItem(Qt::Key_Down);
}
void TestPrintWidget::moveSelectedItem(Qt::Key key)
{
pViewer->setFocus();
auto selectedItems = pPicScene->selectedItems();
QGraphicsItem* lastItem = nullptr;
if(selectedItems.size() >= 1) {
lastItem = selectedItems.last();
}
if(lastItem) {
lastItem->setFocus();
}
#ifndef Q_OS_WIN32
//QWSServer::sendKeyEvent(0,Qt::Key_Up,Qt::NoModifier,true,false); //向系统发送键盘事件
MyInputMethod::sendEvent(key, Qt::NoModifier);
#endif
}
void TestPrintWidget::on_delButton_pressed()
@@ -1371,13 +1381,12 @@ void TestPrintWidget::onBtnItemConfigClicked()
}
if (item->sourceType() == SourceType::CODE) {
QString s = item->source().toString();
editCodeFlag = true;
if (s.contains(QString("QR")) || s.contains(QString("DMT"))) {
emit sendButtonClickedSignal(202);
} else if (s.contains(QString("BAR"))) {
emit sendButtonClickedSignal(201);
}
auto codeItem = dynamic_cast<PicCodeItem*>(item);
if(!codeItem)
return;
m_barcodeEditor.bindViewModel(codeItem->barcodeViewModel());
showBarcodeEditor(false);
return;
}
@@ -1414,26 +1423,37 @@ void TestPrintWidget::on_newfileButton_pressed(){
sendButtonClickedSignal(21); //新建文件完成
}
void TestPrintWidget::slt_BarCodeItemDone(QString str)
void TestPrintWidget::slt_BarCodeItemDone()
{
if (editCodeFlag) {
on_delButton_pressed();
editCodeFlag = false;
auto vm = m_barcodeEditor.viewModel();
// 如果当前选中了一个条形码或二维码,则更新其内容,然后直接返回
bool flag = false;
auto selectedItem = pPicScene->selectedItems();
for(auto item : selectedItem) {
auto codeItem = dynamic_cast<PicCodeItem*>(item);
if(codeItem) {
codeItem->setBarcodeViewModel(vm);
flag = true;
}
}
addCodeItem(str);
m_TextEdit->clear();
if(flag)
return;
int index = checkSelectScene();
if (index == -1) return;
QString html = m_TextEdit->toHtml();
foreach (QGraphicsItem *item, pPicScene->selectedItems())
{
PicCodeItem *pItem = (PicCodeItem*)item;
pItem->setHtml(html);
pItem->setSource(str);
if(vm.contentPattern.isEmpty()) {
qInfo() << "Empty content pattern, the barcode will not be generated.";
return;
}
// 添加条形码或验证码
pPicScene->clearSelection();
PicCodeItem* item = new PicCodeItem(0, 0, SourceType::CODE);
item->setBarcodeViewModel(vm);
auto boundingRect = pPicScene->itemsBoundingRect();
pPicScene->addItem(item);
item->setPos(boundingRect.right(), 0.0);
item->setSelected(true);
}
void TestPrintWidget::slt_QRCodeItemDone(QString str)
@@ -1619,11 +1639,14 @@ void TestPrintWidget::addCounterItem(CounterViewModel vm, QSharedPointer<QFont>
}
}
void TestPrintWidget::on_btnBarcode_clicked()
void TestPrintWidget::showBarcodeEditor(bool restoreViewModel)
{
#if defined(ARCH_AARCH64)
m_barcodeEditor.setWindowState(Qt::WindowFullScreen);
#endif
if(restoreViewModel)
m_barcodeEditor.restoreViewModel();
m_barcodeEditor.show();
}