diff --git a/sources/qetgraphicsitem/independenttextitem.cpp b/sources/qetgraphicsitem/independenttextitem.cpp index d258d463e..6356c38ca 100644 --- a/sources/qetgraphicsitem/independenttextitem.cpp +++ b/sources/qetgraphicsitem/independenttextitem.cpp @@ -52,6 +52,12 @@ void IndependentTextItem::fromXml(const QDomElement &e) { setPos(e.attribute("x").toDouble(), e.attribute("y").toDouble()); setHtml(e.attribute("text")); setRotation(e.attribute("rotation").toDouble()); + if (e.hasAttribute("font")) + { + QFont font; + font.fromString(e.attribute("font")); + setFont(font); + } } /** @@ -65,6 +71,7 @@ QDomElement IndependentTextItem::toXml(QDomDocument &document) const result.setAttribute("y", QString("%1").arg(pos().y())); result.setAttribute("text", toHtml()); result.setAttribute("rotation", QString::number(QET::correctAngle(rotation()))); + result.setAttribute("font", font().toString()); return(result); } diff --git a/sources/ui/inditextpropertieswidget.cpp b/sources/ui/inditextpropertieswidget.cpp index eb8cda9d6..e32e996e6 100644 --- a/sources/ui/inditextpropertieswidget.cpp +++ b/sources/ui/inditextpropertieswidget.cpp @@ -198,6 +198,11 @@ QUndoCommand *IndiTextPropertiesWidget::associatedUndo() const undo = new QPropertyUndoCommand(m_text.data(), "font", m_text->font(), font); undo->setText(tr("Modifier la taille d'un champ texte")); } + if (m_font_is_selected && + m_selected_font != m_text->font()) { + undo = new QPropertyUndoCommand(m_text.data(), "font", m_text->font(), m_selected_font); + undo->setText(tr("Modifier la police d'un champ texte")); + } return undo; } @@ -206,8 +211,10 @@ QUndoCommand *IndiTextPropertiesWidget::associatedUndo() const QUndoCommand *parent_undo = nullptr; bool size_equal = true; bool angle_equal = true; + bool font_equal = true; qreal rotation_ = m_text_list.first()->rotation(); int size_ = m_text_list.first()->font().pointSize(); + QFont font_ = m_text_list.first()->font(); for (QPointer piti : m_text_list) { if (piti->rotation() != rotation_) { @@ -216,6 +223,9 @@ QUndoCommand *IndiTextPropertiesWidget::associatedUndo() const if (piti->font().pointSize() != size_) { size_equal = false; } + if (piti->font() != font_) { + font_equal = false; + } } if ((angle_equal && (ui->m_angle_sb->value() != rotation_)) || @@ -245,8 +255,21 @@ QUndoCommand *IndiTextPropertiesWidget::associatedUndo() const } QFont font = piti->font(); font.setPointSize(ui->m_size_sb->value()); - QPropertyUndoCommand *qpuc = new QPropertyUndoCommand(piti.data(), "font", QVariant(piti->font()), QVariant(font), parent_undo); - qpuc->setAnimated(true, false); + new QPropertyUndoCommand(piti.data(), "font", QVariant(piti->font()), QVariant(font), parent_undo); + } + } + } + else if ((m_font_is_selected && !font_equal) || + (m_font_is_selected && (font_equal && (m_selected_font != font_)))) + { + for (QPointer piti : m_text_list) + { + if (piti) + { + if (!parent_undo) { + parent_undo = new QUndoCommand(tr("Modifier la police de plusieurs champs texte")); + } + new QPropertyUndoCommand(piti.data(), "font", piti->font(), m_selected_font, parent_undo); } } } @@ -275,6 +298,9 @@ QUndoCommand *IndiTextPropertiesWidget::associatedUndo() const font.setPointSize(ui->m_size_sb->value()); new QPropertyUndoCommand(m_text.data(), "font", m_text->font(), font, undo); } + if (m_font_is_selected && m_selected_font != m_text->font()) { + new QPropertyUndoCommand(m_text.data(), "font", m_text->font(), m_selected_font, undo); + } if (undo->childCount()) { return undo; @@ -305,7 +331,11 @@ void IndiTextPropertiesWidget::setUpEditConnection() m_edit_connection << connect(ui->m_line_edit, &QLineEdit::textEdited, this, &IndiTextPropertiesWidget::apply); } m_edit_connection << connect(ui->m_angle_sb, QOverload::of(&QDoubleSpinBox::valueChanged), this, &IndiTextPropertiesWidget::apply); - m_edit_connection << connect(ui->m_size_sb, QOverload::of(&QSpinBox::valueChanged), this, &IndiTextPropertiesWidget::apply); + m_edit_connection << connect(ui->m_size_sb, QOverload::of(&QSpinBox::valueChanged), [this]() + { + this->m_selected_font.setPointSize(ui->m_size_sb->value()); + this->apply(); + }); } /** @@ -341,13 +371,18 @@ void IndiTextPropertiesWidget::updateUi() ui->m_size_sb->setDisabled(m_text->isHtml() ? true : false); ui->m_label->setVisible(m_text->isHtml() ? true : false); ui->m_break_html_pb->setVisible(m_text->isHtml() ? true : false); + ui->m_font_pb->setDisabled(m_text->isHtml() ? true : false); + ui->m_font_pb->setText(m_text->isHtml() ? tr("Police") : m_text->font().family()); } else { bool size_equal = true; bool angle_equal = true; + bool font_equal = true; qreal rotation_ = m_text_list.first()->rotation(); int size_ = m_text_list.first()->font().pointSize(); + QFont font_ = m_text_list.first()->font(); + for (QPointer piti : m_text_list) { if (piti->rotation() != rotation_) { @@ -356,6 +391,9 @@ void IndiTextPropertiesWidget::updateUi() if (piti->font().pointSize() != size_) { size_equal = false; } + if (piti->font() != font_) { + font_equal = false; + } } ui->m_angle_sb->setValue(angle_equal ? rotation_ : 0); @@ -365,6 +403,8 @@ void IndiTextPropertiesWidget::updateUi() valid_ = false; } } + ui->m_font_pb->setEnabled(valid_); + ui->m_font_pb->setText(font_equal ? font_.family() : tr("Police")); ui->m_size_sb->setEnabled(valid_); ui->m_size_sb->setValue(size_equal ? size_ : 0); ui->m_label->setVisible(false); @@ -396,3 +436,22 @@ void IndiTextPropertiesWidget::on_m_break_html_pb_clicked() updateUi(); } + +void IndiTextPropertiesWidget::on_m_font_pb_clicked() +{ + if (!m_text && m_text_list.isEmpty()) { + return; + } + bool ok; + QFont font = m_text ? m_text->font() : m_text_list.first()->font(); + m_selected_font = QFontDialog::getFont(&ok, font, this); + if (ok) { + m_font_is_selected = true; + ui->m_font_pb->setText(font.family()); + ui->m_size_sb->setValue(font.pointSize()); + apply(); + } else { + ui->m_font_pb->setText(tr("Police")); + m_font_is_selected = false; + } +} diff --git a/sources/ui/inditextpropertieswidget.h b/sources/ui/inditextpropertieswidget.h index 6ead20174..20346a90e 100644 --- a/sources/ui/inditextpropertieswidget.h +++ b/sources/ui/inditextpropertieswidget.h @@ -48,8 +48,9 @@ class IndiTextPropertiesWidget : public PropertiesEditorWidget private slots: void on_m_advanced_editor_pb_clicked(); void on_m_break_html_pb_clicked(); - - private: + void on_m_font_pb_clicked(); + + private: void setUpEditConnection(); void updateUi() override; @@ -59,6 +60,8 @@ class IndiTextPropertiesWidget : public PropertiesEditorWidget QList > m_text_list; QList m_connect_list, m_edit_connection; + QFont m_selected_font; + bool m_font_is_selected = false; }; #endif // INDITEXTPROPERTIESWIDGET_H diff --git a/sources/ui/inditextpropertieswidget.ui b/sources/ui/inditextpropertieswidget.ui index 2b72a9945..fe5194a73 100644 --- a/sources/ui/inditextpropertieswidget.ui +++ b/sources/ui/inditextpropertieswidget.ui @@ -6,8 +6,8 @@ 0 0 - 288 - 251 + 340 + 296 @@ -126,17 +126,10 @@ - - - - Texte - - - - Le contenu et la taille du texte ne peuvent être modifié car formaté en html. + Le contenu, la taille et la police du texte ne peuvent être modifié car formaté en html. Veuillez utiliser l'éditeur avancé pour cela. @@ -154,6 +147,20 @@ Veuillez utiliser l'éditeur avancé pour cela. + + + + Texte + + + + + + + Police + + +