Diagram editor : add a new widget in the "curent selection dock" for edit the independent text. WIP

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5737 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2019-02-19 16:42:07 +00:00
parent 2300314bf5
commit 33d757e0d8
12 changed files with 533 additions and 74 deletions

View File

@@ -119,7 +119,7 @@ Conductor::Conductor(Terminal *p1, Terminal* p2) :
// Add the text field
m_text_item = new ConductorTextItem(m_properties.text, this);
connect(m_text_item, &ConductorTextItem::diagramTextChanged, this, &Conductor::displayedTextChanged);
connect(m_text_item, &ConductorTextItem::textEdited, this, &Conductor::displayedTextChanged);
//Set the default conductor properties.
if (p1->diagram())

View File

@@ -1,5 +1,5 @@
/*
Copyright 2006-2013 QElectroTech Team
Copyright 2006-2019 QElectroTech Team
This file is part of QElectroTech.
QElectroTech is free software: you can redistribute it and/or modify
@@ -210,6 +210,22 @@ QRectF DiagramTextItem::frameRect() const
return QRectF(pos, size);
}
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;
}
bool DiagramTextItem::isHtml() const {
return m_is_html;
}
/**
* @brief DiagramTextItem::paint
* Draw this text field. This method draw the text by calling QGraphicsTextItem::paint.
@@ -267,8 +283,6 @@ void DiagramTextItem::focusOutEvent(QFocusEvent *event)
{
QGraphicsTextItem::focusOutEvent(event);
if (toHtml() != m_previous_html_text)
emit(diagramTextChanged(this, m_previous_html_text, toHtml()));
if(toPlainText() != m_previous_text)
emit textEdited(m_previous_text, toPlainText());
@@ -303,13 +317,14 @@ void DiagramTextItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) {
* @brief DiagramTextItem::mousePressEvent
* @param event
*/
void DiagramTextItem::mousePressEvent (QGraphicsSceneMouseEvent *event) {
m_first_move = true;
if (event -> modifiers() & Qt::ControlModifier) {
setSelected(!isSelected());
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();
}
//Save the pos of item at the beggining of the movement
m_mouse_to_origin_movement = pos() - event->scenePos();
QGraphicsTextItem::mousePressEvent(event);
}
@@ -348,13 +363,25 @@ void DiagramTextItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
* @brief DiagramTextItem::mouseReleaseEvent
* @param event
*/
void DiagramTextItem::mouseReleaseEvent (QGraphicsSceneMouseEvent *event) {
//Signal to diagram movement is finish
if (diagram())
void DiagramTextItem::mouseReleaseEvent (QGraphicsSceneMouseEvent *event)
{
//Signal to diagram movement is finish
if (diagram() && (event->button() == Qt::LeftButton))
{
diagram()->elementsMover().endMovement();
if (!(event -> modifiers() & Qt::ControlModifier))
event->accept();
if (event->buttonDownScenePos(Qt::LeftButton) != event->scenePos()) {
return;
}
}
if (event->modifiers() & Qt::ControlModifier && (event->button() == Qt::LeftButton))
{
setSelected(!isSelected());
event->accept();
}
else {
QGraphicsTextItem::mouseReleaseEvent(event);
}
}
/**
@@ -459,7 +486,6 @@ void DiagramTextItem::hoverEnterEvent(QGraphicsSceneHoverEvent *e) {
*/
void DiagramTextItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *e) {
Q_UNUSED(e);
//qDebug() << "Leave mouse over";
m_mouse_hover = false;
update();
}

View File

@@ -36,12 +36,13 @@ class DiagramTextItem : public QGraphicsTextItem
Q_PROPERTY(int fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged)
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged)
Q_PROPERTY(QString plainText READ toPlainText WRITE setPlainText)
signals:
void fontSizeChanged(int size);
void colorChanged(QColor color);
void alignmentChanged(Qt::Alignment alignment);
void diagramTextChanged(DiagramTextItem *, const QString &, const QString &);
void textEdited(const QString &old_str, const QString &new_str);
public:
@@ -78,6 +79,10 @@ class DiagramTextItem : public QGraphicsTextItem
bool m_block_alignment = false;
QRectF frameRect() const;
void setHtml(const QString &text);
void setPlainText(const QString &text);
bool isHtml() const;
protected:
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override;
@@ -101,7 +106,8 @@ class DiagramTextItem : public QGraphicsTextItem
protected:
bool m_mouse_hover = false,
m_first_move = true,
m_no_editable;
m_no_editable,
m_is_html = false;
QString m_previous_html_text,
m_previous_text;

View File

@@ -17,6 +17,8 @@
*/
#include "independenttextitem.h"
#include "qet.h"
#include "diagram.h"
#include "diagramcommands.h"
#include <QDomElement>
/**
@@ -56,13 +58,21 @@ void IndependentTextItem::fromXml(const QDomElement &e) {
@param document Le document XML a utiliser
@return L'element XML representant ce champ de texte
*/
QDomElement IndependentTextItem::toXml(QDomDocument &document) const {
QDomElement IndependentTextItem::toXml(QDomDocument &document) const
{
QDomElement result = document.createElement("input");
result.setAttribute("x", QString("%1").arg(pos().x()));
result.setAttribute("y", QString("%1").arg(pos().y()));
result.setAttribute("text", toHtml());
if (rotation()) {
result.setAttribute("rotation", QString::number(QET::correctAngle(rotation())));
}
result.setAttribute("rotation", QString::number(QET::correctAngle(rotation())));
return(result);
}
void IndependentTextItem::focusOutEvent(QFocusEvent *event)
{
DiagramTextItem::focusOutEvent(event);
if (diagram() && (m_previous_html_text != this->toHtml())) {
diagram()->undoStack().push(new ChangeDiagramTextCommand(this, m_previous_html_text, this->toHtml()));
}
}

View File

@@ -24,30 +24,26 @@
This class represents an independent text field on a particular diagram.
It may be moved, edited, and rotated.
*/
class IndependentTextItem : public DiagramTextItem {
class IndependentTextItem : public DiagramTextItem
{
Q_OBJECT
// constructors, destructor
// constructors, destructor
public:
IndependentTextItem();
IndependentTextItem(const QString &);
~IndependentTextItem() override;
IndependentTextItem();
IndependentTextItem(const QString &);
~IndependentTextItem() override;
// attributes
// attributes
public:
enum { Type = UserType + 1005 };
// methods
public:
/**
Enable the use of qgraphicsitem_cast to safely cast a QGraphicsItem into an
IndependentTextItem.
@return le type de QGraphicsItem
*/
int type() const override { return Type; }
void fromXml(const QDomElement &) override;
QDomElement toXml(QDomDocument &) const override;
private:
QPointF mouse_to_origin_movement_;
enum { Type = UserType + 1005 };
int type() const override { return Type; }
void fromXml(const QDomElement &) override;
QDomElement toXml(QDomDocument &) const override;
protected:
void focusOutEvent(QFocusEvent *event) override;
};
#endif