2026年7月16日 缓存
This commit is contained in:
@@ -59,6 +59,11 @@ BarcodeEditor::BarcodeEditor(QWidget *parent) :
|
||||
|
||||
connect(&m_barcodeFormatEditor, &DlgBarcodeFormat::accepted, this, &BarcodeEditor::onBarcodeFormatConfirmed);
|
||||
connect(&m_qrcodeFormatEditor, &DlgQrcodeFormat::accepted, this, &BarcodeEditor::onQrcodeFormatConfirmed);
|
||||
|
||||
m_barcodeFormatEditor.setWindowModality(Qt::WindowModality::WindowModal);
|
||||
m_qrcodeFormatEditor.setWindowModality(Qt::WindowModality::WindowModal);
|
||||
m_barcodeFormatEditor.setWindowTitle(tr("BarCode Format"));
|
||||
m_qrcodeFormatEditor.setWindowTitle(tr("Qrcode Format"));
|
||||
}
|
||||
|
||||
BarcodeEditor::~BarcodeEditor()
|
||||
|
||||
@@ -55,8 +55,8 @@ static QImage renderDataMatrix(const unsigned char *grid, int cols, int rows, in
|
||||
return QImage();
|
||||
}
|
||||
|
||||
int width = cols * moduleSize;
|
||||
int height = rows * moduleSize;
|
||||
int width = rows * moduleSize;
|
||||
int height = cols * moduleSize;
|
||||
QImage image(width, height, QImage::Format_ARGB32);
|
||||
image.fill(background);
|
||||
|
||||
@@ -64,8 +64,8 @@ static QImage renderDataMatrix(const unsigned char *grid, int cols, int rows, in
|
||||
for (int x = 0; x < cols; ++x) {
|
||||
bool bit = (grid[y * cols + x] & 0x01) != 0;
|
||||
QRgb color = bit ? foreground : background;
|
||||
int px = x * moduleSize;
|
||||
int py = y * moduleSize;
|
||||
int px = y * moduleSize;
|
||||
int py = (cols - 1 - x) * moduleSize;
|
||||
for (int dy = 0; dy < moduleSize; ++dy) {
|
||||
for (int dx = 0; dx < moduleSize; ++dx) {
|
||||
image.setPixel(px + dx, py + dy, color);
|
||||
@@ -573,6 +573,8 @@ QImage ItemUtils::txtToImage(const QString &txt, const QFont &font, const QColor
|
||||
painter.drawText(img.rect(), txt);
|
||||
painter.end();
|
||||
|
||||
return img;
|
||||
|
||||
// 按背景色裁剪,使输出图像紧贴文字像素的最小包围盒(详见函数注释)
|
||||
return clipTxtImage(img, bgRgb);
|
||||
}
|
||||
}
|
||||
+5
-63
@@ -5,6 +5,7 @@
|
||||
#include <QPainter>
|
||||
//#include "moveinput.h"
|
||||
#include <QStyleOptionGraphicsItem>
|
||||
#include "ItemCommon.h"
|
||||
|
||||
//extern MoveInput* moveInput;
|
||||
PicTextItem::PicTextItem(QGraphicsItem *parent, QGraphicsScene *scene, const SourceType t) :
|
||||
@@ -38,54 +39,6 @@ QVariant PicTextItem::source()
|
||||
return m_source;
|
||||
}
|
||||
|
||||
QImage clipImage(QImage img, const QRgb bg)
|
||||
{
|
||||
QRect clipRect;
|
||||
for(int x = 0; x < img.width(); ++x) {
|
||||
for(int y = 0; y < img.height(); ++y) {
|
||||
auto rgb = img.pixel(x, y);
|
||||
if(rgb != bg) {
|
||||
clipRect.setLeft(x);
|
||||
goto top;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
top:
|
||||
for(int y = 0; y < img.height(); ++y) {
|
||||
for(int x = 0; x < img.width(); ++x) {
|
||||
if(img.pixel(x, y) != bg) {
|
||||
clipRect.setTop(y);
|
||||
goto right;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
right:
|
||||
for(int x = img.width() - 1; x >= 0; --x) {
|
||||
for(int y = 0; y < img.height(); ++y) {
|
||||
if(img.pixel(x, y) != bg) {
|
||||
clipRect.setRight(x + 1);
|
||||
goto bottom;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bottom:
|
||||
for(int y = img.height() - 1; y >= 0; --y) {
|
||||
for(int x = 0; x < img.width(); ++x) {
|
||||
if(img.pixel(x, y) != bg) {
|
||||
clipRect.setBottom(y + 1);
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
end:
|
||||
QRect originRect = img.rect();
|
||||
return img.copy(clipRect);
|
||||
}
|
||||
|
||||
QImage PicTextItem::applyImgeTranslation(QImage img)
|
||||
{
|
||||
auto scaledWidth = boldMultiple() * img.width();
|
||||
@@ -212,7 +165,7 @@ QRectF PicTextItem::boundingRect() const
|
||||
if(sourceType() == SourceType::UNKNOWN)
|
||||
return QGraphicsTextItem::boundingRect();
|
||||
|
||||
const QRectF fr(0, 0, m_itemImage.width(), m_itemImage.height());
|
||||
QRectF fr(0, 0, m_itemImage.width(), m_itemImage.height());
|
||||
return fr;
|
||||
}
|
||||
|
||||
@@ -437,21 +390,10 @@ QImage PicTextItem::strToImage(const QString &str)
|
||||
if(str.isEmpty())
|
||||
return QImage();
|
||||
|
||||
QPainter painter;
|
||||
QFontMetrics fm(font());
|
||||
QImage img(fm.horizontalAdvance(str), fm.height(), QImage::Format_ARGB32);
|
||||
QColor txtColor = colorReversal() ? QColor(255, 255, 255) : QColor(0, 0, 0);
|
||||
QColor bgColor = colorReversal() ? QColor(0, 0, 0) : QColor(0, 0, 0, 0);
|
||||
|
||||
QRgb txtColor = colorReversal() ? 0xffffffff : 0xff000000;
|
||||
QRgb bgColor = colorReversal() ? 0xff000000 : 0x00000000;
|
||||
|
||||
img.fill(bgColor);
|
||||
painter.begin(&img);
|
||||
painter.setFont(font());
|
||||
painter.setPen(txtColor);
|
||||
painter.drawText(img.rect(), str);
|
||||
painter.end();
|
||||
|
||||
return clipImage(img, bgColor);
|
||||
return ItemUtils::txtToImage(str, font(), txtColor, bgColor);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user