git-svn-id: svn://db.shs.com.ru/libs@303 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "alignedtextitem.h"
|
||||
#include <QApplication>
|
||||
#include <QPainter>
|
||||
#include <QDebug>
|
||||
|
||||
@@ -6,6 +7,7 @@
|
||||
AlignedTextItem::AlignedTextItem(QGraphicsItem * parent): QGraphicsItem(parent), text_(this) {
|
||||
align_ = Qt::AlignTop | Qt::AlignHCenter;
|
||||
text_.setData(1003, true);
|
||||
setFont(font());
|
||||
_move();
|
||||
}
|
||||
|
||||
@@ -13,9 +15,24 @@ AlignedTextItem::AlignedTextItem(QGraphicsItem * parent): QGraphicsItem(parent),
|
||||
AlignedTextItem::AlignedTextItem(const QString & text, QGraphicsItem * parent): QGraphicsItem(parent), text_(this) {
|
||||
align_ = Qt::AlignTop | Qt::AlignHCenter;
|
||||
text_.setData(1003, true);
|
||||
setFont(font());
|
||||
setText(text);
|
||||
}
|
||||
|
||||
void AlignedTextItem::setFont(const QFont & f) {
|
||||
font_ = f;
|
||||
text_.setFont(sceneFont(f));
|
||||
_move();
|
||||
}
|
||||
|
||||
|
||||
QFont AlignedTextItem::sceneFont(const QFont & f) {
|
||||
QFont ret = f;
|
||||
double scl = 16. / QApplication::fontMetrics().size(0, "0").height();
|
||||
ret.setPointSizeF(ret.pointSizeF() * scl);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
QPointF AlignedTextItem::_point(Qt::Alignment a) const {
|
||||
QRectF br = text_.boundingRect();
|
||||
|
||||
Reference in New Issue
Block a user