Element editor : dynamic text field can be set with element info as source of text.

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5260 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2018-03-11 12:59:53 +00:00
parent 7384f22017
commit 275f20fa61
9 changed files with 336 additions and 178 deletions

View File

@@ -20,6 +20,8 @@
#include "customelementpart.h"
#include "partdynamictextfield.h"
#include "QPropertyUndoCommand/qpropertyundocommand.h"
#include "qetelementeditor.h"
#include "qetapp.h"
#include <QPointer>
#include <QGraphicsItem>
@@ -34,6 +36,7 @@ DynamicTextFieldEditor::DynamicTextFieldEditor(QETElementEditor *editor, PartDyn
ui->m_elmt_info_cb->setDisabled(true);
if(text_field)
setPart(text_field);
fillInfoComboBox();
}
DynamicTextFieldEditor::~DynamicTextFieldEditor()
@@ -75,6 +78,7 @@ bool DynamicTextFieldEditor::setPart(CustomElementPart *part)
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::infoNameChanged, [this](){this->updateForm();});
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::rotationChanged, [this](){this->updateForm();});
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::frameChanged, [this](){this->updateForm();});
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::textWidthChanged,[this]() {this->updateForm();});
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::compositeTextChanged, [this]() {this->updateForm();});
return true;
@@ -99,8 +103,27 @@ void DynamicTextFieldEditor::updateForm()
ui->m_frame_cb->setChecked(m_text_field.data()->frame());
ui->m_user_text_le->setText(m_text_field.data()->text());
ui->m_size_sb->setValue(m_text_field.data()->fontSize());
ui->m_tagg_le->setText(m_text_field.data()->tagg());
setColorPushButton(m_text_field.data()->color());
ui->m_width_sb->setValue(m_text_field.data()->textWidth());
switch (m_text_field.data()->textFrom())
{
case DynamicElementTextItem::UserText:
ui->m_text_from_cb->setCurrentIndex(0);
break;
case DynamicElementTextItem::ElementInfo:
{
ui->m_text_from_cb->setCurrentIndex(1);
ui->m_elmt_info_cb->setCurrentIndex(ui->m_elmt_info_cb->findData(m_text_field.data()->infoName()));
}
break;
case DynamicElementTextItem::CompositeText:
ui->m_text_from_cb->setCurrentIndex(2);
default:
break;
}
on_m_text_from_cb_activated(ui->m_text_from_cb->currentIndex()); //For enable the good widget
}
}
@@ -111,6 +134,32 @@ void DynamicTextFieldEditor::setColorPushButton(QColor color)
ui->m_color_pb->setStyleSheet(QString("background-color: %1; min-height: 1.5em; border-style: outset; border-width: 2px; border-color: gray; border-radius: 4px;").arg(color.name()));
}
/**
* @brief DynamicTextFieldEditor::fillInfoComboBox
* Fill the combo box "element information"
*/
void DynamicTextFieldEditor::fillInfoComboBox()
{
ui->m_elmt_info_cb->clear();
QStringList strl;
QString type = elementEditor()->elementScene()->elementType();
if(type.contains("report"))
strl << "function" << "tension-protocol";
else
strl = QETApp::elementInfoKeys();
//We use a QMap because the keys of the map are sorted, then no matter the curent local,
//the value of the combo box are always alphabetically sorted
QMap <QString, QString> info_map;
for(QString str : strl)
info_map.insert(QETApp::elementTranslatedInfoKey(str), str);
for (QString key : info_map.keys())
ui->m_elmt_info_cb->addItem(key, info_map.value(key));
}
void DynamicTextFieldEditor::on_m_x_sb_editingFinished()
{
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text_field, "x", m_text_field.data()->x(), ui->m_x_sb->value());
@@ -174,3 +223,57 @@ void DynamicTextFieldEditor::on_m_frame_cb_clicked()
undoStack().push(undo);
}
}
void DynamicTextFieldEditor::on_m_width_sb_editingFinished()
{
qreal width = (qreal)ui->m_width_sb->value();
if(width != m_text_field.data()->textWidth())
{
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text_field, "textWidth", m_text_field.data()->textWidth(), width);
undo->setText(tr("Modifier la largeur d'un texte"));
undoStack().push(undo);
}
}
void DynamicTextFieldEditor::on_m_elmt_info_cb_activated(const QString &arg1)
{
Q_UNUSED(arg1)
QString info = ui->m_elmt_info_cb->currentData().toString();
if(info != m_text_field.data()->infoName())
{
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text_field, "infoName", m_text_field.data()->infoName(), info);
undo->setText(tr("Modifier l'information d'un texte"));
undoStack().push(undo);
m_text_field.data()->setPlainText(elementEditor()->elementScene()->elementInformation().value(m_text_field.data()->infoName()).toString());
}
}
void DynamicTextFieldEditor::on_m_text_from_cb_activated(int index)
{
ui->m_user_text_le->setDisabled(true);
ui->m_elmt_info_cb->setDisabled(true);
ui->m_composite_text_pb->setDisabled(true);
if(index == 0)
ui->m_user_text_le->setEnabled(true);
else if (index == 1)
ui->m_elmt_info_cb->setEnabled(true);
else
ui->m_composite_text_pb->setEnabled(true);
DynamicElementTextItem::TextFrom tf;
if(index == 0) tf = DynamicElementTextItem::UserText;
else if(index == 1) tf = DynamicElementTextItem::ElementInfo;
else tf = DynamicElementTextItem::CompositeText;
if(tf != m_text_field.data()->textFrom())
{
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text_field, "textFrom", m_text_field.data()->textFrom(), tf);
undo->setText(tr("Modifier la source de texte, d'un texte"));
undoStack().push(undo);
}
}

View File

@@ -43,6 +43,7 @@ class DynamicTextFieldEditor : public ElementItemEditor
private:
void setColorPushButton(QColor color);
void fillInfoComboBox();
private slots:
void on_m_x_sb_editingFinished();
@@ -52,6 +53,9 @@ class DynamicTextFieldEditor : public ElementItemEditor
void on_m_size_sb_editingFinished();
void on_m_color_pb_clicked();
void on_m_frame_cb_clicked();
void on_m_width_sb_editingFinished();
void on_m_elmt_info_cb_activated(const QString &arg1);
void on_m_text_from_cb_activated(int index);
private:
Ui::DynamicTextFieldEditor *ui;

View File

@@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>419</width>
<width>299</width>
<height>332</height>
</rect>
</property>
@@ -14,7 +14,7 @@
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="1" colspan="6">
<item row="2" column="1" colspan="2">
<widget class="QComboBox" name="m_text_from_cb">
<item>
<property name="text">
@@ -33,107 +33,21 @@
</item>
</widget>
</item>
<item row="8" column="0">
<item row="7" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Couleur</string>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Tagg</string>
</property>
</widget>
</item>
<item row="7" column="1" colspan="6">
<widget class="QLineEdit" name="m_tagg_le"/>
</item>
<item row="0" column="0" colspan="7">
<widget class="QFrame" name="frame">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>X</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="m_x_sb">
<property name="minimum">
<double>-5000.000000000000000</double>
</property>
<property name="maximum">
<double>5000.000000000000000</double>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_6">
<property name="text">
<string>Y</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="m_y_sb">
<property name="minimum">
<double>-5000.000000000000000</double>
</property>
<property name="maximum">
<double>5000.000000000000000</double>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_7">
<property name="text">
<string>Rotation</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="m_rotation_sb">
<property name="maximum">
<number>359</number>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="m_frame_cb">
<property name="text">
<string>cadre</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="8" column="1" colspan="6">
<item row="7" column="1" colspan="2">
<widget class="QPushButton" name="m_color_pb">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="9" column="1">
<item row="8" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
@@ -146,16 +60,16 @@
</property>
</spacer>
</item>
<item row="4" column="1" colspan="6">
<item row="4" column="1" colspan="2">
<widget class="QComboBox" name="m_elmt_info_cb"/>
</item>
<item row="3" column="1" colspan="6">
<item row="3" column="1" colspan="2">
<widget class="QLineEdit" name="m_user_text_le"/>
</item>
<item row="5" column="1" colspan="6">
<item row="5" column="1" colspan="2">
<widget class="QPushButton" name="m_composite_text_pb">
<property name="text">
<string/>
<string>Texte composé</string>
</property>
</widget>
</item>
@@ -166,7 +80,7 @@
</property>
</widget>
</item>
<item row="6" column="1" colspan="6">
<item row="6" column="1" colspan="2">
<widget class="QSpinBox" name="m_size_sb"/>
</item>
<item row="2" column="0">
@@ -189,6 +103,102 @@
</property>
</spacer>
</item>
<item row="0" column="0" colspan="3">
<widget class="QFrame" name="frame">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="1">
<widget class="QDoubleSpinBox" name="m_x_sb">
<property name="minimum">
<double>-5000.000000000000000</double>
</property>
<property name="maximum">
<double>5000.000000000000000</double>
</property>
</widget>
</item>
<item row="0" column="6">
<widget class="QCheckBox" name="m_frame_cb">
<property name="text">
<string>cadre</string>
</property>
</widget>
</item>
<item row="0" column="5">
<widget class="QSpinBox" name="m_rotation_sb">
<property name="maximum">
<number>359</number>
</property>
</widget>
</item>
<item row="0" column="4">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Rotation</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>X</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="5">
<widget class="QSpinBox" name="m_width_sb">
<property name="minimum">
<number>-1</number>
</property>
<property name="maximum">
<number>500</number>
</property>
</widget>
</item>
<item row="1" column="4">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Largeur</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Y</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="m_y_sb">
<property name="minimum">
<double>-5000.000000000000000</double>
</property>
<property name="maximum">
<double>5000.000000000000000</double>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>