抽离场景打开逻辑、添加编辑界面的左右拖动功能

This commit is contained in:
2026-07-16 11:04:12 +08:00
parent 570f359339
commit 808a38628e
10 changed files with 330 additions and 27 deletions
+37 -10
View File
@@ -10,6 +10,7 @@
#include <QRgb>
#include <QDebug>
#include <QScrollBar>
#include <algorithm>
#include <QFontMetrics>
#include <QChar>
#include <stdlib.h>
@@ -507,10 +508,10 @@ void MainWidget::generateCharRamData()
}
QRect MainWidget::variableItemsUpdate()
QList<QRect> MainWidget::variableItemsUpdate()
{
if(!pPicScene) {
return QRect();
return QList<QRect>();
}
int totalOfProcessedDots = 0;
@@ -518,7 +519,7 @@ QRect MainWidget::variableItemsUpdate()
int nbInvaliedDatetimePreview = 0;
int nbClipDatetimePreview = 0;
QRect updateArea = {0, 0, 0, 0};
QList<QRect> updateAreas;
auto items = pPicScene->items();
for(auto i : items) {
@@ -594,10 +595,36 @@ QRect MainWidget::variableItemsUpdate()
totalOfProcessedDots += imageToPrintData(img, (int)itemRect.left(), (int)itemRect.top());
updateArea = updateArea.united(itemRect);
updateAreas.append(itemRect);
}
return updateArea;
if(updateAreas.isEmpty())
return updateAreas;
// 把 updateAreas 里 x 轴相交或相连的矩形合并,避免某些区域重复更新而导致的串口资源浪费
std::sort(updateAreas.begin(), updateAreas.end(), [](const QRect &a, const QRect &b) {
if (a.left() != b.left())
return a.left() < b.left();
return a.right() < b.right();
});
QList<QRect> mergedAreas;
mergedAreas.append(updateAreas.first());
for (int i = 1; i < updateAreas.size(); ++i) {
QRect current = updateAreas.at(i);
QRect &last = mergedAreas.last();
if (last.right() + 1 >= current.left()) {
int left = qMin(last.left(), current.left());
int right = qMax(last.right(), current.right());
int top = qMin(last.top(), current.top());
int bottom = qMax(last.bottom(), current.bottom());
last = QRect(QPoint(left, top), QPoint(right, bottom));
} else {
mergedAreas.append(current);
}
}
return mergedAreas;
}
int MainWidget::imageToPrintData(QImage &image, int startX, int startY)
@@ -619,7 +646,7 @@ int MainWidget::imageToPrintData(QImage &image, int startX, int startY)
unsigned char c = 0;
int hStart = startY;
c = dat[(wStart)*5 + (hStart)/8];
c = dat[wStart * MAX_PRINT_ROW_BYTE_NUM + (hStart) / 8];
for(int k = 0; k < height; k++)
{
@@ -634,14 +661,14 @@ int MainWidget::imageToPrintData(QImage &image, int startX, int startY)
}
if(hStart % 8 == 7) {
dat[(wStart)*5 + (hStart)/8] = c;
c = dat[(wStart)*5 + (hStart + 1)/8];
dat[wStart * MAX_PRINT_ROW_BYTE_NUM + (hStart) / 8] = c;
c = dat[wStart * MAX_PRINT_ROW_BYTE_NUM + (hStart + 1) / 8];
++totalOfProcessedDots;
}
hStart++;
}
dat[(wStart)*5 + (hStart)/8] = c;
dat[wStart * MAX_PRINT_ROW_BYTE_NUM + (hStart) / 8] = c;
wStart++;
totalOfProcessedDots++;
}
@@ -1348,7 +1375,7 @@ void MainWidget::slt_setNum()
void MainWidget::slt_clearCnt()
{
if (sysPara) {
sysPara->devOp->clearProductCnt(3 | 0x10);// 重新计米
sysPara->devOp->clearProductCnt(1);//当前产品计数器立即清零
ui.labelProductCnt->setText("0");
// SendPrintDataToFpga(0);
}