/* QAD - Qt ADvanced Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ #ifndef ALIGNEDTEXTITEM_H #define ALIGNEDTEXTITEM_H #include "qad_blockview_export.h" #include #include #include #include class QAD_BLOCKVIEW_EXPORT AlignedTextItem: public QGraphicsItem { public: AlignedTextItem(QGraphicsItem * parent = 0); AlignedTextItem(const QString & text, QGraphicsItem * parent = 0); void setText(const QString & t) { text_.setText(t); _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 font_; } QPen pen() const { return text_.pen(); } QBrush brush() const { return text_.brush(); } Qt::Alignment alignment() const { return align_; } 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()); } virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0); virtual int type() const { return Type; } void _move() { text_.setPos(-_point(align_)); } QPointF _point(Qt::Alignment a) const; QGraphicsSimpleTextItem text_; Qt::Alignment align_; QFont font_; }; #endif // ALIGNEDTEXTITEM_H