2007-12-01 10:47:15 +00:00
|
|
|
/*
|
2020-06-15 17:42:37 +02:00
|
|
|
Copyright 2006-2020 The QElectroTech Team
|
2007-12-01 10:47:15 +00:00
|
|
|
This file is part of QElectroTech.
|
2020-10-13 21:51:34 +02:00
|
|
|
|
2007-12-01 10:47:15 +00:00
|
|
|
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.
|
2020-10-13 21:51:34 +02:00
|
|
|
|
2007-12-01 10:47:15 +00:00
|
|
|
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.
|
2020-10-13 21:51:34 +02:00
|
|
|
|
2007-12-01 10:47:15 +00:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2007-06-30 17:41:07 +00:00
|
|
|
#include "parttext.h"
|
|
|
|
#include "texteditor.h"
|
2013-02-08 22:05:15 +00:00
|
|
|
#include "elementprimitivedecorator.h"
|
2007-08-25 03:43:05 +00:00
|
|
|
#include "elementscene.h"
|
2007-12-21 18:20:18 +00:00
|
|
|
#include "qetapp.h"
|
2015-07-24 11:34:45 +00:00
|
|
|
#include "QPropertyUndoCommand/qpropertyundocommand.h"
|
2007-12-05 21:16:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Constructeur
|
|
|
|
@param editor L'editeur d'element concerne
|
|
|
|
@param parent Le QGraphicsItem parent de ce texte statique
|
|
|
|
*/
|
2017-08-01 19:37:04 +00:00
|
|
|
PartText::PartText(QETElementEditor *editor, QGraphicsItem *parent) :
|
2015-03-02 20:14:56 +00:00
|
|
|
QGraphicsTextItem(parent),
|
2013-02-08 22:05:15 +00:00
|
|
|
CustomElementPart(editor),
|
2020-08-13 12:01:27 +01:00
|
|
|
previous_text()
|
2007-08-25 03:43:05 +00:00
|
|
|
{
|
2009-08-25 23:31:31 +00:00
|
|
|
document() -> setDocumentMargin(1.0);
|
2007-11-01 23:56:19 +00:00
|
|
|
setDefaultTextColor(Qt::black);
|
2009-06-26 19:59:49 +00:00
|
|
|
setFont(QETApp::diagramTextsFont());
|
2013-02-08 22:05:15 +00:00
|
|
|
real_font_size_ = font().pointSize();
|
2020-08-20 21:58:23 +02:00
|
|
|
setFlags(QGraphicsItem::ItemIsSelectable
|
|
|
|
| QGraphicsItem::ItemSendsGeometryChanges
|
|
|
|
| QGraphicsItem::ItemIsMovable);
|
2013-02-08 22:05:15 +00:00
|
|
|
setAcceptHoverEvents(true);
|
2012-03-31 22:48:40 +00:00
|
|
|
setDefaultTextColor(Qt::black);
|
2020-08-20 21:58:23 +02:00
|
|
|
setPlainText(QObject::tr(
|
2020-10-13 21:51:34 +02:00
|
|
|
"T",
|
|
|
|
"default text when adding a text in the element editor"));
|
2020-08-13 12:01:27 +01:00
|
|
|
|
2010-07-25 15:29:58 +00:00
|
|
|
adjustItemPosition(1);
|
2012-05-27 15:18:21 +00:00
|
|
|
// adjust textfield position after line additions/deletions
|
2020-08-20 21:58:23 +02:00
|
|
|
connect(document(),
|
|
|
|
SIGNAL(blockCountChanged(int)),
|
|
|
|
this,
|
|
|
|
SLOT(adjustItemPosition(int)));
|
|
|
|
connect(document(),
|
|
|
|
SIGNAL(contentsChanged()),
|
|
|
|
this,
|
|
|
|
SLOT(adjustItemPosition()));
|
2007-06-30 17:41:07 +00:00
|
|
|
}
|
|
|
|
|
2007-12-05 21:16:01 +00:00
|
|
|
/// Destructeur
|
2020-09-07 22:03:40 +02:00
|
|
|
PartText::~PartText()
|
|
|
|
{
|
2007-06-30 17:41:07 +00:00
|
|
|
}
|
|
|
|
|
2007-12-05 21:16:01 +00:00
|
|
|
/**
|
|
|
|
Importe les proprietes d'un texte statique depuis un element XML
|
|
|
|
@param xml_element Element XML a lire
|
|
|
|
*/
|
2020-08-24 20:34:18 +02:00
|
|
|
bool PartText::fromXml(const QDomElement &xml_element)
|
2019-03-10 17:58:33 +00:00
|
|
|
{
|
2020-10-13 21:51:34 +02:00
|
|
|
int size;
|
|
|
|
QString font;
|
2019-03-10 17:58:33 +00:00
|
|
|
|
2020-10-13 21:51:34 +02:00
|
|
|
if (propertyInteger(xml_element, "size", &size) != PropertyFlags::NotFound)
|
2019-03-10 17:58:33 +00:00
|
|
|
{
|
2020-10-13 21:51:34 +02:00
|
|
|
if (size < 1) {
|
|
|
|
size = 20;
|
2019-03-10 17:58:33 +00:00
|
|
|
}
|
|
|
|
QFont font_ = this->font();
|
2020-10-13 21:51:34 +02:00
|
|
|
font_.setPointSize(size);
|
2019-03-10 17:58:33 +00:00
|
|
|
setFont(font_);
|
|
|
|
}
|
2020-10-13 21:51:34 +02:00
|
|
|
else if (propertyString(xml_element, "font", &font) != PropertyFlags::NotFound)
|
2019-03-10 17:58:33 +00:00
|
|
|
{
|
|
|
|
QFont font_;
|
2020-10-13 21:51:34 +02:00
|
|
|
font_.fromString(font);
|
2019-03-10 17:58:33 +00:00
|
|
|
setFont(font_);
|
2020-10-13 21:51:34 +02:00
|
|
|
} else {
|
|
|
|
return false;
|
2010-07-25 15:29:58 +00:00
|
|
|
}
|
2020-08-13 12:01:27 +01:00
|
|
|
|
2020-10-13 21:51:34 +02:00
|
|
|
QColor color;
|
|
|
|
QString text;
|
|
|
|
propertyColor(xml_element, "color", &color);
|
|
|
|
setDefaultTextColor(color);
|
|
|
|
|
|
|
|
|
|
|
|
propertyString(xml_element, "text", &text);
|
|
|
|
setPlainText(text);
|
|
|
|
|
|
|
|
double x=0, y=0, rot=0;
|
|
|
|
if (propertyDouble(xml_element, "x", &x) == PropertyFlags::NoValidConversion ||
|
|
|
|
propertyDouble(xml_element, "y", &y) == PropertyFlags::NoValidConversion)
|
|
|
|
return false;
|
|
|
|
setPos(x, y);
|
|
|
|
|
|
|
|
if (propertyDouble(xml_element, "rotation", &rot) == PropertyFlags::NoValidConversion)
|
|
|
|
return false;
|
|
|
|
setRotation(rot);
|
|
|
|
|
|
|
|
return true;
|
2007-06-30 17:41:07 +00:00
|
|
|
}
|
|
|
|
|
2007-12-05 21:16:01 +00:00
|
|
|
/**
|
|
|
|
Exporte le texte statique en XML
|
|
|
|
@param xml_document Document XML a utiliser pour creer l'element XML
|
|
|
|
@return un element XML decrivant le texte statique
|
|
|
|
*/
|
2020-08-24 20:34:18 +02:00
|
|
|
QDomElement PartText::toXml(QDomDocument &xml_document) const
|
2020-09-07 22:03:40 +02:00
|
|
|
{
|
2019-03-10 17:58:33 +00:00
|
|
|
QDomElement xml_element = xml_document.createElement(xmlName());
|
|
|
|
|
2020-10-13 21:51:34 +02:00
|
|
|
xml_element.appendChild(createXmlProperty(xml_document, "x", pos().x()));
|
|
|
|
xml_element.appendChild(createXmlProperty(xml_document, "y", pos().y()));
|
|
|
|
xml_element.appendChild(createXmlProperty(xml_document, "text", toPlainText()));
|
|
|
|
xml_element.appendChild(createXmlProperty(xml_document, "font", font().toString()));
|
|
|
|
xml_element.appendChild(createXmlProperty(xml_document, "rotation", rotation()));
|
|
|
|
xml_element.appendChild(createXmlProperty(xml_document, "color", defaultTextColor().name()));
|
2019-03-10 17:58:33 +00:00
|
|
|
|
2007-06-30 17:41:07 +00:00
|
|
|
return(xml_element);
|
|
|
|
}
|
|
|
|
|
2020-08-25 20:14:38 +02:00
|
|
|
bool PartText::valideXml(QDomElement& element) {
|
|
|
|
|
2020-10-13 21:51:34 +02:00
|
|
|
if (propertyInteger(element, "size") == PropertyFlags::NotFound ||
|
|
|
|
propertyString(element, "font") == PropertyFlags::NotFound) {
|
|
|
|
return false;
|
|
|
|
}
|
2020-08-25 20:14:38 +02:00
|
|
|
|
2020-10-13 21:51:34 +02:00
|
|
|
if (propertyString(element, "color") == PropertyFlags::NoValidConversion)
|
|
|
|
return false;
|
2020-08-25 20:14:38 +02:00
|
|
|
|
|
|
|
|
2020-10-13 21:51:34 +02:00
|
|
|
if (propertyString(element, "text"))
|
|
|
|
return false;
|
2020-08-25 20:14:38 +02:00
|
|
|
|
2020-10-13 21:51:34 +02:00
|
|
|
if (propertyDouble(element, "x") == PropertyFlags::NoValidConversion ||
|
|
|
|
propertyDouble(element, "y") == PropertyFlags::NoValidConversion)
|
|
|
|
return false;
|
2020-08-25 20:14:38 +02:00
|
|
|
|
2020-10-13 21:51:34 +02:00
|
|
|
if (propertyDouble(element, "rotation", 0) == PropertyFlags::NoValidConversion)
|
|
|
|
return false;
|
2020-08-25 20:14:38 +02:00
|
|
|
|
2020-10-13 21:51:34 +02:00
|
|
|
return true;
|
2020-08-25 20:14:38 +02:00
|
|
|
}
|
|
|
|
|
2007-06-30 17:41:07 +00:00
|
|
|
/**
|
|
|
|
@return Les coordonnees du point situe en bas a gauche du texte.
|
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
QPointF PartText::margin() const
|
|
|
|
{
|
2007-06-30 17:41:07 +00:00
|
|
|
QFont used_font = font();
|
|
|
|
QFontMetrics qfm(used_font);
|
2009-08-31 21:26:08 +00:00
|
|
|
qreal document_margin = document() -> documentMargin();
|
2020-08-13 12:01:27 +01:00
|
|
|
|
2007-06-30 17:41:07 +00:00
|
|
|
QPointF margin(
|
2009-08-25 23:31:31 +00:00
|
|
|
// marge autour du texte
|
2009-08-31 21:26:08 +00:00
|
|
|
document_margin,
|
2009-08-25 23:31:31 +00:00
|
|
|
// marge au-dessus du texte + distance entre le plafond du texte et la baseline
|
2009-08-31 21:26:08 +00:00
|
|
|
document_margin + qfm.ascent()
|
2007-06-30 17:41:07 +00:00
|
|
|
);
|
|
|
|
return(margin);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-20 21:57:35 +02:00
|
|
|
@brief PartText::focusInEvent
|
|
|
|
@param e : The QFocusEvent object describing the focus gain.
|
2013-02-08 22:05:15 +00:00
|
|
|
Start text edition when the item gains focus.
|
2020-08-20 21:57:35 +02:00
|
|
|
@see QGraphicsItem::focusInEvent(QFocusEvent *)
|
2013-02-08 22:05:15 +00:00
|
|
|
*/
|
|
|
|
void PartText::focusInEvent(QFocusEvent *e) {
|
|
|
|
startEdition();
|
|
|
|
QGraphicsTextItem::focusInEvent(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-20 21:57:35 +02:00
|
|
|
@brief PartText::focusOutEvent
|
|
|
|
@param e : The QFocusEvent object describing the focus loss.
|
2013-02-08 22:05:15 +00:00
|
|
|
End text edition when the item loses focus.
|
2020-08-20 21:57:35 +02:00
|
|
|
@see QGraphicsItem::focusOutEvent(QFocusEvent *)
|
2007-06-30 17:41:07 +00:00
|
|
|
*/
|
|
|
|
void PartText::focusOutEvent(QFocusEvent *e) {
|
|
|
|
QGraphicsTextItem::focusOutEvent(e);
|
2013-02-08 22:05:15 +00:00
|
|
|
endEdition();
|
2007-06-30 17:41:07 +00:00
|
|
|
}
|
|
|
|
|
2013-02-08 22:05:22 +00:00
|
|
|
/**
|
2020-08-20 21:57:35 +02:00
|
|
|
@brief PartText::keyPressEvent
|
|
|
|
Used to handle the escape key when the event is delivered to the field,
|
|
|
|
not to the decorator.
|
|
|
|
@param event
|
|
|
|
@see QGraphicsTextItem::keyPressEvent()
|
2013-02-08 22:05:22 +00:00
|
|
|
*/
|
|
|
|
void PartText::keyPressEvent(QKeyEvent *event) {
|
|
|
|
if (event -> key() == Qt::Key_Escape) {
|
|
|
|
endEdition();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
QGraphicsTextItem::keyPressEvent(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-30 17:41:07 +00:00
|
|
|
/**
|
|
|
|
Permet a l'element texte de devenir editable lorsqu'on double-clique dessus
|
|
|
|
@param e Le QGraphicsSceneMouseEvent qui decrit le double-clic
|
|
|
|
*/
|
|
|
|
void PartText::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *e) {
|
|
|
|
QGraphicsTextItem::mouseDoubleClickEvent(e);
|
2013-02-08 22:05:15 +00:00
|
|
|
if (e -> button() == Qt::LeftButton) {
|
|
|
|
setEditable(true);
|
|
|
|
}
|
2007-06-30 17:41:07 +00:00
|
|
|
}
|
|
|
|
|
2007-12-05 21:16:01 +00:00
|
|
|
/**
|
|
|
|
Gere les changements intervenant sur cette partie
|
|
|
|
@param change Type de changement
|
|
|
|
@param value Valeur numerique relative au changement
|
|
|
|
*/
|
2007-06-30 17:41:07 +00:00
|
|
|
QVariant PartText::itemChange(GraphicsItemChange change, const QVariant &value) {
|
2020-08-13 12:01:27 +01:00
|
|
|
if (change == QGraphicsItem::ItemPositionHasChanged ||
|
|
|
|
change == QGraphicsItem::ItemSceneHasChanged ||
|
|
|
|
change == QGraphicsItem::ItemSelectedHasChanged) {
|
|
|
|
updateCurrentPartEditor();
|
2007-06-30 17:41:07 +00:00
|
|
|
}
|
|
|
|
return(QGraphicsTextItem::itemChange(change, value));
|
|
|
|
}
|
|
|
|
|
2007-12-05 21:16:01 +00:00
|
|
|
/**
|
|
|
|
@return le rectangle delimitant cette partie.
|
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
QRectF PartText::boundingRect() const
|
|
|
|
{
|
2007-06-30 17:41:07 +00:00
|
|
|
QRectF r = QGraphicsTextItem::boundingRect();
|
2009-08-25 23:31:31 +00:00
|
|
|
r.adjust(0.0, -1.1, 0.0, 0.0);
|
2007-06-30 17:41:07 +00:00
|
|
|
return(r);
|
|
|
|
}
|
2007-12-15 21:57:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
@return true si cette partie n'est pas pertinente et ne merite pas d'etre
|
|
|
|
conservee / enregistree.
|
|
|
|
Un texte statique n'est pas pertinent lorsque son texte est vide.
|
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
bool PartText::isUseless() const
|
|
|
|
{
|
2007-12-15 21:57:00 +00:00
|
|
|
return(toPlainText().isEmpty());
|
|
|
|
}
|
2009-08-25 23:25:28 +00:00
|
|
|
|
2013-02-11 18:35:13 +00:00
|
|
|
/**
|
|
|
|
@return the minimum, margin-less rectangle this part can fit into, in scene
|
|
|
|
coordinates. It is different from boundingRect() because it is not supposed
|
|
|
|
to imply any margin, and it is different from shape because it is a regular
|
|
|
|
rectangle, not a complex shape.
|
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
QRectF PartText::sceneGeometricRect() const
|
|
|
|
{
|
2013-02-11 18:35:13 +00:00
|
|
|
return(sceneBoundingRect());
|
|
|
|
}
|
|
|
|
|
2013-02-08 22:05:12 +00:00
|
|
|
/**
|
|
|
|
Start the user-induced transformation, provided this primitive is contained
|
|
|
|
within the \a rect bounding rectangle.
|
|
|
|
*/
|
|
|
|
void PartText::startUserTransformation(const QRectF &rect) {
|
|
|
|
Q_UNUSED(rect)
|
|
|
|
saved_point_ = pos(); // scene coordinates, no need to mapFromScene()
|
2013-02-08 22:05:15 +00:00
|
|
|
saved_font_size_ = real_font_size_;
|
2013-02-08 22:05:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Handle the user-induced transformation from \a initial_selection_rect to \a new_selection_rect
|
|
|
|
*/
|
|
|
|
void PartText::handleUserTransformation(const QRectF &initial_selection_rect, const QRectF &new_selection_rect) {
|
|
|
|
// let's try the naive approach
|
|
|
|
QPointF new_pos = mapPoints(initial_selection_rect, new_selection_rect, QList<QPointF>() << saved_point_).first();
|
|
|
|
setPos(new_pos);
|
2020-08-13 12:01:27 +01:00
|
|
|
|
2013-02-08 22:05:15 +00:00
|
|
|
// adjust the font size following the vertical scale factor
|
2013-02-08 22:05:12 +00:00
|
|
|
qreal sy = new_selection_rect.height() / initial_selection_rect.height();
|
2013-02-08 22:05:15 +00:00
|
|
|
qreal new_font_size = saved_font_size_ * sy;
|
|
|
|
setProperty("real_size", qMax(1, qRound(new_font_size)));
|
2013-02-08 22:05:12 +00:00
|
|
|
}
|
|
|
|
|
2020-08-13 12:01:27 +01:00
|
|
|
void PartText::setDefaultTextColor(const QColor &color) {
|
|
|
|
if (color != this -> defaultTextColor()) {
|
2019-03-10 17:58:33 +00:00
|
|
|
QGraphicsTextItem::setDefaultTextColor(color);
|
|
|
|
emit colorChanged(color);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-13 12:01:27 +01:00
|
|
|
void PartText::setPlainText(const QString &text) {
|
|
|
|
if (text != this -> toPlainText()) {
|
2019-03-10 17:58:33 +00:00
|
|
|
QGraphicsTextItem::setPlainText(text);
|
|
|
|
emit plainTextChanged(text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-13 12:01:27 +01:00
|
|
|
void PartText::setFont(const QFont &font) {
|
|
|
|
if (font != this -> font()) {
|
2019-03-10 17:58:33 +00:00
|
|
|
QGraphicsTextItem::setFont(font);
|
|
|
|
emit fontChanged(font);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-13 12:01:27 +01:00
|
|
|
void PartText::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
|
|
|
|
if((event -> buttons() & Qt::LeftButton) && (flags() & QGraphicsItem::ItemIsMovable)) {
|
|
|
|
QPointF pos = event -> scenePos() + (m_origine_pos - event -> buttonDownScenePos(Qt::LeftButton));
|
|
|
|
event -> modifiers() == Qt::ControlModifier ? setPos(pos) : setPos(elementScene() -> snapToGrid(pos));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
QGraphicsObject::mouseMoveEvent(event);
|
|
|
|
}
|
2013-02-08 22:05:15 +00:00
|
|
|
}
|
|
|
|
|
2020-08-13 12:01:27 +01:00
|
|
|
void PartText::mousePressEvent(QGraphicsSceneMouseEvent *event) {
|
|
|
|
if(event -> button() == Qt::LeftButton)
|
|
|
|
m_origine_pos = this -> pos();
|
2013-02-08 22:05:15 +00:00
|
|
|
|
2020-08-13 12:01:27 +01:00
|
|
|
QGraphicsObject::mousePressEvent(event);
|
2013-02-08 22:05:15 +00:00
|
|
|
}
|
|
|
|
|
2020-08-13 12:01:27 +01:00
|
|
|
void PartText::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
|
|
|
|
if((event -> button() & Qt::LeftButton) &&
|
|
|
|
(flags() & QGraphicsItem::ItemIsMovable) &&
|
|
|
|
m_origine_pos != pos())
|
|
|
|
{
|
|
|
|
QPropertyUndoCommand *undo = new QPropertyUndoCommand(this, "pos", QVariant(m_origine_pos), QVariant(pos()));
|
|
|
|
undo -> setText(tr("Déplacer un texte"));
|
|
|
|
undo -> enableAnimation();
|
|
|
|
elementScene() -> undoStack().push(undo);
|
|
|
|
}
|
|
|
|
|
|
|
|
QGraphicsObject::mouseReleaseEvent(event);
|
2013-02-08 22:05:15 +00:00
|
|
|
}
|
|
|
|
|
2010-01-17 16:09:46 +00:00
|
|
|
/**
|
|
|
|
Cette methode s'assure que la position du champ de texte est coherente
|
|
|
|
en repositionnant son origine (c-a-d le milieu du bord gauche du champ de
|
|
|
|
texte) a la position originale. Cela est notamment utile lorsque le champ
|
|
|
|
de texte est agrandi ou retreci verticalement (ajout ou retrait de lignes).
|
|
|
|
@param new_block_count Nombre de blocs dans le PartText
|
|
|
|
*/
|
|
|
|
void PartText::adjustItemPosition(int new_block_count) {
|
|
|
|
Q_UNUSED(new_block_count);
|
2010-07-25 15:29:58 +00:00
|
|
|
QPointF origin_offset = margin();
|
2020-08-13 12:01:27 +01:00
|
|
|
|
2010-07-25 15:29:58 +00:00
|
|
|
QTransform base_translation;
|
|
|
|
base_translation.translate(-origin_offset.x(), -origin_offset.y());
|
|
|
|
setTransform(base_translation, false);
|
|
|
|
setTransformOriginPoint(origin_offset);
|
2010-01-17 16:09:46 +00:00
|
|
|
}
|
|
|
|
|
2013-02-08 22:05:15 +00:00
|
|
|
/**
|
|
|
|
@param editable Whether this text item should be interactively editable.
|
|
|
|
*/
|
|
|
|
void PartText::setEditable(bool editable) {
|
|
|
|
if (editable) {
|
|
|
|
setFlag(QGraphicsItem::ItemIsFocusable, true);
|
|
|
|
setTextInteractionFlags(Qt::TextEditorInteraction);
|
|
|
|
setFocus(Qt::MouseFocusReason);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
setTextInteractionFlags(Qt::NoTextInteraction);
|
|
|
|
setFlag(QGraphicsItem::ItemIsFocusable, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Start text edition by storing the former value of the text.
|
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
void PartText::startEdition()
|
|
|
|
{
|
2013-02-08 22:05:15 +00:00
|
|
|
// !previous_text.isNull() means the text is being edited
|
|
|
|
previous_text = toPlainText();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
End text edition, potentially generating a ChangePartCommand if the text
|
|
|
|
has changed.
|
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
void PartText::endEdition()
|
|
|
|
{
|
2020-08-13 12:01:27 +01:00
|
|
|
if (!previous_text.isNull()) {
|
2015-07-24 11:34:45 +00:00
|
|
|
// the text was being edited
|
2013-02-08 22:05:15 +00:00
|
|
|
QString new_text = toPlainText();
|
2020-08-13 12:01:27 +01:00
|
|
|
if (previous_text != new_text) {
|
2015-07-24 11:34:45 +00:00
|
|
|
QPropertyUndoCommand *undo = new QPropertyUndoCommand(this, "text", previous_text, new_text);
|
2020-08-13 12:01:27 +01:00
|
|
|
undo -> setText(tr("Modifier un champ texte"));
|
2015-07-24 11:34:45 +00:00
|
|
|
undoStack().push(undo);
|
2013-02-08 22:05:15 +00:00
|
|
|
previous_text = QString();
|
|
|
|
}
|
|
|
|
}
|
2015-07-24 11:34:45 +00:00
|
|
|
|
2013-02-08 22:05:15 +00:00
|
|
|
// deselectionne le texte
|
|
|
|
QTextCursor qtc = textCursor();
|
|
|
|
qtc.clearSelection();
|
|
|
|
setTextCursor(qtc);
|
2015-07-24 11:34:45 +00:00
|
|
|
|
2013-02-08 22:05:15 +00:00
|
|
|
setEditable(false);
|
2009-08-25 23:25:28 +00:00
|
|
|
}
|