2007-12-01 10:47:15 +00:00
|
|
|
/*
|
2017-01-20 10:55:49 +00:00
|
|
|
Copyright 2006-2017 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>
|
|
|
|
|
|
|
|
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
|
2017-08-03 17:36:08 +00:00
|
|
|
|
|
|
|
Q_PROPERTY(int fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged)
|
|
|
|
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void fontSizeChanged(int size);
|
|
|
|
void colorChanged(QColor color);
|
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-03 17:36:08 +00:00
|
|
|
virtual 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;
|
|
|
|
qreal rotationAngle() const;
|
|
|
|
void setRotationAngle(const qreal &);
|
|
|
|
void rotateBy(const qreal &);
|
|
|
|
void edit();
|
|
|
|
|
|
|
|
QPointF mapMovementToScene (const QPointF &) const;
|
|
|
|
QPointF mapMovementFromScene (const QPointF &) const;
|
|
|
|
QPointF mapMovementToParent (const QPointF &) const;
|
|
|
|
QPointF mapMovementFromParent (const QPointF &) const;
|
|
|
|
|
2017-08-03 17:36:08 +00:00
|
|
|
void setFontSize(int s);
|
|
|
|
int fontSize()const;
|
|
|
|
|
|
|
|
void setColor(QColor color);
|
|
|
|
QColor color() const;
|
|
|
|
|
|
|
|
void setNoEditable(bool e = true) {m_no_editable = e;}
|
2015-08-08 13:06:21 +00:00
|
|
|
|
2007-09-26 22:57:53 +00:00
|
|
|
protected:
|
2017-08-03 17:36:08 +00:00
|
|
|
virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override;
|
|
|
|
virtual void focusInEvent(QFocusEvent *) override;
|
|
|
|
virtual void focusOutEvent(QFocusEvent *) override;
|
2014-10-17 21:30:42 +00:00
|
|
|
|
2017-08-03 17:36:08 +00:00
|
|
|
virtual void mouseDoubleClickEvent (QGraphicsSceneMouseEvent *event) override;
|
|
|
|
virtual void mousePressEvent (QGraphicsSceneMouseEvent *event) override;
|
|
|
|
virtual void mouseMoveEvent (QGraphicsSceneMouseEvent *event) override;
|
|
|
|
virtual void mouseReleaseEvent (QGraphicsSceneMouseEvent *event) override;
|
2014-10-17 21:30:42 +00:00
|
|
|
|
2017-08-03 17:36:08 +00:00
|
|
|
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *) override;
|
|
|
|
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *) override;
|
|
|
|
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *) override;
|
2015-08-08 13:06:21 +00:00
|
|
|
|
|
|
|
virtual void applyRotation(const qreal &);
|
2014-11-16 14:15:32 +00:00
|
|
|
|
2007-10-27 13:18:17 +00:00
|
|
|
signals:
|
2015-08-08 13:06:21 +00:00
|
|
|
void diagramTextChanged(DiagramTextItem *, const QString &, const QString &);
|
2017-08-03 17:36:08 +00:00
|
|
|
void textEdited(const QString &old_str, const QString &new_str);
|
2009-11-29 21:56:48 +00:00
|
|
|
|
2014-10-17 21:30:42 +00:00
|
|
|
protected:
|
2017-08-03 17:36:08 +00:00
|
|
|
bool m_mouse_hover = false,
|
|
|
|
m_first_move = true,
|
|
|
|
m_no_editable;
|
|
|
|
|
|
|
|
QString m_previous_html_text,
|
|
|
|
m_previous_text;
|
|
|
|
|
|
|
|
qreal m_rotation_angle;
|
2015-08-08 13:06:21 +00:00
|
|
|
QPointF m_mouse_to_origin_movement;
|
2007-09-26 22:57:53 +00:00
|
|
|
};
|
|
|
|
#endif
|