mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 12:40:35 +01:00
Independent text editor can now edit several texts.
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5738 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -39,6 +39,19 @@ IndiTextPropertiesWidget::IndiTextPropertiesWidget(IndependentTextItem *text, QW
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief IndiTextPropertiesWidget::IndiTextPropertiesWidget
|
||||
* @param text_list : a list of texts to edit
|
||||
* @param parent : the parent widget of this widget
|
||||
*/
|
||||
IndiTextPropertiesWidget::IndiTextPropertiesWidget(QList<IndependentTextItem *> text_list, QWidget *parent) :
|
||||
PropertiesEditorWidget (parent),
|
||||
ui(new Ui::IndiTextPropertiesWidget)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
setText(text_list);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief IndiTextPropertiesWidget::~IndiTextPropertiesWidget
|
||||
*/
|
||||
@@ -69,6 +82,32 @@ void IndiTextPropertiesWidget::setText(IndependentTextItem *text)
|
||||
updateUi();
|
||||
}
|
||||
|
||||
void IndiTextPropertiesWidget::setText(QList<IndependentTextItem *> text_list)
|
||||
{
|
||||
for (QMetaObject::Connection c : m_connect_list) {
|
||||
disconnect(c);
|
||||
}
|
||||
m_connect_list.clear();
|
||||
m_text_list.clear();
|
||||
m_text = nullptr;
|
||||
|
||||
if (text_list.size() == 0) {
|
||||
updateUi();
|
||||
}
|
||||
else if (text_list.size() == 1)
|
||||
{
|
||||
setText(text_list.first());
|
||||
m_text_list.clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
for (IndependentTextItem *iti : text_list) {
|
||||
m_text_list.append(QPointer<IndependentTextItem>(iti));
|
||||
}
|
||||
updateUi();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief IndiTextPropertiesWidget::apply
|
||||
* Apply the current edition through a QUndoCommand pushed
|
||||
@@ -76,11 +115,24 @@ void IndiTextPropertiesWidget::setText(IndependentTextItem *text)
|
||||
*/
|
||||
void IndiTextPropertiesWidget::apply()
|
||||
{
|
||||
if (m_text && m_text->diagram())
|
||||
Diagram *d = nullptr;
|
||||
|
||||
if (m_text && m_text->diagram()) {
|
||||
d = m_text->diagram();
|
||||
} else if (!m_text_list.isEmpty()) {
|
||||
for (QPointer<IndependentTextItem> piti : m_text_list) {
|
||||
if (piti->diagram()) {
|
||||
d = piti->diagram();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (d)
|
||||
{
|
||||
QUndoCommand *undo = associatedUndo();
|
||||
if (undo) {
|
||||
m_text->diagram()->undoStack().push(undo);
|
||||
d->undoStack().push(undo);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -118,34 +170,88 @@ QUndoCommand *IndiTextPropertiesWidget::associatedUndo() const
|
||||
if (m_live_edit)
|
||||
{
|
||||
QPropertyUndoCommand *undo = nullptr;
|
||||
if(ui->m_x_sb->value() != m_text->pos().x()) {
|
||||
undo = new QPropertyUndoCommand(m_text.data(), "x", QVariant(m_text->pos().x()), QVariant(ui->m_x_sb->value()));
|
||||
undo->setAnimated(true, false);
|
||||
undo->setText(tr("Déplacer un champ texte"));
|
||||
//One text is edited
|
||||
if (m_text_list.isEmpty())
|
||||
{
|
||||
if(ui->m_x_sb->value() != m_text->pos().x()) {
|
||||
undo = new QPropertyUndoCommand(m_text.data(), "x", QVariant(m_text->pos().x()), QVariant(ui->m_x_sb->value()));
|
||||
undo->setAnimated(true, false);
|
||||
undo->setText(tr("Déplacer un champ texte"));
|
||||
}
|
||||
if(ui->m_y_sb->value() != m_text->pos().y()) {
|
||||
undo = new QPropertyUndoCommand(m_text.data(), "y", QVariant(m_text->pos().y()), QVariant(ui->m_y_sb->value()));
|
||||
undo->setAnimated(true, false);
|
||||
undo->setText(tr("Déplacer un champ texte"));
|
||||
}
|
||||
if(ui->m_angle_sb->value() != m_text->rotation()) {
|
||||
undo = new QPropertyUndoCommand(m_text.data(), "rotation", QVariant(m_text->rotation()), QVariant(ui->m_angle_sb->value()));
|
||||
undo->setAnimated(true, false);
|
||||
undo->setText(tr("Pivoter un champ texte"));
|
||||
}
|
||||
if (ui->m_line_edit->text() != m_text->toPlainText()) {
|
||||
undo = new QPropertyUndoCommand(m_text.data(), "plainText", m_text->toPlainText(), ui->m_line_edit->text());
|
||||
undo->setText(tr("Modifier un champ texte"));
|
||||
}
|
||||
if (ui->m_size_sb->value() != m_text->fontSize()) {
|
||||
undo = new QPropertyUndoCommand(m_text.data(), "fontSize", m_text->fontSize(), ui->m_size_sb->value());
|
||||
undo->setAnimated(true, false);
|
||||
undo->setText(tr("Modifier la taille d'un champ texte"));
|
||||
}
|
||||
|
||||
return undo;
|
||||
}
|
||||
if(ui->m_y_sb->value() != m_text->pos().y()) {
|
||||
undo = new QPropertyUndoCommand(m_text.data(), "y", QVariant(m_text->pos().y()), QVariant(ui->m_y_sb->value()));
|
||||
undo->setAnimated(true, false);
|
||||
undo->setText(tr("Déplacer un champ texte"));
|
||||
else //several text are edited, only size and rotation is available for edition
|
||||
{
|
||||
QUndoCommand *parent_undo = nullptr;
|
||||
bool size_equal = true;
|
||||
bool angle_equal = true;
|
||||
qreal rotation_ = m_text_list.first()->rotation();
|
||||
int size_ = m_text_list.first()->fontSize();
|
||||
for (QPointer<IndependentTextItem> piti : m_text_list)
|
||||
{
|
||||
if (piti->rotation() != rotation_) {
|
||||
angle_equal = false;
|
||||
}
|
||||
if (piti->fontSize() != size_) {
|
||||
size_equal = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ((angle_equal && (ui->m_angle_sb->value() != rotation_)) ||
|
||||
(!angle_equal && (ui->m_angle_sb->value() != ui->m_angle_sb->minimum())))
|
||||
{
|
||||
for (QPointer<IndependentTextItem> piti : m_text_list)
|
||||
{
|
||||
if (piti)
|
||||
{
|
||||
if (!parent_undo) {
|
||||
parent_undo = new QUndoCommand(tr("Pivoter plusieurs champs texte"));
|
||||
}
|
||||
QPropertyUndoCommand *qpuc = new QPropertyUndoCommand(piti.data(), "rotation", QVariant(m_text->rotation()), QVariant(ui->m_angle_sb->value()), parent_undo);
|
||||
qpuc->setAnimated(true, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ((size_equal && (ui->m_size_sb->value() != size_)) ||
|
||||
(!size_equal && (ui->m_size_sb->value() != ui->m_size_sb->minimum())))
|
||||
{
|
||||
for (QPointer<IndependentTextItem> piti : m_text_list)
|
||||
{
|
||||
if (piti)
|
||||
{
|
||||
if (!parent_undo) {
|
||||
parent_undo = new QUndoCommand(tr("Modifier la taille de plusieurs champs texte"));
|
||||
}
|
||||
QPropertyUndoCommand *qpuc = new QPropertyUndoCommand(piti.data(), "fontSize", m_text->fontSize(), ui->m_size_sb->value(), parent_undo);
|
||||
qpuc->setAnimated(true, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
return parent_undo;
|
||||
}
|
||||
if(ui->m_angle_sb->value() != m_text->rotation()) {
|
||||
undo = new QPropertyUndoCommand(m_text.data(), "rotation", QVariant(m_text->rotation()), QVariant(ui->m_angle_sb->value()));
|
||||
undo->setAnimated(true, false);
|
||||
undo->setText(tr("Pivoter un champ texte"));
|
||||
}
|
||||
if (ui->m_line_edit->text() != m_text->toPlainText()) {
|
||||
undo = new QPropertyUndoCommand(m_text.data(), "plainText", m_text->toPlainText(), ui->m_line_edit->text());
|
||||
undo->setText(tr("Modifier un champ texte"));
|
||||
}
|
||||
if (ui->m_size_sb->value() != m_text->fontSize()) {
|
||||
undo = new QPropertyUndoCommand(m_text.data(), "fontSize", m_text->fontSize(), ui->m_size_sb->value());
|
||||
undo->setAnimated(true, false);
|
||||
undo->setText(tr("Modifier la taille d'un champ texte"));
|
||||
}
|
||||
|
||||
return undo;
|
||||
}
|
||||
else
|
||||
//In mode not live edit, only one text can be edited
|
||||
else if (m_text_list.isEmpty())
|
||||
{
|
||||
QUndoCommand *undo = new QUndoCommand(tr("Modifier les propriétées d'un texte"));
|
||||
if(ui->m_x_sb->value() != m_text->pos().x()) {
|
||||
@@ -170,11 +276,14 @@ QUndoCommand *IndiTextPropertiesWidget::associatedUndo() const
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief IndiTextPropertiesWidget::setUpEditConnection
|
||||
* Disconnect the previous connection, and reconnect the connection between the editors widgets and apply function
|
||||
* Disconnect the previous connection, and reconnect the connection between the editors widgets and void IndiTextPropertiesWidget::apply function
|
||||
*/
|
||||
void IndiTextPropertiesWidget::setUpEditConnection()
|
||||
{
|
||||
@@ -182,10 +291,14 @@ void IndiTextPropertiesWidget::setUpEditConnection()
|
||||
disconnect(c);
|
||||
}
|
||||
m_edit_connection.clear();
|
||||
m_edit_connection << connect(ui->m_x_sb, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &IndiTextPropertiesWidget::apply);
|
||||
m_edit_connection << connect(ui->m_y_sb, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &IndiTextPropertiesWidget::apply);
|
||||
|
||||
if (m_text_list.isEmpty())
|
||||
{
|
||||
m_edit_connection << connect(ui->m_x_sb, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &IndiTextPropertiesWidget::apply);
|
||||
m_edit_connection << connect(ui->m_y_sb, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &IndiTextPropertiesWidget::apply);
|
||||
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_line_edit, &QLineEdit::textEdited, this, &IndiTextPropertiesWidget::apply);
|
||||
m_edit_connection << connect(ui->m_size_sb, QOverload<int>::of(&QSpinBox::valueChanged), this, &IndiTextPropertiesWidget::apply);
|
||||
}
|
||||
|
||||
@@ -194,7 +307,7 @@ void IndiTextPropertiesWidget::setUpEditConnection()
|
||||
*/
|
||||
void IndiTextPropertiesWidget::updateUi()
|
||||
{
|
||||
if (!m_text) {
|
||||
if (!m_text && m_text_list.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -205,14 +318,45 @@ void IndiTextPropertiesWidget::updateUi()
|
||||
}
|
||||
m_edit_connection.clear();
|
||||
|
||||
ui->m_x_sb->setValue(m_text->pos().x());
|
||||
ui->m_y_sb->setValue(m_text->pos().y());
|
||||
ui->m_angle_sb->setValue(m_text->rotation());
|
||||
ui->m_line_edit->setText(m_text->toPlainText());
|
||||
ui->m_size_sb->setValue(m_text->fontSize());
|
||||
ui->m_x_sb->setEnabled(m_text_list.isEmpty() ? true : false);
|
||||
ui->m_y_sb->setEnabled(m_text_list.isEmpty() ? true : false);
|
||||
ui->m_line_edit->setEnabled(m_text_list.isEmpty() ? true : false);
|
||||
ui->m_advanced_editor_pb->setEnabled(m_text_list.isEmpty() ? true : false);
|
||||
|
||||
ui->m_line_edit->setDisabled(m_text->isHtml() ? true : false);
|
||||
ui->m_size_sb->setDisabled(m_text->isHtml() ? true : false);
|
||||
if (m_text_list.isEmpty())
|
||||
{
|
||||
ui->m_x_sb->setValue(m_text->pos().x());
|
||||
ui->m_y_sb->setValue(m_text->pos().y());
|
||||
ui->m_line_edit->setText(m_text->toPlainText());
|
||||
ui->m_angle_sb->setValue(m_text->rotation());
|
||||
ui->m_size_sb->setValue(m_text->fontSize());
|
||||
|
||||
ui->m_line_edit->setDisabled(m_text->isHtml() ? true : false);
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
bool size_equal = true;
|
||||
bool angle_equal = true;
|
||||
qreal rotation_ = m_text_list.first()->rotation();
|
||||
int size_ = m_text_list.first()->fontSize();
|
||||
for (QPointer<IndependentTextItem> piti : m_text_list)
|
||||
{
|
||||
if (piti->rotation() != rotation_) {
|
||||
angle_equal = false;
|
||||
}
|
||||
if (piti->fontSize() != size_) {
|
||||
size_equal = false;
|
||||
}
|
||||
}
|
||||
ui->m_angle_sb->setValue(angle_equal ? rotation_ : 0);
|
||||
ui->m_size_sb->setValue(size_equal ? size_ : 0);
|
||||
ui->m_label->setVisible(false);
|
||||
ui->m_break_html_pb->setVisible(false);
|
||||
}
|
||||
|
||||
|
||||
//Set the connection now
|
||||
setUpEditConnection();
|
||||
@@ -226,3 +370,12 @@ void IndiTextPropertiesWidget::on_m_advanced_editor_pb_clicked() {
|
||||
m_text->edit();
|
||||
}
|
||||
}
|
||||
|
||||
void IndiTextPropertiesWidget::on_m_break_html_pb_clicked()
|
||||
{
|
||||
if (m_text)
|
||||
{
|
||||
m_text->setPlainText(m_text->toPlainText());
|
||||
updateUi();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user