2007-12-01 10:47:15 +00:00
|
|
|
/*
|
2021-02-20 12:13:46 +01:00
|
|
|
Copyright 2006-2021 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
|
|
|
#include "diagramtextitem.h"
|
2020-12-08 19:57:35 +01:00
|
|
|
|
|
|
|
#include "../diagram.h"
|
|
|
|
#include "../diagramcommands.h"
|
|
|
|
#include "../qetapp.h"
|
|
|
|
#include "../richtext/richtexteditor_p.h"
|
2013-04-09 11:26:53 +00:00
|
|
|
|
2007-09-26 22:57:53 +00:00
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief DiagramTextItem::DiagramTextItem
|
|
|
|
@param parent : parent item
|
|
|
|
*/
|
2014-12-14 13:06:21 +00:00
|
|
|
DiagramTextItem::DiagramTextItem(QGraphicsItem *parent) :
|
2018-03-25 18:42:18 +00:00
|
|
|
QGraphicsTextItem(parent)
|
2015-08-08 13:06:21 +00:00
|
|
|
{ build(); }
|
2007-09-26 22:57:53 +00:00
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief DiagramTextItem::DiagramTextItem
|
|
|
|
@param text : text to display
|
|
|
|
@param parent : parent item
|
|
|
|
*/
|
2014-12-14 13:06:21 +00:00
|
|
|
DiagramTextItem::DiagramTextItem(const QString &text, QGraphicsItem *parent) :
|
|
|
|
QGraphicsTextItem(text, parent),
|
2015-03-02 20:14:56 +00:00
|
|
|
m_mouse_hover(false),
|
2018-03-25 18:42:18 +00:00
|
|
|
m_previous_html_text(text)
|
2015-08-08 13:06:21 +00:00
|
|
|
{ build(); }
|
2014-10-18 12:25:16 +00:00
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief DiagramTextItem::build
|
|
|
|
Build this item with default value
|
|
|
|
*/
|
2015-08-08 13:06:21 +00:00
|
|
|
void DiagramTextItem::build()
|
|
|
|
{
|
|
|
|
//set Zvalue at 10 to be upper than the DiagramImageItem
|
2013-08-24 15:18:45 +00:00
|
|
|
setZValue(10);
|
2015-08-08 13:06:21 +00:00
|
|
|
setAcceptHoverEvents(true);
|
2007-11-01 23:56:19 +00:00
|
|
|
setDefaultTextColor(Qt::black);
|
2017-12-10 01:03:36 +00:00
|
|
|
setFont(QETApp::diagramTextsItemFont());
|
2015-08-08 13:06:21 +00:00
|
|
|
setFlags(QGraphicsItem::ItemIsSelectable|QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemSendsGeometryChanges);
|
2013-12-29 18:09:25 +00:00
|
|
|
setNoEditable(false);
|
2015-03-02 20:14:56 +00:00
|
|
|
setToolTip(tr("Maintenir ctrl pour un déplacement libre"));
|
2007-09-26 22:57:53 +00:00
|
|
|
}
|
|
|
|
|
2010-04-18 17:59:54 +00:00
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief DiagramTextItem::diagram
|
|
|
|
@return The diagram of this item or 0 if this text isn't in a diagram
|
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
Diagram *DiagramTextItem::diagram() const
|
|
|
|
{
|
2010-05-02 22:21:53 +00:00
|
|
|
return(qobject_cast<Diagram *>(scene()));
|
2007-09-26 22:57:53 +00:00
|
|
|
}
|
|
|
|
|
2014-11-14 13:06:24 +00:00
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief DiagramTextItem::toXml
|
|
|
|
This method do nothing and return an empty DomElement
|
|
|
|
This is used to be inherited by child class
|
|
|
|
@return
|
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
QDomElement DiagramTextItem::toXml(QDomDocument &) const
|
|
|
|
{
|
2014-11-14 13:06:24 +00:00
|
|
|
return QDomElement();
|
|
|
|
}
|
|
|
|
|
2014-10-25 21:21:52 +00:00
|
|
|
/**
|
|
|
|
Traduit en coordonnees de la scene un mouvement / vecteur initialement
|
|
|
|
exprime en coordonnees locales.
|
|
|
|
@param movement Vecteur exprime en coordonnees locales
|
|
|
|
@return le meme vecteur, exprime en coordonnees de la scene
|
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
QPointF DiagramTextItem::mapMovementToScene(const QPointF &movement) const
|
|
|
|
{
|
2014-10-25 21:21:52 +00:00
|
|
|
// on definit deux points en coordonnees locales
|
|
|
|
QPointF local_origin(0.0, 0.0);
|
|
|
|
QPointF local_movement_point(movement);
|
|
|
|
|
|
|
|
// on les mappe sur la scene
|
|
|
|
QPointF scene_origin(mapToScene(local_origin));
|
|
|
|
QPointF scene_movement_point(mapToScene(local_movement_point));
|
|
|
|
|
|
|
|
// on calcule le vecteur represente par ces deux points
|
|
|
|
return(scene_movement_point - scene_origin);
|
|
|
|
}
|
|
|
|
|
2010-04-24 20:42:20 +00:00
|
|
|
/**
|
|
|
|
Traduit en coordonnees locales un mouvement / vecteur initialement
|
|
|
|
exprime en coordonnees de la scene.
|
|
|
|
@param movement Vecteur exprime en coordonnees de la scene
|
|
|
|
@return le meme vecteur, exprime en coordonnees locales
|
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
QPointF DiagramTextItem::mapMovementFromScene(const QPointF &movement) const
|
|
|
|
{
|
2010-04-24 20:42:20 +00:00
|
|
|
// on definit deux points sur la scene
|
|
|
|
QPointF scene_origin(0.0, 0.0);
|
|
|
|
QPointF scene_movement_point(movement);
|
2014-10-25 21:21:52 +00:00
|
|
|
|
2010-04-24 20:42:20 +00:00
|
|
|
// on les mappe sur ce QGraphicsItem
|
|
|
|
QPointF local_origin(mapFromScene(scene_origin));
|
|
|
|
QPointF local_movement_point(mapFromScene(scene_movement_point));
|
2014-10-25 21:21:52 +00:00
|
|
|
|
2010-04-24 20:42:20 +00:00
|
|
|
// on calcule le vecteur represente par ces deux points
|
|
|
|
return(local_movement_point - local_origin);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Traduit en coordonnees de l'item parent un mouvement / vecteur initialement
|
|
|
|
exprime en coordonnees locales.
|
|
|
|
@param movement Vecteur exprime en coordonnees locales
|
|
|
|
@return le meme vecteur, exprime en coordonnees du parent
|
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
QPointF DiagramTextItem::mapMovementToParent(const QPointF &movement) const
|
|
|
|
{
|
2010-04-24 20:42:20 +00:00
|
|
|
// on definit deux points en coordonnees locales
|
|
|
|
QPointF local_origin(0.0, 0.0);
|
|
|
|
QPointF local_movement_point(movement);
|
2014-10-25 21:21:52 +00:00
|
|
|
|
2010-04-24 20:42:20 +00:00
|
|
|
// on les mappe sur la scene
|
|
|
|
QPointF parent_origin(mapToParent(local_origin));
|
|
|
|
QPointF parent_movement_point(mapToParent(local_movement_point));
|
2014-10-25 21:21:52 +00:00
|
|
|
|
2010-04-24 20:42:20 +00:00
|
|
|
// on calcule le vecteur represente par ces deux points
|
|
|
|
return(parent_movement_point - parent_origin);
|
|
|
|
}
|
|
|
|
|
2014-10-25 21:21:52 +00:00
|
|
|
/**
|
|
|
|
Traduit en coordonnees locales un mouvement / vecteur initialement
|
|
|
|
exprime en coordonnees du parent.
|
|
|
|
@param movement Vecteur exprime en coordonnees du parent
|
|
|
|
@return le meme vecteur, exprime en coordonnees locales
|
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
QPointF DiagramTextItem::mapMovementFromParent(const QPointF &movement) const
|
|
|
|
{
|
2014-10-25 21:21:52 +00:00
|
|
|
// on definit deux points sur le parent
|
|
|
|
QPointF parent_origin(0.0, 0.0);
|
|
|
|
QPointF parent_movement_point(movement);
|
|
|
|
|
|
|
|
// on les mappe sur ce QGraphicsItem
|
|
|
|
QPointF local_origin(mapFromParent(parent_origin));
|
|
|
|
QPointF local_movement_point(mapFromParent(parent_movement_point));
|
|
|
|
|
|
|
|
// on calcule le vecteur represente par ces deux points
|
|
|
|
return(local_movement_point - local_origin);
|
|
|
|
}
|
|
|
|
|
2019-03-08 10:27:33 +00:00
|
|
|
void DiagramTextItem::setFont(const QFont &font)
|
|
|
|
{
|
|
|
|
if (this->font() == font) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
prepareAlignment();
|
|
|
|
QGraphicsTextItem::setFont(font);
|
|
|
|
finishAlignment();
|
|
|
|
emit fontChanged(font);
|
|
|
|
}
|
2017-08-03 17:36:08 +00:00
|
|
|
}
|
|
|
|
|
2018-07-19 14:14:31 +00:00
|
|
|
void DiagramTextItem::setColor(const QColor& color)
|
2017-08-03 17:36:08 +00:00
|
|
|
{
|
2020-08-16 14:24:51 +02:00
|
|
|
setDefaultTextColor(color);
|
2017-08-03 17:36:08 +00:00
|
|
|
emit colorChanged(color);
|
|
|
|
}
|
|
|
|
|
2020-09-07 22:03:40 +02:00
|
|
|
QColor DiagramTextItem::color() const
|
|
|
|
{
|
2017-08-03 17:36:08 +00:00
|
|
|
return defaultTextColor();
|
2013-12-03 10:17:49 +00:00
|
|
|
}
|
|
|
|
|
2018-05-11 18:14:41 +00:00
|
|
|
void DiagramTextItem::setAlignment(const Qt::Alignment &alignment)
|
|
|
|
{
|
|
|
|
m_alignment = alignment;
|
|
|
|
emit alignmentChanged(alignment);
|
|
|
|
}
|
|
|
|
|
|
|
|
Qt::Alignment DiagramTextItem::alignment() const
|
|
|
|
{
|
|
|
|
return m_alignment;
|
|
|
|
}
|
|
|
|
|
2018-06-24 11:16:37 +00:00
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief DiagramTextItem::frameRect
|
|
|
|
@return the rect used to draw a frame around this text
|
|
|
|
*/
|
2018-06-24 11:16:37 +00:00
|
|
|
QRectF DiagramTextItem::frameRect() const
|
|
|
|
{
|
|
|
|
//Get the bounding rectangle of the text
|
|
|
|
QSizeF size = document()->size();
|
|
|
|
size.setWidth(document()->idealWidth());
|
|
|
|
//Remove the margin. Size is exactly the bounding rect of the text
|
|
|
|
size.rheight() -= document()->documentMargin()*2;
|
|
|
|
size.rwidth() -= document()->documentMargin()*2;
|
|
|
|
//Add a little margin only for a better visual;
|
|
|
|
size.rheight() += 2;
|
|
|
|
size.rwidth() += 2;
|
|
|
|
|
|
|
|
//The pos of the rect
|
|
|
|
QPointF pos = boundingRect().center();
|
|
|
|
pos.rx() -= size.width()/2;
|
|
|
|
pos.ry() -= size.height()/2;
|
|
|
|
|
|
|
|
return QRectF(pos, size);
|
|
|
|
}
|
|
|
|
|
2019-02-19 16:42:07 +00:00
|
|
|
void DiagramTextItem::setHtml(const QString &text)
|
|
|
|
{
|
|
|
|
QGraphicsTextItem::setHtml(text);
|
|
|
|
m_is_html = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DiagramTextItem::setPlainText(const QString &text)
|
|
|
|
{
|
|
|
|
QGraphicsTextItem::setPlainText(text);
|
|
|
|
m_is_html = false;
|
|
|
|
}
|
|
|
|
|
2020-09-07 22:03:40 +02:00
|
|
|
bool DiagramTextItem::isHtml() const
|
|
|
|
{
|
2019-02-19 16:42:07 +00:00
|
|
|
return m_is_html;
|
|
|
|
}
|
|
|
|
|
2010-05-08 17:03:05 +00:00
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief DiagramTextItem::paint
|
2022-12-04 08:21:12 -05:00
|
|
|
Draw this text field. This method draws the text by calling QGraphicsTextItem::paint.
|
|
|
|
If text is hovered, this method draws the bounding rect in grey
|
2020-08-16 11:19:36 +02:00
|
|
|
@param painter : painter to use
|
|
|
|
@param option : style option
|
2022-12-04 08:21:12 -05:00
|
|
|
@param widget : widget that is drawn to
|
2020-08-16 11:19:36 +02:00
|
|
|
*/
|
2015-03-02 20:14:56 +00:00
|
|
|
void DiagramTextItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
|
|
|
{
|
2014-11-16 20:32:55 +00:00
|
|
|
painter -> setRenderHint(QPainter::Antialiasing, false);
|
2010-05-08 17:03:05 +00:00
|
|
|
QGraphicsTextItem::paint(painter, option, widget);
|
2014-11-16 14:15:32 +00:00
|
|
|
|
2015-03-02 20:14:56 +00:00
|
|
|
if (m_mouse_hover && !isSelected())
|
|
|
|
{
|
2014-11-16 14:15:32 +00:00
|
|
|
painter -> save();
|
2015-03-02 20:14:56 +00:00
|
|
|
|
|
|
|
//Disable renderhints
|
2014-11-16 14:15:32 +00:00
|
|
|
painter -> setRenderHint(QPainter::Antialiasing, false);
|
|
|
|
painter -> setRenderHint(QPainter::TextAntialiasing, false);
|
|
|
|
painter -> setRenderHint(QPainter::SmoothPixmapTransform, false);
|
2015-03-02 20:14:56 +00:00
|
|
|
|
|
|
|
//Draw the selected rect in grey
|
2014-11-16 14:15:32 +00:00
|
|
|
QPen t;
|
|
|
|
t.setColor(Qt::gray);
|
|
|
|
t.setStyle(Qt::DashDotLine);
|
2015-03-02 20:14:56 +00:00
|
|
|
t.setCosmetic(true);
|
2014-11-16 14:15:32 +00:00
|
|
|
painter -> setPen(t);
|
2020-06-01 22:52:15 +02:00
|
|
|
painter -> drawRoundedRect(boundingRect(), 10, 10);
|
2015-03-02 20:14:56 +00:00
|
|
|
|
2014-11-16 14:15:32 +00:00
|
|
|
painter -> restore();
|
|
|
|
}
|
2014-11-16 20:32:55 +00:00
|
|
|
|
2010-05-08 17:03:05 +00:00
|
|
|
}
|
|
|
|
|
2010-04-23 22:39:59 +00:00
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief DiagramTextItem::focusInEvent
|
2020-08-20 21:57:35 +02:00
|
|
|
@param event
|
2020-08-16 11:19:36 +02:00
|
|
|
*/
|
2017-08-03 17:36:08 +00:00
|
|
|
void DiagramTextItem::focusInEvent(QFocusEvent *event)
|
|
|
|
{
|
|
|
|
QGraphicsTextItem::focusInEvent(event);
|
|
|
|
|
2010-05-08 21:24:43 +00:00
|
|
|
setFlag(QGraphicsItem::ItemIsMovable, false);
|
|
|
|
|
2017-08-03 17:36:08 +00:00
|
|
|
m_previous_html_text = toHtml();
|
|
|
|
m_previous_text = toPlainText();
|
2010-04-23 22:39:59 +00:00
|
|
|
}
|
|
|
|
|
2010-04-18 17:59:54 +00:00
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief DiagramTextItem::focusOutEvent
|
|
|
|
@param event
|
|
|
|
*/
|
2017-08-03 17:36:08 +00:00
|
|
|
void DiagramTextItem::focusOutEvent(QFocusEvent *event)
|
|
|
|
{
|
|
|
|
QGraphicsTextItem::focusOutEvent(event);
|
|
|
|
|
|
|
|
if(toPlainText() != m_previous_text)
|
|
|
|
emit textEdited(m_previous_text, toPlainText());
|
2007-10-14 14:44:33 +00:00
|
|
|
|
|
|
|
QTextCursor cursor = textCursor();
|
|
|
|
cursor.clearSelection();
|
|
|
|
setTextCursor(cursor);
|
2017-08-03 17:36:08 +00:00
|
|
|
|
|
|
|
//Bad hack to be re-entrant
|
2009-12-06 23:18:47 +00:00
|
|
|
setTextInteractionFlags(Qt::NoTextInteraction);
|
2017-08-03 17:36:08 +00:00
|
|
|
|
2010-05-08 21:24:43 +00:00
|
|
|
setFlag(QGraphicsItem::ItemIsMovable, true);
|
2015-08-08 13:06:21 +00:00
|
|
|
setFlag(QGraphicsTextItem::ItemIsFocusable, false);
|
2007-10-27 13:18:17 +00:00
|
|
|
}
|
|
|
|
|
2007-12-16 13:21:28 +00:00
|
|
|
/**
|
|
|
|
Gere les double-clics sur ce champ de texte.
|
|
|
|
@param event un QGraphicsSceneMouseEvent decrivant le double-clic
|
|
|
|
*/
|
2007-10-27 13:18:17 +00:00
|
|
|
void DiagramTextItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) {
|
2017-08-03 17:36:08 +00:00
|
|
|
if (!(textInteractionFlags() & Qt::TextEditable) && !m_no_editable) {
|
2007-10-27 13:18:17 +00:00
|
|
|
// rend le champ de texte editable
|
|
|
|
setTextInteractionFlags(Qt::TextEditorInteraction);
|
|
|
|
|
2009-12-06 23:18:47 +00:00
|
|
|
// edite le champ de texte
|
|
|
|
setFocus(Qt::MouseFocusReason);
|
2007-10-27 13:18:17 +00:00
|
|
|
} else {
|
|
|
|
QGraphicsTextItem::mouseDoubleClickEvent(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-17 21:30:42 +00:00
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief DiagramTextItem::mousePressEvent
|
|
|
|
@param event
|
|
|
|
*/
|
2019-02-19 16:42:07 +00:00
|
|
|
void DiagramTextItem::mousePressEvent (QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
|
|
|
if (event->button() == Qt::LeftButton)
|
|
|
|
{
|
|
|
|
m_first_move = true;
|
|
|
|
//Save the pos of item at the beggining of the movement
|
|
|
|
m_mouse_to_origin_movement = pos() - event->scenePos();
|
2014-10-17 21:30:42 +00:00
|
|
|
}
|
|
|
|
QGraphicsTextItem::mousePressEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief DiagramTextItem::mouseMoveEvent
|
|
|
|
@param event
|
|
|
|
*/
|
2014-10-17 21:30:42 +00:00
|
|
|
void DiagramTextItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
|
|
|
|
if (textInteractionFlags() & Qt::TextEditable) QGraphicsTextItem::mouseMoveEvent(event);
|
|
|
|
|
|
|
|
else if ((flags() & QGraphicsItem::ItemIsMovable) && (event -> buttons() & Qt::LeftButton)) {
|
|
|
|
Diagram *diagram_ = diagram();
|
|
|
|
|
|
|
|
//This is first move, we signal it to parent diagram
|
|
|
|
if(diagram_ && m_first_move)
|
2018-04-05 09:37:35 +00:00
|
|
|
diagram_->elementsMover().beginMovement(diagram_, this);
|
2014-10-17 21:30:42 +00:00
|
|
|
|
|
|
|
QPointF old_pos = pos();
|
|
|
|
|
|
|
|
//Set the actual pos
|
2014-10-18 12:25:16 +00:00
|
|
|
QPointF new_pos = event->scenePos() + m_mouse_to_origin_movement;
|
|
|
|
event->modifiers() == Qt::ControlModifier ? setPos(new_pos) : setPos(Diagram::snapToGrid(new_pos));
|
|
|
|
|
2014-10-17 21:30:42 +00:00
|
|
|
|
|
|
|
//Update the actual movement for other selected item
|
|
|
|
if (diagram_)
|
2018-04-05 09:37:35 +00:00
|
|
|
diagram_->elementsMover().continueMovement(pos() - old_pos);
|
2014-10-17 21:30:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else event -> ignore();
|
|
|
|
|
|
|
|
m_first_move = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief DiagramTextItem::mouseReleaseEvent
|
|
|
|
@param event
|
|
|
|
*/
|
2019-02-19 16:42:07 +00:00
|
|
|
void DiagramTextItem::mouseReleaseEvent (QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
|
|
|
//Signal to diagram movement is finish
|
|
|
|
if (diagram() && (event->button() == Qt::LeftButton))
|
|
|
|
{
|
2018-04-05 09:37:35 +00:00
|
|
|
diagram()->elementsMover().endMovement();
|
2019-02-19 16:42:07 +00:00
|
|
|
event->accept();
|
|
|
|
if (event->buttonDownScenePos(Qt::LeftButton) != event->scenePos()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (event->modifiers() & Qt::ControlModifier && (event->button() == Qt::LeftButton))
|
|
|
|
{
|
|
|
|
setSelected(!isSelected());
|
|
|
|
event->accept();
|
|
|
|
}
|
|
|
|
else {
|
2014-10-17 21:30:42 +00:00
|
|
|
QGraphicsTextItem::mouseReleaseEvent(event);
|
2019-02-19 16:42:07 +00:00
|
|
|
}
|
2014-10-17 21:30:42 +00:00
|
|
|
}
|
|
|
|
|
2009-12-13 22:12:52 +00:00
|
|
|
/**
|
2010-07-18 01:46:30 +00:00
|
|
|
Effectue la rotation du texte en elle-meme
|
2009-12-13 22:12:52 +00:00
|
|
|
Pour les DiagramTextItem, la rotation s'effectue autour du point (0, 0).
|
2010-07-18 01:46:30 +00:00
|
|
|
Cette methode peut toutefois etre redefinie dans des classes filles
|
2009-12-13 22:12:52 +00:00
|
|
|
@param angle Angle de la rotation a effectuer
|
|
|
|
*/
|
|
|
|
void DiagramTextItem::applyRotation(const qreal &angle) {
|
2013-09-09 13:29:28 +00:00
|
|
|
setRotation(QET::correctAngle(rotation()+angle));
|
2009-12-13 22:12:52 +00:00
|
|
|
}
|
|
|
|
|
2018-05-11 18:14:41 +00:00
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief DiagramTextItem::prepareAlignment
|
|
|
|
Call this function before changing the bounding rect of this text.
|
|
|
|
*/
|
2018-05-11 18:14:41 +00:00
|
|
|
void DiagramTextItem::prepareAlignment()
|
|
|
|
{
|
2018-05-12 12:59:49 +00:00
|
|
|
m_alignment_rect = boundingRect();
|
2018-05-11 18:14:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief DiagramTextItem::finishAlignment
|
2022-12-04 08:21:12 -05:00
|
|
|
Call this function after changing the bounding rect of this text
|
2020-08-16 11:19:36 +02:00
|
|
|
to set the position of this text according to the alignment property.
|
|
|
|
*/
|
2018-05-11 18:14:41 +00:00
|
|
|
void DiagramTextItem::finishAlignment()
|
|
|
|
{
|
|
|
|
if(m_block_alignment)
|
|
|
|
return;
|
|
|
|
|
2018-05-12 12:59:49 +00:00
|
|
|
QTransform transform;
|
|
|
|
transform.rotate(this->rotation());
|
|
|
|
qreal x,xa, y,ya;
|
|
|
|
x=xa=0;
|
|
|
|
y=ya=0;
|
2018-05-11 18:14:41 +00:00
|
|
|
|
|
|
|
if(m_alignment &Qt::AlignRight)
|
2018-05-12 12:59:49 +00:00
|
|
|
{
|
|
|
|
x = m_alignment_rect.right();
|
|
|
|
xa = boundingRect().right();
|
|
|
|
}
|
2018-05-11 18:14:41 +00:00
|
|
|
else if(m_alignment &Qt::AlignHCenter)
|
|
|
|
{
|
2018-05-12 12:59:49 +00:00
|
|
|
x = m_alignment_rect.center().x();
|
|
|
|
xa = boundingRect().center().x();
|
2018-05-11 18:14:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(m_alignment &Qt::AlignBottom)
|
2018-05-12 12:59:49 +00:00
|
|
|
{
|
|
|
|
y = m_alignment_rect.bottom();
|
|
|
|
ya = boundingRect().bottom();
|
|
|
|
}
|
2018-05-11 18:14:41 +00:00
|
|
|
else if(m_alignment &Qt::AlignVCenter)
|
|
|
|
{
|
2018-05-12 12:59:49 +00:00
|
|
|
y = m_alignment_rect.center().y();
|
|
|
|
ya = boundingRect().center().y();
|
2018-05-11 18:14:41 +00:00
|
|
|
}
|
2018-05-12 12:59:49 +00:00
|
|
|
|
|
|
|
QPointF p = transform.map(QPointF(x,y));
|
|
|
|
QPointF pa = transform.map(QPointF(xa,ya));
|
|
|
|
QPointF diff = pa-p;
|
2018-05-11 18:14:41 +00:00
|
|
|
|
2018-05-12 12:59:49 +00:00
|
|
|
setPos(this->pos() - diff);
|
2018-05-11 18:14:41 +00:00
|
|
|
}
|
|
|
|
|
2013-04-01 13:49:34 +00:00
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief Edit the text with HtmlEditor
|
|
|
|
*/
|
2015-08-08 13:06:21 +00:00
|
|
|
void DiagramTextItem::edit()
|
|
|
|
{
|
2015-03-11 21:18:05 +00:00
|
|
|
QWidget *parent = nullptr;
|
|
|
|
if (scene() && scene()->views().size())
|
|
|
|
parent = scene()->views().first();
|
2015-08-08 13:06:21 +00:00
|
|
|
|
|
|
|
qdesigner_internal::RichTextEditorDialog editor(parent);
|
|
|
|
connect(&editor, &qdesigner_internal::RichTextEditorDialog::applyEditText, [this](QString text) {this->setHtml(text);});
|
|
|
|
editor.setText(toHtml());
|
|
|
|
editor.exec();
|
2013-04-01 13:49:34 +00:00
|
|
|
}
|
|
|
|
|
2014-11-16 14:15:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
When mouse over element
|
2015-03-02 20:14:56 +00:00
|
|
|
change m_mouse_hover to true (used in paint() function )
|
2014-11-16 14:15:32 +00:00
|
|
|
@param e QGraphicsSceneHoverEvent
|
|
|
|
*/
|
|
|
|
void DiagramTextItem::hoverEnterEvent(QGraphicsSceneHoverEvent *e) {
|
|
|
|
Q_UNUSED(e);
|
|
|
|
|
2015-03-02 20:14:56 +00:00
|
|
|
m_mouse_hover = true;
|
2014-11-16 14:15:32 +00:00
|
|
|
QString str_ToolTip = toPlainText();
|
2025-03-12 21:16:25 +01:00
|
|
|
|
|
|
|
// Add movement instruction for DynamicElementTextItem
|
|
|
|
if (inherits("DynamicElementTextItem")) {
|
|
|
|
str_ToolTip += tr("\n<Shift> to move");
|
|
|
|
}
|
|
|
|
|
|
|
|
setToolTip(str_ToolTip);
|
2014-11-16 14:15:32 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
When mouse over element leave the position
|
2015-03-02 20:14:56 +00:00
|
|
|
change m_mouse_hover to false (used in paint() function )
|
2014-11-16 14:15:32 +00:00
|
|
|
@param e QGraphicsSceneHoverEvent
|
|
|
|
*/
|
|
|
|
void DiagramTextItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *e) {
|
|
|
|
Q_UNUSED(e);
|
2015-03-02 20:14:56 +00:00
|
|
|
m_mouse_hover = false;
|
2014-11-16 14:15:32 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Do nothing default function .
|
|
|
|
@param e QGraphicsSceneHoverEvent
|
|
|
|
*/
|
|
|
|
void DiagramTextItem::hoverMoveEvent(QGraphicsSceneHoverEvent *e) {
|
|
|
|
Q_UNUSED(e);
|
|
|
|
QGraphicsTextItem::hoverMoveEvent(e);
|
|
|
|
}
|