QElectroTech  0.70
replaceconductordialog.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 */
18 #include "replaceconductordialog.h"
19 #include "ui_replaceconductordialog.h"
20 #include "searchandreplaceworker.h"
21 
22 #include <QPainter>
23 #include <QColorDialog>
24 
26 
32  QDialog(parent),
33  ui(new Ui::ReplaceConductorDialog)
34 {
35  ui->setupUi(this);
36  initWidget();
38 }
39 
41 {
42  delete ui;
43 }
44 
52 {
53  const QRect pixmap_rect(0, 0, 96, 96);
54  QPixmap pixmap(pixmap_rect.width(), pixmap_rect.height());
55  QPainter painter;
56  painter.begin(&pixmap);
57  painter.eraseRect(pixmap_rect);
58  painter.drawRect(pixmap_rect.adjusted(0,0,-1,-1));
59  painter.drawLine(QLineF(0, pixmap_rect.height() / 2, pixmap_rect.width(), pixmap_rect.height() / 2));
60 
61  if (b) {
62  properties().singleLineProperties.draw(&painter, QET::Horizontal, pixmap_rect);
63  } else {
64  m_properties.singleLineProperties.draw(&painter, QET::Horizontal, pixmap_rect);
65  }
66 
67  painter.end();
68  ui -> m_preview_label -> setPixmap(pixmap);
69 }
70 
72 {
74 
76  ui->m_singlewire_gb->setChecked(true);
77  } else {
78  ui->m_multi_gb->setChecked(true);
79  }
80  ui->m_text_size_sb->setValue(m_properties.text_size);
81  ui->m_show_text->setChecked(m_properties.m_show_text);
82  sarw::setupLineEdit(ui->m_formula_le, ui->m_erase_formula_cb, m_properties.m_formula);
83  sarw::setupLineEdit(ui->m_text_le, ui->m_erase_text_cb, m_properties.text);
84  sarw::setupLineEdit(ui->m_function_le, ui->m_erase_function_cb, m_properties.m_function);
85  sarw::setupLineEdit(ui->m_tension_protocol_le, ui->m_erase_tension_protocol_cb, m_properties.m_tension_protocol);
87  case Qt::AlignLeft: ui->m_vertical_align_cb->setCurrentIndex(1);break;
88  case Qt::AlignRight: ui->m_vertical_align_cb->setCurrentIndex(2);break;
89  default: ui->m_vertical_align_cb->setCurrentIndex(0); break;
90  }
92  case Qt::AlignTop: ui->m_horizontal_align_cb->setCurrentIndex(1); break;
93  case Qt::AlignBottom: ui->m_horizontal_align_cb->setCurrentIndex(2); break;
94  default: ui->m_horizontal_align_cb->setCurrentIndex(0); break;
95  }
96  ui->m_vertical_angle_sb->setValue(m_properties.verti_rotate_text);
97  ui->m_horizontal_angle_sb->setValue(m_properties.horiz_rotate_text);
98  if (m_properties.color.isValid())
99  {
101  ui->m_mod_color_cb->setChecked(true);
102  }
103  int index = ui->m_line_style_cb->findData(QPen(m_properties.style));
104  if (index != -1) {
105  ui->m_line_style_cb->setCurrentIndex(index);
106  }
107  ui->m_second_color_gb->setChecked(m_properties.m_bicolor);
108  if (m_properties.m_color_2.isValid())
109  {
111  ui->m_mod_color_2_cb->setChecked(true);
112  }
113  ui->m_color_2_dash_size_sb->setValue(m_properties.m_dash_size);
114 
115  ui->m_earth_cb ->setChecked (m_properties.singleLineProperties.hasGround);
116  ui->m_neutral_cb ->setChecked (m_properties.singleLineProperties.hasNeutral);
117  ui->m_pen_cb ->setChecked (m_properties.singleLineProperties.isPen());
118  ui->m_phase_cb ->setChecked (m_properties.singleLineProperties.phasesCount());
119  ui->m_phase_slider->setValue (m_properties.singleLineProperties.phasesCount());
120 
121  updatePreview(false);
122 }
123 
129 {
130  ConductorProperties properties_;
131  if (ui->m_multi_gb->isChecked()) {
132  properties_.type = ConductorProperties::Multi;
133  } else {
134  properties_.type = ConductorProperties::Single;
135  }
136 
137  properties_.text_size = ui->m_text_size_sb->value();
138  properties_.m_formula = ui->m_formula_le->text();
139  properties_.text = ui->m_text_le->text();
140  properties_.m_show_text = ui->m_show_text->isChecked();
141  properties_.m_function = ui->m_function_le->text();
142  properties_.m_tension_protocol = ui->m_tension_protocol_le->text();
143  switch (ui->m_vertical_align_cb->currentIndex()) {
144  case 0: properties_.m_vertical_alignment = Qt::AlignAbsolute; break;
145  case 1: properties_.m_vertical_alignment = Qt::AlignLeft; break;
146  case 2: properties_.m_vertical_alignment = Qt::AlignRight; break;
147  default:break;
148  }
149  switch (ui->m_horizontal_align_cb->currentIndex()) {
150  case 0: properties_.m_horizontal_alignment = Qt::AlignAbsolute; break;
151  case 1: properties_.m_horizontal_alignment = Qt::AlignTop; break;
152  case 2: properties_.m_horizontal_alignment = Qt::AlignBottom; break;
153  default: break;
154  }
155  properties_.verti_rotate_text = ui->m_vertical_angle_sb->value();
156  properties_.horiz_rotate_text = ui->m_horizontal_angle_sb->value();
157  properties_.color = ui->m_mod_color_cb->isChecked() ? ui->m_color_pb->palette().color(QPalette::Button) : QColor();
158  properties_.style = ui->m_line_style_cb->itemData(ui->m_line_style_cb->currentIndex()).value<QPen>().style();
159  properties_.cond_size = ui->m_cond_size_sb->value();
160  properties_.m_bicolor = ui->m_second_color_gb->isChecked();
161  properties_.m_color_2 = ui->m_mod_color_2_cb->isChecked() ? ui->m_color_2_pb->palette().color(QPalette::Button) : QColor();
162  properties_.m_dash_size = ui->m_color_2_dash_size_sb->value();
163 
164  properties_.singleLineProperties.hasGround = ui->m_earth_cb->isChecked();
165  properties_.singleLineProperties.hasNeutral = ui->m_neutral_cb->isChecked();
166  properties_.singleLineProperties.is_pen = ui->m_pen_cb->isChecked();
167  properties_.singleLineProperties.setPhasesCount(ui->m_phase_cb->isChecked() ? ui->m_phase_sb->value() : 0);
168 
169  return properties_;
170 }
171 
173 {
174  connect(ui->m_button_box, &QDialogButtonBox::clicked, [this](QAbstractButton *button_) {
175  this->done(ui->m_button_box->buttonRole(button_));
176  });
177 
178  ui->m_update_preview_pb->setHidden(true);
179 
180  ui->m_line_style_cb->addItem(tr("Ne pas modifier"), QPen(Qt::NoPen));
181  ui->m_line_style_cb->addItem(tr("Trait plein", "conductor style: solid line"), QPen(Qt::SolidLine));
182  ui->m_line_style_cb->addItem(tr("Trait en pointillés", "conductor style: dashed line"), QPen(Qt::DashLine));
183  ui->m_line_style_cb->addItem(tr("Traits et points", "conductor style: dashed and dotted line"), QPen(Qt::DashDotLine));
184 
185  connect(ui->m_multi_gb, &QGroupBox::toggled, [this](bool toggle) {this->ui->m_singlewire_gb->setChecked(!toggle);});
186  connect(ui->m_singlewire_gb, &QGroupBox::toggled, [this](bool toggle) {this->ui->m_multi_gb->setChecked(!toggle);});
187  connect(ui->m_formula_le, &QLineEdit::textChanged, [this](QString text) {this->ui->m_text_le->setEnabled(text.isEmpty());});
188  ui->m_multi_gb->setChecked(true);
189  ui->m_singlewire_gb->setChecked(true);
190 }
191 
192 void ReplaceConductorDialog::setColorButton(const QColor &color)
193 {
194  QPalette palette;
195  palette.setColor(QPalette::Button, color);
196  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()));
197 }
198 
200 {
201  QPalette palette;
202  palette.setColor(QPalette::Button, color);
203  ui->m_color_2_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()));
204 }
205 
207 {
208  ui->m_formula_le->setText(ui->m_erase_formula_cb->isChecked() ? SearchAndReplaceWorker::eraseText() : QString());
209  ui->m_formula_le->setDisabled(ui->m_erase_formula_cb->isChecked());
210 }
211 
213 {
214  ui->m_text_le->setText(ui->m_erase_text_cb->isChecked() ? SearchAndReplaceWorker::eraseText() : QString());
215  ui->m_text_le->setDisabled(ui->m_erase_text_cb->isChecked());
216 }
217 
219 {
220  ui->m_function_le->setText(ui->m_erase_function_cb->isChecked() ? SearchAndReplaceWorker::eraseText() : QString());
221  ui->m_function_le->setDisabled(ui->m_erase_function_cb->isChecked());
222 }
223 
225 {
226  ui->m_tension_protocol_le->setText(ui->m_erase_tension_protocol_cb->isChecked() ? SearchAndReplaceWorker::eraseText() : QString());
227  ui->m_tension_protocol_le->setDisabled(ui->m_erase_tension_protocol_cb->isChecked());
228 }
229 
231 {
232  if (checked && ui->m_neutral_cb -> isChecked()) {
233  ui -> m_pen_cb -> setEnabled(true);
234  } else {
235  ui -> m_pen_cb -> setDisabled(true);
236  }
237 }
238 
240 {
241  if (checked && ui->m_earth_cb->isChecked()) {
242  ui->m_pen_cb->setEnabled(true);
243  } else {
244  ui->m_pen_cb->setDisabled(true);
245  }
246 }
247 
249  updatePreview();
250 }
251 
253 {
254  QColor color = QColorDialog::getColor(m_properties.color, this);
255  if (color.isValid()) {
256  setColorButton(color);
257  }
258 }
259 
261 {
262  QColor color = QColorDialog::getColor(m_properties.m_color_2, this);
263  if (color.isValid()) {
264  setColorButton2(color);
265  }
266 }
bool hasGround
Whether the singleline conductor should display the ground symbol.
Qt::Alignment m_vertical_alignment
unsigned short int phasesCount()
void on_m_earth_cb_toggled(bool checked)
SingleLineProperties singleLineProperties
void setColorButton2(const QColor &color)
Qt::Alignment m_horizontal_alignment
Ui::ReplaceConductorDialog * ui
ReplaceConductorDialog(const ConductorProperties &properties, QWidget *parent=0)
ReplaceConductorDialog::ReplaceConductorDialog.
void updatePreview(bool b=true)
ReplaceConductorDialog::updatePreview Update the preview for single line.
The ReplaceConductorDialog class A Qdialog to edit a conductor properties, use for the search and rep...
bool hasNeutral
Whether the singleline conductor should display the neutral symbol.
void setColorButton(const QColor &color)
QIcon tr
Definition: qeticons.cpp:204
void setProperties(const ConductorProperties &properties)
ConductorProperties m_properties
static void setupLineEdit(QLineEdit *l, QCheckBox *cb, QString str)
SearchAndReplaceWorker::setupLineEdit With search and replace, when the variable to edit is a text...
The SearchAndReplaceWorker class This class is the worker use to change properties when use the searc...
bool is_pen
Protective Earth Neutral: visually merge neutral and ground.
SearchAndReplaceWorker sarw
void on_m_neutral_cb_toggled(bool checked)
Horizontal segment.
Definition: qet.h:87
void draw(QPainter *, QET::ConductorSegmentType, const QRectF &)
ConductorProperties properties() const
ReplaceConductorDialog::properties.