mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 12:40:35 +01:00
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:
@@ -1068,14 +1068,9 @@ void Diagram::addItem(QGraphicsItem *item)
|
||||
conductor->terminal1->addConductor(conductor);
|
||||
conductor->terminal2->addConductor(conductor);
|
||||
conductor->calculateTextItemPosition();
|
||||
}
|
||||
break;
|
||||
|
||||
case IndependentTextItem::Type:
|
||||
{
|
||||
const IndependentTextItem *text = static_cast<const IndependentTextItem *>(item);
|
||||
connect(text, &IndependentTextItem::diagramTextChanged, this, &Diagram::diagramTextChanged);
|
||||
}
|
||||
default: {break;}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1095,21 +1090,16 @@ void Diagram::removeItem(QGraphicsItem *item)
|
||||
{
|
||||
Element *elmt = static_cast<Element*>(item);
|
||||
elmt->unlinkAllElements();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Conductor::Type:
|
||||
{
|
||||
Conductor *conductor = static_cast<Conductor *>(item);
|
||||
conductor->terminal1->removeConductor(conductor);
|
||||
conductor->terminal2->removeConductor(conductor);
|
||||
}
|
||||
break;
|
||||
|
||||
case IndependentTextItem::Type:
|
||||
{
|
||||
const IndependentTextItem *text = static_cast<const IndependentTextItem *>(item);
|
||||
disconnect(text, &IndependentTextItem::diagramTextChanged, this, &Diagram::diagramTextChanged);
|
||||
}
|
||||
default: {break;}
|
||||
}
|
||||
|
||||
QGraphicsScene::removeItem(item);
|
||||
@@ -1119,17 +1109,6 @@ void Diagram::titleChanged(const QString &title) {
|
||||
emit(diagramTitleChanged(this, title));
|
||||
}
|
||||
|
||||
/**
|
||||
Gere le fait qu'un texte du schema ait ete modifie
|
||||
@param text_item Texte modifie
|
||||
@param old_text Ancien texte
|
||||
@param new_text Nouveau texte
|
||||
*/
|
||||
void Diagram::diagramTextChanged(DiagramTextItem *text_item, const QString &old_text, const QString &new_text) {
|
||||
if (!text_item) return;
|
||||
undoStack().push(new ChangeDiagramTextCommand(text_item, old_text, new_text));
|
||||
}
|
||||
|
||||
/**
|
||||
This slot may be used to inform the diagram object that the given title
|
||||
block template has changed. The diagram will thus flush its title
|
||||
|
||||
@@ -216,7 +216,6 @@ class Diagram : public QGraphicsScene
|
||||
public slots:
|
||||
void adjustSceneRect ();
|
||||
void titleChanged(const QString &);
|
||||
void diagramTextChanged(DiagramTextItem *, const QString &, const QString &);
|
||||
void titleBlockTemplateChanged(const QString &);
|
||||
void titleBlockTemplateRemoved(const QString &, const QString & = QString());
|
||||
void setTitleBlockTemplate(const QString &);
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
@@ -79,6 +80,10 @@ class DiagramTextItem : public QGraphicsTextItem
|
||||
|
||||
QRectF frameRect() const;
|
||||
|
||||
void setHtml(const QString &text);
|
||||
void setPlainText(const QString &text);
|
||||
bool isHtml() const;
|
||||
|
||||
protected:
|
||||
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override;
|
||||
void focusInEvent(QFocusEvent *) 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;
|
||||
|
||||
@@ -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()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
public:
|
||||
IndependentTextItem();
|
||||
IndependentTextItem(const QString &);
|
||||
~IndependentTextItem() override;
|
||||
|
||||
// attributes
|
||||
// constructors, destructor
|
||||
public:
|
||||
enum { Type = UserType + 1005 };
|
||||
IndependentTextItem();
|
||||
IndependentTextItem(const QString &);
|
||||
~IndependentTextItem() override;
|
||||
|
||||
// methods
|
||||
// attributes
|
||||
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;
|
||||
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;
|
||||
|
||||
private:
|
||||
QPointF mouse_to_origin_movement_;
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2006-2019 The QElectroTech Team
|
||||
Copyright 2006-2017 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech is free software: you can redistribute it and/or modify
|
||||
@@ -25,6 +25,8 @@
|
||||
#include "shapegraphicsitempropertieswidget.h"
|
||||
#include "dynamicelementtextitem.h"
|
||||
#include "elementtextitemgroup.h"
|
||||
#include "independenttextitem.h"
|
||||
#include "inditextpropertieswidget.h"
|
||||
|
||||
/**
|
||||
* @brief DiagramPropertiesEditorDockWidget::DiagramPropertiesEditorDockWidget
|
||||
@@ -91,7 +93,7 @@ void DiagramPropertiesEditorDockWidget::selectionChanged()
|
||||
|
||||
switch (type_)
|
||||
{
|
||||
case Element::Type:
|
||||
case Element::Type: //1000
|
||||
{
|
||||
//We already edit an element, just update the editor with a new element
|
||||
if (m_edited_qgi_type == type_)
|
||||
@@ -105,14 +107,27 @@ void DiagramPropertiesEditorDockWidget::selectionChanged()
|
||||
addEditor(new ElementPropertiesWidget(static_cast<Element*>(item), this));
|
||||
break;
|
||||
}
|
||||
case DiagramImageItem::Type:
|
||||
case IndependentTextItem::Type: //1005
|
||||
{
|
||||
if (m_edited_qgi_type == type_)
|
||||
{
|
||||
static_cast<IndiTextPropertiesWidget*>(editors().first())->setText(static_cast<IndependentTextItem*>(item));
|
||||
return;
|
||||
}
|
||||
|
||||
clear();
|
||||
m_edited_qgi_type = type_;
|
||||
addEditor(new IndiTextPropertiesWidget(static_cast<IndependentTextItem*>(item), this));
|
||||
break;
|
||||
}
|
||||
case DiagramImageItem::Type: //1007
|
||||
{
|
||||
clear();
|
||||
m_edited_qgi_type = type_;
|
||||
addEditor(new ImagePropertiesWidget(static_cast<DiagramImageItem*>(item), this));
|
||||
break;
|
||||
}
|
||||
case QetShapeItem::Type:
|
||||
case QetShapeItem::Type: //1008
|
||||
{
|
||||
if (m_edited_qgi_type == type_)
|
||||
{
|
||||
@@ -125,7 +140,7 @@ void DiagramPropertiesEditorDockWidget::selectionChanged()
|
||||
addEditor(new ShapeGraphicsItemPropertiesWidget(static_cast<QetShapeItem*>(item), this));
|
||||
break;
|
||||
}
|
||||
case DynamicElementTextItem::Type:
|
||||
case DynamicElementTextItem::Type: //1010
|
||||
{
|
||||
DynamicElementTextItem *deti = static_cast<DynamicElementTextItem *>(item);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2006-2019 The QElectroTech Team
|
||||
Copyright 2006-2017 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech is free software: you can redistribute it and/or modify
|
||||
|
||||
228
sources/ui/inditextpropertieswidget.cpp
Normal file
228
sources/ui/inditextpropertieswidget.cpp
Normal file
@@ -0,0 +1,228 @@
|
||||
/*
|
||||
Copyright 2006-2019 The QElectroTech Team
|
||||
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/>.
|
||||
*/
|
||||
#include "inditextpropertieswidget.h"
|
||||
#include "ui_inditextpropertieswidget.h"
|
||||
#include "independenttextitem.h"
|
||||
#include "QPropertyUndoCommand/qpropertyundocommand.h"
|
||||
#include "diagram.h"
|
||||
#include "diagramcommands.h"
|
||||
#include <QtGlobal>
|
||||
#include <QLineEdit>
|
||||
|
||||
/**
|
||||
* @brief IndiTextPropertiesWidget::IndiTextPropertiesWidget
|
||||
* @param text : the text to edit
|
||||
* @param parent : the parent widget of this widget
|
||||
*/
|
||||
IndiTextPropertiesWidget::IndiTextPropertiesWidget(IndependentTextItem *text, QWidget *parent) :
|
||||
PropertiesEditorWidget(parent),
|
||||
ui(new Ui::IndiTextPropertiesWidget)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
if (text) {
|
||||
setText(text);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief IndiTextPropertiesWidget::~IndiTextPropertiesWidget
|
||||
*/
|
||||
IndiTextPropertiesWidget::~IndiTextPropertiesWidget() {
|
||||
delete ui;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief IndiTextPropertiesWidget::setText
|
||||
* @param text : set @text as edited text
|
||||
*/
|
||||
void IndiTextPropertiesWidget::setText(IndependentTextItem *text)
|
||||
{
|
||||
if (m_text) {
|
||||
for (QMetaObject::Connection c : m_connect_list) {
|
||||
disconnect(c);
|
||||
}
|
||||
}
|
||||
|
||||
m_text = text;
|
||||
m_connect_list.clear();
|
||||
m_connect_list << connect(m_text.data(), &IndependentTextItem::xChanged, this, &IndiTextPropertiesWidget::updateUi);
|
||||
m_connect_list << connect(m_text.data(), &IndependentTextItem::yChanged, this, &IndiTextPropertiesWidget::updateUi);
|
||||
m_connect_list << connect(m_text.data(), &IndependentTextItem::rotationChanged, this, &IndiTextPropertiesWidget::updateUi);
|
||||
m_connect_list << connect(m_text.data(), &IndependentTextItem::fontSizeChanged, this, &IndiTextPropertiesWidget::updateUi);
|
||||
m_connect_list << connect(m_text.data(), &IndependentTextItem::textEdited, this, &IndiTextPropertiesWidget::updateUi);
|
||||
|
||||
updateUi();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief IndiTextPropertiesWidget::apply
|
||||
* Apply the current edition through a QUndoCommand pushed
|
||||
* to the undo stack of text's diagram.
|
||||
*/
|
||||
void IndiTextPropertiesWidget::apply()
|
||||
{
|
||||
if (m_text && m_text->diagram())
|
||||
{
|
||||
QUndoCommand *undo = associatedUndo();
|
||||
if (undo) {
|
||||
m_text->diagram()->undoStack().push(undo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief IndiTextPropertiesWidget::setLiveEdit
|
||||
* @param live_edit
|
||||
* @return
|
||||
*/
|
||||
bool IndiTextPropertiesWidget::setLiveEdit(bool live_edit)
|
||||
{
|
||||
if (m_live_edit == live_edit) {
|
||||
return true;
|
||||
}
|
||||
m_live_edit = live_edit;
|
||||
|
||||
if (m_live_edit) {
|
||||
setUpEditConnection();
|
||||
}
|
||||
else {
|
||||
for (QMetaObject::Connection c : m_edit_connection) {
|
||||
disconnect(c);
|
||||
}
|
||||
m_edit_connection.clear();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief IndiTextPropertiesWidget::associatedUndo
|
||||
* @return
|
||||
*/
|
||||
QUndoCommand *IndiTextPropertiesWidget::associatedUndo() const
|
||||
{
|
||||
if (m_live_edit)
|
||||
{
|
||||
QPropertyUndoCommand *undo = nullptr;
|
||||
if(ui->m_x_sb->value() != m_text->pos().x()) {
|
||||
undo = new QPropertyUndoCommand(m_text.data(), "x", QVariant(m_text->pos().x()), QVariant(ui->m_x_sb->value()));
|
||||
undo->setAnimated(true, false);
|
||||
undo->setText(tr("Déplacer un champ texte"));
|
||||
}
|
||||
if(ui->m_y_sb->value() != m_text->pos().y()) {
|
||||
undo = new QPropertyUndoCommand(m_text.data(), "y", QVariant(m_text->pos().y()), QVariant(ui->m_y_sb->value()));
|
||||
undo->setAnimated(true, false);
|
||||
undo->setText(tr("Déplacer un champ texte"));
|
||||
}
|
||||
if(ui->m_angle_sb->value() != m_text->rotation()) {
|
||||
undo = new QPropertyUndoCommand(m_text.data(), "rotation", QVariant(m_text->rotation()), QVariant(ui->m_angle_sb->value()));
|
||||
undo->setAnimated(true, false);
|
||||
undo->setText(tr("Pivoter un champ texte"));
|
||||
}
|
||||
if (ui->m_line_edit->text() != m_text->toPlainText()) {
|
||||
undo = new QPropertyUndoCommand(m_text.data(), "plainText", m_text->toPlainText(), ui->m_line_edit->text());
|
||||
undo->setText(tr("Modifier un champ texte"));
|
||||
}
|
||||
if (ui->m_size_sb->value() != m_text->fontSize()) {
|
||||
undo = new QPropertyUndoCommand(m_text.data(), "fontSize", m_text->fontSize(), ui->m_size_sb->value());
|
||||
undo->setAnimated(true, false);
|
||||
undo->setText(tr("Modifier la taille d'un champ texte"));
|
||||
}
|
||||
|
||||
return undo;
|
||||
}
|
||||
else
|
||||
{
|
||||
QUndoCommand *undo = new QUndoCommand(tr("Modifier les propriétées d'un texte"));
|
||||
if(ui->m_x_sb->value() != m_text->pos().x()) {
|
||||
new QPropertyUndoCommand(m_text.data(), "x", QVariant(m_text->pos().x()), QVariant(ui->m_x_sb->value()), undo);
|
||||
}
|
||||
if(ui->m_y_sb->value() != m_text->pos().y()) {
|
||||
new QPropertyUndoCommand(m_text.data(), "y", QVariant(m_text->pos().y()), QVariant(ui->m_y_sb->value()), undo);
|
||||
}
|
||||
if(ui->m_angle_sb->value() != m_text->rotation()) {
|
||||
new QPropertyUndoCommand(m_text.data(), "rotation", QVariant(m_text->rotation()), QVariant(ui->m_angle_sb->value()), undo);
|
||||
}
|
||||
if (ui->m_line_edit->text() != m_text->toPlainText()) {
|
||||
new ChangeDiagramTextCommand(m_text.data(), m_text->toHtml(), ui->m_line_edit->text(), undo);
|
||||
}
|
||||
if (ui->m_size_sb->value() != m_text->fontSize()) {
|
||||
new QPropertyUndoCommand(m_text.data(), "fontSize", m_text->fontSize(), ui->m_size_sb->value(), undo);
|
||||
}
|
||||
|
||||
if (undo->childCount()) {
|
||||
return undo;
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief IndiTextPropertiesWidget::setUpEditConnection
|
||||
* Disconnect the previous connection, and reconnect the connection between the editors widgets and apply function
|
||||
*/
|
||||
void IndiTextPropertiesWidget::setUpEditConnection()
|
||||
{
|
||||
for (QMetaObject::Connection c : m_edit_connection) {
|
||||
disconnect(c);
|
||||
}
|
||||
m_edit_connection.clear();
|
||||
m_edit_connection << connect(ui->m_x_sb, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &IndiTextPropertiesWidget::apply);
|
||||
m_edit_connection << connect(ui->m_y_sb, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &IndiTextPropertiesWidget::apply);
|
||||
m_edit_connection << connect(ui->m_angle_sb, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &IndiTextPropertiesWidget::apply);
|
||||
m_edit_connection << connect(ui->m_line_edit, &QLineEdit::textEdited, this, &IndiTextPropertiesWidget::apply);
|
||||
m_edit_connection << connect(ui->m_size_sb, QOverload<int>::of(&QSpinBox::valueChanged), this, &IndiTextPropertiesWidget::apply);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief IndiTextPropertiesWidget::updateUi
|
||||
*/
|
||||
void IndiTextPropertiesWidget::updateUi()
|
||||
{
|
||||
if (!m_text) {
|
||||
return;
|
||||
}
|
||||
|
||||
//Disconnect every connections of editor widgets
|
||||
//to avoid an unwanted edition (QSpinBox emit valueChanged no matter if changer by user or by program)
|
||||
for (QMetaObject::Connection c : m_edit_connection) {
|
||||
disconnect(c);
|
||||
}
|
||||
m_edit_connection.clear();
|
||||
|
||||
ui->m_x_sb->setValue(m_text->pos().x());
|
||||
ui->m_y_sb->setValue(m_text->pos().y());
|
||||
ui->m_angle_sb->setValue(m_text->rotation());
|
||||
ui->m_line_edit->setText(m_text->toPlainText());
|
||||
ui->m_size_sb->setValue(m_text->fontSize());
|
||||
|
||||
ui->m_line_edit->setDisabled(m_text->isHtml() ? true : false);
|
||||
ui->m_size_sb->setDisabled(m_text->isHtml() ? true : false);
|
||||
|
||||
//Set the connection now
|
||||
setUpEditConnection();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief IndiTextPropertiesWidget::on_m_advanced_editor_pb_clicked
|
||||
*/
|
||||
void IndiTextPropertiesWidget::on_m_advanced_editor_pb_clicked() {
|
||||
if (m_text) {
|
||||
m_text->edit();
|
||||
}
|
||||
}
|
||||
60
sources/ui/inditextpropertieswidget.h
Normal file
60
sources/ui/inditextpropertieswidget.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
Copyright 2006-2019 The QElectroTech Team
|
||||
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/>.
|
||||
*/
|
||||
#ifndef INDITEXTPROPERTIESWIDGET_H
|
||||
#define INDITEXTPROPERTIESWIDGET_H
|
||||
|
||||
#include "PropertiesEditor/propertieseditorwidget.h"
|
||||
#include <QPointer>
|
||||
class IndependentTextItem;
|
||||
|
||||
namespace Ui {
|
||||
class IndiTextPropertiesWidget;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief The IndiTextPropertiesWidget class
|
||||
* This widget is used to edit the properties of an independent text item
|
||||
*/
|
||||
class IndiTextPropertiesWidget : public PropertiesEditorWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
IndiTextPropertiesWidget(IndependentTextItem *text = nullptr, QWidget *parent = nullptr);
|
||||
~IndiTextPropertiesWidget() override;
|
||||
void setText (IndependentTextItem *text);
|
||||
|
||||
void apply() override;
|
||||
bool setLiveEdit(bool live_edit) override;
|
||||
QUndoCommand* associatedUndo() const override;
|
||||
|
||||
private slots:
|
||||
void on_m_advanced_editor_pb_clicked();
|
||||
|
||||
private:
|
||||
void setUpEditConnection();
|
||||
void updateUi() override;
|
||||
|
||||
private:
|
||||
Ui::IndiTextPropertiesWidget *ui;
|
||||
QPointer <IndependentTextItem> m_text;
|
||||
QList <QMetaObject::Connection> m_connect_list,
|
||||
m_edit_connection;
|
||||
};
|
||||
|
||||
#endif // INDITEXTPROPERTIESWIDGET_H
|
||||
140
sources/ui/inditextpropertieswidget.ui
Normal file
140
sources/ui/inditextpropertieswidget.ui
Normal file
@@ -0,0 +1,140 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>IndiTextPropertiesWidget</class>
|
||||
<widget class="QWidget" name="IndiTextPropertiesWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>299</width>
|
||||
<height>237</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="2" column="1">
|
||||
<widget class="QDoubleSpinBox" name="m_x_sb">
|
||||
<property name="suffix">
|
||||
<string>px</string>
|
||||
</property>
|
||||
<property name="decimals">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>10000.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="4">
|
||||
<widget class="QPushButton" name="m_advanced_editor_pb">
|
||||
<property name="text">
|
||||
<string>Éditeur avancé</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Angle :</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QDoubleSpinBox" name="m_angle_sb">
|
||||
<property name="wrapping">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="suffix">
|
||||
<string>°</string>
|
||||
</property>
|
||||
<property name="decimals">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>359.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="4">
|
||||
<widget class="QLineEdit" name="m_line_edit">
|
||||
<property name="placeholderText">
|
||||
<string>Texte</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="2" column="3">
|
||||
<widget class="QDoubleSpinBox" name="m_y_sb">
|
||||
<property name="suffix">
|
||||
<string>px</string>
|
||||
</property>
|
||||
<property name="decimals">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>10000.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>X :</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Y :</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="3">
|
||||
<widget class="QSpinBox" name="m_size_sb">
|
||||
<property name="minimum">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>50</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="2">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Taille :</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user