2007-12-01 10:47:15 +00:00
|
|
|
/*
|
2025-01-04 13:37:40 +01:00
|
|
|
Copyright 2006-2025 The QElectroTech Team
|
2007-12-01 10:47:15 +00:00
|
|
|
This file is part of QElectroTech.
|
|
|
|
|
|
|
|
QElectroTech is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
QElectroTech is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2007-09-26 22:57:53 +00:00
|
|
|
#ifndef DIAGRAM_TEXT_ITEM_H
|
|
|
|
#define DIAGRAM_TEXT_ITEM_H
|
2014-07-21 20:44:32 +00:00
|
|
|
|
|
|
|
#include <QGraphicsTextItem>
|
2019-03-08 10:27:33 +00:00
|
|
|
#include <QFont>
|
2014-07-21 20:44:32 +00:00
|
|
|
|
|
|
|
class Diagram;
|
|
|
|
class QDomElement;
|
|
|
|
class QDomDocument;
|
|
|
|
|
2007-10-10 17:50:26 +00:00
|
|
|
/**
|
2012-11-09 21:09:24 +00:00
|
|
|
This class represents a selectable, movable and editable text field on a
|
|
|
|
diagram.
|
2009-12-06 23:18:47 +00:00
|
|
|
@see QGraphicsItem::GraphicsItemFlags
|
2007-10-10 17:50:26 +00:00
|
|
|
*/
|
2015-08-08 13:06:21 +00:00
|
|
|
class DiagramTextItem : public QGraphicsTextItem
|
|
|
|
{
|
2007-10-27 13:18:17 +00:00
|
|
|
Q_OBJECT
|
2020-08-16 14:24:51 +02:00
|
|
|
|
|
|
|
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
|
2018-05-11 18:14:41 +00:00
|
|
|
Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged)
|
2019-02-19 16:42:07 +00:00
|
|
|
Q_PROPERTY(QString plainText READ toPlainText WRITE setPlainText)
|
2019-03-08 10:27:33 +00:00
|
|
|
Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
|
2019-02-19 16:42:07 +00:00
|
|
|
|
2017-08-03 17:36:08 +00:00
|
|
|
|
|
|
|
signals:
|
|
|
|
void colorChanged(QColor color);
|
2018-05-11 18:14:41 +00:00
|
|
|
void alignmentChanged(Qt::Alignment alignment);
|
|
|
|
void textEdited(const QString &old_str, const QString &new_str);
|
2019-03-08 10:27:33 +00:00
|
|
|
void fontChanged(QFont font);
|
2015-08-08 13:06:21 +00:00
|
|
|
|
2007-09-26 22:57:53 +00:00
|
|
|
public:
|
2017-08-05 02:06:59 +00:00
|
|
|
DiagramTextItem(QGraphicsItem * = nullptr);
|
|
|
|
DiagramTextItem(const QString &, QGraphicsItem * = nullptr);
|
2014-10-18 12:25:16 +00:00
|
|
|
|
|
|
|
private:
|
2015-08-08 13:06:21 +00:00
|
|
|
void build();
|
2007-09-26 22:57:53 +00:00
|
|
|
|
|
|
|
public:
|
2015-08-08 13:06:21 +00:00
|
|
|
enum { Type = UserType + 1004 };
|
2017-08-05 02:10:01 +00:00
|
|
|
int type() const override { return Type; }
|
2015-08-08 13:06:21 +00:00
|
|
|
|
|
|
|
Diagram *diagram() const;
|
|
|
|
virtual void fromXml(const QDomElement &) = 0;
|
|
|
|
virtual QDomElement toXml(QDomDocument &) const;
|
|
|
|
void edit();
|
|
|
|
|
|
|
|
QPointF mapMovementToScene (const QPointF &) const;
|
|
|
|
QPointF mapMovementFromScene (const QPointF &) const;
|
|
|
|
QPointF mapMovementToParent (const QPointF &) const;
|
|
|
|
QPointF mapMovementFromParent (const QPointF &) const;
|
|
|
|
|
2019-03-08 10:27:33 +00:00
|
|
|
void setFont(const QFont &font);
|
2020-08-16 14:24:51 +02:00
|
|
|
|
|
|
|
void setColor(const QColor& color);
|
|
|
|
QColor color() const;
|
|
|
|
|
2017-08-03 17:36:08 +00:00
|
|
|
void setNoEditable(bool e = true) {m_no_editable = e;}
|
2018-05-11 18:14:41 +00:00
|
|
|
|
|
|
|
void setAlignment(const Qt::Alignment &alignment);
|
|
|
|
Qt::Alignment alignment() const;
|
|
|
|
bool m_block_alignment = false;
|
2018-06-24 11:16:37 +00:00
|
|
|
|
|
|
|
QRectF frameRect() const;
|
2019-02-19 16:42:07 +00:00
|
|
|
|
|
|
|
void setHtml(const QString &text);
|
|
|
|
void setPlainText(const QString &text);
|
|
|
|
bool isHtml() const;
|
2015-08-08 13:06:21 +00:00
|
|
|
|
2007-09-26 22:57:53 +00:00
|
|
|
protected:
|
2020-08-16 14:24:51 +02:00
|
|
|
void paint(QPainter *,
|
|
|
|
const QStyleOptionGraphicsItem *,
|
|
|
|
QWidget *) override;
|
2017-08-05 02:10:01 +00:00
|
|
|
void focusInEvent(QFocusEvent *) override;
|
|
|
|
void focusOutEvent(QFocusEvent *) override;
|
2014-10-17 21:30:42 +00:00
|
|
|
|
2017-08-05 02:10:01 +00:00
|
|
|
void mouseDoubleClickEvent (QGraphicsSceneMouseEvent *event) override;
|
|
|
|
void mousePressEvent (QGraphicsSceneMouseEvent *event) override;
|
|
|
|
void mouseMoveEvent (QGraphicsSceneMouseEvent *event) override;
|
|
|
|
void mouseReleaseEvent (QGraphicsSceneMouseEvent *event) override;
|
2014-10-17 21:30:42 +00:00
|
|
|
|
2017-08-05 02:10:01 +00:00
|
|
|
void hoverEnterEvent(QGraphicsSceneHoverEvent *) override;
|
|
|
|
void hoverLeaveEvent(QGraphicsSceneHoverEvent *) override;
|
|
|
|
void hoverMoveEvent(QGraphicsSceneHoverEvent *) override;
|
2015-08-08 13:06:21 +00:00
|
|
|
|
|
|
|
virtual void applyRotation(const qreal &);
|
2018-05-11 18:14:41 +00:00
|
|
|
void prepareAlignment();
|
|
|
|
void finishAlignment();
|
2014-11-16 14:15:32 +00:00
|
|
|
|
2009-11-29 21:56:48 +00:00
|
|
|
|
2014-10-17 21:30:42 +00:00
|
|
|
protected:
|
2020-08-16 14:24:51 +02:00
|
|
|
bool
|
|
|
|
m_mouse_hover = false,
|
|
|
|
m_first_move = true,
|
|
|
|
m_no_editable,
|
|
|
|
m_is_html = false;
|
2017-08-03 17:36:08 +00:00
|
|
|
|
2020-08-16 14:24:51 +02:00
|
|
|
QString
|
|
|
|
m_previous_html_text,
|
|
|
|
m_previous_text;
|
2017-08-03 17:36:08 +00:00
|
|
|
|
2015-08-08 13:06:21 +00:00
|
|
|
QPointF m_mouse_to_origin_movement;
|
2018-05-11 18:14:41 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
QRectF m_alignment_rect;
|
|
|
|
Qt::Alignment m_alignment = (Qt::AlignTop | Qt::AlignLeft);
|
2007-09-26 22:57:53 +00:00
|
|
|
};
|
|
|
|
#endif
|