1
git-svn-id: svn://db.shs.com.ru/libs@1 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
44
qad_blockview/alignedtextitem.cpp
Normal file
44
qad_blockview/alignedtextitem.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#include "alignedtextitem.h"
|
||||
#include <QPainter>
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
AlignedTextItem::AlignedTextItem(QGraphicsItem * parent): QGraphicsItem(parent), text_(this) {
|
||||
align_ = Qt::AlignTop | Qt::AlignHCenter;
|
||||
text_.setData(1003, true);
|
||||
_move();
|
||||
}
|
||||
|
||||
|
||||
AlignedTextItem::AlignedTextItem(const QString & text, QGraphicsItem * parent): QGraphicsItem(parent), text_(this) {
|
||||
align_ = Qt::AlignTop | Qt::AlignHCenter;
|
||||
setText(text);
|
||||
}
|
||||
|
||||
|
||||
QPointF AlignedTextItem::_point(Qt::Alignment a) const {
|
||||
QRectF br = text_.boundingRect();
|
||||
QPointF ret;
|
||||
switch (Qt::AlignmentFlag(int(align_ & Qt::AlignHorizontal_Mask))) {
|
||||
case Qt::AlignRight: ret.rx() = br.left(); break;
|
||||
case Qt::AlignHCenter: ret.rx() = br.center().x(); break;
|
||||
case Qt::AlignLeft: ret.rx() = br.right(); break;
|
||||
default: break;
|
||||
}
|
||||
switch (Qt::AlignmentFlag(int(align_ & Qt::AlignVertical_Mask))) {
|
||||
case Qt::AlignBottom: ret.ry() = br.top(); break;
|
||||
case Qt::AlignVCenter: ret.ry() = br.center().y(); break;
|
||||
case Qt::AlignTop: ret.ry() = br.bottom(); break;
|
||||
default: break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void AlignedTextItem::paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) {
|
||||
if (isSelected()) {
|
||||
painter->setPen(QPen(Qt::DashLine));
|
||||
painter->setBrush(Qt::NoBrush);
|
||||
painter->drawRect(boundingRect());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user