2017-09-25 17:44:02 +00:00
|
|
|
/*
|
2020-06-15 17:42:37 +02:00
|
|
|
Copyright 2006-2020 The QElectroTech Team
|
2017-09-25 17:44:02 +00:00
|
|
|
This file is part of QElectroTech.
|
|
|
|
|
|
|
|
QElectroTech is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
QElectroTech is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#include "dynamictextfieldeditor.h"
|
|
|
|
#include "ui_dynamictextfieldeditor.h"
|
|
|
|
#include "customelementpart.h"
|
|
|
|
#include "partdynamictextfield.h"
|
|
|
|
#include "QPropertyUndoCommand/qpropertyundocommand.h"
|
2018-03-11 12:59:53 +00:00
|
|
|
#include "qetelementeditor.h"
|
|
|
|
#include "qetapp.h"
|
2018-03-11 16:00:58 +00:00
|
|
|
#include "compositetexteditdialog.h"
|
2018-05-13 19:03:38 +00:00
|
|
|
#include "alignmenttextdialog.h"
|
2020-11-08 19:05:11 +01:00
|
|
|
#include "qetinformation.h"
|
2020-06-14 17:49:50 +02:00
|
|
|
#include <assert.h>
|
2017-09-25 17:44:02 +00:00
|
|
|
|
|
|
|
#include <QPointer>
|
|
|
|
#include <QGraphicsItem>
|
|
|
|
#include <QColorDialog>
|
|
|
|
|
2020-08-05 09:13:02 +01:00
|
|
|
DynamicTextFieldEditor::DynamicTextFieldEditor(
|
|
|
|
QETElementEditor *editor, PartDynamicTextField *text_field, QWidget *parent) :
|
|
|
|
ElementItemEditor(editor, parent),
|
|
|
|
ui(new Ui::DynamicTextFieldEditor) {
|
|
|
|
ui -> setupUi(this);
|
|
|
|
ui -> m_composite_text_pb -> setDisabled(true);
|
|
|
|
ui -> m_elmt_info_cb -> setDisabled(true);
|
|
|
|
if(text_field) {
|
2017-09-25 17:44:02 +00:00
|
|
|
setPart(text_field);
|
2020-08-05 09:13:02 +01:00
|
|
|
}
|
2017-09-25 17:44:02 +00:00
|
|
|
}
|
|
|
|
|
2020-09-07 22:03:40 +02:00
|
|
|
DynamicTextFieldEditor::~DynamicTextFieldEditor()
|
|
|
|
{
|
2017-09-25 17:44:02 +00:00
|
|
|
delete ui;
|
2020-08-05 09:13:02 +01:00
|
|
|
if(!m_connection_list.isEmpty()) {
|
|
|
|
for(const QMetaObject::Connection& con : m_connection_list) {
|
2017-09-25 17:44:02 +00:00
|
|
|
disconnect(con);
|
2020-08-05 09:13:02 +01:00
|
|
|
}
|
|
|
|
}
|
2017-09-25 17:44:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief DynamicTextFieldEditor::setPart
|
2020-08-20 21:57:35 +02:00
|
|
|
Set part as current edited part of this widget.
|
2020-08-16 11:19:36 +02:00
|
|
|
@param part
|
2020-08-20 21:57:35 +02:00
|
|
|
@return true if part can be edited by this widget
|
2020-08-16 11:19:36 +02:00
|
|
|
*/
|
2020-08-05 09:13:02 +01:00
|
|
|
bool DynamicTextFieldEditor::setPart(CustomElementPart *part) {
|
2020-07-15 20:20:07 +02:00
|
|
|
disconnectConnections();
|
2020-08-05 09:13:02 +01:00
|
|
|
|
|
|
|
QGraphicsItem *qgi = part -> toItem();
|
|
|
|
if(!qgi) {
|
2017-09-25 17:44:02 +00:00
|
|
|
return false;
|
2020-08-05 09:13:02 +01:00
|
|
|
}
|
|
|
|
else if (qgi -> type() != PartDynamicTextField::Type) {
|
2017-09-25 17:44:02 +00:00
|
|
|
return false;
|
2020-08-05 09:13:02 +01:00
|
|
|
}
|
|
|
|
|
2017-09-25 17:44:02 +00:00
|
|
|
m_text_field = static_cast<PartDynamicTextField *>(qgi);
|
|
|
|
updateForm();
|
2020-07-15 20:20:07 +02:00
|
|
|
setUpConnections();
|
2020-11-08 19:05:11 +01:00
|
|
|
fillInfoComboBox();
|
2017-09-25 17:44:02 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-06-01 19:38:07 +02:00
|
|
|
bool DynamicTextFieldEditor::setParts(QList <CustomElementPart *> parts) {
|
2020-08-05 09:13:02 +01:00
|
|
|
if (parts.isEmpty()) {
|
2020-07-15 20:20:07 +02:00
|
|
|
m_parts.clear();
|
|
|
|
if (m_text_field) {
|
|
|
|
disconnectConnections();
|
|
|
|
}
|
|
|
|
m_text_field = nullptr;
|
|
|
|
return true;
|
|
|
|
}
|
2020-08-05 09:13:02 +01:00
|
|
|
|
2020-11-08 19:05:11 +01:00
|
|
|
if (PartDynamicTextField *part = static_cast<PartDynamicTextField *>(parts.first())) {
|
2020-07-15 20:20:07 +02:00
|
|
|
if (m_text_field) {
|
|
|
|
disconnectConnections();
|
|
|
|
}
|
2020-08-05 09:13:02 +01:00
|
|
|
|
2020-07-15 20:20:07 +02:00
|
|
|
m_text_field = part;
|
|
|
|
m_parts.clear();
|
|
|
|
m_parts.append(part);
|
|
|
|
for (int i=1; i < parts.length(); i++)
|
|
|
|
m_parts.append(static_cast<PartDynamicTextField*>(parts[i]));
|
2020-08-05 09:13:02 +01:00
|
|
|
|
2020-07-15 20:20:07 +02:00
|
|
|
setUpConnections();
|
|
|
|
updateForm();
|
2020-11-08 19:05:11 +01:00
|
|
|
fillInfoComboBox();
|
2020-07-15 20:20:07 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return(false);
|
2020-06-01 19:38:07 +02:00
|
|
|
}
|
|
|
|
|
2017-09-25 17:44:02 +00:00
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief DynamicTextFieldEditor::currentPart
|
|
|
|
@return The current edited part, note they can return nullptr if
|
|
|
|
there is not a currently edited part.
|
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
CustomElementPart *DynamicTextFieldEditor::currentPart() const
|
|
|
|
{
|
2017-09-25 17:44:02 +00:00
|
|
|
return m_text_field.data();
|
|
|
|
}
|
|
|
|
|
2020-09-07 22:03:40 +02:00
|
|
|
QList<CustomElementPart*> DynamicTextFieldEditor::currentParts() const
|
|
|
|
{
|
2020-07-15 20:20:07 +02:00
|
|
|
QList<CustomElementPart*> parts;
|
|
|
|
for (auto part: m_parts) {
|
|
|
|
parts.append(static_cast<CustomElementPart*>(part));
|
|
|
|
}
|
|
|
|
return parts;
|
2020-06-01 20:45:01 +02:00
|
|
|
}
|
|
|
|
|
2020-09-07 22:03:40 +02:00
|
|
|
void DynamicTextFieldEditor::updateForm()
|
|
|
|
{
|
2020-08-05 09:13:02 +01:00
|
|
|
if(m_text_field) {
|
|
|
|
ui -> m_x_sb -> setValue(m_text_field.data() -> x());
|
|
|
|
ui -> m_y_sb -> setValue(m_text_field.data() ->y ());
|
|
|
|
ui -> m_rotation_sb -> setValue(QET::correctAngle(m_text_field.data() -> rotation()));
|
|
|
|
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() -> font().pointSize());
|
|
|
|
ui -> m_color_kpb -> setColor(m_text_field.data() -> color());
|
|
|
|
ui -> m_width_sb -> setValue(m_text_field.data() -> textWidth());
|
|
|
|
ui -> m_font_pb -> setText(m_text_field -> font().family());
|
|
|
|
|
|
|
|
switch (m_text_field.data() -> textFrom()) {
|
|
|
|
case DynamicElementTextItem::UserText: {
|
|
|
|
ui -> m_text_from_cb -> setCurrentIndex(0);
|
2018-03-11 12:59:53 +00:00
|
|
|
break;
|
2020-08-05 09:13:02 +01:00
|
|
|
}
|
|
|
|
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()));
|
2018-03-11 12:59:53 +00:00
|
|
|
break;
|
2019-03-10 17:58:33 +00:00
|
|
|
}
|
2020-08-05 09:13:02 +01:00
|
|
|
case DynamicElementTextItem::CompositeText: {
|
|
|
|
ui -> m_text_from_cb -> setCurrentIndex(2);
|
|
|
|
}
|
2018-03-11 12:59:53 +00:00
|
|
|
}
|
|
|
|
|
2020-08-05 09:13:02 +01:00
|
|
|
on_m_text_from_cb_activated(ui -> m_text_from_cb -> currentIndex()); //For enable the good widget
|
2017-09-25 17:44:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-07 22:03:40 +02:00
|
|
|
void DynamicTextFieldEditor::setUpConnections()
|
|
|
|
{
|
2020-07-15 20:20:07 +02:00
|
|
|
assert(m_connection_list.isEmpty());
|
|
|
|
//Setup the connection
|
2020-08-05 09:13:02 +01:00
|
|
|
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::colorChanged,
|
|
|
|
[this](){this -> updateForm();});
|
|
|
|
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::fontChanged,
|
|
|
|
[this](){this -> updateForm();});
|
|
|
|
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::taggChanged,
|
|
|
|
[this](){this -> updateForm();});
|
|
|
|
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::textFromChanged,
|
|
|
|
[this](){this -> updateForm();});
|
|
|
|
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::textChanged,
|
|
|
|
[this](){this -> updateForm();});
|
|
|
|
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();});
|
2020-06-01 19:38:07 +02:00
|
|
|
}
|
|
|
|
|
2020-09-07 22:03:40 +02:00
|
|
|
void DynamicTextFieldEditor::disconnectConnections()
|
|
|
|
{
|
2020-07-15 20:20:07 +02:00
|
|
|
//Remove previous connection
|
|
|
|
if(!m_connection_list.isEmpty())
|
2020-08-05 09:13:02 +01:00
|
|
|
for(const QMetaObject::Connection& con : m_connection_list) {
|
2020-07-15 20:20:07 +02:00
|
|
|
disconnect(con);
|
2020-08-05 09:13:02 +01:00
|
|
|
}
|
2020-07-15 20:20:07 +02:00
|
|
|
m_connection_list.clear();
|
2020-06-01 19:38:07 +02:00
|
|
|
}
|
|
|
|
|
2018-03-11 12:59:53 +00:00
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief DynamicTextFieldEditor::fillInfoComboBox
|
|
|
|
Fill the combo box "element information"
|
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
void DynamicTextFieldEditor::fillInfoComboBox()
|
|
|
|
{
|
2020-08-05 09:13:02 +01:00
|
|
|
ui -> m_elmt_info_cb -> clear();
|
|
|
|
|
2018-03-11 12:59:53 +00:00
|
|
|
QStringList strl;
|
2020-08-05 09:13:02 +01:00
|
|
|
QString type = elementEditor() -> elementScene() -> elementType();
|
|
|
|
|
|
|
|
if(type.contains("report")) {
|
2020-11-08 19:05:11 +01:00
|
|
|
strl = QETInformation::folioReportInfoKey();
|
2020-08-05 09:13:02 +01:00
|
|
|
}
|
|
|
|
else {
|
2018-03-11 12:59:53 +00:00
|
|
|
strl = QETApp::elementInfoKeys();
|
2020-08-05 09:13:02 +01:00
|
|
|
}
|
2018-03-11 12:59:53 +00:00
|
|
|
//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;
|
2018-07-19 14:14:31 +00:00
|
|
|
for(const QString& str : strl)
|
2020-11-08 19:05:11 +01:00
|
|
|
info_map.insert(QETInformation::translatedInfoKey(str), str);
|
|
|
|
|
2018-03-11 12:59:53 +00:00
|
|
|
|
2018-07-19 14:14:31 +00:00
|
|
|
for (const QString& key : info_map.keys())
|
2020-08-05 09:13:02 +01:00
|
|
|
ui -> m_elmt_info_cb -> addItem(key, info_map.value(key));
|
2018-03-11 12:59:53 +00:00
|
|
|
}
|
|
|
|
|
2020-09-07 22:03:40 +02:00
|
|
|
void DynamicTextFieldEditor::on_m_x_sb_editingFinished()
|
|
|
|
{
|
2020-08-05 09:13:02 +01:00
|
|
|
double value = ui -> m_x_sb -> value();
|
2020-07-15 20:20:07 +02:00
|
|
|
for (int i = 0; i < m_parts.length(); i++) {
|
2020-08-05 09:13:02 +01:00
|
|
|
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "x", m_parts[i] -> x(), value);
|
|
|
|
undo -> setText(tr("Déplacer un champ texte"));
|
|
|
|
undo -> enableAnimation(true);
|
2020-07-15 20:20:07 +02:00
|
|
|
undoStack().push(undo);
|
|
|
|
}
|
2017-09-25 17:44:02 +00:00
|
|
|
}
|
|
|
|
|
2020-09-07 22:03:40 +02:00
|
|
|
void DynamicTextFieldEditor::on_m_y_sb_editingFinished()
|
|
|
|
{
|
2020-08-05 09:13:02 +01:00
|
|
|
double value = ui -> m_y_sb -> value();
|
2020-07-15 20:20:07 +02:00
|
|
|
for (int i = 0; i < m_parts.length(); i++) {
|
2020-08-05 09:13:02 +01:00
|
|
|
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "y", m_parts[i] -> y(), value);
|
|
|
|
undo -> setText(tr("Déplacer un champ texte"));
|
|
|
|
undo -> enableAnimation(true);
|
2020-07-15 20:20:07 +02:00
|
|
|
undoStack().push(undo);
|
|
|
|
}
|
2017-09-25 17:44:02 +00:00
|
|
|
}
|
|
|
|
|
2020-09-07 22:03:40 +02:00
|
|
|
void DynamicTextFieldEditor::on_m_rotation_sb_editingFinished()
|
|
|
|
{
|
2020-08-05 09:13:02 +01:00
|
|
|
int value = ui -> m_rotation_sb -> value();
|
2020-07-15 20:20:07 +02:00
|
|
|
for (int i = 0; i < m_parts.length(); i++) {
|
2020-08-05 09:13:02 +01:00
|
|
|
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "rotation", m_parts[i] -> rotation(), value);
|
|
|
|
undo -> setText(tr("Pivoter un champ texte"));
|
|
|
|
undo -> enableAnimation(true);
|
2020-07-15 20:20:07 +02:00
|
|
|
undoStack().push(undo);
|
|
|
|
}
|
2017-09-25 17:44:02 +00:00
|
|
|
}
|
|
|
|
|
2020-09-07 22:03:40 +02:00
|
|
|
void DynamicTextFieldEditor::on_m_user_text_le_editingFinished()
|
|
|
|
{
|
2020-08-05 09:13:02 +01:00
|
|
|
QString text = ui -> m_user_text_le -> text();
|
2020-07-15 20:20:07 +02:00
|
|
|
for (int i = 0; i < m_parts.length(); i++) {
|
2020-08-05 09:13:02 +01:00
|
|
|
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "text", m_parts[i] -> text(), text);
|
|
|
|
undo -> setText(tr("Modifier le texte d'un champ texte"));
|
2020-07-15 20:20:07 +02:00
|
|
|
undoStack().push(undo);
|
|
|
|
}
|
2017-09-25 17:44:02 +00:00
|
|
|
}
|
|
|
|
|
2020-09-07 22:03:40 +02:00
|
|
|
void DynamicTextFieldEditor::on_m_size_sb_editingFinished()
|
|
|
|
{
|
2020-08-05 09:13:02 +01:00
|
|
|
QFont font_ = m_text_field -> font();
|
|
|
|
font_.setPointSize(ui -> m_size_sb -> value());
|
2020-07-15 20:20:07 +02:00
|
|
|
for (int i = 0; i < m_parts.length(); i++) {
|
2020-08-05 09:13:02 +01:00
|
|
|
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "font", m_parts[i] -> font(), font_);
|
|
|
|
undo -> setText(tr("Modifier la police d'un champ texte"));
|
2020-07-15 20:20:07 +02:00
|
|
|
undoStack().push(undo);
|
|
|
|
}
|
2017-09-25 17:44:02 +00:00
|
|
|
}
|
|
|
|
|
2020-09-07 22:03:40 +02:00
|
|
|
void DynamicTextFieldEditor::on_m_frame_cb_clicked()
|
|
|
|
{
|
2020-08-05 09:13:02 +01:00
|
|
|
bool frame = ui -> m_frame_cb -> isChecked();
|
|
|
|
|
2020-07-15 20:20:07 +02:00
|
|
|
for (int i = 0; i < m_parts.length(); i++) {
|
2020-08-05 09:13:02 +01:00
|
|
|
if(frame != m_parts[i] -> frame()) {
|
|
|
|
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "frame", m_parts[i] -> frame(), frame);
|
|
|
|
undo -> setText(tr("Modifier le cadre d'un champ texte"));
|
2020-07-15 20:20:07 +02:00
|
|
|
undoStack().push(undo);
|
|
|
|
}
|
|
|
|
}
|
2017-11-07 18:35:26 +00:00
|
|
|
}
|
2018-03-11 12:59:53 +00:00
|
|
|
|
2020-09-07 22:03:40 +02:00
|
|
|
void DynamicTextFieldEditor::on_m_width_sb_editingFinished()
|
|
|
|
{
|
2020-08-05 09:13:02 +01:00
|
|
|
qreal width = (qreal)ui -> m_width_sb -> value();
|
|
|
|
|
2020-07-15 20:20:07 +02:00
|
|
|
for (int i = 0; i < m_parts.length(); i++) {
|
2020-08-05 09:13:02 +01:00
|
|
|
if(width != m_parts[i] -> textWidth()) {
|
|
|
|
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "textWidth", m_parts[i] -> textWidth(), width);
|
|
|
|
undo -> setText(tr("Modifier la largeur d'un texte"));
|
2020-07-15 20:20:07 +02:00
|
|
|
undoStack().push(undo);
|
|
|
|
}
|
|
|
|
}
|
2018-03-11 12:59:53 +00:00
|
|
|
}
|
|
|
|
|
2020-08-05 09:13:02 +01:00
|
|
|
void DynamicTextFieldEditor::on_m_elmt_info_cb_activated(const QString &arg1) {
|
2020-07-15 20:20:07 +02:00
|
|
|
Q_UNUSED(arg1)
|
2020-08-05 09:13:02 +01:00
|
|
|
|
|
|
|
QString info = ui -> m_elmt_info_cb -> currentData().toString();
|
2020-07-15 20:20:07 +02:00
|
|
|
for (int i = 0; i < m_parts.length(); i++) {
|
2020-08-05 09:13:02 +01:00
|
|
|
if(info != m_parts[i] -> infoName()) {
|
|
|
|
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "infoName", m_parts[i] -> infoName(), info);
|
2020-07-15 20:20:07 +02:00
|
|
|
undo->setText(tr("Modifier l'information d'un texte"));
|
|
|
|
undoStack().push(undo);
|
2020-08-05 09:13:02 +01:00
|
|
|
m_parts[i] -> setPlainText(
|
|
|
|
elementEditor() -> elementScene() -> elementInformation().value(m_parts[i] -> infoName()).toString());
|
2020-07-15 20:20:07 +02:00
|
|
|
}
|
|
|
|
}
|
2018-03-11 12:59:53 +00:00
|
|
|
}
|
|
|
|
|
2020-08-05 09:13:02 +01:00
|
|
|
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) {
|
2018-03-11 12:59:53 +00:00
|
|
|
ui->m_user_text_le->setEnabled(true);
|
2020-08-05 09:13:02 +01:00
|
|
|
}
|
|
|
|
else if (index == 1) {
|
2018-03-11 12:59:53 +00:00
|
|
|
ui->m_elmt_info_cb->setEnabled(true);
|
2020-08-05 09:13:02 +01:00
|
|
|
}
|
|
|
|
else {
|
2018-03-11 12:59:53 +00:00
|
|
|
ui->m_composite_text_pb->setEnabled(true);
|
2020-08-05 09:13:02 +01:00
|
|
|
}
|
|
|
|
|
2018-03-11 12:59:53 +00:00
|
|
|
DynamicElementTextItem::TextFrom tf;
|
2020-08-05 09:13:02 +01:00
|
|
|
if(index == 0) {
|
|
|
|
tf = DynamicElementTextItem::UserText;
|
|
|
|
}
|
|
|
|
else if(index == 1) {
|
|
|
|
tf = DynamicElementTextItem::ElementInfo;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
tf = DynamicElementTextItem::CompositeText;
|
|
|
|
}
|
|
|
|
|
2020-07-15 20:20:07 +02:00
|
|
|
for (int i = 0; i < m_parts.length(); i++) {
|
2020-08-05 09:13:02 +01:00
|
|
|
if(tf != m_parts[i] -> textFrom()) {
|
|
|
|
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "textFrom", m_parts[i] -> textFrom(), tf);
|
|
|
|
undo -> setText(tr("Modifier la source de texte, d'un texte"));
|
2020-07-15 20:20:07 +02:00
|
|
|
undoStack().push(undo);
|
|
|
|
}
|
|
|
|
}
|
2018-03-11 12:59:53 +00:00
|
|
|
}
|
2018-03-11 16:00:58 +00:00
|
|
|
|
2020-09-07 22:03:40 +02:00
|
|
|
void DynamicTextFieldEditor::on_m_composite_text_pb_clicked()
|
|
|
|
{
|
2020-08-05 09:13:02 +01:00
|
|
|
CompositeTextEditDialog ctd(m_text_field.data() -> compositeText(), this);
|
|
|
|
if(ctd.exec()) {
|
2018-03-11 16:00:58 +00:00
|
|
|
QString ct = ctd.plainText();
|
2020-07-15 20:20:07 +02:00
|
|
|
for (int i = 0; i < m_parts.length(); i++) {
|
2020-08-05 09:13:02 +01:00
|
|
|
if(ct != m_parts[i] -> compositeText()) {
|
|
|
|
QPropertyUndoCommand *undo =\
|
|
|
|
new QPropertyUndoCommand(m_parts[i], "compositeText", m_parts[i] -> compositeText(), ctd.plainText());
|
2020-07-15 20:20:07 +02:00
|
|
|
undoStack().push(undo);
|
|
|
|
}
|
|
|
|
}
|
2018-03-11 16:00:58 +00:00
|
|
|
}
|
|
|
|
}
|
2018-05-13 19:03:38 +00:00
|
|
|
|
2020-09-07 22:03:40 +02:00
|
|
|
void DynamicTextFieldEditor::on_m_alignment_pb_clicked()
|
|
|
|
{
|
2020-08-05 09:13:02 +01:00
|
|
|
AlignmentTextDialog atd(m_text_field.data() -> alignment(), this);
|
2018-05-13 19:03:38 +00:00
|
|
|
atd.exec();
|
2020-08-05 09:13:02 +01:00
|
|
|
|
2020-07-15 20:20:07 +02:00
|
|
|
for (int i = 0; i < m_parts.length(); i++) {
|
2020-08-05 09:13:02 +01:00
|
|
|
if(atd.alignment() != m_parts[i] -> alignment()) {
|
|
|
|
QPropertyUndoCommand *undo =\
|
|
|
|
new QPropertyUndoCommand(
|
|
|
|
m_parts[i], "alignment", QVariant(m_parts[i] -> alignment()), QVariant(atd.alignment()));
|
|
|
|
undo -> setText(tr("Modifier l'alignement d'un champ texte"));
|
2020-07-15 20:20:07 +02:00
|
|
|
undoStack().push(undo);
|
|
|
|
}
|
|
|
|
}
|
2018-05-13 19:03:38 +00:00
|
|
|
}
|
2019-03-10 17:58:33 +00:00
|
|
|
|
2020-09-07 22:03:40 +02:00
|
|
|
void DynamicTextFieldEditor::on_m_font_pb_clicked()
|
|
|
|
{
|
2019-03-10 17:58:33 +00:00
|
|
|
bool ok;
|
2020-08-05 09:13:02 +01:00
|
|
|
QFont font_ = QFontDialog::getFont(&ok, m_text_field -> font(), this);
|
|
|
|
if (ok && font_ != this -> font()) {
|
|
|
|
ui -> m_font_pb -> setText(font_.family());
|
|
|
|
ui -> m_size_sb -> setValue(font_.pointSize());
|
|
|
|
|
2020-07-15 20:20:07 +02:00
|
|
|
for (int i = 0; i < m_parts.length(); i++) {
|
2020-08-05 09:13:02 +01:00
|
|
|
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "font", m_parts[i] -> font(), font_);
|
|
|
|
undo -> setText(tr("Modifier la police d'un champ texte"));
|
2020-07-15 20:20:07 +02:00
|
|
|
undoStack().push(undo);
|
|
|
|
}
|
2019-03-10 17:58:33 +00:00
|
|
|
}
|
|
|
|
}
|
2019-03-15 18:07:57 +00:00
|
|
|
|
2020-08-05 09:13:02 +01:00
|
|
|
void DynamicTextFieldEditor::on_m_color_kpb_changed(const QColor &newColor) {
|
|
|
|
if (!newColor.isValid()) {
|
2020-07-15 20:20:07 +02:00
|
|
|
return;
|
2020-08-05 09:13:02 +01:00
|
|
|
}
|
|
|
|
|
2020-07-15 20:20:07 +02:00
|
|
|
for (int i = 0; i < m_parts.length(); i++) {
|
2020-08-05 09:13:02 +01:00
|
|
|
if(newColor != m_parts[i] -> color()) {
|
|
|
|
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "color", m_parts[i] -> color(), newColor);
|
|
|
|
undo -> setText(tr("Modifier la couleur d'un champ texte"));
|
2020-07-15 20:20:07 +02:00
|
|
|
undoStack().push(undo);
|
|
|
|
}
|
|
|
|
}
|
2019-03-15 18:07:57 +00:00
|
|
|
}
|