From b07378bf6e39d58c27135cb68d72088039adad1c Mon Sep 17 00:00:00 2001 From: Beat Hangartner Date: Mon, 5 Oct 2026 17:52:44 +0200 Subject: [PATCH 1/2] Set the width of free texts in their properties A "Width" spin box in the properties of a free text sets the width it wraps to (previous commit). "Auto" (-1) is the automatic width. It also works with several selected texts, like the size and the angle; texts with different widths show "Auto" and are left alone unless the box is changed. Co-Authored-By: Claude Opus 5.5 --- sources/ui/inditextpropertieswidget.cpp | 45 +++++++++++++++++++++++++ sources/ui/inditextpropertieswidget.ui | 39 +++++++++++++++++++-- 2 files changed, 81 insertions(+), 3 deletions(-) diff --git a/sources/ui/inditextpropertieswidget.cpp b/sources/ui/inditextpropertieswidget.cpp index 0ebe9ba15..bae484752 100644 --- a/sources/ui/inditextpropertieswidget.cpp +++ b/sources/ui/inditextpropertieswidget.cpp @@ -27,6 +27,15 @@ #include #include +/** + @return width as shown in the width spin box: whole pixels, -1 for + the automatic width ("Auto"). +*/ +static int spinBoxWidth(qreal width) +{ + return width > 0 ? qRound(width) : -1; +} + /** @brief IndiTextPropertiesWidget::IndiTextPropertiesWidget @param text : the text to edit @@ -84,6 +93,7 @@ void IndiTextPropertiesWidget::setText(IndependentTextItem *text) m_connect_list << connect(m_text.data(), &IndependentTextItem::rotationChanged, this, &IndiTextPropertiesWidget::updateUi); m_connect_list << connect(m_text.data(), &IndependentTextItem::fontChanged, this, &IndiTextPropertiesWidget::updateUi); m_connect_list << connect(m_text.data(), &IndependentTextItem::textEdited, this, &IndiTextPropertiesWidget::updateUi); + m_connect_list << connect(m_text.data(), &IndependentTextItem::textWidthChanged, this, &IndiTextPropertiesWidget::updateUi); updateUi(); } @@ -209,6 +219,10 @@ QUndoCommand *IndiTextPropertiesWidget::associatedUndo() const undo = new QPropertyUndoCommand(m_text.data(), "font", m_text->font(), m_selected_font); undo->setText(tr("Modifier la police d'un champ texte")); } + if (ui->m_width_sb->value() != spinBoxWidth(m_text->textWidth())) { + undo = new QPropertyUndoCommand(m_text.data(), "textWidth", m_text->textWidth(), qreal(ui->m_width_sb->value())); + undo->setText(tr("Modifier la largeur d'un champ texte")); + } return undo; } @@ -218,9 +232,11 @@ QUndoCommand *IndiTextPropertiesWidget::associatedUndo() const bool size_equal = true; bool angle_equal = true; bool font_equal = true; + bool width_equal = true; qreal rotation_ = m_text_list.first()->rotation(); int size_ = m_text_list.first()->font().pointSize(); QFont font_ = m_text_list.first()->font(); + int width_ = spinBoxWidth(m_text_list.first()->textWidth()); for (QPointer piti : m_text_list) { if (piti->rotation() != rotation_) { @@ -232,6 +248,9 @@ QUndoCommand *IndiTextPropertiesWidget::associatedUndo() const if (piti->font() != font_) { font_equal = false; } + if (spinBoxWidth(piti->textWidth()) != width_) { + width_equal = false; + } } if ((angle_equal && (ui->m_angle_sb->value() != rotation_)) || @@ -279,6 +298,20 @@ QUndoCommand *IndiTextPropertiesWidget::associatedUndo() const } } } + else if ((width_equal && (ui->m_width_sb->value() != width_)) || + (!width_equal && (ui->m_width_sb->value() != ui->m_width_sb->minimum()))) + { + for (QPointer piti : m_text_list) + { + if (piti) + { + if (!parent_undo) { + parent_undo = new QUndoCommand(tr("Modifier la largeur de plusieurs champs texte")); + } + new QPropertyUndoCommand(piti.data(), "textWidth", piti->textWidth(), qreal(ui->m_width_sb->value()), parent_undo); + } + } + } return parent_undo; } } @@ -307,6 +340,9 @@ QUndoCommand *IndiTextPropertiesWidget::associatedUndo() const 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 (ui->m_width_sb->value() != spinBoxWidth(m_text->textWidth())) { + new QPropertyUndoCommand(m_text.data(), "textWidth", m_text->textWidth(), qreal(ui->m_width_sb->value()), undo); + } if (undo->childCount()) { return undo; @@ -337,6 +373,7 @@ 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_width_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()); @@ -372,6 +409,7 @@ void IndiTextPropertiesWidget::updateUi() ui->m_line_edit->setText(m_text->toPlainText()); ui->m_angle_sb->setValue(m_text->rotation()); ui->m_size_sb->setValue(m_text->font().pointSize()); + ui->m_width_sb->setValue(spinBoxWidth(m_text->textWidth())); ui->m_line_edit->setDisabled(m_text->isHtml() ? true : false); ui->m_size_sb->setDisabled(m_text->isHtml() ? true : false); @@ -385,9 +423,11 @@ void IndiTextPropertiesWidget::updateUi() bool size_equal = true; bool angle_equal = true; bool font_equal = true; + bool width_equal = true; qreal rotation_ = m_text_list.first()->rotation(); int size_ = m_text_list.first()->font().pointSize(); QFont font_ = m_text_list.first()->font(); + int width_ = spinBoxWidth(m_text_list.first()->textWidth()); for (QPointer piti : m_text_list) { @@ -400,8 +440,13 @@ void IndiTextPropertiesWidget::updateUi() if (piti->font() != font_) { font_equal = false; } + if (spinBoxWidth(piti->textWidth()) != width_) { + width_equal = false; + } } ui->m_angle_sb->setValue(angle_equal ? rotation_ : 0); + //Different widths show the minimum, as the other boxes do + ui->m_width_sb->setValue(width_equal ? width_ : ui->m_width_sb->minimum()); bool valid_ = true; for (QPointer piti : m_text_list) { diff --git a/sources/ui/inditextpropertieswidget.ui b/sources/ui/inditextpropertieswidget.ui index 6b370bf5f..6bdb94422 100644 --- a/sources/ui/inditextpropertieswidget.ui +++ b/sources/ui/inditextpropertieswidget.ui @@ -64,7 +64,7 @@ - + Qt::Vertical @@ -126,7 +126,39 @@ - + + + + Largeur : + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Largeur du texte, le texte passe à la ligne. Auto : pas de retour à la ligne automatique + + + Auto + + + px + + + -1 + + + 10000 + + + -1 + + + + Le contenu, la taille et la police du texte ne peuvent être modifié car formaté en html. @@ -140,7 +172,7 @@ Veuillez utiliser l'éditeur avancé pour cela. - + Cliquez ici pour annuler le formatage html @@ -171,6 +203,7 @@ Veuillez utiliser l'éditeur avancé pour cela. m_y_sb m_angle_sb m_size_sb + m_width_sb m_break_html_pb From 2c9900eca8d203d8201c5d0eca1fcea40da85c1b Mon Sep 17 00:00:00 2001 From: Beat Hangartner Date: Wed, 7 Oct 2026 01:51:00 +0200 Subject: [PATCH 2/2] Make 0 the automatic width in the free text width box The box showed Auto for -1 while IndependentTextItem::setTextWidth() treats every value up to 0 as automatic. Typing 0, or the first click on the up arrow from Auto, then put a width change in the undo history that changed nothing, left the box on 0, and in live edit every later change of X, Y, angle, text or size was replaced by that empty command. Auto is 0 in the box now, like in the setter: no number is the automatic width, and the first step up is 1 px. Co-Authored-By: Claude Fable 5.1 --- sources/ui/inditextpropertieswidget.cpp | 8 +++++--- sources/ui/inditextpropertieswidget.ui | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/sources/ui/inditextpropertieswidget.cpp b/sources/ui/inditextpropertieswidget.cpp index bae484752..afb2e0157 100644 --- a/sources/ui/inditextpropertieswidget.cpp +++ b/sources/ui/inditextpropertieswidget.cpp @@ -28,12 +28,14 @@ #include /** - @return width as shown in the width spin box: whole pixels, -1 for - the automatic width ("Auto"). + @return width as shown in the width spin box: whole pixels, 0 for the + automatic width ("Auto"). The box starts at 0, so no number means Auto + and the first step up is 1 px; IndependentTextItem::setTextWidth() + treats 0 as -1, the automatic width, so the two never disagree. */ static int spinBoxWidth(qreal width) { - return width > 0 ? qRound(width) : -1; + return width > 0 ? qRound(width) : 0; } /** diff --git a/sources/ui/inditextpropertieswidget.ui b/sources/ui/inditextpropertieswidget.ui index 6bdb94422..1572b1a34 100644 --- a/sources/ui/inditextpropertieswidget.ui +++ b/sources/ui/inditextpropertieswidget.ui @@ -148,13 +148,13 @@ px - -1 + 0 10000 - -1 + 0