mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-19 20:44:16 +02:00
34557928d1
Add two realistic drawing styles for the terminal strip plan, besides
the existing schematic one:
- Realistic (push-in) and Realistic (screw): the strip seen from above,
at scale (real width of each terminal), like a cabinet mounting
drawing: end stops, group marker carrier with the strip name, one row
of wire entries per level, bridge channels with red bridges, marker
tags with the terminal number, type symbol (fuse, LED, diode,
sectional, ground...), green/yellow PE and terminal color.
The style is chosen for each plan in the "Add terminal strip plan"
dialog and saved with the item (attribute draw_style of
terminal_strip_item). Items saved before keep the schematic style.
Several plans of the same strip can use different styles.
The values used by the realistic styles are in the layout (scale in
px/mm, terminal length in mm, end stops, group marker) and can be set
in the layout editor, whose style combo box only changes the preview.
Separator plates: a new "Separator plate after" check box column in
the terminal strip editor, stored in the terminal element informations
(key terminal_separator). Drawn as a plate at scale in the realistic
styles and as a thick line in the schematic style.
New files: realisticterminalstripdrawer.{h,cpp} (realistic drawing) and
terminalstripdrawerhelpers.h (helpers shared with the schematic drawer).
323 lines
12 KiB
C++
323 lines
12 KiB
C++
/*
|
|
Copyright 2006-2026 The QElectroTech Team
|
|
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 <QFontDialog>
|
|
|
|
#include <algorithm>
|
|
|
|
#include "terminalstriplayouteditor.h"
|
|
#include "ui_terminalstriplayouteditor.h"
|
|
#include "../GraphicsItem/properties/terminalstriplayoutpattern.h"
|
|
|
|
TerminalStripLayoutEditor::TerminalStripLayoutEditor(QSharedPointer<TerminalStripLayoutPattern> layout,
|
|
QWidget *parent) :
|
|
QWidget{ parent },
|
|
ui{ new Ui::TerminalStripLayoutEditor },
|
|
m_layout{ layout }
|
|
{
|
|
ui->setupUi(this);
|
|
ui->m_graphics_view->setScene(new QGraphicsScene{ this });
|
|
// The preview is printed output: black ink on a white page, whatever
|
|
// the application palette.
|
|
ui->m_graphics_view->setBackgroundBrush(Qt::white);
|
|
ui->m_graphics_view->scene()->addItem(&m_preview_strip_item);
|
|
|
|
//Drawing style
|
|
//The style is chosen for each item when it is added to a folio,
|
|
//here it only change the preview, to see the values of each style.
|
|
connect(ui->m_draw_style_cb, &QComboBox::currentIndexChanged, this, [this](int index) {
|
|
m_preview_strip_item.prepareGeometryChange();
|
|
m_preview_strip_item.m_drawer.setDrawStyle(
|
|
static_cast<TerminalStripLayoutPattern::DrawStyle>(std::clamp(index, 0, 2)));
|
|
m_preview_strip_item.update();
|
|
updatePreview();
|
|
});
|
|
connect(ui->m_realistic_scale_sb, &QDoubleSpinBox::valueChanged,
|
|
this, &TerminalStripLayoutEditor::valueEdited);
|
|
connect(ui->m_realistic_length_sb, &QSpinBox::valueChanged,
|
|
this, &TerminalStripLayoutEditor::valueEdited);
|
|
connect(ui->m_realistic_end_stops_cb, &QCheckBox::toggled,
|
|
this, &TerminalStripLayoutEditor::valueEdited);
|
|
connect(ui->m_realistic_group_marker_cb, &QCheckBox::toggled,
|
|
this, &TerminalStripLayoutEditor::valueEdited);
|
|
|
|
updateUi();
|
|
}
|
|
|
|
TerminalStripLayoutEditor::~TerminalStripLayoutEditor()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
void TerminalStripLayoutEditor::resizeEvent(QResizeEvent *event)
|
|
{
|
|
QWidget::resizeEvent(event);
|
|
updatePreview();
|
|
}
|
|
|
|
void TerminalStripLayoutEditor::showEvent(QShowEvent *event)
|
|
{
|
|
QWidget::showEvent(event);
|
|
updatePreview();
|
|
}
|
|
|
|
void TerminalStripLayoutEditor::valueEdited()
|
|
{
|
|
if (!m_layout || m_ui_updating) {
|
|
return;
|
|
}
|
|
|
|
m_layout.data()->m_header_rect.setRect(0,
|
|
ui->m_y_header_sb->value(),
|
|
ui->m_width_header_sb->value(),
|
|
ui->m_height_header_sb->value());
|
|
|
|
m_layout.data()->m_spacer_rect.setRect(0,
|
|
ui->m_y_spacer_sb->value(),
|
|
ui->m_width_spacer_sb->value(),
|
|
ui->m_height_spacer_sb->value());
|
|
|
|
m_layout.data()->m_terminal_rect[0].setRect(0,
|
|
ui->m_y_terminal_0_sb->value(),
|
|
ui->m_width_terminal_0_sb->value(),
|
|
ui->m_height_terminal_0_sb->value());
|
|
|
|
m_layout.data()->m_terminal_rect[1].setRect(0,
|
|
ui->m_y_terminal_1_sb->value(),
|
|
ui->m_width_terminal_1_sb->value(),
|
|
ui->m_height_terminal_1_sb->value());
|
|
|
|
m_layout.data()->m_terminal_rect[2].setRect(0,
|
|
ui->m_y_terminal_2_sb->value(),
|
|
ui->m_width_terminal_2_sb->value(),
|
|
ui->m_height_terminal_2_sb->value());
|
|
|
|
m_layout.data()->m_terminal_rect[3].setRect(0,
|
|
ui->m_y_terminal_3_sb->value(),
|
|
ui->m_width_terminal_3_sb->value(),
|
|
ui->m_height_terminal_3_sb->value());
|
|
|
|
m_layout.data()->m_bridge_point_y_offset[0] = ui->m_bridge_point_0_sb->value();
|
|
m_layout.data()->m_bridge_point_y_offset[1] = ui->m_bridge_point_1_sb->value();
|
|
m_layout.data()->m_bridge_point_y_offset[2] = ui->m_bridge_point_2_sb->value();
|
|
m_layout.data()->m_bridge_point_y_offset[3] = ui->m_bridge_point_3_sb->value();
|
|
|
|
auto font_ = ui->m_font_cb->currentFont();
|
|
font_.setPixelSize(ui->m_font_size_sb->value());
|
|
m_layout->setFont(font_);
|
|
|
|
m_layout.data()->m_header_text_orientation = ui->m_header_text_orientation_cb->currentIndex() == 0 ?
|
|
Qt::Horizontal :
|
|
Qt::Vertical;
|
|
|
|
switch (ui->m_header_text_alignment_cb->currentIndex()) {
|
|
case 0:
|
|
m_layout.data()->setHeaderTextAlignment(Qt::AlignLeft | Qt::AlignVCenter); break;
|
|
case 1:
|
|
m_layout.data()->setHeaderTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter); break;
|
|
default:
|
|
m_layout.data()->setHeaderTextAlignment(Qt::AlignRight | Qt::AlignVCenter); break;
|
|
}
|
|
|
|
//Terminal text
|
|
m_layout.data()->m_terminals_text_orientation = ui->m_terminal_text_orientation_cb->currentIndex() == 0 ?
|
|
Qt::Horizontal :
|
|
Qt::Vertical;
|
|
|
|
switch (ui->m_terminal_text_alignment_cb->currentIndex()) {
|
|
case 0:
|
|
m_layout.data()->setTerminalsTextAlignment(Qt::Alignment {Qt::AlignLeft | Qt::AlignVCenter});
|
|
break;
|
|
case 1:
|
|
m_layout.data()->setTerminalsTextAlignment(Qt::Alignment { Qt::AlignHCenter | Qt::AlignVCenter});
|
|
break;
|
|
default:
|
|
m_layout.data()->setTerminalsTextAlignment(Qt::Alignment { Qt::AlignRight | Qt::AlignVCenter});
|
|
break;
|
|
}
|
|
|
|
m_layout.data()->m_terminals_text_y = ui->m_terminal_text_y_sb->value();
|
|
m_layout.data()->m_terminals_text_height = ui->m_terminal_text_height_sb->value();
|
|
|
|
//Xref text
|
|
m_layout.data()->m_xref_text_orientation = ui->m_xref_orientation_cb->currentIndex() == 0 ?
|
|
Qt::Horizontal :
|
|
Qt::Vertical;
|
|
|
|
switch (ui->m_xref_alignment_cb->currentIndex()) {
|
|
case 0:
|
|
m_layout.data()->setXrefTextAlignment(Qt::Alignment {Qt::AlignLeft | Qt::AlignVCenter});
|
|
break;
|
|
case 1:
|
|
m_layout.data()->setXrefTextAlignment(Qt::Alignment { Qt::AlignHCenter | Qt::AlignVCenter});
|
|
break;
|
|
default:
|
|
m_layout.data()->setXrefTextAlignment(Qt::Alignment { Qt::AlignRight | Qt::AlignVCenter});
|
|
break;
|
|
}
|
|
|
|
m_layout.data()->m_xref_text_y = ui->m_xref_y_sb->value();
|
|
m_layout.data()->m_xref_text_height = ui->m_xref_height_sb->value();
|
|
|
|
//Terminal type symbol
|
|
m_layout.data()->m_type_symbol_y = ui->m_type_symbol_y_sb->value();
|
|
m_layout.data()->m_type_symbol_height = ui->m_type_symbol_height_sb->value();
|
|
m_layout.data()->m_connection_length = ui->m_connection_length_sb->value();
|
|
m_layout.data()->m_cable_wire_length = ui->m_cable_wire_length_sb->value();
|
|
m_layout.data()->m_cable_length = ui->m_cable_length_sb->value();
|
|
m_layout.data()->m_cable_end_length = ui->m_cable_end_length_sb->value();
|
|
|
|
//Values of the realistic styles
|
|
m_layout.data()->m_realistic_px_per_mm = ui->m_realistic_scale_sb->value();
|
|
m_layout.data()->m_realistic_length_mm = ui->m_realistic_length_sb->value();
|
|
m_layout.data()->m_realistic_end_stops = ui->m_realistic_end_stops_cb->isChecked();
|
|
m_layout.data()->m_realistic_group_marker = ui->m_realistic_group_marker_cb->isChecked();
|
|
|
|
updateUi();
|
|
m_preview_strip_item.update();
|
|
}
|
|
|
|
void TerminalStripLayoutEditor::updateUi()
|
|
{
|
|
if (!m_layout) {
|
|
return;
|
|
}
|
|
|
|
const auto data = m_layout.data();
|
|
|
|
m_ui_updating = true;
|
|
|
|
ui->m_y_header_sb->setValue(data->m_header_rect.y());
|
|
ui->m_width_header_sb->setValue(data->m_header_rect.width());
|
|
ui->m_height_header_sb->setValue(data->m_header_rect.height());
|
|
|
|
ui->m_y_spacer_sb->setValue(data->m_spacer_rect.y());
|
|
ui->m_width_spacer_sb->setValue(data->m_spacer_rect.width());
|
|
ui->m_height_spacer_sb->setValue(data->m_spacer_rect.height());
|
|
|
|
const auto terminal_0 = data->m_terminal_rect[0];
|
|
ui->m_y_terminal_0_sb->setValue(terminal_0.y());
|
|
ui->m_height_terminal_0_sb->setValue(terminal_0.height());
|
|
ui->m_width_terminal_0_sb->setValue(terminal_0.width());
|
|
|
|
const auto terminal_1 = data->m_terminal_rect[1];
|
|
ui->m_y_terminal_1_sb->setValue(terminal_1.y());
|
|
ui->m_height_terminal_1_sb->setValue(terminal_1.height());
|
|
ui->m_width_terminal_1_sb->setValue(terminal_1.width());
|
|
|
|
const auto terminal_2 = data->m_terminal_rect[2];
|
|
ui->m_y_terminal_2_sb->setValue(terminal_2.y());
|
|
ui->m_height_terminal_2_sb->setValue(terminal_2.height());
|
|
ui->m_width_terminal_2_sb->setValue(terminal_2.width());
|
|
|
|
const auto terminal_3 = data->m_terminal_rect[3];
|
|
ui->m_y_terminal_3_sb->setValue(terminal_3.y());
|
|
ui->m_height_terminal_3_sb->setValue(terminal_3.height());
|
|
ui->m_width_terminal_3_sb->setValue(terminal_3.width());
|
|
|
|
const auto bridge_point = data->m_bridge_point_y_offset;
|
|
ui->m_bridge_point_0_sb->setValue(bridge_point[0]);
|
|
ui->m_bridge_point_1_sb->setValue(bridge_point[1]);
|
|
ui->m_bridge_point_2_sb->setValue(bridge_point[2]);
|
|
ui->m_bridge_point_3_sb->setValue(bridge_point[3]);
|
|
|
|
const auto font = m_layout->font();
|
|
ui->m_font_size_sb->setValue(font.pixelSize());
|
|
ui->m_font_cb->setCurrentFont(font);
|
|
|
|
if (data->m_header_text_orientation == Qt::Horizontal) {
|
|
ui->m_header_text_orientation_cb->setCurrentIndex(0);
|
|
} else {
|
|
ui->m_header_text_orientation_cb->setCurrentIndex(1);
|
|
}
|
|
|
|
if (data->m_terminals_text_orientation == Qt::Horizontal) {
|
|
ui->m_terminal_text_orientation_cb->setCurrentIndex(0);
|
|
} else {
|
|
ui->m_terminal_text_orientation_cb->setCurrentIndex(1);
|
|
}
|
|
|
|
const auto header_alignment = data->headerTextAlignment();
|
|
if (header_alignment &Qt::AlignLeft) {
|
|
ui->m_header_text_alignment_cb->setCurrentIndex(0);
|
|
} else if (header_alignment &Qt::AlignHCenter) {
|
|
ui->m_header_text_alignment_cb->setCurrentIndex(1);
|
|
} else if (header_alignment &Qt::AlignRight) {
|
|
ui->m_header_text_alignment_cb->setCurrentIndex(2);
|
|
}
|
|
|
|
//Terminal text
|
|
const auto terminal_alignment = data->terminalsTextAlignment();
|
|
if (terminal_alignment &Qt::AlignLeft) {
|
|
ui->m_terminal_text_alignment_cb->setCurrentIndex(0);
|
|
} else if (terminal_alignment &Qt::AlignHCenter) {
|
|
ui->m_terminal_text_alignment_cb->setCurrentIndex(1);
|
|
} else if (terminal_alignment &Qt::AlignRight) {
|
|
ui->m_terminal_text_alignment_cb->setCurrentIndex(2);
|
|
}
|
|
|
|
ui->m_terminal_text_y_sb->setValue(data->m_terminals_text_y);
|
|
ui->m_terminal_text_height_sb->setValue(data->m_terminals_text_height);
|
|
|
|
//Xref text
|
|
if (data->m_xref_text_orientation == Qt::Horizontal) {
|
|
ui->m_xref_orientation_cb->setCurrentIndex(0);
|
|
} else {
|
|
ui->m_xref_orientation_cb->setCurrentIndex(1);
|
|
}
|
|
|
|
const auto xref_alignment = data->xrefTextAlignment();
|
|
if (xref_alignment &Qt::AlignLeft) {
|
|
ui->m_xref_alignment_cb->setCurrentIndex(0);
|
|
} else if (xref_alignment &Qt::AlignHCenter) {
|
|
ui->m_xref_alignment_cb->setCurrentIndex(1);
|
|
} else if (xref_alignment &Qt::AlignRight) {
|
|
ui->m_xref_alignment_cb->setCurrentIndex(2);
|
|
}
|
|
|
|
ui->m_xref_y_sb->setValue(data->m_xref_text_y);
|
|
ui->m_xref_height_sb->setValue(data->m_xref_text_height);
|
|
|
|
ui->m_type_symbol_y_sb->setValue(data->m_type_symbol_y);
|
|
ui->m_type_symbol_height_sb->setValue(data->m_type_symbol_height);
|
|
ui->m_connection_length_sb->setValue(data->m_connection_length);
|
|
ui->m_cable_wire_length_sb->setValue(data->m_cable_wire_length);
|
|
ui->m_cable_length_sb->setValue(data->m_cable_length);
|
|
ui->m_cable_end_length_sb->setValue(data->m_cable_end_length);
|
|
|
|
//Values of the realistic styles
|
|
ui->m_realistic_scale_sb->setValue(data->m_realistic_px_per_mm);
|
|
ui->m_realistic_length_sb->setValue(qRound(data->m_realistic_length_mm));
|
|
ui->m_realistic_end_stops_cb->setChecked(data->m_realistic_end_stops);
|
|
ui->m_realistic_group_marker_cb->setChecked(data->m_realistic_group_marker);
|
|
|
|
m_ui_updating = false;
|
|
updatePreview();
|
|
}
|
|
|
|
void TerminalStripLayoutEditor::updatePreview()
|
|
{
|
|
ui->m_graphics_view->fitInView(m_preview_strip_item.boundingRect().adjusted(-5,-5,5,5),
|
|
Qt::KeepAspectRatio);
|
|
}
|
|
|
|
void TerminalStripLayoutEditor::on_m_display_preview_help_clicked(bool checked)
|
|
{
|
|
m_preview_strip_item.m_drawer.setPreviewDraw(checked);
|
|
m_preview_strip_item.update();
|
|
}
|