QElectroTech  0.70
conductorpropertieswidget.cpp
Go to the documentation of this file.
1 /*
2  Copyright 2006-2019 The QElectroTech Team
3  This file is part of QElectroTech.
4 
5  QElectroTech is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 2 of the License, or
8  (at your option) any later version.
9 
10  QElectroTech is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
17 */
19 #include "ui_conductorpropertieswidget.h"
20 #include "conductorproperties.h"
21 #include "qetapp.h"
23 
30  QWidget(parent),
32 {
33  ui->setupUi(this);
34  initWidget();
35 }
36 
37 
38 
39 
47  QWidget(parent),
49 {
50  ui -> setupUi(this);
51  initWidget();
53 }
54 
60 {
61  delete ui;
62 }
63 
70 {
71  if (m_properties == properties)
72  return;
73 
75 
76  int index = ui -> m_line_style_cb -> findData(QPen(m_properties.style));
77  if (index != -1) ui -> m_line_style_cb -> setCurrentIndex(index);
78 
79  ui->m_color_2_gb -> setChecked (m_properties.m_bicolor);
80  ui->m_dash_size_sb -> setValue (m_properties.m_dash_size);
81  ui->m_formula_le -> setText (m_properties.m_formula);
82  ui->m_text_le -> setText (m_properties.text);
83  ui->m_function_le -> setText (m_properties.m_function);
84  ui->m_tension_protocol_le -> setText (m_properties.m_tension_protocol);
85  ui->m_text_size_sb -> setValue (m_properties.text_size);
86  ui->m_cond_size_sb -> setValue (m_properties.cond_size);
87  ui->m_show_text_cb -> setChecked (m_properties.m_show_text);
88  ui->m_one_text_per_folio_cb -> setChecked (m_properties.m_one_text_per_folio);
89  ui->m_earth_cb -> setChecked (m_properties.singleLineProperties.hasGround);
90  ui->m_neutral_cb -> setChecked (m_properties.singleLineProperties.hasNeutral);
91  ui->m_pen_cb -> setChecked (m_properties.singleLineProperties.isPen());
92  ui->m_phase_cb -> setChecked (m_properties.singleLineProperties.phasesCount());
93  ui->m_phase_slider -> setValue (m_properties.singleLineProperties.phasesCount());
94  ui->m_color_kpb -> setColor(m_properties.color);
95  ui->m_color_2_kpb -> setColor(m_properties.m_color_2);
96 
97  ui->m_horiz_cb->setCurrentIndex(m_properties.m_horizontal_alignment == Qt::AlignTop? 0 : 1);
98  ui->m_verti_cb->setCurrentIndex(m_properties.m_vertical_alignment == Qt::AlignLeft? 0 : 1);
101 
103  updatePreview(false);
104 }
105 
111 {
112  ConductorProperties properties_;
113  if (ui -> m_multiwires_gb -> isChecked()) properties_.type = ConductorProperties::Multi;
114  else if (ui -> m_singlewire_gb -> isChecked()) properties_.type = ConductorProperties::Single;
115 
116  properties_.color = ui -> m_color_kpb->color();
117  properties_.m_bicolor = ui->m_color_2_gb->isChecked();
118  properties_.m_color_2 = ui->m_color_2_kpb->color();
119  properties_.m_dash_size = ui->m_dash_size_sb->value();
120  properties_.style = ui -> m_line_style_cb->itemData(ui->m_line_style_cb->currentIndex()).value<QPen>().style();
121  properties_.m_formula = ui->m_formula_le->text();
122  properties_.text = ui -> m_text_le -> text();
123  properties_.m_function = ui -> m_function_le->text();
124  properties_.m_tension_protocol = ui -> m_tension_protocol_le->text();
125  properties_.text_size = ui -> m_text_size_sb -> value();
126  properties_.cond_size = ui -> m_cond_size_sb -> value();
127  properties_.m_show_text = ui -> m_show_text_cb -> isChecked();
128  properties_.m_one_text_per_folio = ui -> m_one_text_per_folio_cb -> isChecked();
129  properties_.verti_rotate_text = m_verti_select -> value();
130  properties_.horiz_rotate_text = m_horiz_select -> value();
131  properties_.m_vertical_alignment = ui->m_verti_cb->currentIndex() == 0? Qt::AlignLeft : Qt::AlignRight;
132  properties_.m_horizontal_alignment = ui->m_horiz_cb->currentIndex() == 0? Qt::AlignTop : Qt::AlignBottom;
133 
134  properties_.singleLineProperties.hasGround = ui -> m_earth_cb -> isChecked();
135  properties_.singleLineProperties.hasNeutral = ui -> m_neutral_cb -> isChecked();
136  properties_.singleLineProperties.is_pen = ui -> m_pen_cb -> isChecked();
137  properties_.singleLineProperties.setPhasesCount(ui -> m_phase_cb -> isChecked() ? ui -> m_phase_sb -> value() : 0);
138 
139  return properties_;
140 }
141 
148 {
149  if (event->type() == QEvent::WindowActivate) {
150  ui -> m_formula_le -> setFocus();
151  }
152  return(QWidget::event(event));
153 }
154 
155 
161  this->setDisabled(ro);
162 }
163 
169  ui->m_autonum_layout->addWidget(widget);
170 }
171 
177  ui -> m_one_text_per_folio_cb -> setHidden(hide);
178 }
179 
185  ui->m_show_text_cb->setDisabled(disable==true? true : false);
186 }
187 
194 {
195  ui->m_autonum_label->setHidden(hide);
196  ui->m_available_autonum_cb->setHidden(hide);
197  ui->m_edit_autonum_pb->setHidden(hide);
198 }
199 
201 {
202  return ui->m_available_autonum_cb;
203 }
204 
206 {
207  return ui->m_edit_autonum_pb;
208 }
209 
215  ui -> m_text_angle_gl -> addWidget(m_verti_select, 2, 0, Qt::AlignHCenter);
217  ui -> m_text_angle_gl -> addWidget(m_horiz_select, 2, 1, Qt::AlignHCenter);
218 
219  ui -> m_line_style_cb -> addItem(tr("Trait plein", "conductor style: solid line"), QPen(Qt::SolidLine));
220  ui -> m_line_style_cb -> addItem(tr("Trait en pointillés", "conductor style: dashed line"), QPen(Qt::DashLine));
221  ui -> m_line_style_cb -> addItem(tr("Traits et points", "conductor style: dashed and dotted line"), QPen(Qt::DashDotLine));
222 
223  ui -> m_update_preview_pb -> setHidden(true);
224 
225  connect(ui->m_multiwires_gb, &QGroupBox::toggled, [this](bool toggle) {this->ui->m_singlewire_gb->setChecked(!toggle);});
226  connect(ui->m_singlewire_gb, &QGroupBox::toggled, [this](bool toggle) {this->ui->m_multiwires_gb->setChecked(!toggle);});
227  connect(ui->m_formula_le, &QLineEdit::textChanged, [this](QString text) {this->ui->m_text_le->setEnabled(text.isEmpty());});
228  ui->m_multiwires_gb->setChecked(true);
229  ui->m_singlewire_gb->setChecked(true);
230 }
231 
238  switch (type) {
240  ui -> m_multiwires_gb -> setChecked(true);
241  break;
243  ui -> m_singlewire_gb -> setChecked(true);
244  break;
245  default:
246  ui -> m_multiwires_gb -> setChecked(true);
247  break;
248  }
249 }
250 
258  const QRect pixmap_rect(0, 0, 96, 96);
259  QPixmap pixmap(pixmap_rect.width(), pixmap_rect.height());
260  QPainter painter;
261  painter.begin(&pixmap);
262  painter.eraseRect(pixmap_rect);
263  painter.drawRect(pixmap_rect.adjusted(0,0,-1,-1));
264  painter.drawLine(QLineF(0, pixmap_rect.height() / 2, pixmap_rect.width(), pixmap_rect.height() / 2));
265 
266  if (b) properties().singleLineProperties.draw(&painter, QET::Horizontal, pixmap_rect);
267  else m_properties.singleLineProperties.draw(&painter, QET::Horizontal, pixmap_rect);
268 
269  painter.end();
270  ui -> m_preview_label -> setPixmap(pixmap);
271 }
272 
279  if (checked && ui -> m_neutral_cb -> isChecked())
280  ui -> m_pen_cb -> setEnabled(true);
281  else ui -> m_pen_cb -> setDisabled(true);
282 }
283 
290  if (checked && ui -> m_earth_cb -> isChecked())
291  ui -> m_pen_cb -> setEnabled(true);
292  else ui -> m_pen_cb -> setDisabled(true);
293 }
294 
303  updatePreview();
304 }
static QTextOrientationSpinBoxWidget * createTextOrientationSpinBoxWidget()
Definition: qetapp.cpp:1072
bool hasGround
Whether the singleline conductor should display the ground symbol.
ConductorProperties properties() const
ConductorPropertiesWidget::properties.
Qt::Alignment m_vertical_alignment
unsigned short int phasesCount()
Ui::ConductorPropertiesWidget * ui
~ConductorPropertiesWidget() override
ConductorPropertiesWidget::~ConductorPropertiesWidget destructor.
void on_m_earth_cb_toggled(bool checked)
ConductorPropertiesWidget::on_m_earth_cb_toggled Update the widget when toggled.
void initWidget()
ConductorPropertiesWidget::initWidget.
ConductorPropertiesWidget(QWidget *parent=nullptr)
ConductorPropertiesWidget::ConductorPropertiesWidget Constructor.
SingleLineProperties singleLineProperties
void setConductorType(ConductorProperties::ConductorType type)
ConductorPropertiesWidget::setConductorType Update this widget to the new conductor type...
Qt::Alignment m_horizontal_alignment
QTextOrientationSpinBoxWidget * m_horiz_select
void on_m_update_preview_pb_clicked()
ConductorPropertiesWidget::on_m_update_preview_pb_clicked Update the preview of single line...
bool hasNeutral
Whether the singleline conductor should display the neutral symbol.
void setDisabledShowText(const bool &disable=true)
ConductorPropertiesWidget::setDisabledShowText.
QTextOrientationSpinBoxWidget * m_verti_select
QIcon tr
Definition: qeticons.cpp:204
bool event(QEvent *event) override
ConductorPropertiesWidget::event.
void setProperties(const ConductorProperties &properties)
ConductorPropertiesWidget::setProperties Set the properties.
ConductorType
The ConductorType enum Represents the kind of a particular conductor: Single: singleline symbols...
QPushButton * editAutonumPushButton() const
QIcon ro
Definition: qeticons.cpp:199
void setHiddenAvailableAutonum(const bool &hide)
ConductorPropertiesWidget::setHiddenAvailableAutonum Hide the label, combo box and push button of ava...
bool is_pen
Protective Earth Neutral: visually merge neutral and ground.
void on_m_neutral_cb_toggled(bool checked)
ConductorPropertiesWidget::on_m_neutral_cb_toggled Update the widget when toggled.
void addAutonumWidget(QWidget *widget)
ConductorPropertiesWidget::addAutonumWidget.
void setHiddenOneTextPerFolio(const bool &hide)
ConductorPropertiesWidget::setHiddenOneTextPerFolio.
Horizontal segment.
Definition: qet.h:87
void updatePreview(bool b=true)
ConductorPropertiesWidget::updatePreview Update the preview for single lien.
void draw(QPainter *, QET::ConductorSegmentType, const QRectF &)
void setReadOnly(const bool &ro)
ConductorPropertiesWidget::setReadOnly.