Merge branch 'master' into qt6_cmake_joshua

This commit is contained in:
joshua
2026-07-31 21:15:21 +02:00
parent f16cf7dac8
commit e6d29cf345
297 changed files with 82691 additions and 27463 deletions
+333 -1
View File
@@ -21,6 +21,12 @@
#include "../../qet.h"
#include "../graphicspart/partterminal.h"
#include "../../QPropertyUndoCommand/qpropertyundocommand.h"
#include "../../ui/alignmenttextdialog.h"
#include <QColorDialog>
#include <QFontDialog>
#include "../elementscene.h"
#include "qetelementeditor.h"
/**
* @brief TerminalEditor::TerminalEditor
@@ -33,6 +39,22 @@ TerminalEditor::TerminalEditor(QETElementEditor *editor, QWidget *parent) :
ui(new Ui::TerminalEditor)
{
ui->setupUi(this);
#ifdef BUILD_WITHOUT_KF5
m_color_pb = new QPushButton(this);
m_color_pb->setMinimumSize(40, 24);
connect(m_color_pb, &QPushButton::clicked, this, &TerminalEditor::labelColorClicked);
#else
m_color_pb = new KColorButton(this);
m_color_pb->setMinimumSize(40, 24);
connect(m_color_pb, &KColorButton::changed, this, &TerminalEditor::labelColorClicked);
#endif
QLayout *layout = ui->m_color_widget->parentWidget()->layout();
layout->replaceWidget(ui->m_color_widget, m_color_pb);
delete ui->m_color_widget;
ui->m_color_widget = nullptr;
init();
}
@@ -63,6 +85,44 @@ void TerminalEditor::updateForm()
ui->m_name_le->setText(m_part->terminalName());
ui->m_type_cb->setCurrentIndex(ui->m_type_cb->findData(m_part->terminalType()));
ui->m_show_name_cb->setChecked(m_part->showName());
ui->m_label_x_dsb->setValue(m_part->labelPos().x());
ui->m_label_y_dsb->setValue(m_part->labelPos().y());
ui->m_font_pb->setText(m_part->labelFont().family());
ui->m_label_size_sb->setValue(m_part->labelFont().pointSize());
ui->m_label_rotation_sb->setValue(static_cast<int>(m_part->labelRotation()));
ui->m_label_frame_cb->setChecked(m_part->labelFrame());
#ifdef BUILD_WITHOUT_KF5
QPixmap px(16, 16);
px.fill(m_part->labelColor());
m_color_pb->setIcon(QIcon(px));
#else
m_color_pb->setColor(m_part->labelColor());
#endif
ui->m_text_props_gb->setEnabled(m_part->showName());
// Update master label fields
bool is_slave = updateMasterLabelVisibility();
if (is_slave) {
PartTerminal *pt = m_part;
if (pt) {
ui->m_use_master_label_cb->setChecked(pt->useMasterLabel());
ui->m_master_label_cb->setEnabled(pt->useMasterLabel());
ui->m_name_le->setEnabled(!pt->useMasterLabel());
int idx = ui->m_master_label_cb->findData(pt->masterLabelIndex());
if (idx >= 0) {
ui->m_master_label_cb->setCurrentIndex(idx);
}
// Show T-label in name field when master label is active
if (pt->useMasterLabel()) {
int label_idx = pt->masterLabelIndex();
ui->m_name_le->setText(tr("T%1").arg(label_idx + 1));
}
}
}
activeConnections(true);
}
@@ -125,6 +185,16 @@ void TerminalEditor::init()
ui->m_type_cb->addItem(tr("NO (contact SW)"), TerminalData::No);
ui->m_type_cb->addItem(tr("NC (contact SW)"), TerminalData::Nc);
ui->m_type_cb->addItem(tr("Commun (contact SW)"), TerminalData::Common);
ui->m_text_props_gb->setEnabled(false);
// Populate master label dropdown (T1-T20)
for (int i = 1; i <= 20; ++i) {
ui->m_master_label_cb->addItem(tr("T%1").arg(i), i - 1);
}
// Check if parent element is a Slave to show/hide master label group
updateMasterLabelVisibility();
}
/**
@@ -218,6 +288,146 @@ void TerminalEditor::typeEdited()
* and method of this class.
* @param active
*/
void TerminalEditor::showNameEdited()
{
if (m_locked) return;
m_locked = true;
bool show = ui->m_show_name_cb->isChecked();
if (m_part->showName() != show) {
auto undo = new QPropertyUndoCommand(m_part, "show_name", m_part->showName(), show);
undo->setText(tr("Afficher/cacher le nom du terminal"));
undoStack().push(undo);
}
ui->m_text_props_gb->setEnabled(show);
m_locked = false;
}
void TerminalEditor::labelPosEdited()
{
if (m_locked) return;
m_locked = true;
QPointF new_pos(ui->m_label_x_dsb->value(), ui->m_label_y_dsb->value());
if (m_part->labelPos() != new_pos) {
auto undo = new QPropertyUndoCommand(m_part, "label_pos", m_part->labelPos(), new_pos);
undo->setText(tr("Modifier la position du label"));
undoStack().push(undo);
}
m_locked = false;
}
void TerminalEditor::labelFontClicked()
{
if (m_locked) return;
m_locked = true;
bool ok;
QFont font = QFontDialog::getFont(&ok, m_part->labelFont(), this);
if (ok && font != m_part->labelFont()) {
ui->m_font_pb->setText(font.family());
ui->m_label_size_sb->blockSignals(true);
ui->m_label_size_sb->setValue(font.pointSize());
ui->m_label_size_sb->blockSignals(false);
auto undo = new QPropertyUndoCommand(m_part, "label_font", m_part->labelFont(), font);
undo->setText(tr("Modifier la police du label"));
undoStack().push(undo);
}
m_locked = false;
}
void TerminalEditor::labelSizeEdited()
{
if (m_locked) return;
m_locked = true;
QFont new_font = m_part->labelFont();
new_font.setPointSize(ui->m_label_size_sb->value());
if (m_part->labelFont() != new_font) {
auto undo = new QPropertyUndoCommand(m_part, "label_font", m_part->labelFont(), new_font);
undo->setText(tr("Modifier la taille de police du label"));
undoStack().push(undo);
}
m_locked = false;
}
void TerminalEditor::labelRotationEdited()
{
if (m_locked) return;
m_locked = true;
qreal rot = static_cast<qreal>(ui->m_label_rotation_sb->value());
if (!qFuzzyCompare(m_part->labelRotation(), rot)) {
auto undo = new QPropertyUndoCommand(m_part, "label_rotation", m_part->labelRotation(), rot);
undo->setText(tr("Modifier la rotation du label"));
undoStack().push(undo);
}
m_locked = false;
}
void TerminalEditor::labelAlignClicked()
{
Qt::Alignment align = m_part->labelHAlignment() | m_part->labelVAlignment();
AlignmentTextDialog dialog(align, this);
if (dialog.exec() == QDialog::Accepted) {
Qt::Alignment new_align = dialog.alignment();
Qt::Alignment new_h = new_align & Qt::AlignHorizontal_Mask;
Qt::Alignment new_v = new_align & Qt::AlignVertical_Mask;
if (new_h != m_part->labelHAlignment()) {
auto undo = new QPropertyUndoCommand(m_part, "label_halignment",
QVariant::fromValue(m_part->labelHAlignment()), QVariant::fromValue(new_h));
undo->setText(tr("Modifier l'alignement du label"));
undoStack().push(undo);
}
if (new_v != m_part->labelVAlignment()) {
auto undo = new QPropertyUndoCommand(m_part, "label_valignment",
QVariant::fromValue(m_part->labelVAlignment()), QVariant::fromValue(new_v));
undo->setText(tr("Modifier l'alignement du label"));
undoStack().push(undo);
}
}
}
void TerminalEditor::labelFrameEdited()
{
if (m_locked) return;
m_locked = true;
bool frame = ui->m_label_frame_cb->isChecked();
if (m_part->labelFrame() != frame) {
auto undo = new QPropertyUndoCommand(m_part, "label_frame", m_part->labelFrame(), frame);
undo->setText(tr("Afficher/cacher le cadre du label"));
undoStack().push(undo);
}
m_locked = false;
}
void TerminalEditor::labelColorClicked()
{
if (m_locked) return;
m_locked = true;
#ifdef BUILD_WITHOUT_KF5
QColor new_color = QColorDialog::getColor(m_part->labelColor(), this);
if (new_color.isValid() && m_part->labelColor() != new_color) {
auto undo = new QPropertyUndoCommand(m_part, "label_color", m_part->labelColor(), new_color);
undo->setText(tr("Modifier la couleur du label"));
undoStack().push(undo);
}
#else
QColor new_color = m_color_pb->color();
if (new_color.isValid() && m_part->labelColor() != new_color) {
auto undo = new QPropertyUndoCommand(m_part, "label_color", m_part->labelColor(), new_color);
undo->setText(tr("Modifier la couleur du label"));
undoStack().push(undo);
}
#endif
m_locked = false;
}
void TerminalEditor::activeConnections(bool active)
{
if (active) {
@@ -231,8 +441,28 @@ void TerminalEditor::activeConnections(bool active)
this, &TerminalEditor::nameEdited);
m_editor_connections << connect(ui->m_type_cb, QOverload<int>::of(&QComboBox::activated),
this, &TerminalEditor::typeEdited);
m_editor_connections << connect(ui->m_show_name_cb, &QCheckBox::toggled,
this, &TerminalEditor::showNameEdited);
m_editor_connections << connect(ui->m_label_x_dsb, QOverload<qreal>::of(&QDoubleSpinBox::valueChanged),
[this]() { TerminalEditor::labelPosEdited(); ui->m_label_x_dsb->setFocus(); });
m_editor_connections << connect(ui->m_label_y_dsb, QOverload<qreal>::of(&QDoubleSpinBox::valueChanged),
[this]() { TerminalEditor::labelPosEdited(); ui->m_label_y_dsb->setFocus(); });
m_editor_connections << connect(ui->m_font_pb, &QPushButton::clicked,
this, &TerminalEditor::labelFontClicked);
m_editor_connections << connect(ui->m_label_size_sb, QOverload<int>::of(&QSpinBox::valueChanged),
[this]() { TerminalEditor::labelSizeEdited(); ui->m_label_size_sb->setFocus(); });
m_editor_connections << connect(ui->m_label_rotation_sb, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
[this]() { TerminalEditor::labelRotationEdited(); ui->m_label_rotation_sb->setFocus(); });
m_editor_connections << connect(ui->m_align_pb, &QPushButton::clicked,
this, &TerminalEditor::labelAlignClicked);
m_editor_connections << connect(ui->m_label_frame_cb, &QCheckBox::toggled,
this, &TerminalEditor::labelFrameEdited);
m_editor_connections << connect(ui->m_use_master_label_cb, &QCheckBox::toggled,
this, &TerminalEditor::useMasterLabelEdited);
m_editor_connections << connect(ui->m_master_label_cb, QOverload<int>::of(&QComboBox::activated),
this, &TerminalEditor::masterLabelIndexEdited);
} else {
for (auto const & con : qAsConst(m_editor_connections)) {
for (auto const & con : std::as_const(m_editor_connections)) {
QObject::disconnect(con);
}
m_editor_connections.clear();
@@ -248,6 +478,16 @@ void TerminalEditor::activeChangeConnections(bool active)
m_change_connections << connect(m_part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm);
m_change_connections << connect(m_part, &PartTerminal::nameChanged, this, &TerminalEditor::updateForm);
m_change_connections << connect(m_part, &PartTerminal::terminalTypeChanged, this, &TerminalEditor::updateForm);
m_change_connections << connect(m_part, &PartTerminal::showNameChanged, this, &TerminalEditor::updateForm);
m_change_connections << connect(m_part, &PartTerminal::labelPosChanged, this, &TerminalEditor::updateForm);
m_change_connections << connect(m_part, &PartTerminal::labelFontChanged, this, &TerminalEditor::updateForm);
m_change_connections << connect(m_part, &PartTerminal::labelRotationChanged, this, &TerminalEditor::updateForm);
m_change_connections << connect(m_part, &PartTerminal::labelHAlignmentChanged, this, &TerminalEditor::updateForm);
m_change_connections << connect(m_part, &PartTerminal::labelVAlignmentChanged, this, &TerminalEditor::updateForm);
m_change_connections << connect(m_part, &PartTerminal::labelFrameChanged, this, &TerminalEditor::updateForm);
m_change_connections << connect(m_part, &PartTerminal::labelColorChanged, this, &TerminalEditor::updateForm);
m_change_connections << connect(m_part, &PartTerminal::useMasterLabelChanged, this, &TerminalEditor::updateForm);
m_change_connections << connect(m_part, &PartTerminal::masterLabelIndexChanged, this, &TerminalEditor::updateForm);
} else {
for (auto &con : m_change_connections) {
QObject::disconnect(con);
@@ -255,3 +495,95 @@ void TerminalEditor::activeChangeConnections(bool active)
m_change_connections.clear();
}
}
void TerminalEditor::useMasterLabelEdited()
{
if (m_locked) return;
m_locked = true;
bool use = ui->m_use_master_label_cb->isChecked();
ui->m_master_label_cb->setEnabled(use);
QSignalBlocker name_blocker(ui->m_name_le);
if (m_part->useMasterLabel() != use) {
auto undo = new QPropertyUndoCommand(m_part, "use_master_label",
m_part->useMasterLabel(), use);
undo->setText(tr("Modifier l'étiquette du maître"));
undoStack().push(undo);
}
if (use) {
int idx = ui->m_master_label_cb->currentData().toInt();
QString t_label = tr("T%1").arg(idx + 1);
ui->m_name_le->setText(t_label);
ui->m_name_le->setEnabled(false);
if (m_part->terminalName() != t_label) {
auto undo = new QPropertyUndoCommand(m_part, "terminal_name",
m_part->terminalName(), t_label);
undo->setText(tr("Modifier le nom de la borne"));
undoStack().push(undo);
}
} else {
ui->m_name_le->setEnabled(true);
if (!m_part->terminalName().isEmpty()) {
auto undo = new QPropertyUndoCommand(m_part, "terminal_name",
m_part->terminalName(), QString());
undo->setText(tr("Modifier le nom de la borne"));
undoStack().push(undo);
}
ui->m_name_le->clear();
}
m_locked = false;
}
void TerminalEditor::masterLabelIndexEdited()
{
if (m_locked) return;
m_locked = true;
int idx = ui->m_master_label_cb->currentData().toInt();
if (m_part->masterLabelIndex() != idx) {
auto undo = new QPropertyUndoCommand(m_part, "master_label_index",
m_part->masterLabelIndex(), idx);
undo->setText(tr("Modifier l'index de l'étiquette du maître"));
undoStack().push(undo);
}
if (ui->m_use_master_label_cb->isChecked()) {
QString t_label = tr("T%1").arg(idx + 1);
ui->m_name_le->setText(t_label);
if (m_part->terminalName() != t_label) {
auto undo = new QPropertyUndoCommand(m_part, "terminal_name",
m_part->terminalName(), t_label);
undo->setText(tr("Modifier le nom de la borne"));
undoStack().push(undo);
}
}
m_locked = false;
}
bool TerminalEditor::updateMasterLabelVisibility()
{
QETElementEditor *editor = elementEditor();
if (!editor || !editor->elementScene()) {
ui->m_master_label_gb->setVisible(false);
return false;
}
ElementData data = editor->elementScene()->elementData();
bool is_slave = (data.m_type == ElementData::Slave);
ui->m_master_label_gb->setVisible(is_slave);
return is_slave;
}
void TerminalEditor::refreshMasterLabelVisibility()
{
updateMasterLabelVisibility();
if (m_part) {
updateForm();
}
}