hlp:编辑内容不裁剪和对齐左上角,使用绝对坐标;修改编辑框滚动条样式;上下颠倒默认取反
This commit is contained in:
+41
-14
@@ -699,18 +699,40 @@ QList<QRect> MainWidget::variableItemsUpdate()
|
||||
continue;
|
||||
}
|
||||
|
||||
// const QRectF itemSceneRect = item->sceneBoundingRect();
|
||||
// const QRectF itemBufferRect = itemSceneRect.translated(-contentRect.topLeft());
|
||||
// const QRectF clippedBufferRect = itemBufferRect.intersected(outputRect);
|
||||
// if(clippedBufferRect.isEmpty())
|
||||
// continue;
|
||||
|
||||
// QRect targetRect = clippedBufferRect.toAlignedRect();
|
||||
// totalOfDatetimeNumber++;
|
||||
|
||||
// if(targetRect != itemBufferRect.toAlignedRect()) {
|
||||
// const int cropX = qMax(0, targetRect.left() - itemBufferRect.toAlignedRect().left());
|
||||
// const int cropY = qMax(0, targetRect.top() - itemBufferRect.toAlignedRect().top());
|
||||
// img = img.copy(cropX, cropY, targetRect.width(), targetRect.height());
|
||||
// ++nbClipDatetimePreview;
|
||||
// }
|
||||
// 获取 item 的场景绝对坐标
|
||||
const QRectF itemSceneRect = item->sceneBoundingRect();
|
||||
const QRectF itemBufferRect = itemSceneRect.translated(-contentRect.topLeft());
|
||||
const QRectF clippedBufferRect = itemBufferRect.intersected(outputRect);
|
||||
if(clippedBufferRect.isEmpty())
|
||||
// 与输出区域裁剪(使用绝对坐标)
|
||||
const QRectF clippedSceneRect = itemSceneRect.intersected(outputRect);
|
||||
if(clippedSceneRect.isEmpty())
|
||||
continue;
|
||||
|
||||
QRect targetRect = clippedBufferRect.toAlignedRect();
|
||||
QRect targetRect = clippedSceneRect.toAlignedRect();
|
||||
totalOfDatetimeNumber++;
|
||||
|
||||
if(targetRect != itemBufferRect.toAlignedRect()) {
|
||||
const int cropX = qMax(0, targetRect.left() - itemBufferRect.toAlignedRect().left());
|
||||
const int cropY = qMax(0, targetRect.top() - itemBufferRect.toAlignedRect().top());
|
||||
// 计算 item 在场景中的绝对矩形(整数对齐)
|
||||
QRect itemSceneAlignedRect = itemSceneRect.toAlignedRect();
|
||||
// 如果 targetRect 和 item 原始场景矩形不一致,说明被 outputRect 裁剪了
|
||||
if(targetRect != itemSceneAlignedRect) {
|
||||
// 计算裁剪偏移量:相对于 item 左上角的偏移
|
||||
const int cropX = targetRect.left() - itemSceneAlignedRect.left();
|
||||
const int cropY = targetRect.top() - itemSceneAlignedRect.top();
|
||||
// 从 preview 图片中裁剪出对应区域
|
||||
// 注意:preview 图片的尺寸等于 itemSceneAlignedRect 的尺寸(假设 preview 生成时使用了完整的 boundingRect)
|
||||
img = img.copy(cropX, cropY, targetRect.width(), targetRect.height());
|
||||
++nbClipDatetimePreview;
|
||||
}
|
||||
@@ -1976,11 +1998,13 @@ void MainWidget::onPreviewScene()
|
||||
const QRectF contentRect = pPicScene->itemsBoundingRect();
|
||||
const QRect sceneRect = contentRect.toAlignedRect();
|
||||
qDebug() << "sceneRect: " << sceneRect;
|
||||
|
||||
// 限定最大高度和宽度
|
||||
int coldot = qMin(sceneRect.width(), MaxCol4000 ? MAX_PRINT_COL_NUM_Normal : MAX_PRINT_COL_NUM_Wide);
|
||||
int maxPicHeight = qMin(sceneRect.height(), int(sysPara->para.canvasHeight));
|
||||
QSize size(coldot,maxPicHeight);
|
||||
// int coldot = qMin(sceneRect.width(), MaxCol4000 ? MAX_PRINT_COL_NUM_Normal : MAX_PRINT_COL_NUM_Wide);
|
||||
// int maxPicHeight = qMin(sceneRect.height(), int(sysPara->para.canvasHeight));
|
||||
// QSize size(coldot,maxPicHeight);
|
||||
int coldot = qMin(int(contentRect.right()), MaxCol4000 ? MAX_PRINT_COL_NUM_Normal : MAX_PRINT_COL_NUM_Wide);
|
||||
QSize size(MAX_PRINT_COL_NUM_Normal,sysPara->para.canvasHeight);
|
||||
|
||||
|
||||
if(size.isEmpty()) {
|
||||
//场景为空时,渲染空场景并刷新界面
|
||||
@@ -2035,9 +2059,12 @@ void MainWidget::onPreviewScene()
|
||||
if(clippedSceneRect.isEmpty())
|
||||
continue;
|
||||
|
||||
const QRect itemRect = clippedSceneRect.translated(-contentRect.topLeft()).toAlignedRect();
|
||||
// const QRect itemRect = clippedSceneRect.translated(-contentRect.topLeft()).toAlignedRect();
|
||||
// 直接使用场景绝对坐标,不进行平移
|
||||
const QRect itemRect = clippedSceneRect.toAlignedRect();
|
||||
const QRectF sourceRect = clippedSceneRect;
|
||||
|
||||
|
||||
if(picText && picText->sourceType() == SourceType::COUNTER) {
|
||||
PicCounterItem* counterItem = qgraphicsitem_cast<PicCounterItem*>(picText);
|
||||
if(!counterItem)
|
||||
@@ -2075,8 +2102,8 @@ void MainWidget::onPreviewScene()
|
||||
pPicScene->render(&painter, itemRect, sourceRect);
|
||||
}
|
||||
|
||||
sysPara->status.currPrintRow = sceneRect.height();
|
||||
sysPara->status.currPrintCol = sceneRect.width();
|
||||
sysPara->status.currPrintRow = contentRect.bottom();
|
||||
sysPara->status.currPrintCol = contentRect.right();
|
||||
|
||||
imageToPrintData(image, 0, 0);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user