mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-07 20:34:14 +02:00
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 <noreply@anthropic.com>
This commit is contained in:
@@ -27,6 +27,15 @@
|
||||
#include <QLineEdit>
|
||||
#include <QtGlobal>
|
||||
|
||||
/**
|
||||
@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<IndependentTextItem> 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<IndependentTextItem> 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<double>::of(&QDoubleSpinBox::valueChanged), this, &IndiTextPropertiesWidget::apply);
|
||||
m_edit_connection << connect(ui->m_width_sb, QOverload<int>::of(&QSpinBox::valueChanged), this, &IndiTextPropertiesWidget::apply);
|
||||
m_edit_connection << connect(ui->m_size_sb, QOverload<int>::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<IndependentTextItem> 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<IndependentTextItem> piti : m_text_list) {
|
||||
|
||||
@@ -64,7 +64,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<item row="7" column="0">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
@@ -126,7 +126,39 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0" colspan="4">
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>Largeur :</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QSpinBox" name="m_width_sb">
|
||||
<property name="toolTip">
|
||||
<string>Largeur du texte, le texte passe à la ligne. Auto : pas de retour à la ligne automatique</string>
|
||||
</property>
|
||||
<property name="specialValueText">
|
||||
<string>Auto</string>
|
||||
</property>
|
||||
<property name="suffix">
|
||||
<string>px</string>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>-1</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>10000</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>-1</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0" colspan="4">
|
||||
<widget class="QLabel" name="m_label">
|
||||
<property name="text">
|
||||
<string>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.</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0" colspan="4">
|
||||
<item row="6" column="0" colspan="4">
|
||||
<widget class="QPushButton" name="m_break_html_pb">
|
||||
<property name="text">
|
||||
<string>Cliquez ici pour annuler le formatage html</string>
|
||||
@@ -171,6 +203,7 @@ Veuillez utiliser l'éditeur avancé pour cela.</string>
|
||||
<tabstop>m_y_sb</tabstop>
|
||||
<tabstop>m_angle_sb</tabstop>
|
||||
<tabstop>m_size_sb</tabstop>
|
||||
<tabstop>m_width_sb</tabstop>
|
||||
<tabstop>m_break_html_pb</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
|
||||
Reference in New Issue
Block a user