void GIPlot
::drawText(QPainter* painter,
const QPointF
& pos,
const QString
& text,
QFont* font, Qt
::Alignment align,
QRectF* boundingRect
) {
qreal m11,m22;
if(font
==0) fnt
=QFont(baseFont
);
else fnt
=QFont(*font
);
painter->setFont(fnt);
qreal sw,sh;
sw=fm.width(text);sh=fm.height();
QRectF rect
(-sw,
-sh,
2*sw,
2*sh
);
if(align
& Qt
::AlignLeft) p
+=QPointF(-sw,
0);
else if(align
& Qt
::AlignRight) p
+=QPointF(sw,
0);
else if(align
& Qt
::AlignHCenter) p
+=QPointF(-sw
/2,
0);
if(align
& Qt
::AlignTop && isYInverted
()) p
+=QPointF(0,
-sh
);
else if(align
& Qt
::AlignBottom && !isYInverted
()) p
+=QPointF(0,
-sh
);
else if(align
& Qt
::AlignVCenter) p
+=QPointF(0,
-sh
/2);
bRect.moveTopLeft(p);
if(boundingRect!=0)//just return the boundingrect
{
*boundingRect=bRect;
return;
};
painter->save();
painter->translate(pos);
m11=painter->matrix().m11();m22=painter->matrix().m22();
painter->setViewTransformEnabled(false);
painter->scale(1.0/m11,1.0/m22);
qDebug()<<"fs1:"<<painter->font().pointSizeF();
painter->drawText(rect, align, text,&rr);
sw=fm.width(text);sh=fm.height();
qDebug()<<"drawText:"<<text<<rr<<sw<<sh;
painter->restore();
painter->drawRect(bRect);
}
void GIPlot::drawText(QPainter* painter, const QPointF& pos, const QString& text, QFont* font, Qt::Alignment align, QRectF* boundingRect)
{
QFont fnt;
QRectF bRect;
qreal m11,m22;
if(font==0) fnt=QFont(baseFont); else fnt=QFont(*font);
painter->setFont(fnt);
QFontMetricsF fm(fnt);
qreal sw,sh;
sw=fm.width(text);sh=fm.height();
QRectF rect(-sw, -sh,2*sw,2*sh);
bRect=QRectF(0,0,sw,sh);
QPointF p(pos);
if(align & Qt::AlignLeft) p+=QPointF(-sw,0);
else if(align & Qt::AlignRight) p+=QPointF(sw,0);
else if(align & Qt::AlignHCenter) p+=QPointF(-sw/2,0);
if(align & Qt::AlignTop && isYInverted()) p+=QPointF(0,-sh);
else if(align & Qt::AlignBottom && !isYInverted()) p+=QPointF(0,-sh);
else if(align & Qt::AlignVCenter) p+=QPointF(0,-sh/2);
bRect.moveTopLeft(p);
if(boundingRect!=0)//just return the boundingrect
{
*boundingRect=bRect;
return;
};
painter->save();
painter->translate(pos);
m11=painter->matrix().m11();m22=painter->matrix().m22();
painter->setViewTransformEnabled(false);
painter->scale(1.0/m11,1.0/m22);
QRectF rr;
qDebug()<<"fs1:"<<painter->font().pointSizeF();
painter->drawText(rect, align, text,&rr);
fm=QFontMetricsF(painter->fontMetrics());
sw=fm.width(text);sh=fm.height();
qDebug()<<"drawText:"<<text<<rr<<sw<<sh;
painter->restore();
painter->drawRect(bRect);
}
To copy to clipboard, switch view to plain text mode
Bookmarks