2026年5月25日15:57:50
This commit is contained in:
+127
-132
@@ -137,12 +137,8 @@ TestPrintWidget::TestPrintWidget(QWidget* parent)
|
||||
});
|
||||
|
||||
// 控制区第一行按钮
|
||||
connect(ui.m_btnLeft_Control1, &QPushButton::clicked, [this]() {
|
||||
emit sendButtonClickedSignal(14);
|
||||
});
|
||||
connect(ui.m_btnRight_Control1, &QPushButton::clicked, [this]() {
|
||||
emit sendButtonClickedSignal(15);
|
||||
});
|
||||
connect(ui.m_btnLeft_Control1, &QPushButton::clicked, this, &TestPrintWidget::selectPreviousItem);
|
||||
connect(ui.m_btnRight_Control1, &QPushButton::clicked, this, &TestPrintWidget::selectNextItem);
|
||||
|
||||
// 方向箭头按钮
|
||||
connect(ui.m_btnUp, &QPushButton::clicked, [this]() {
|
||||
@@ -221,6 +217,9 @@ TestPrintWidget::TestPrintWidget(QWidget* parent)
|
||||
|
||||
connect(&m_barcodeEditor, &BarcodeEditor::accepted, this, &TestPrintWidget::slt_BarCodeItemDone);
|
||||
|
||||
m_LineEdit->setProperty("Enter replace enter", true);
|
||||
connect(m_LineEdit, &QLineEdit::returnPressed, this, &TestPrintWidget::onLineEditReturnPressed);
|
||||
|
||||
initSelecteCodeDlg();
|
||||
|
||||
// 网络通信,暂时屏蔽
|
||||
@@ -264,106 +263,12 @@ void TestPrintWidget::on_openfileButton_pressed()
|
||||
dialogFileOperation->exec();
|
||||
}
|
||||
|
||||
void TestPrintWidget::on_buttonSelectFont_pressed(){
|
||||
|
||||
if(dialogFontSize->exec() == QDialog::Accepted){
|
||||
int fontSize;
|
||||
QString fontFamily;
|
||||
dialogFontSize->getValue(&fontSize);
|
||||
fontFamily = dialogFontSize->getFontFamily();
|
||||
// if(ui->checkBoxBold->isChecked())
|
||||
// fontFamily = getFamilyName(fontSize);
|
||||
// ui->labFontFamily->setText(fontFamily);
|
||||
#ifdef EnableArabic
|
||||
bool switchArabicFlag=false;
|
||||
bool arabicSelect=fontFamily.contains("arabic");
|
||||
if((fontFamily=="biyang" || fontFamily=="wenquanyi")&&(fontSize==7 || fontSize==9)){
|
||||
switchArabicFlag=true;
|
||||
emit EnableSwitchArabicFlag(switchArabicFlag);
|
||||
}else {
|
||||
emit EnableSwitchArabicFlag(switchArabicFlag);
|
||||
}
|
||||
dialogSaveFile->setFileNameEnglishOrArabic(false);
|
||||
emit fontSizeArabicSelect(arabicSelect);
|
||||
#endif
|
||||
// if(sysPara){
|
||||
// sysPara->para.fontPixelSize = fontSize;
|
||||
// }
|
||||
// ui->labelFontSize->setText(QString::number(fontSize));
|
||||
setFontFormat(fontSize,fontFamily);
|
||||
m_TextEdit->setFocus();
|
||||
// emit fontSizeChange(fontSize);
|
||||
// bool flagBangal=false;
|
||||
// if(dialogFontSize->getFontFamily() == "bangla")
|
||||
// flagBangal = true;
|
||||
// emit switchBengalLanguage(flagBangal);
|
||||
|
||||
// toggleVirtualKeyboard();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TestPrintWidget::setFontFormat(int fontsize,QString fontfamily){
|
||||
//if(sysPara){
|
||||
|
||||
//qreal pixelSize = ui->labelFontSize->text().toFloat();
|
||||
qreal pixelSize = fontsize;
|
||||
// if(pixelSize < Public::getMinFontPixelSize())
|
||||
// pixelSize = sysPara->para.fontPixelSize;
|
||||
|
||||
// if(pixelSize < Public::getMinFontPixelSize()){
|
||||
// pixelSize = Public::getMinFontPixelSize();
|
||||
// }
|
||||
|
||||
if (pixelSize >= 0) {
|
||||
QTextCharFormat fmt;
|
||||
int DPI = m_TextEdit->logicalDpiX();
|
||||
DPI = DPI?DPI:1;
|
||||
qreal pointSize = pixelSize*72/DPI; //Pixel = DPI * Point / 72
|
||||
fmt.setFontPointSize(pointSize);
|
||||
|
||||
#ifdef VNLGXX
|
||||
QString fontFamily = dialogFontSize->getFontFamily();
|
||||
|
||||
#else
|
||||
// QString fontFamily = ui->labFontFamily->text();
|
||||
QString fontFamily = fontfamily;
|
||||
fontFamily = dialogFontSize->getFontFamily();
|
||||
// if(ui->checkBoxBold->isChecked())
|
||||
// fontFamily = getFamilyName(pixelSize);
|
||||
// ui->labFontFamily->setText(fontFamily);
|
||||
#endif
|
||||
|
||||
fmt.setFontFamily(fontFamily);
|
||||
fmt.setFontWeight(0 && (pixelSize<=16)? QFont::Bold:QFont::Normal);
|
||||
mergeFormatOnWordOrSelection(fmt);
|
||||
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
void TestPrintWidget::mergeFormatOnWordOrSelection(const QTextCharFormat &format)
|
||||
{
|
||||
|
||||
QTextCursor cursor = m_TextEdit->textCursor();
|
||||
//if (!cursor.hasSelection())
|
||||
// cursor.select(QTextCursor::WordUnderCursor);
|
||||
//cursor.mergeCharFormat(format);
|
||||
//textEdit->setTextCursor(cursor);
|
||||
//qDebug()<<"mergeFormatOnWordOrSelection"<<format;
|
||||
//qDebug()<<cursor;
|
||||
m_TextEdit->mergeCurrentCharFormat(format);
|
||||
}
|
||||
|
||||
|
||||
void TestPrintWidget::addDateItem()
|
||||
{
|
||||
// 将sendButtonClickedSignal(16) 转由专门处理
|
||||
pPicScene->clearSelection();
|
||||
emit sig_showEditDataTime(nullptr);
|
||||
emit sig_showEditDateTime(DateItemModel::createDefaultReplaceModel(), TextItemModel{});
|
||||
}
|
||||
|
||||
|
||||
QTextEdit* TestPrintWidget::getQTextEdit(){
|
||||
return m_TextEdit;
|
||||
}
|
||||
@@ -583,6 +488,11 @@ void TestPrintWidget::getShowSelectItemText(){
|
||||
|
||||
if(lastSelectedTxtItem) {
|
||||
|
||||
// 对于文本item,将它的文本显示到编辑框
|
||||
if(lastSelectedTxtItem->sourceType() == SourceType::TEXT) {
|
||||
m_LineEdit->setText(lastSelectedTxtItem->source().toString());
|
||||
}
|
||||
|
||||
QString currItemFontFamily = lastSelectedTxtItem->font().family();
|
||||
|
||||
QHash<QString, int> fontNameToIndex;
|
||||
@@ -980,29 +890,6 @@ void TestPrintWidget::parseVbfile(QXmlStreamReader &reader) {
|
||||
}
|
||||
pPictText->setHtml(strCDATA);
|
||||
}
|
||||
|
||||
// if(Condition)
|
||||
// {
|
||||
// SpecialVarPrint specialVarPrint;
|
||||
// specialVarPrint.SpecialVarEnable = Condition;
|
||||
// specialVarPrint.SpecialVarCountStart = CatchStartValue;
|
||||
// specialVarPrint.SpecialVarCountEnd = CatchValue;
|
||||
// specialVarPrint.SpecialVarColStart = 3 + pos_x- pPicScene->itemsBoundingRect().x();
|
||||
// specialVarPrint.SpecialVarColEnd = 3 + pos_x - pPicScene->itemsBoundingRect().x()+ pPictText->boundingRect().width();
|
||||
// specialVarPrint.SpecialVarRowStart = pos_y - pPicScene->itemsBoundingRect().y();
|
||||
// specialVarPrint.SpecialVarRowEnd = pos_y - pPicScene->itemsBoundingRect().y()+ pPictText->boundingRect().height();
|
||||
// sysPara->devOp->fpgaWr(0xa4b0,(unsigned char *)&specialVarPrint,sizeof(SpecialVarPrint)); // Send specialVarPrint 2022-8-6
|
||||
// LogInfo::setRunStatusText(tr("发送特殊变量内容:"));
|
||||
// LogInfo::setRunStatusText(tr("SpecialVarEnable:%1").arg(QString().sprintf("%02X",specialVarPrint.SpecialVarEnable)));
|
||||
// LogInfo::setRunStatusText(tr("SpecialVarCountStart:%1").arg(QString().sprintf("%02X",specialVarPrint.SpecialVarCountStart)));
|
||||
// LogInfo::setRunStatusText(tr("SpecialVarCountEnd:%1").arg(QString().sprintf("%02X",specialVarPrint.SpecialVarCountEnd)));
|
||||
// LogInfo::setRunStatusText(tr("SpecialVarColStart:%1").arg(QString().sprintf("%02X",specialVarPrint.SpecialVarColStart)));
|
||||
// LogInfo::setRunStatusText(tr("SpecialVarColEnd:%1").arg(QString().sprintf("%02X",specialVarPrint.SpecialVarColEnd)));
|
||||
// LogInfo::setRunStatusText(tr("SpecialVarRowStart:%1").arg(QString().sprintf("%02X",specialVarPrint.SpecialVarRowStart)));
|
||||
// LogInfo::setRunStatusText(tr("SpecialVarRowEnd:%1").arg(QString().sprintf("%02X",specialVarPrint.SpecialVarRowEnd)));
|
||||
// LogInfo::setRunStatusText(tr("itemsBoundingRect().y():%1").arg(QString().sprintf("%02X",pPicScene->itemsBoundingRect().y())));
|
||||
// LogInfo::setRunStatusText(tr("itemsBoundingRect().x():%1").arg(QString().sprintf("%02X",pPicScene->itemsBoundingRect().x())));
|
||||
// }
|
||||
Condition= false ;
|
||||
CatchValue = -1;
|
||||
CatchStartValue = -1;
|
||||
@@ -1144,7 +1031,7 @@ bool TestPrintWidget::cacheSelectedLayerForPaste(PicTextItem *srcItem)
|
||||
m_copiedHtml = srcItem->toHtml();
|
||||
m_copiedSpecialConditions = srcItem->SpecialConditions;
|
||||
m_copiedCatchCnt1StartValue = srcItem->CatchCnt1StartValue;
|
||||
m_copiedCatchCnt1CurrValue = srcItem->CatchCnt1CurrValue;
|
||||
m_copiedCatchCnt1CurrValue = srcItem->CatchCnt1CurrValue;
|
||||
m_copiedPos = srcItem->pos();
|
||||
|
||||
m_copiedAttrs.clear();
|
||||
@@ -1370,7 +1257,7 @@ void TestPrintWidget::onBtnItemConfigClicked()
|
||||
if(item->sourceType() == SourceType::DATETIME) {
|
||||
// @see TestPrintWidget::addDateTimeItem
|
||||
auto dateTimeItem = dynamic_cast<PicDateItem*>(item);
|
||||
emit sig_showEditDataTime(dateTimeItem);
|
||||
emit sig_showEditDateTime(dateTimeItem->model(), dateTimeItem->textItemModel());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1403,7 +1290,8 @@ void TestPrintWidget::onItemEditorAccepted()
|
||||
if(itemEditor->currentItem()->source() == SourceType::UNKNOWN)
|
||||
onEditItemCounterDone();
|
||||
else {
|
||||
itemEditor->currentItem()->applyModify();
|
||||
PicTextItem* textItem = itemEditor->currentItem();
|
||||
textItem->applyModify();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1477,6 +1365,106 @@ void TestPrintWidget::slt_QRCodeItemDone(QString str)
|
||||
}
|
||||
}
|
||||
|
||||
QGraphicsItem* findClosestItemToViewCenter(QGraphicsView* view)
|
||||
{
|
||||
if (!view || !view->scene())
|
||||
return nullptr;
|
||||
|
||||
// 1. 获取视口中心点(视口坐标)并映射到场景坐标
|
||||
QPoint viewCenter = view->viewport()->rect().center();
|
||||
QPointF sceneCenter = view->mapToScene(viewCenter);
|
||||
|
||||
// 2. 获取场景中所有项
|
||||
QList<QGraphicsItem*> items = view->scene()->items();
|
||||
|
||||
// 3. 寻找最近项
|
||||
QGraphicsItem* closestItem = nullptr;
|
||||
qreal minDistSq = std::numeric_limits<qreal>::max();
|
||||
|
||||
for (QGraphicsItem* item : items) {
|
||||
// 可选项:跳过不可见项(根据需求决定)
|
||||
if (!item->isVisible()) continue;
|
||||
|
||||
// 计算项的场景位置到中心点的平方距离(避免开方,性能更好)
|
||||
QPointF itemPos = item->scenePos();
|
||||
qreal dx = itemPos.x() - sceneCenter.x();
|
||||
qreal dy = itemPos.y() - sceneCenter.y();
|
||||
qreal distSq = dx * dx + dy * dy;
|
||||
|
||||
if (distSq < minDistSq) {
|
||||
minDistSq = distSq;
|
||||
closestItem = item;
|
||||
}
|
||||
}
|
||||
|
||||
return closestItem;
|
||||
}
|
||||
|
||||
void TestPrintWidget::selectItemByDirection(bool forward)
|
||||
{
|
||||
auto selectedItems = pPicScene->selectedItems();
|
||||
|
||||
// 如果当前没有选中项,且场景中存在项,则选择距离当前视图中心的项
|
||||
if(selectedItems.isEmpty() && !pPicScene->items().isEmpty()) {
|
||||
auto closestItem = findClosestItemToViewCenter(pViewer);
|
||||
if(closestItem) {
|
||||
closestItem->setSelected(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(selectedItems.isEmpty())
|
||||
return;
|
||||
|
||||
auto currItem = selectedItems.last();
|
||||
if(!currItem)
|
||||
return;
|
||||
|
||||
auto items = pPicScene->items();
|
||||
if(items.size() <= 1)
|
||||
return;
|
||||
|
||||
std::sort(items.begin(), items.end(), [](QGraphicsItem* a, QGraphicsItem* b) {
|
||||
return a->pos().x() < b->pos().x();
|
||||
});
|
||||
|
||||
auto it = std::find(items.begin(), items.end(), currItem);
|
||||
if(it == items.end())
|
||||
it = items.begin();
|
||||
|
||||
QGraphicsItem* nextItem = nullptr;
|
||||
if(forward) {
|
||||
nextItem = (it + 1 == items.end()) ? items.first() : *(it + 1);
|
||||
} else {
|
||||
nextItem = (it == items.begin()) ? items.last() : *(it - 1);
|
||||
}
|
||||
|
||||
if(nextItem) {
|
||||
pPicScene->clearSelection();
|
||||
nextItem->setSelected(true);
|
||||
}
|
||||
}
|
||||
|
||||
void TestPrintWidget::selectNextItem()
|
||||
{
|
||||
selectItemByDirection(true);
|
||||
}
|
||||
|
||||
void TestPrintWidget::selectPreviousItem()
|
||||
{
|
||||
selectItemByDirection(false);
|
||||
}
|
||||
|
||||
void TestPrintWidget::onLineEditReturnPressed()
|
||||
{
|
||||
if(pPicScene->selectedItems().size() != 0) {
|
||||
qDebug() << "Change current item text";
|
||||
}
|
||||
else {
|
||||
qDebug() << "Add new item text";
|
||||
}
|
||||
}
|
||||
|
||||
void TestPrintWidget::on_cbResolution_currentIndexChanged(int index)
|
||||
{
|
||||
constexpr char* IdxToFontFamily[] = {"WenQuanYi5",
|
||||
@@ -1537,7 +1525,7 @@ void TestPrintWidget::setFontNameIndex(float fontsize)
|
||||
ui.cbResolution->setCurrentIndex(currIndex);
|
||||
}
|
||||
|
||||
void TestPrintWidget::addDateTimeItem(const DateItemModel &model)
|
||||
void TestPrintWidget::addDateTimeItem(const DateItemModel &model, const TextItemModel& textModel)
|
||||
{
|
||||
// 如果当前选中了一个日期时间item,则直接设置模型
|
||||
auto selectItems = pPicScene->selectedItems();
|
||||
@@ -1545,6 +1533,7 @@ void TestPrintWidget::addDateTimeItem(const DateItemModel &model)
|
||||
auto item = dynamic_cast<PicTextItem*>(selectItems[0]);
|
||||
if(item->sourceType() == SourceType::DATETIME) {
|
||||
auto dateTimeItem = dynamic_cast<PicDateItem*>(item);
|
||||
dateTimeItem->setTextItemModel(textModel);
|
||||
dateTimeItem->setModel(model);
|
||||
return;
|
||||
}
|
||||
@@ -1662,15 +1651,21 @@ void TestPrintWidget::onBtnArrowClicked()
|
||||
void TestPrintWidget::on_btn_copy_clicked()
|
||||
{
|
||||
int index = checkSelectScene();
|
||||
if (index < 0) return;
|
||||
if (index < 0) {
|
||||
qInfo() << "Not selected any item.";
|
||||
return;
|
||||
}
|
||||
|
||||
PicTextItem* srcItem = dynamic_cast<PicTextItem*>(pPicScene->items().at(index));
|
||||
if (!srcItem) return;
|
||||
cacheSelectedLayerForPaste(srcItem);
|
||||
if (!srcItem) {
|
||||
qWarning() << "Cannot cast item type to correct type";
|
||||
return;
|
||||
}
|
||||
|
||||
cacheSelectedLayerForPaste(srcItem);
|
||||
}
|
||||
|
||||
void TestPrintWidget::on_btn_paste_clicked()
|
||||
{
|
||||
pasteCopiedLayer();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user