QElectroTech  0.70
templatecellwidget.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 "templatecellwidget.h"
19 #include "titleblockcell.h"
20 #include "nameslist.h"
21 #include "titleblocktemplate.h"
22 #include "templatecommands.h"
23 #include "qeticons.h"
24 #include "namelistdialog.h"
25 #include "namelistwidget.h"
26 #include "qetinformation.h"
27 
33  QWidget(parent),
34  read_only_(false)
35 {
36  initWidgets();
37  updateLogosComboBox(parent_template);
38 }
39 
44 }
45 
50  // type combo box: always displayed
51  cell_type_label_ = new QLabel(tr("Type de cellule :"));
52  cell_type_input_ = new QComboBox();
53  cell_type_input_ -> addItem(tr("Vide"), TitleBlockCell::EmptyCell);
54  cell_type_input_ -> addItem(tr("Texte"), TitleBlockCell::TextCell);
55  cell_type_input_ -> addItem(tr("Logo"), TitleBlockCell::LogoCell);
56 
57  // name input: displayed for text and logo cells
58  name_label_ = new QLabel(tr("Nom :"));
59  name_input_ = new QLineEdit();
60 
61  // widgets specific to empty cells
62  empty_label_ = new QLabel(tr("Attention : les bordures des cellules vides n'apparaissent pas lors du rendu final sur le folio."));
63 
64  // widgets specific to logo cells
65  logo_label_ = new QLabel(tr("Logo"));
66  logo_input_ = new QComboBox();
67  logo_input_ -> addItem(tr("Aucun logo"));
68  add_logo_input_ = new QPushButton(QET::Icons::InsertImage, tr("Gérer les logos"));
69 
70  // widgets specific to text cells
71  label_checkbox_ = new QCheckBox(tr("Afficher un label :"));
72  label_input_ = new QLineEdit();
73  label_input_ -> setReadOnly(true);
74  label_edit_ = new QPushButton(tr("Editer"));
75  value_label_ = new QLabel(tr("Texte :"));
76  value_input_ = new QLineEdit();
77  value_input_ -> setReadOnly(true);
78  value_edit_ = new QPushButton(tr("Editer"));
79  align_label_ = new QLabel(tr("Alignement :"));
80  horiz_align_label_ = new QLabel(tr("horizontal :"));
81  horiz_align_input_ = new QComboBox();
82  horiz_align_input_ -> addItem(tr("Gauche"), Qt::AlignLeft);
83  horiz_align_input_ -> addItem(tr("Centré"), Qt::AlignHCenter);
84  horiz_align_input_ -> addItem(tr("Droite"), Qt::AlignRight);
85  horiz_align_indexes_.insert(Qt::AlignLeft, 0);
86  horiz_align_indexes_.insert(Qt::AlignHCenter, 1);
87  horiz_align_indexes_.insert(Qt::AlignRight, 2);
88  vert_align_label_= new QLabel(tr("vertical :"));
89  vert_align_input_ = new QComboBox();
90  vert_align_input_ -> addItem(tr("Haut"), Qt::AlignTop);
91  vert_align_input_ -> addItem(tr("Milieu"), Qt::AlignVCenter);
92  vert_align_input_ -> addItem(tr("Bas"), Qt::AlignBottom);
93  vert_align_indexes_.insert(Qt::AlignTop, 0);
94  vert_align_indexes_.insert(Qt::AlignVCenter, 1);
95  vert_align_indexes_.insert(Qt::AlignBottom, 2);
96  font_size_label_ = new QLabel(tr("Police :"));
97  font_size_input_ = new QSpinBox();
98  font_adjust_input_ = new QCheckBox(tr("Ajuster la taille de police si besoin"));
99 
100  // layout
101  QHBoxLayout *label_edition = new QHBoxLayout();
102  label_edition -> addWidget(label_input_);
103  label_edition -> addWidget(label_edit_);
104 
105  QHBoxLayout *value_edition = new QHBoxLayout();
106  value_edition -> addWidget(value_input_);
107  value_edition -> addWidget(value_edit_);
108 
109  cell_editor_type_and_name_layout_ = new QHBoxLayout();
114  cell_editor_type_and_name_layout_ -> addStretch(5);
115 
116  cell_editor_text_layout_ = new QGridLayout();
117  cell_editor_text_layout_ -> addWidget(label_checkbox_, 2, 0);
118  cell_editor_text_layout_ -> addLayout(label_edition, 2, 1);
119  cell_editor_text_layout_ -> addWidget(value_label_, 3, 0);
120  cell_editor_text_layout_ -> addLayout(value_edition, 3, 1);
121  cell_editor_text_layout_ -> addWidget(align_label_, 1, 2, 1, 2, Qt::AlignHCenter);
122  cell_editor_text_layout_ -> addWidget(horiz_align_label_, 2, 2);
123  cell_editor_text_layout_ -> addWidget(horiz_align_input_, 2, 3);
124  cell_editor_text_layout_ -> addWidget(vert_align_label_, 3, 2);
125  cell_editor_text_layout_ -> addWidget(vert_align_input_, 3, 3);
126  cell_editor_text_layout_ -> addWidget(font_size_label_, 4, 0);
127  cell_editor_text_layout_ -> addWidget(font_size_input_, 4, 1);
128  cell_editor_text_layout_ -> addWidget(font_adjust_input_, 4, 2, 1, 2, Qt::AlignLeft);
129  cell_editor_text_layout_ -> addWidget(logo_label_, 5, 0);
130  cell_editor_text_layout_ -> addWidget(logo_input_, 5, 1);
131  cell_editor_text_layout_ -> addWidget(add_logo_input_, 5, 2);
132  cell_editor_text_layout_ -> addWidget(empty_label_, 6, 0);
133  cell_editor_text_layout_ -> setColumnStretch(4, 4000);
134  cell_editor_layout_ = new QVBoxLayout();
137  cell_editor_layout_ -> addStretch();
138  setLayout(cell_editor_layout_);
139 
140  // trigger the logo manager
141  connect(add_logo_input_, SIGNAL(released()), this, SIGNAL(logoEditionRequested()));
142 
143  // handle cell modifications
144  connect(cell_type_input_, SIGNAL(activated(int)), this, SLOT(updateFormType(int)));
145  connect(cell_type_input_, SIGNAL(activated(int)), this, SLOT(editType()));
146  connect(name_input_, SIGNAL(editingFinished()), this, SLOT(editName()));
147  connect(label_checkbox_, SIGNAL(clicked(bool)), this, SLOT(editLabelDisplayed()));
148  connect(label_edit_, SIGNAL(released()), this, SLOT(editLabel()));
149  connect(value_edit_, SIGNAL(released()), this, SLOT(editValue()));
150  connect(horiz_align_input_, SIGNAL(activated(int)), this, SLOT(editAlignment()));
151  connect(vert_align_input_, SIGNAL(activated(int)), this, SLOT(editAlignment()));
152  connect(font_size_input_, SIGNAL(valueChanged(int)), this, SLOT(editFontSize()));
153  connect(font_adjust_input_, SIGNAL(clicked(bool)), this, SLOT(editAdjust()));
154  connect(logo_input_, SIGNAL(activated(int)), this, SLOT(editLogo()));
155 
157 }
158 
163  if (cell_type_input_ -> currentIndex() != cell_type) {
164  cell_type_input_ -> setCurrentIndex(cell_type);
165  }
166 
167  name_label_ -> setVisible(cell_type);
168  name_input_ -> setVisible(cell_type);
169 
170  empty_label_ -> setVisible(cell_type == TitleBlockCell::EmptyCell);
171 
172  logo_label_ -> setVisible(cell_type == TitleBlockCell::LogoCell);
173  logo_input_ -> setVisible(cell_type == TitleBlockCell::LogoCell);
174  add_logo_input_ -> setVisible(cell_type == TitleBlockCell::LogoCell);
175 
176  label_checkbox_ -> setVisible(cell_type == TitleBlockCell::TextCell);
177  label_input_ -> setVisible(cell_type == TitleBlockCell::TextCell);
178  label_edit_ -> setVisible(cell_type == TitleBlockCell::TextCell);
179  value_label_ -> setVisible(cell_type == TitleBlockCell::TextCell);
180  value_input_ -> setVisible(cell_type == TitleBlockCell::TextCell);
181  value_edit_ -> setVisible(cell_type == TitleBlockCell::TextCell);
182  align_label_ -> setVisible(cell_type == TitleBlockCell::TextCell);
183  horiz_align_label_ -> setVisible(cell_type == TitleBlockCell::TextCell);
184  horiz_align_input_ -> setVisible(cell_type == TitleBlockCell::TextCell);
185  vert_align_label_ -> setVisible(cell_type == TitleBlockCell::TextCell);
186  vert_align_input_ -> setVisible(cell_type == TitleBlockCell::TextCell);
187  font_size_label_ -> setVisible(cell_type == TitleBlockCell::TextCell);
188  font_size_input_ -> setVisible(cell_type == TitleBlockCell::TextCell);
189  font_adjust_input_ -> setVisible(cell_type == TitleBlockCell::TextCell);
190 }
191 
200  if (!cell) return;
201  edited_cell_ = cell;
202  int type = cell -> type();
203  updateFormType(type);
204 
205  name_input_ -> setText(cell -> value_name);
206  label_checkbox_ -> setChecked(cell -> display_label);
207  label_input_ -> setText(cell -> label.name());
208  value_input_ -> setText(cell -> value.name());
209  font_adjust_input_ -> setChecked(cell -> hadjust);
210  horiz_align_input_ -> setCurrentIndex(horiz_align_indexes_[cell -> horizontalAlign()]);
211  vert_align_input_ -> setCurrentIndex(vert_align_indexes_[cell -> verticalAlign()]);
212 
213  font_size_input_ -> blockSignals(true); // QSpinBox has no signal triggered for each non-programmatic change
214  font_size_input_ -> setValue(TitleBlockTemplate::fontForCell(*cell).pointSize());
215  font_size_input_ -> blockSignals(false);
216 
217  logo_input_ -> setCurrentIndex(logo_input_ -> findData(cell -> logo_reference));
218 }
219 
225  emitModification("type", cell_type_input_ -> itemData(cell_type_input_ -> currentIndex()));
226 }
227 
233  emitModification("name", name_input_ -> text());
234 }
235 
241  emitModification("displaylabel", label_checkbox_ -> isChecked());
242 }
243 
249  if (!edited_cell_) return;
250  editTranslatableValue(edited_cell_ -> label, "label", tr("Label de cette cellule"));
251  label_input_ -> setText(edited_cell_ -> label.name());
252 }
253 
259  if (!edited_cell_) return;
260  editTranslatableValue(edited_cell_ -> value, "value", tr("Valeur de cette cellule"));
261  value_input_ -> setText(edited_cell_ -> value.name());
262 }
263 
269  emitModification("alignment", alignment());
270 }
271 
277  emitModification("fontsize", font_size_input_ -> value());
278 }
279 
285  emitModification("horizontal_adjust", font_adjust_input_ -> isChecked());
286 }
287 
293  emitModification("logo", logo_input_ -> currentText());
294 }
295 
301  // saves the current value before erasing all entries
302  QVariant current_value = logo_input_ -> itemData(logo_input_ -> currentIndex());
303  logo_input_ -> clear();
304 
305  // default choice (the parent template may have no logo yet)
306  logo_input_ -> addItem(
307  tr("Aucun logo", "text displayed in the combo box when a template has no logo"),
308  QVariant(QString(""))
309  );
310  logo_input_ -> setCurrentIndex(0);
311 
312  if (!parent_template) return;
313  foreach (QString logo, parent_template -> logos()) {
314  logo_input_ -> addItem(logo, QVariant(logo));
315  }
316  int current_value_index = logo_input_ -> findData(current_value);
317  if (current_value_index != -1) {
318  logo_input_ -> setCurrentIndex(current_value_index);
319  }
320 }
321 
326  if (read_only_ == read_only) return;
327  read_only_ = read_only;
328 
329  cell_type_input_ -> setEnabled(!read_only_);
330  logo_input_ -> setEnabled(!read_only_);
332  label_checkbox_ -> setEnabled(!read_only_);
333  label_edit_ -> setEnabled(!read_only_);
334  value_edit_ -> setEnabled(!read_only_);
335  horiz_align_input_ -> setEnabled(!read_only_);
336  vert_align_input_ -> setEnabled(!read_only_);
338  font_adjust_input_ -> setEnabled(!read_only_);
339 }
340 
346  return(horiz_align_indexes_.key(horiz_align_input_ -> currentIndex()));
347 }
348 
354  return(vert_align_indexes_.key(vert_align_input_ -> currentIndex()));
355 }
356 
362 }
363 
368  return(read_only_);
369 }
370 
379 void TitleBlockTemplateCellWidget::editTranslatableValue(NamesList &names, const QString &attribute, const QString &title) const
380 {
381  NameListDialog dialog_;
382 
383  dialog_.setWindowTitle(title);
386 
387  NameListWidget *nlw_ = dialog_.namelistWidget();
388  nlw_->setNames(names);
390 
391  if(dialog_.exec() == QDialog::Accepted) {
392  emitModification(attribute, qVariantFromValue(nlw_->names()));
393  }
394 }
395 
403 void TitleBlockTemplateCellWidget::emitModification(const QString &attribute, const QVariant &new_value) const {
404  if (!edited_cell_) return;
405 
406  // avoid creating a QUndoCommand object when no modification was actually done
407  if (edited_cell_ -> attribute(attribute) == new_value) return;
408 
410  command -> addModification(attribute, new_value);
411  command -> setText(
412  tr("Édition d'une cellule : %1", "label of and undo command when editing a cell")
413  .arg(TitleBlockCell::attributeName(attribute))
414  );
415  emit(cellModified(command));
416 }
417 
423  QString def_var_string = tr(
424  "Par défaut, les variables suivantes sont disponibles :"
425  "<ul>"
426  "<li>%{author} : auteur du folio</li>"
427  "<li>%{date} : date du folio</li>"
428  "<li>%{title} : titre du folio</li>"
429  "<li>%{filename} : nom de fichier du projet</li>"
430  "<li>%{plant} : nom de l'installation (=) dans laquelle se trouve le folio</li>"
431  "<li>%{locmach} : nom de la localisation (+) dans laquelle se trouve le folio</li>"
432  "<li>%{indexrev} : indice de révision du folio</li>"
433  "<li>%{version} : version du logiciel</li>"
434  "<li>%{folio} : numéro du folio</li>"
435  "<li>%{folio-id} : position du folio dans le projet</li>"
436  "<li>%{folio-total} : nombre total de folios dans le projet</li>"
437  "<li>%{previous-folio-num} : numéro du folio précédent</li>"
438  "<li>%{next-folio-num} : numéro du folio suivant</li>"
439  "<li>%{projecttitle} : titre du projet</li>"
440  "<li>%{projectpath} : chemin du projet</li>"
441  "<li>%{projectfilename} : nom du fichier</li>"
442  "<li>%{saveddate} : date d'enregistrement du fichier</li>"
443  "<li>%{savedtime} : heure d'enregistrement du fichier</li>"
444  "<li>%{savedfilename} : nom du fichier enregistré</li>"
445  "<li>%{savedfilepath} : chemin du fichier enregistré</li>"
446  "</ul>"
447  );
448  return(def_var_string);
449 }
450 
455  QString lab_val_inf_string = tr(
456  "Chaque cellule d'un cartouche affiche une valeur, optionnellement "
457  "précédée d'un label. Tous deux peuvent être traduits en "
458  "plusieurs langues."
459  "<br/>"
460  "Comme ce que vous éditez actuellement est un "
461  "<em>modèle</em> de cartouche, ne saisissez pas directement des "
462  "données brutes : insérez plutôt des variables sous la forme "
463  "%{nom-de-variable}, qui seront ensuite remplacées par les valeurs "
464  "adéquates sur le folio."
465  );
466  return(lab_val_inf_string);
467 }
QHash< QString, QString > titleblockTranslatedKeyHashVar()
QETInformation::titleblockTranslatedKeyHashVar.
void setInformationText(const QString &text)
void setNames(const NamesList &name_list)
NameListWidget::setNames Set the current names of this dialog from .
void emitModification(const QString &, const QVariant &) const
QHBoxLayout * cell_editor_type_and_name_layout_
NamesList names() const
NameListWidget::names.
QHash< int, int > horiz_align_indexes_
NameListWidget * namelistWidget() const
NameListDialog::namelistWidget.
QHash< int, int > vert_align_indexes_
The NameListDialog class Provide a dialog for let user define localized string;.
QIcon InsertImage
Definition: qeticons.cpp:116
QIcon tr
Definition: qeticons.cpp:204
static QFont fontForCell(const TitleBlockCell &)
static QString attributeName(const QString &)
void setClipboardValue(QHash< QString, QString > value)
void cellModified(ModifyTitleBlockCellCommand *) const
void updateLogosComboBox(const TitleBlockTemplate *)
TitleBlockTemplateCellWidget(TitleBlockTemplate *=nullptr, QWidget *=nullptr)
void editTranslatableValue(NamesList &, const QString &, const QString &) const
void setHelpText(const QString &text)
bool read_only_
is the template read-only?
The NameListWidget class Provide a widget for let user define localized string;.