[qet] qet/qet: [5089] Dynamic element text editor : |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 5089
Author: blacksun
Date: 2017-11-05 15:33:03 +0100 (Sun, 05 Nov 2017)
Log Message:
-----------
Dynamic element text editor :
When add a new text, the item text in the tree view is selected and expanded.
When edit the pos of a text in the tree view, the new position is set directly, no need to lose focus or press enter key anymore for update the pos of the text.
Modified Paths:
--------------
trunk/sources/QPropertyUndoCommand/qpropertyundocommand.cpp
trunk/sources/QPropertyUndoCommand/qpropertyundocommand.h
trunk/sources/ui/dynamicelementtextitemeditor.cpp
trunk/sources/ui/dynamicelementtextmodel.cpp
trunk/sources/ui/dynamicelementtextmodel.h
Modified: trunk/sources/QPropertyUndoCommand/qpropertyundocommand.cpp
===================================================================
--- trunk/sources/QPropertyUndoCommand/qpropertyundocommand.cpp 2017-10-29 10:43:34 UTC (rev 5088)
+++ trunk/sources/QPropertyUndoCommand/qpropertyundocommand.cpp 2017-11-05 14:33:03 UTC (rev 5089)
@@ -52,6 +52,16 @@
m_animate(false)
{}
+QPropertyUndoCommand::QPropertyUndoCommand(const QPropertyUndoCommand *other)
+{
+ m_object = other->m_object;
+ m_property_name = other->m_property_name;
+ m_old_value = other->m_old_value;
+ m_new_value = other->m_new_value;
+ m_animate = other->m_animate;
+ setText(other->text());
+}
+
/**
* @brief QPropertyUndoCommand::setNewValue
* Set the new value of the property (set with redo) to @new_value
Modified: trunk/sources/QPropertyUndoCommand/qpropertyundocommand.h
===================================================================
--- trunk/sources/QPropertyUndoCommand/qpropertyundocommand.h 2017-10-29 10:43:34 UTC (rev 5088)
+++ trunk/sources/QPropertyUndoCommand/qpropertyundocommand.h 2017-11-05 14:33:03 UTC (rev 5089)
@@ -35,6 +35,7 @@
public:
QPropertyUndoCommand(QObject *object, const char *property_name, const QVariant &old_value, const QVariant &new_value, QUndoCommand *parent = nullptr);
QPropertyUndoCommand(QObject *object, const char *property_name, const QVariant &old_value, QUndoCommand *parent = nullptr);
+ QPropertyUndoCommand(const QPropertyUndoCommand *other);
void setNewValue(const QVariant &new_value);
void enableAnimation (bool animate = true);
Modified: trunk/sources/ui/dynamicelementtextitemeditor.cpp
===================================================================
--- trunk/sources/ui/dynamicelementtextitemeditor.cpp 2017-10-29 10:43:34 UTC (rev 5088)
+++ trunk/sources/ui/dynamicelementtextitemeditor.cpp 2017-11-05 14:33:03 UTC (rev 5089)
@@ -23,6 +23,7 @@
#include "diagram.h"
#include "undocommand/deleteqgraphicsitemcommand.h"
#include "undocommand/addelementtextcommand.h"
+#include "QPropertyUndoCommand/qpropertyundocommand.h"
#include <QTreeView>
#include <QUndoCommand>
@@ -78,7 +79,16 @@
for (DynamicElementTextItem *deti : m_element->dynamicTextItems())
{
QUndoCommand *undo = m_model->undoForEditedText(deti);
- if(undo->childCount())
+
+ if (undo->childCount() == 1)
+ {
+ QPropertyUndoCommand *quc = new QPropertyUndoCommand(static_cast<const QPropertyUndoCommand *>(undo->child(0)));
+ if (quc->text().isEmpty())
+ quc->setText(undo->text());
+ undo_list << quc;
+ delete undo;
+ }
+ else if(undo->childCount() > 1)
undo_list << undo;
else
delete undo;
@@ -90,7 +100,9 @@
if(!undo_list.isEmpty() && m_element->diagram())
{
if (undo_list.size() == 1)
+ {
m_element->diagram()->undoStack().push(undo_list.first());
+ }
else
{
QUndoStack &us = m_element->diagram()->undoStack();
@@ -117,6 +129,7 @@
return;
m_tree_view->expand(index);
+ m_tree_view->expand(index.child(0,0));
m_tree_view->setCurrentIndex(index);
}
@@ -157,6 +170,8 @@
{
m_element->diagram()->undoStack().push(new AddElementTextCommand(m_element, deti));
m_model->addText(deti);
+
+ setCurrentText(deti);
}
else
{
Modified: trunk/sources/ui/dynamicelementtextmodel.cpp
===================================================================
--- trunk/sources/ui/dynamicelementtextmodel.cpp 2017-10-29 10:43:34 UTC (rev 5088)
+++ trunk/sources/ui/dynamicelementtextmodel.cpp 2017-11-05 14:33:03 UTC (rev 5089)
@@ -314,21 +314,33 @@
}
int fs = text_qsi->child(1,1)->data(Qt::EditRole).toInt();
- if (fs != deti->fontSize())
- new QPropertyUndoCommand(deti, "fontSize", QVariant(deti->fontSize()), QVariant(fs), undo);
+ if (fs != deti->fontSize())
+ {
+ QUndoCommand *quc = new QPropertyUndoCommand(deti, "fontSize", QVariant(deti->fontSize()), QVariant(fs), undo);
+ quc->setText(tr("Modifier la taille d'un texte d'élément"));
+ }
QString tagg = text_qsi->child(2,1)->data(Qt::DisplayRole).toString();
if(tagg != deti->tagg())
- new QPropertyUndoCommand(deti, "tagg", QVariant(deti->tagg()), QVariant(tagg), undo);
+ {
+ QUndoCommand *quc = new QPropertyUndoCommand(deti, "tagg", QVariant(deti->tagg()), QVariant(tagg), undo);
+ quc->setText(tr("Modifier le tagg d'un texte d'élément"));
+ }
QColor color = text_qsi->child(3,1)->data(Qt::EditRole).value<QColor>();
if(color != deti->color())
- new QPropertyUndoCommand(deti, "color", QVariant(deti->color()), QVariant(color), undo);
+ {
+ QUndoCommand *quc = new QPropertyUndoCommand(deti, "color", QVariant(deti->color()), QVariant(color), undo);
+ quc->setText(tr("Modifier la couleur d'un texte d'élément"));
+ }
QPointF p(text_qsi->child(4,1)->data(Qt::EditRole).toDouble(),
text_qsi->child(5,1)->data(Qt::EditRole).toDouble());
if(p != deti->pos())
- new QPropertyUndoCommand(deti, "pos", QVariant(deti->pos()), QVariant(p), undo);
+ {
+ QPropertyUndoCommand *quc = new QPropertyUndoCommand(deti, "pos", QVariant(deti->pos()), QVariant(p), undo);
+ quc->setText(tr("Déplacer un texte d'élément"));
+ }
return undo;
@@ -598,6 +610,13 @@
cted->setObjectName("composite_text");
return cted;
}
+ case DynamicElementTextModel::size:
+ {
+ QSpinBox *sb = new QSpinBox(parent);
+ sb->setObjectName("font_size");
+ sb->setFrame(false);
+ return sb;
+ }
case DynamicElementTextModel::color:
{
QColorDialog *cd = new QColorDialog(index.data(Qt::EditRole).value<QColor>());
@@ -606,15 +625,12 @@
}
case DynamicElementTextModel::pos:
{
- QWidget *w = QStyledItemDelegate::createEditor(parent, option, index);
-
- if(QDoubleSpinBox *dsb = dynamic_cast<QDoubleSpinBox *>(w))
- {
- dsb->setDecimals(0);
- dsb->setSuffix(" px");
- }
-
- return w;
+ QSpinBox *sb = new QSpinBox(parent);
+ sb->setObjectName("pos_dialog");
+ sb->setRange(-1000,10000);
+ sb->setFrame(false);
+ sb->setSuffix(" px");
+ return sb;
}
}
return QStyledItemDelegate::createEditor(parent, option, index);
@@ -685,6 +701,24 @@
QStyledItemDelegate::setModelData(editor, model, index);
}
+bool DynamicTextItemDelegate::eventFilter(QObject *object, QEvent *event)
+{
+ //This is a bad hack, for change the normal behavior :
+ //in normal behavior, the value is commited when the spinbox lose focus or enter key is pressed
+ //With this hack the value is commited each time the value change, so the text is moved in live.
+ //We also use this hack for the font size spinbox
+ if(object->objectName() == "pos_dialog" || object->objectName() == "font_size")
+ {
+ QSpinBox *sb = static_cast<QSpinBox *>(object);
+ if(event->type() == QEvent::KeyRelease)
+ emit commitData(sb);
+ else if (event->type() == QEvent::MouseButtonRelease)
+ emit commitData(sb);
+ }
+
+ return QStyledItemDelegate::eventFilter(object, event);
+}
+
/**
* @brief DynamicTextItemDelegate::availableInfo
* @param deti
Modified: trunk/sources/ui/dynamicelementtextmodel.h
===================================================================
--- trunk/sources/ui/dynamicelementtextmodel.h 2017-10-29 10:43:34 UTC (rev 5088)
+++ trunk/sources/ui/dynamicelementtextmodel.h 2017-11-05 14:33:03 UTC (rev 5089)
@@ -79,6 +79,9 @@
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
+ protected:
+ bool eventFilter(QObject *object, QEvent *event) override;
+
private:
QStringList availableInfo(DynamicElementTextItem *deti) const;
};