File indexing completed on 2022-10-04 14:29:26

0001 /*
0002     SPDX-FileCopyrightText: 2007 Paolo Capriotti <p.capriotti@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "message.h"
0008 #include <QTextOption>
0009 #include <QTextDocument>
0010 
0011 Message::Message(const QString& text, const QFont& font, int maxwidth)
0012 : QGraphicsTextItem(text)
0013 , m_velocity(0.0, 0.0)
0014 {
0015     setFont(font);
0016     setDefaultTextColor(Qt::black);
0017     setAcceptHoverEvents(false);
0018     document()->setTextWidth(maxwidth);
0019     QTextOption opts = document()->defaultTextOption();
0020     opts.setAlignment(Qt::AlignHCenter);
0021     document()->setDefaultTextOption(opts);
0022     
0023     // translate so that the origin is the center
0024     setTransform(QTransform::fromTranslate(-document()->size().width() / 2, -document()->size().height() / 2), true);
0025 }
0026 
0027 void Message::setOpacityF(qreal opacity)
0028 {
0029     QGraphicsItem::setOpacity(opacity);
0030 }
0031 
0032 qreal Message::opacityF() const
0033 {
0034     return QGraphicsItem::opacity();
0035 }
0036 
0037 void Message::setVelocity(const QPointF& vel)
0038 {
0039     m_velocity = vel;
0040 }
0041 
0042 QPointF Message::velocity() const
0043 {
0044     return m_velocity;
0045 }
0046 
0047 void Message::setPosition(const QPointF& pos)
0048 {
0049     QGraphicsTextItem::setPos(pos);
0050 }
0051 
0052 QPointF Message::position() const
0053 {
0054     return QGraphicsTextItem::pos();
0055 }
0056 
0057 int Message::height() const
0058 {
0059     return document()->size().height();
0060 }