Go to the documentation of this file.00001 #include "constants.h"
00002
00003 #include "label.h"
00004 #include "stringProcessor.h"
00005 #include "transition.h"
00006
00007 #include <QPainter>
00008 #include <QGraphicsScene>
00009 #include <QGraphicsSceneMouseEvent>
00010 #include <QPointF>
00011
00012 #include <QtDebug>
00013
00014 LabelX::LabelX(Transition *tr, const QString &text, bool leftOriented, int fontSize,
00015 const QColor &color, float posParam, const QPointF &pos)
00016 : m_pTransition(tr), m_text(text), m_leftOriented(leftOriented), m_fontSize(fontSize),
00017 m_color(color), m_posParam(posParam)
00018 {
00019 setPos(pos);
00020
00021 setFlag(QGraphicsItem::ItemIsMovable, false);
00022 setFlag(QGraphicsItem::ItemIsSelectable, false);
00023
00024 m_pStringProcessor = new StringProcessor(m_text, m_fontSize);
00025 }
00026
00027 LabelX::~LabelX()
00028 {
00029 DBGLOG("called");
00030 if (m_pStringProcessor != NULL) delete m_pStringProcessor;
00031 }
00032
00033 QRectF LabelX::boundingRect() const
00034 {
00035 int adjust = 5;
00036 QRectF rect = QRectF(0,
00037 0,
00038 m_pStringProcessor->getWidth(),
00039 m_pStringProcessor->getHeight()).adjusted(-adjust, -adjust, adjust, adjust);
00040 return rect;
00041 }
00042
00043 QPainterPath LabelX::shape() const
00044 {
00045 QPainterPath path;
00046 path.setFillRule(Qt::WindingFill);
00047 path.addRect(boundingRect());
00048 return path;
00049 }
00050
00051 void LabelX::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
00052 {
00053 painter->setPen(QColor(m_color));
00054 QPointF position(0, getHeight());
00055 if (m_text != "")
00056 {
00057 m_pStringProcessor->drawText(painter, position);
00058 }
00059 }
00060
00061 bool LabelX::setText(const QString &text)
00062 {
00063 prepareGeometryChange();
00064
00065 if (!m_pStringProcessor->setText(text))
00066 {
00067 return false;
00068 }
00069
00070 m_text = m_pStringProcessor->text();
00071 return true;
00072 }
00073
00074 int LabelX::getWidth() const
00075 {
00076 return m_pStringProcessor->getWidth();
00077 }
00078
00079 int LabelX::getHeight() const
00080 {
00081 return m_pStringProcessor->getHeight();
00082 }
00083
00084 void LabelX::setFontSize(int fontSize)
00085 {
00086 prepareGeometryChange();
00087 m_fontSize = fontSize;
00088 m_pStringProcessor->setFontSize(fontSize);
00089 }
00090
00091 QStringList LabelX::getCharacters() const
00092 {
00093 Q_ASSERT(m_pStringProcessor);
00094 return m_pStringProcessor->getCharacters();
00095 }
00096
00097 StringProcessor::TCharacterList LabelX::getCharacterList() const
00098 {
00099 Q_ASSERT(m_pStringProcessor);
00100 return m_pStringProcessor->getCharacterList();
00101 }
00102
00103 void LabelX::mousePressEvent(QGraphicsSceneMouseEvent *event)
00104 {
00105 event->ignore();
00106 }