2026年7月16日 缓存
This commit is contained in:
+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