Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
* \file QNonScalableGraphicsTextItem.cpp
* KR Initial implementation
*/
#include <QPainter>
#include "QNonScalableGraphicsTextItem.h"
/// Constructor using a QGraphicsTextItem.
QNonScalableGraphicsTextItem::QNonScalableGraphicsTextItem(QGraphicsItem* parent) : QGraphicsTextItem(parent)
{
setAcceptDrops(true);
setAcceptHoverEvents(true);
setFlag(QGraphicsItem::ItemIgnoresTransformations, true);
}
/// Constructor using a QString.
QNonScalableGraphicsTextItem::QNonScalableGraphicsTextItem(const QString & text, QGraphicsItem * parent) :
QGraphicsTextItem(parent)
{
if (!text.isEmpty())
setPlainText(text);
setAcceptDrops(true);
setAcceptHoverEvents(true);
setFlag(QGraphicsItem::ItemIgnoresTransformations, true);
}
QNonScalableGraphicsTextItem::~QNonScalableGraphicsTextItem()
{
}
/// Paints the text item.
void QNonScalableGraphicsTextItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
//painter->drawRect(boundingRect());
QRectF rect = boundingRect();
painter->translate(-rect.width()/2, -rect.height()/2);
QGraphicsTextItem::paint(painter, option, widget);
}
/// Returns the bounding rectangle of the text item.
QRectF QNonScalableGraphicsTextItem::boundingRect()
{
QRectF rect = QGraphicsTextItem::boundingRect();
return QRectF(rect.x()-rect.width()/2, rect.y()-rect.height()/2,rect.width(), rect.height());
}