修复文本类型下面总是多一行的问题,同时取消限制item高度加1
This commit is contained in:
@@ -557,6 +557,23 @@ QImage ItemUtils::txtToImage(const QString &txt, const QFont &font, const QColor
|
||||
QFontMetrics fm(font);
|
||||
int width = fm.horizontalAdvance(txt);
|
||||
int height = fm.height();
|
||||
|
||||
// 优先使用字体名中后缀标识的字体高度
|
||||
QString fontname = font.family();
|
||||
QString numStr = "";
|
||||
for(int i = fontname.length() - 1; i >= 0; --i) {
|
||||
if(fontname[i].isDigit()) {
|
||||
numStr.prepend(fontname[i]);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!numStr.isEmpty()) {
|
||||
height = numStr.toInt();
|
||||
if(height < 5 || height > 32)
|
||||
height = fm.height();
|
||||
}
|
||||
|
||||
if (width <= 0 || height <= 0) {
|
||||
return QImage();
|
||||
}
|
||||
|
||||
@@ -404,7 +404,7 @@ QImage PicTextItem::strToImage(const QString &str)
|
||||
QPointF PicTextItem::clampItemPos(const QPointF &p)
|
||||
{
|
||||
return QPointF (std::min(qreal(scene()->width() - boundingRect().width()), std::max(0.0, p.x())),
|
||||
std::min((qreal(scene()->height() + 1) - boundingRect().height()), std::max(0.0, p.y())));
|
||||
std::min((qreal(scene()->height()) - boundingRect().height()), std::max(0.0, p.y())));
|
||||
}
|
||||
|
||||
TextItemModel TextItemModel::fromItem(PicTextItem *item)
|
||||
|
||||
Reference in New Issue
Block a user