diff --git a/sources/ui/dynamicelementtextmodel.cpp b/sources/ui/dynamicelementtextmodel.cpp index 11c6170ee..f84f22f71 100644 --- a/sources/ui/dynamicelementtextmodel.cpp +++ b/sources/ui/dynamicelementtextmodel.cpp @@ -241,6 +241,19 @@ QList DynamicElementTextModel::itemsForText(DynamicElementTextI qsi_list.clear(); qsi_list << y_pos << y_pos_a; + qsi->appendRow(qsi_list); + + //Rotation + QStandardItem *rot = new QStandardItem(tr("Rotation")); + rot->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); + + QStandardItem *rot_a = new QStandardItem; + rot_a->setData(deti->rotation(), Qt::EditRole); + rot_a->setData(DynamicElementTextModel::rotation, Qt::UserRole+1); + rot_a->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable); + + qsi_list.clear();; + qsi_list << rot << rot_a; qsi->appendRow(qsi_list); } @@ -447,6 +460,17 @@ QUndoCommand *DynamicElementTextModel::undoForEditedText(DynamicElementTextItem quc->setText(tr("Déplacer un texte d'élément")); } } + //When text is in a group, they're isn't item for the rotation of the text + if(text_qsi->child(7,1)) + { + qreal rot = text_qsi->child(7,1)->data(Qt::EditRole).toDouble(); + rot = QET::correctAngle(rot); + if(rot != deti->rotation()) + { + QPropertyUndoCommand *quc = new QPropertyUndoCommand(deti, "rotation", QVariant(deti->rotation()), QVariant(rot), undo); + quc->setText(tr("Pivoter un texte d'élément")); + } + } return undo; } @@ -686,6 +710,7 @@ void DynamicElementTextModel::setConnection(DynamicElementTextItem *deti, bool s connection_list << connect(deti, &DynamicElementTextItem::xChanged, [deti,this](){this->updateDataFromText(deti, pos);}); connection_list << connect(deti, &DynamicElementTextItem::yChanged, [deti,this](){this->updateDataFromText(deti, pos);}); connection_list << connect(deti, &DynamicElementTextItem::frameChanged, [deti,this](){this->updateDataFromText(deti, frame);}); + connection_list << connect(deti, &DynamicElementTextItem::rotationChanged, [deti,this](){this->updateDataFromText(deti, rotation);}); connection_list << connect(deti, &DynamicElementTextItem::compositeTextChanged, [deti, this]() {this->updateDataFromText(deti, compositeText);}); m_hash_text_connect.insert(deti, connection_list); @@ -775,6 +800,12 @@ void DynamicElementTextModel::updateDataFromText(DynamicElementTextItem *deti, V qsi->child(4,1)->setCheckState(deti->frame()? Qt::Checked : Qt::Unchecked); break; } + case rotation: + { + if(qsi->child(7,1)) + qsi->child(7,1)->setData(deti->rotation(), Qt::EditRole); + break; + } } m_block_dataForTextChanged = false; @@ -867,6 +898,16 @@ QWidget *DynamicTextItemDelegate::createEditor(QWidget *parent, const QStyleOpti sb->setSuffix(" px"); return sb; } + case DynamicElementTextModel::rotation: + { + QSpinBox *sb = new QSpinBox(parent); + sb->setObjectName("rot_spinbox"); + sb->setRange(0, 359); + sb->setWrapping(true); + sb->setFrame(false); + sb->setSuffix(" °"); + return sb; + } } return QStyledItemDelegate::createEditor(parent, option, index); } @@ -942,7 +983,7 @@ bool DynamicTextItemDelegate::eventFilter(QObject *object, QEvent *event) //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") + if(object->objectName() == "pos_dialog" || object->objectName() == "font_size" || object->objectName() == "rot_spinbox") { QSpinBox *sb = static_cast(object); if(event->type() == QEvent::KeyRelease) diff --git a/sources/ui/dynamicelementtextmodel.h b/sources/ui/dynamicelementtextmodel.h index d4e166447..b25f12707 100644 --- a/sources/ui/dynamicelementtextmodel.h +++ b/sources/ui/dynamicelementtextmodel.h @@ -46,7 +46,8 @@ class DynamicElementTextModel : public QStandardItemModel tagg, color, pos, - frame + frame, + rotation }; DynamicElementTextModel(Element *element, QObject *parent = nullptr);