mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-21 16:50:53 +01:00
part text and part text field : use QPropertyUndoCommand instead of ChangePartCommand
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4070 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -17,10 +17,10 @@
|
|||||||
*/
|
*/
|
||||||
#include "parttext.h"
|
#include "parttext.h"
|
||||||
#include "texteditor.h"
|
#include "texteditor.h"
|
||||||
#include "editorcommands.h"
|
|
||||||
#include "elementprimitivedecorator.h"
|
#include "elementprimitivedecorator.h"
|
||||||
#include "elementscene.h"
|
#include "elementscene.h"
|
||||||
#include "qetapp.h"
|
#include "qetapp.h"
|
||||||
|
#include "QPropertyUndoCommand/qpropertyundocommand.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Constructeur
|
Constructeur
|
||||||
@@ -35,16 +35,11 @@ PartText::PartText(QETElementEditor *editor, QGraphicsItem *parent, ElementScene
|
|||||||
decorator_(0)
|
decorator_(0)
|
||||||
{
|
{
|
||||||
Q_UNUSED(scene)
|
Q_UNUSED(scene)
|
||||||
#if QT_VERSION >= 0x040500
|
|
||||||
document() -> setDocumentMargin(1.0);
|
document() -> setDocumentMargin(1.0);
|
||||||
#endif
|
|
||||||
setDefaultTextColor(Qt::black);
|
setDefaultTextColor(Qt::black);
|
||||||
setFont(QETApp::diagramTextsFont());
|
setFont(QETApp::diagramTextsFont());
|
||||||
real_font_size_ = font().pointSize();
|
real_font_size_ = font().pointSize();
|
||||||
setFlags(QGraphicsItem::ItemIsSelectable);
|
setFlags(QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemSendsGeometryChanges);
|
||||||
#if QT_VERSION >= 0x040600
|
|
||||||
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
|
|
||||||
#endif
|
|
||||||
setAcceptHoverEvents(true);
|
setAcceptHoverEvents(true);
|
||||||
setDefaultTextColor(Qt::black);
|
setDefaultTextColor(Qt::black);
|
||||||
setPlainText(QObject::tr("T", "default text when adding a text in the element editor"));
|
setPlainText(QObject::tr("T", "default text when adding a text in the element editor"));
|
||||||
@@ -432,29 +427,26 @@ void PartText::startEdition() {
|
|||||||
End text edition, potentially generating a ChangePartCommand if the text
|
End text edition, potentially generating a ChangePartCommand if the text
|
||||||
has changed.
|
has changed.
|
||||||
*/
|
*/
|
||||||
void PartText::endEdition() {
|
void PartText::endEdition()
|
||||||
if (!previous_text.isNull()) {
|
{
|
||||||
// the text was being edited
|
if (!previous_text.isNull())
|
||||||
|
{
|
||||||
|
// the text was being edited
|
||||||
QString new_text = toPlainText();
|
QString new_text = toPlainText();
|
||||||
if (previous_text != new_text) {
|
if (previous_text != new_text)
|
||||||
// the text was changed
|
{
|
||||||
ChangePartCommand *text_change = new ChangePartCommand(
|
QPropertyUndoCommand *undo = new QPropertyUndoCommand(this, "text", previous_text, new_text);
|
||||||
TextEditor::tr("contenu") + " " + name(),
|
undo->setText(tr("Modifier un champ texte"));
|
||||||
this,
|
undoStack().push(undo);
|
||||||
"text",
|
|
||||||
previous_text,
|
|
||||||
new_text
|
|
||||||
);
|
|
||||||
previous_text = QString();
|
previous_text = QString();
|
||||||
undoStack().push(text_change);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// deselectionne le texte
|
// deselectionne le texte
|
||||||
QTextCursor qtc = textCursor();
|
QTextCursor qtc = textCursor();
|
||||||
qtc.clearSelection();
|
qtc.clearSelection();
|
||||||
setTextCursor(qtc);
|
setTextCursor(qtc);
|
||||||
|
|
||||||
setEditable(false);
|
setEditable(false);
|
||||||
if (decorator_) {
|
if (decorator_) {
|
||||||
decorator_ -> setFocus();
|
decorator_ -> setFocus();
|
||||||
|
|||||||
@@ -17,9 +17,9 @@
|
|||||||
*/
|
*/
|
||||||
#include "parttextfield.h"
|
#include "parttextfield.h"
|
||||||
#include "textfieldeditor.h"
|
#include "textfieldeditor.h"
|
||||||
#include "editorcommands.h"
|
|
||||||
#include "elementprimitivedecorator.h"
|
#include "elementprimitivedecorator.h"
|
||||||
#include "qetapp.h"
|
#include "qetapp.h"
|
||||||
|
#include "QPropertyUndoCommand/qpropertyundocommand.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Constructeur
|
Constructeur
|
||||||
@@ -39,10 +39,7 @@ PartTextField::PartTextField(QETElementEditor *editor, QGraphicsItem *parent, QG
|
|||||||
setDefaultTextColor(Qt::black);
|
setDefaultTextColor(Qt::black);
|
||||||
setFont(QETApp::diagramTextsFont());
|
setFont(QETApp::diagramTextsFont());
|
||||||
real_font_size_ = font().pointSize();
|
real_font_size_ = font().pointSize();
|
||||||
setFlags(QGraphicsItem::ItemIsSelectable);
|
setFlags(QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemSendsGeometryChanges);
|
||||||
#if QT_VERSION >= 0x040600
|
|
||||||
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
|
|
||||||
#endif
|
|
||||||
setAcceptHoverEvents(true);
|
setAcceptHoverEvents(true);
|
||||||
setPlainText(QObject::tr("_", "default text when adding a textfield in the element editor"));
|
setPlainText(QObject::tr("_", "default text when adding a textfield in the element editor"));
|
||||||
|
|
||||||
@@ -416,21 +413,18 @@ void PartTextField::startEdition() {
|
|||||||
End text edition, potentially generating a ChangePartCommand if the text
|
End text edition, potentially generating a ChangePartCommand if the text
|
||||||
has changed.
|
has changed.
|
||||||
*/
|
*/
|
||||||
void PartTextField::endEdition() {
|
void PartTextField::endEdition()
|
||||||
if (!previous_text.isNull()) {
|
{
|
||||||
// the text was being edited
|
if (!previous_text.isNull())
|
||||||
|
{
|
||||||
|
// the text was being edited
|
||||||
QString new_text = toPlainText();
|
QString new_text = toPlainText();
|
||||||
if (previous_text != new_text) {
|
if (previous_text != new_text)
|
||||||
// the text was changed
|
{
|
||||||
ChangePartCommand *text_change = new ChangePartCommand(
|
QPropertyUndoCommand *undo = new QPropertyUndoCommand(this, "text", previous_text, new_text);
|
||||||
TextFieldEditor::tr("contenu") + " " + name(),
|
undo->setText(tr("Modifier un champ texte"));
|
||||||
this,
|
undoStack().push(undo);
|
||||||
"text",
|
|
||||||
previous_text,
|
|
||||||
new_text
|
|
||||||
);
|
|
||||||
previous_text = QString();
|
previous_text = QString();
|
||||||
undoStack().push(text_change);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user