1
git-svn-id: svn://db.shs.com.ru/libs@1 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
45
qad_blockview/alignedtextitem.h
Normal file
45
qad_blockview/alignedtextitem.h
Normal file
@@ -0,0 +1,45 @@
|
||||
#ifndef ALIGNEDTEXTITEM_H
|
||||
#define ALIGNEDTEXTITEM_H
|
||||
|
||||
#include <QGraphicsSimpleTextItem>
|
||||
#include <QPen>
|
||||
#include <QBrush>
|
||||
#include <QFont>
|
||||
|
||||
|
||||
class 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) {text_.setFont(f); _move();}
|
||||
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();}
|
||||
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};
|
||||
|
||||
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_;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // ALIGNEDTEXTITEM_H
|
||||
Reference in New Issue
Block a user