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();
|
||||
|
||||
@@ -13,13 +13,13 @@ public:
|
||||
AlignedTextItem(const QString & text, QGraphicsItem * parent = 0);
|
||||
|
||||
void setText(const QString & t) {text_.setText(t); _move();}
|
||||
void setFont(const QFont & f) {text_.setFont(f); _move();}
|
||||
void setFont(const QFont & f);
|
||||
void setPen(const QPen & p) {text_.setPen(p); _move();}
|
||||
void setBrush(const QBrush & b) {text_.setBrush(b); _move();}
|
||||
void setAlignment(Qt::Alignment align) {align_ = align; _move();}
|
||||
|
||||
QString text() const {return text_.text();}
|
||||
QFont font() const {return text_.font();}
|
||||
QFont font() const {return /*text_.font()*/font_;}
|
||||
QPen pen() const {return text_.pen();}
|
||||
QBrush brush() const {return text_.brush();}
|
||||
Qt::Alignment alignment() const {return align_;}
|
||||
@@ -27,6 +27,8 @@ public:
|
||||
void clear() {setText(QString());}
|
||||
|
||||
enum {Type = UserType + 0x100};
|
||||
|
||||
static QFont sceneFont(const QFont & f);
|
||||
|
||||
protected:
|
||||
virtual QRectF boundingRect() const {return text_.boundingRect().translated(text_.pos());}
|
||||
@@ -38,6 +40,7 @@ protected:
|
||||
|
||||
QGraphicsSimpleTextItem text_;
|
||||
Qt::Alignment align_;
|
||||
QFont font_;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "blockitem.h"
|
||||
#include <QApplication>
|
||||
|
||||
|
||||
|
||||
@@ -30,6 +31,7 @@ void BlockItemPin::resizePin(double r) {
|
||||
|
||||
|
||||
void BlockItemPin::_init(bool affect_parent) {
|
||||
text_item.setFont(AlignedTextItem::sceneFont(QApplication::font()));
|
||||
QRectF tbr = text_item.boundingRect();
|
||||
const double r = 7.;
|
||||
ell_item.setRect(-r, -r, r+r, r+r);
|
||||
@@ -54,6 +56,13 @@ void BlockItemPin::_reparent() {
|
||||
if (qgraphicsitem_cast<BlockItem*>(parentItem()) == 0) return;
|
||||
QPen p = qgraphicsitem_cast<BlockItem*>(parentItem())->g_main.pen();
|
||||
ell_item.setPen(p);
|
||||
if (scene()) {
|
||||
text_item.setFont(AlignedTextItem::sceneFont(scene()->font()));
|
||||
QRectF tbr = text_item.boundingRect();
|
||||
text_item.resetTransform();
|
||||
text_item.setPos(0, -tbr.height() / 2.);
|
||||
text_item.setTransformOriginPoint(0, tbr.height() / 2.);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user