Independent text can have custom font.

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5766 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2019-03-08 13:47:33 +00:00
parent c9ebb78639
commit a58cecc22a
4 changed files with 91 additions and 15 deletions

View File

@@ -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);
}

View File

@@ -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<IndependentTextItem> 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<IndependentTextItem> 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<double>::of(&QDoubleSpinBox::valueChanged), this, &IndiTextPropertiesWidget::apply);
m_edit_connection << connect(ui->m_size_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());
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<IndependentTextItem> 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;
}
}

View File

@@ -48,6 +48,7 @@ class IndiTextPropertiesWidget : public PropertiesEditorWidget
private slots:
void on_m_advanced_editor_pb_clicked();
void on_m_break_html_pb_clicked();
void on_m_font_pb_clicked();
private:
void setUpEditConnection();
@@ -59,6 +60,8 @@ class IndiTextPropertiesWidget : public PropertiesEditorWidget
QList <QPointer<IndependentTextItem>> m_text_list;
QList <QMetaObject::Connection> m_connect_list,
m_edit_connection;
QFont m_selected_font;
bool m_font_is_selected = false;
};
#endif // INDITEXTPROPERTIESWIDGET_H

View File

@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>288</width>
<height>251</height>
<width>340</width>
<height>296</height>
</rect>
</property>
<property name="windowTitle">
@@ -126,17 +126,10 @@
</property>
</widget>
</item>
<item row="0" column="0" colspan="4">
<widget class="QLineEdit" name="m_line_edit">
<property name="placeholderText">
<string>Texte</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="4">
<widget class="QLabel" name="m_label">
<property name="text">
<string>Le contenu et la taille du texte ne peuvent être modifié car formaté en html.
<string>Le contenu, la taille et la police du texte ne peuvent être modifié car formaté en html.
Veuillez utiliser l'éditeur avancé pour cela.</string>
</property>
<property name="scaledContents">
@@ -154,6 +147,20 @@ Veuillez utiliser l'éditeur avancé pour cela.</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="3">
<widget class="QLineEdit" name="m_line_edit">
<property name="placeholderText">
<string>Texte</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QPushButton" name="m_font_pb">
<property name="text">
<string>Police</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>