QElectroTech  0.70
qettemplateeditor.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 "qettemplateeditor.h"
19 #include "qetmessagebox.h"
20 #include "qeticons.h"
21 #include "qetapp.h"
22 #include "qetproject.h"
23 #include "templatecellwidget.h"
24 #include "templatecommands.h"
25 #include "templateview.h"
26 #include "templatelocationsaver.h"
27 #include "templatelogomanager.h"
28 #include "templatecellwidget.h"
29 
34  QETMainWindow(parent),
35  opened_from_file_(false),
36  read_only_(false),
37  duplicate_(false),
38  tb_template_(nullptr),
39  logo_manager_(nullptr)
40 {
41  setWindowIcon(QET::Icons::QETLogo);
42  setAttribute(Qt::WA_DeleteOnClose);
43 
44  initWidgets();
45  initActions();
46  initMenus();
47  initToolbars();
48  readSettings();
49 }
50 
55 }
56 
61  return(location_);
62 }
63 
68 bool QETTitleBlockTemplateEditor::isEditing(const QString &filepath) {
69  QString current_filepath;
70  if (opened_from_file_) {
71  current_filepath = filepath_;
72  } else {
73  current_filepath = QETApp::realPath(location_.toString());
74  }
75 
76  return(
78  current_filepath,
79  filepath
80  )
81  );
82 }
83 
89  duplicate_ = duplicate;
90 }
91 
97  return(duplicate_);
98 }
99 
106  if (undo_stack_ -> isClean()) return(true);
107  // ask the user whether he wants to save the current template
108  QMessageBox::StandardButton answer = QET::QetMessageBox::question(
109  this,
110  tr("Enregistrer le modèle en cours ?", "dialog title"),
111  QString(
112  tr(
113  "Voulez-vous enregistrer le modèle %1 ?",
114  "dialog content - %1 is a title block template name"
115  )
116  ).arg(location_.name()),
117  QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
119  );
120  bool result;
121  switch(answer) {
122  case QMessageBox::Cancel: result = false; break; // the user hits Cancel or closes the dialog: abort the closing
123  case QMessageBox::Yes: result = save(); break; // the user hits Yes: la reussite depend de l'enregistrement
124  default: result = true; // the user hits no: the editor can be closed
125  }
126  return(result);
127 }
128 
133  Q_UNUSED(event)
135  // this editor is supposed to duplicate its current location
136  QTimer::singleShot(250, this, SLOT(duplicateCurrentLocation()));
137  }
138 }
139 
145  if (canClose()) {
146  writeSettings();
147  setAttribute(Qt::WA_DeleteOnClose);
148  qce -> accept();
149  } else qce -> ignore();
150 }
151 
157  // this method does not work for templates edited from the filesystem
158  if (opened_from_file_) return;
159 
160  QString proposed_name;
161  if (location_.name().isEmpty()) {
162  proposed_name = tr("nouveau_modele", "template name suggestion when duplicating the default one");
163  } else {
164  proposed_name = QString("%1_copy").arg(location_.name());
165  }
166 
167  bool accepted = false;
168  QString new_template_name = QInputDialog::getText(
169  this,
170  tr("Dupliquer un modèle de cartouche", "input dialog title"),
171  tr("Pour dupliquer ce modèle, entrez le nom voulu pour sa copie", "input dialog text"),
172  QLineEdit::Normal,
173  proposed_name,
174  &accepted
175  );
176  if (accepted) {
177  TitleBlockTemplateLocation new_template_location(new_template_name, location_.parentCollection());
178  saveAs(new_template_location);
179  }
180 }
181 
186  // the template name may be empty to create a new one
187  const TitleBlockTemplate *tb_template_orig;
188  if (location.name().isEmpty()) {
189  // loads the default title block template provided by the application
190  // it will be used as a start point to design the title block
191  tb_template_orig = QETApp::defaultTitleBlockTemplate();
192  } else {
193  tb_template_orig = location.getTemplate();
194  }
195  if (!tb_template_orig) {
197  return(false);
198  }
199 
200  opened_from_file_ = false;
203  editCopyOf(tb_template_orig);
204  return(true);
205 }
206 
213 bool QETTitleBlockTemplateEditor::edit(QETProject *project, const QString &template_name)
214 {
215  // we require a project we will rattach templates to
216  if (!project) return(false);
217 
218  // the template name may be empty to create a new one
219  const TitleBlockTemplate *tb_template_orig;
220  if (template_name.isEmpty())
221  {
222  // loads the default title block template provided by the application
223  // it will be used as a start point to design the title block
224  tb_template_orig = QETApp::defaultTitleBlockTemplate();
225  }
226  else
227  {
228  tb_template_orig = project->embeddedTitleBlockTemplatesCollection()->getTemplate(template_name);
229  }
230 
231  if (!tb_template_orig) {
233  return(false);
234  }
235 
236  opened_from_file_ = false;
237  location_.setParentCollection(project -> embeddedTitleBlockTemplatesCollection());
238  location_.setName(template_name);
239  setReadOnly(project -> isReadOnly());
240  return(editCopyOf(tb_template_orig));
241 }
242 
247 bool QETTitleBlockTemplateEditor::edit(const QString &file_path) {
248  // get title block template object from the file, edit it
250  bool loading = tbt -> loadFromXmlFile(file_path);
251  if (!loading) {
253  return(false);
254  }
255 
256  bool editing = edit(tbt);
257  if (!editing) {
259  return(false);
260  }
261 
262  QFileInfo file_path_info(file_path);
263  filepath_ = file_path;
264  opened_from_file_ = true;
265  setReadOnly(!file_path_info.isWritable());
266  return(true);
267 }
268 
274  if (!tbt) return(false);
275  return(edit(tbt -> clone()));
276 }
277 
283  if (!tbt) return(false);
284  tb_template_ = tbt;
285  template_edition_area_view_ -> setTitleBlockTemplate(tb_template_);
286  template_cell_editor_widget_ -> updateLogosComboBox(tb_template_);
288  return(true);
289 }
290 
296  if (tb_template_) {
297  if (!logo_manager_) {
298  initLogoManager();
299  }
300 
301  logo_manager_ -> layout() -> setContentsMargins(0, 0, 0, 0);
302  QDialogButtonBox *buttons = new QDialogButtonBox(QDialogButtonBox::Close);
303 
304  QVBoxLayout *vlayout0 = new QVBoxLayout();
305  vlayout0 -> addWidget(logo_manager_);
306  vlayout0 -> addWidget(buttons);
307 
308  QDialog d(this);
309  d.setWindowTitle(logo_manager_ -> windowTitle());
310  d.setLayout(vlayout0);
311  connect(buttons, SIGNAL(rejected()), &d, SLOT(reject()));
312  d.exec();
313 
314  // prevent the logo manager from being deleted along with the dialog
315  logo_manager_ -> setParent(this);
316  }
317 }
318 
323  QETTitleBlockTemplateEditor *qet_template_editor = new QETTitleBlockTemplateEditor();
324  qet_template_editor -> edit(TitleBlockTemplateLocation());
325  qet_template_editor -> show();
326 }
327 
332  new_ = new QAction(QET::Icons::DocumentNew, tr("&Nouveau", "menu entry"), this);
333  open_ = new QAction(QET::Icons::DocumentOpen, tr("&Ouvrir", "menu entry"), this);
334  open_from_file_ = new QAction(QET::Icons::DocumentOpen, tr("Ouvrir depuis un fichier", "menu entry"), this);
335  save_ = new QAction(QET::Icons::DocumentSave, tr("&Enregistrer", "menu entry"), this);
336  save_as_ = new QAction(QET::Icons::DocumentSaveAs, tr("Enregistrer sous", "menu entry"), this);
337  save_as_file_ = new QAction(QET::Icons::DocumentSaveAs, tr("Enregistrer vers un fichier", "menu entry"), this);
338  quit_ = new QAction(QET::Icons::ApplicationExit, tr("&Quitter", "menu entry"), this);
339  undo_ = undo_stack_ -> createUndoAction(this);
340  redo_ = undo_stack_ -> createRedoAction(this);
341  cut_ = new QAction(QET::Icons::EditCut, tr("Co&uper", "menu entry"), this);
342  copy_ = new QAction(QET::Icons::EditCopy, tr("Cop&ier", "menu entry"), this);
343  paste_ = new QAction(QET::Icons::EditPaste, tr("C&oller", "menu entry"), this);
344  edit_logos_ = new QAction(QET::Icons::InsertImage, tr("Gérer les logos", "menu entry"), this);
345  edit_info_ = new QAction(QET::Icons::UserInformations, tr("Éditer les informations complémentaires", "menu entry"), this);
346  zoom_in_ = new QAction(QET::Icons::ZoomIn, tr("Zoom avant", "menu entry"), this);
347  zoom_out_ = new QAction(QET::Icons::ZoomOut, tr("Zoom arrière", "menu entry"), this);
348  zoom_fit_ = new QAction(QET::Icons::ZoomFitBest, tr("Zoom adapté", "menu entry"), this);
349  zoom_reset_ = new QAction(QET::Icons::ZoomOriginal, tr("Pas de zoom", "menu entry"), this);
350  add_row_ = new QAction(QET::Icons::EditTableInsertRowAbove, tr("Ajouter une &ligne", "menu entry"), this);
351  add_col_ = new QAction(QET::Icons::EditTableInsertColumnRight, tr("Ajouter une &colonne", "menu entry"), this);
352  merge_cells_ = new QAction(QET::Icons::EditTableCellMerge, tr("&Fusionner les cellules", "menu entry"), this);
353  split_cell_ = new QAction(QET::Icons::EditTableCellSplit, tr("&Séparer les cellules", "menu entry"), this);
354 
355  undo_ -> setIcon(QET::Icons::EditUndo);
356  redo_ -> setIcon(QET::Icons::EditRedo);
357 
358  new_ -> setShortcut(QKeySequence::New);
359  open_ -> setShortcut(QKeySequence::Open);
360  open_from_file_ -> setShortcut(tr("Ctrl+Shift+O", "shortcut to open a template from a file"));
361  save_ -> setShortcut(QKeySequence::Save);
362  save_as_file_ -> setShortcut(tr("Ctrl+Shift+S", "shortcut to save a template to a file"));
363  quit_ -> setShortcut(QKeySequence(tr("Ctrl+Q", "shortcut to quit")));
364  undo_ -> setShortcut(QKeySequence::Undo);
365  redo_ -> setShortcut(QKeySequence::Redo);
366  cut_ -> setShortcut(QKeySequence::Cut);
367  copy_ -> setShortcut(QKeySequence::Copy);
368  paste_ -> setShortcut(QKeySequence::Paste);
369  edit_logos_ -> setShortcut(QKeySequence(tr("Ctrl+T", "shortcut to manage embedded logos")));
370  edit_info_ -> setShortcut(QKeySequence(tr("Ctrl+Y", "shortcut to edit extra information")));
371  merge_cells_ -> setShortcut(QKeySequence(tr("Ctrl+J", "shortcut to merge cells")));
372  split_cell_ -> setShortcut(QKeySequence(tr("Ctrl+K", "shortcut to split merged cell")));
373  zoom_in_ -> setShortcut(QKeySequence::ZoomIn);
374  zoom_out_ -> setShortcut(QKeySequence::ZoomOut);
375  zoom_fit_ -> setShortcut(QKeySequence(tr("Ctrl+9", "shortcut to enable fit zoom")));
376  zoom_reset_ -> setShortcut(QKeySequence(tr("Ctrl+0", "shortcut to reset zoom")));
377 
378  connect(new_, SIGNAL(triggered()), this, SLOT(newTemplate()));
379  connect(open_, SIGNAL(triggered()), this, SLOT(open()));
380  connect(open_from_file_, SIGNAL(triggered()), this, SLOT(openFromFile()));
381  connect(save_, SIGNAL(triggered()), this, SLOT(save()));
382  connect(save_as_, SIGNAL(triggered()), this, SLOT(saveAs()));
383  connect(save_as_file_, SIGNAL(triggered()), this, SLOT(saveAsFile()));
384  connect(quit_, SIGNAL(triggered()), this, SLOT(quit()));
385  connect(cut_, SIGNAL(triggered()), template_edition_area_view_, SLOT(cut()));
386  connect(copy_, SIGNAL(triggered()), template_edition_area_view_, SLOT(copy()));
387  connect(paste_, SIGNAL(triggered()), template_edition_area_view_, SLOT(paste()));
388  connect(zoom_in_, SIGNAL(triggered()), template_edition_area_view_, SLOT(zoomIn()));
389  connect(zoom_out_, SIGNAL(triggered()), template_edition_area_view_, SLOT(zoomOut()));
390  connect(zoom_fit_, SIGNAL(triggered()), template_edition_area_view_, SLOT(zoomFit()));
391  connect(zoom_reset_, SIGNAL(triggered()), template_edition_area_view_, SLOT(zoomReset()));
392  connect(edit_logos_, SIGNAL(triggered()), this, SLOT(editLogos()));
393  connect(edit_info_, SIGNAL(triggered()), this, SLOT(editTemplateInformation()));
394  connect(add_row_, SIGNAL(triggered()), template_edition_area_view_, SLOT(addRowAtEnd()));
395  connect(add_col_, SIGNAL(triggered()), template_edition_area_view_, SLOT(addColumnAtEnd()));
396  connect(merge_cells_, SIGNAL(triggered()), template_edition_area_view_, SLOT(mergeSelectedCells()));
397  connect(split_cell_, SIGNAL(triggered()), template_edition_area_view_, SLOT(splitSelectedCell()));
398 }
399 
404  file_menu_ = new QMenu(tr("&Fichier", "menu title"), this);
405  edit_menu_ = new QMenu(tr("&Édition", "menu title"), this);
406  display_menu_ = new QMenu(tr("Afficha&ge", "menu title"), this);
407 
408  file_menu_ -> addAction(new_);
409  file_menu_ -> addAction(open_);
410  file_menu_ -> addAction(open_from_file_);
411  file_menu_ -> addAction(save_);
412  file_menu_ -> addAction(save_as_);
413  file_menu_ -> addAction(save_as_file_);
414  file_menu_ -> addSeparator();
415  file_menu_ -> addAction(quit_);
416 
417  edit_menu_ -> addAction(undo_);
418  edit_menu_ -> addAction(redo_);
419  edit_menu_ -> addSeparator();
420  edit_menu_ -> addAction(cut_);
421  edit_menu_ -> addAction(copy_);
422  edit_menu_ -> addAction(paste_);
423  edit_menu_ -> addSeparator();
424  edit_menu_ -> addAction(add_row_);
425  edit_menu_ -> addAction(add_col_);
426  edit_menu_ -> addAction(merge_cells_);
427  edit_menu_ -> addAction(split_cell_);
428  edit_menu_ -> addSeparator();
429  edit_menu_ -> addAction(edit_logos_);
430  edit_menu_ -> addAction(edit_info_);
431  display_menu_ -> addAction(zoom_in_);
432  display_menu_ -> addAction(zoom_out_);
433  display_menu_ -> addAction(zoom_fit_);
434  display_menu_ -> addAction(zoom_reset_);
435 
439 }
440 
445  QToolBar *main_toolbar = new QToolBar(tr("Outils", "toolbar title"), this);
446  main_toolbar -> setObjectName("tbt_main_toolbar");
447  main_toolbar -> addAction(new_);
448  main_toolbar -> addAction(open_);
449  main_toolbar -> addAction(save_);
450  main_toolbar -> addAction(save_as_);
451  addToolBar(Qt::TopToolBarArea, main_toolbar);
452 
453  QToolBar *edit_toolbar = new QToolBar(tr("Édition", "toolbar title"), this);
454  edit_toolbar -> setObjectName("tbt_edit_toolbar");
455  edit_toolbar -> addAction(undo_);
456  edit_toolbar -> addAction(redo_);
457  edit_toolbar -> addSeparator();
458  edit_toolbar -> addAction(merge_cells_);
459  edit_toolbar -> addAction(split_cell_);
460  addToolBar(Qt::TopToolBarArea, edit_toolbar);
461 
462  QToolBar *display_toolbar = new QToolBar(tr("Affichage", "toolbar title"), this);
463  display_toolbar -> setObjectName("tbt_display_toolbar");
464  display_toolbar -> addAction(zoom_in_);
465  display_toolbar -> addAction(zoom_out_);
466  display_toolbar -> addAction(zoom_fit_);
467  display_toolbar -> addAction(zoom_reset_);
468  addToolBar(Qt::TopToolBarArea, display_toolbar);
469 }
470 
475 {
476  QSettings settings;
477 
478  // undo list on the right
479  undo_stack_ = new QUndoStack(this);
480  undo_view_ = new QUndoView(undo_stack_);
481  undo_view_ -> setEmptyLabel(tr("Aucune modification", "label displayed in the undo list when empty"));
482 
483  undo_dock_widget_ = new QDockWidget(tr("Annulations", "dock title"));
484  undo_dock_widget_ -> setObjectName("tbt_undo_dock");
485  undo_dock_widget_ -> setFeatures(QDockWidget::AllDockWidgetFeatures);
486  undo_dock_widget_ -> setWidget(undo_view_);
487  undo_dock_widget_ -> setMinimumWidth(290);
488  addDockWidget(Qt::RightDockWidgetArea, undo_dock_widget_);
489 
490  // WYSIWYG editor as central widget
491  template_edition_area_scene_ = new QGraphicsScene(this);
493  bool conv_ok;
494  int conf_preview_width = settings.value("titleblocktemplateeditor/preview_width", -1).toInt(&conv_ok);
495  if (conv_ok && conf_preview_width != -1) {
496  template_edition_area_view_ -> setPreviewWidth(conf_preview_width);
497  }
498  setCentralWidget(template_edition_area_view_);
499 
500  // cell edition widget at the bottom
502  template_cell_editor_dock_widget_ = new QDockWidget(tr("Propriétés de la cellule", "dock title"), this);
503  template_cell_editor_dock_widget_ -> setObjectName("tbt_celleditor_dock");
504  template_cell_editor_dock_widget_ -> setFeatures(QDockWidget::AllDockWidgetFeatures);
506  template_cell_editor_dock_widget_ -> setMinimumWidth(180);
507  template_cell_editor_dock_widget_ -> setMinimumHeight(250);
508  addDockWidget(Qt::BottomDockWidgetArea, template_cell_editor_dock_widget_);
509  template_cell_editor_widget_ -> setVisible(false);
510 
511  connect(
513  SIGNAL(selectedCellsChanged(QList<TitleBlockCell *>)),
514  this,
515  SLOT(selectedCellsChanged(QList<TitleBlockCell *>))
516  );
517  connect(template_cell_editor_widget_, SIGNAL(logoEditionRequested()), this, SLOT(editLogos()));
518  connect(
520  SIGNAL(cellModified(ModifyTitleBlockCellCommand *)),
521  this,
523  );
524  connect(
526  SIGNAL(gridModificationRequested(TitleBlockTemplateCommand *)),
527  this,
529  );
530  connect(
532  SIGNAL(previewWidthChanged(int,int)),
533  this,
535  );
536  connect(undo_stack_, SIGNAL(cleanChanged(bool)), this, SLOT(updateEditorTitle()));
537  connect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(updateActions()));
538 }
539 
546  connect(
548  SIGNAL(logosChanged(const TitleBlockTemplate *)),
550  SLOT(updateLogosComboBox(const TitleBlockTemplate *))
551  );
552 }
553 
559  QString titleblock_title;
560  if (opened_from_file_) {
561  titleblock_title = filepath_;
562  } else {
563  titleblock_title = location_.name();
564  }
565 
566  // if a (file)name has been added, also add a "[Changed]" tag if needed
567  if (!titleblock_title.isEmpty()) {
568  QString tag;
569  if (!undo_stack_ -> isClean()) {
570  tag = tr("[Modifié]", "window title tag");
571  }
572  if (read_only_) {
573  tag = tr("[Lecture seule]", "window title tag");
574  }
575  titleblock_title = QString(
576  tr(
577  "%1 %2",
578  "part of the window title - %1 is the filepath or template name, %2 is the [Changed] or [Read only] tag"
579  )
580  ).arg(titleblock_title).arg(tag);
581  }
582 
583  return(titleblock_title);
584 }
585 
591 {
592  QSettings settings;
593 
594  // window size and position
595  QVariant geometry = settings.value("titleblocktemplateeditor/geometry");
596  if (geometry.isValid()) restoreGeometry(geometry.toByteArray());
597 
598  // window state (toolbars, docks...)
599  QVariant state = settings.value("titleblocktemplateeditor/state");
600  if (state.isValid()) restoreState(state.toByteArray());
601 }
602 
608 {
609  QSettings settings;
610  settings.setValue("titleblocktemplateeditor/geometry", saveGeometry());
611  settings.setValue("titleblocktemplateeditor/state", saveState());
612 }
613 
618 void QETTitleBlockTemplateEditor::selectedCellsChanged(const QList<TitleBlockCell *>& selected_cells) {
619  if (selected_cells.count() == 1) {
620  template_cell_editor_widget_ -> edit(selected_cells.at(0));
621  template_cell_editor_widget_ -> setVisible(true);
622  } else {
623  template_cell_editor_widget_ -> setVisible(false);
624  }
625  updateActions();
626 }
627 
633  command -> setView(template_edition_area_view_);
634  pushUndoCommand(command);
635 }
636 
642  pushUndoCommand(command);
643 }
644 
649 void QETTitleBlockTemplateEditor::pushUndoCommand(QUndoCommand *command) {
650  undo_stack_ -> push(command);
651 }
652 
657  // base title
658  QString min_title(
659  tr(
660  "QElectroTech - Éditeur de modèle de cartouche",
661  "titleblock template editor: base window title"
662  )
663  );
664 
665  // get the currently edited template (file)name
666  QString titleblock_title = currentlyEditedTitle();
667 
668  // generate the final window title
669  QString title;
670  if (titleblock_title.isEmpty()) {
671  title = min_title;
672  } else {
673  title = QString(
674  tr(
675  "%1 - %2",
676  "window title: %1 is the base window title, %2 is a template name"
677  )
678  ).arg(min_title).arg(titleblock_title);
679  }
680  setWindowTitle(title);
681 }
682 
688  save_ -> setEnabled(!read_only_);
689 
690  bool can_merge = true;
691  bool can_split = true;
692  int count = 0;
693  if (!read_only_) {
694  template_edition_area_view_ -> analyzeSelectedCells(&can_merge, &can_split, &count);
695  }
696  cut_ -> setEnabled(!read_only_ && count);
697  copy_ -> setEnabled(count);
698  paste_ -> setEnabled(!read_only_ && count && template_edition_area_view_ -> mayPaste());
699  add_row_ -> setEnabled(!read_only_);
700  add_col_ -> setEnabled(!read_only_);
701  merge_cells_ -> setEnabled(!read_only_ && can_merge);
702  split_cell_ -> setEnabled(!read_only_ && can_split);
703 }
704 
712  if (!collection) return(false);
713 
714  QDomDocument doc;
715  QDomElement elmt = doc.createElement("root");
716  tb_template_ -> saveToXmlElement(elmt);
717  elmt.setAttribute("name", location.name());
718  doc.appendChild(elmt);
719 
720  collection -> setTemplateXmlDescription(location.name(), elmt);
721 
722  opened_from_file_ = false;
724  undo_stack_ -> setClean();
725  setReadOnly(false);
726  return(true);
727 }
728 
734 bool QETTitleBlockTemplateEditor::saveAs(const QString &filepath) {
735  bool saving = tb_template_ -> saveToXmlFile(filepath);
736  if (!saving) return(false);
737 
738  opened_from_file_ = true;
739  filepath_ = filepath;
740  undo_stack_ -> setClean();
741  setReadOnly(false);
742  return(true);
743 }
744 
751  tr("Ouvrir un modèle", "File > open dialog window title"),
752  true
753  );
754  if (location.isValid()) {
755  QETApp::instance() -> openTitleBlockTemplate(location);
756  }
757 }
758 
764  // directory to show
765  QString initial_dir = filepath_.isEmpty() ? QETApp::customTitleBlockTemplatesDir() : QDir(filepath_).absolutePath();
766 
767  // ask the user to choose a filepath
768  QString user_filepath = QFileDialog::getOpenFileName(
769  this,
770  tr("Ouvrir un fichier", "dialog title"),
771  initial_dir,
772  tr(
773  "Modèles de cartouches QElectroTech (*%1);;"
774  "Fichiers XML (*.xml);;"
775  "Tous les fichiers (*)",
776  "filetypes allowed when opening a title block template file - %1 is the .titleblock extension"
777  ).arg(QString(TITLEBLOCKS_FILE_EXTENSION))
778  );
779 
780 
781  if (!user_filepath.isEmpty()) QETApp::instance() -> openTitleBlockTemplate(user_filepath);
782 }
783 
788  if (opened_from_file_) {
789  if (!filepath_.isEmpty()) {
790  QFileInfo file_path_info(filepath_);
791  if (file_path_info.isWritable()) {
792  return(saveAs(filepath_));
793  }
794  }
795  return(saveAsFile());
796  } else {
797  if (location_.isValid()) {
798  if (!location_.isReadOnly()) {
799  return(saveAs(location_));
800  }
801  }
802  return(saveAs());
803  }
804 }
805 
811  tr("Enregistrer le modèle sous", "dialog window title"),
812  false
813  );
814  if (location.isValid()) {
815  return(saveAs(location));
816  }
817  return(false);
818 }
819 
824  // directory to show
825  QString initial_dir = filepath_.isEmpty() ? QETApp::customTitleBlockTemplatesDir() : QDir(filepath_).absolutePath();
826 
827  // ask the user to choose a target file
828  QString filepath = QFileDialog::getSaveFileName(
829  this,
830  tr("Enregistrer sous", "dialog title"),
831  initial_dir,
832  tr(
833  "Modèles de cartouches QElectroTech (*%1)",
834  "filetypes allowed when saving a title block template file - %1 is the .titleblock extension"
835  ).arg(QString(TITLEBLOCKS_FILE_EXTENSION))
836  );
837 
838  // if no name was entered, return false
839  if (filepath.isEmpty()) return(false);
840 
841  // if the name does not end with ".titleblock", add it
842  if (!filepath.endsWith(".titleblock", Qt::CaseInsensitive)) filepath += ".titleblock";
843 
844  // attempts to save the file
845  bool saving = saveAs(filepath);
846 
847  // retourne un booleen representatif de la reussite de l'enregistrement
848  return(saving);
849 }
850 
856  if (read_only != read_only_) {
857  read_only_ = read_only;
858  if (logo_manager_) {
860  }
863  }
864  updateActions();
866 }
867 
878  if (existing_only) {
880  } else {
882  }
883  QDialogButtonBox *buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
884 
885  QVBoxLayout *dialog_layout = new QVBoxLayout();
886  dialog_layout -> addWidget(widget);
887  dialog_layout -> addWidget(buttons);
888 
889  QDialog dialog;
890  dialog.setWindowTitle(title);
891  dialog.setLayout(dialog_layout);
892 
893  connect(buttons, SIGNAL(accepted()), &dialog, SLOT(accept()));
894  connect(buttons, SIGNAL(rejected()), &dialog, SLOT(reject()));
895 
896  if (dialog.exec() == QDialog::Accepted) {
897  return(widget -> location());
898  }
900 }
901 
906  close();
907 }
908 
915 void QETTitleBlockTemplateEditor::savePreviewWidthToApplicationSettings(int former_preview_width, int new_preview_width)
916 {
917  Q_UNUSED(former_preview_width)
918  QSettings settings;
919  settings.setValue("titleblocktemplateeditor/preview_width", new_preview_width);
920 }
921 
926  if (!tb_template_) return;
927 
928  QDialog dialog_author(this);
929  dialog_author.setModal(true);
930 #ifdef Q_OS_MAC
931  dialog_author.setWindowFlags(Qt::Sheet);
932 #endif
933  dialog_author.setMinimumSize(400, 260);
934  dialog_author.setWindowTitle(tr("Éditer les informations complémentaires", "window title"));
935  QVBoxLayout *dialog_layout = new QVBoxLayout(&dialog_author);
936 
937  // explanation label
938  QLabel *information_label = new QLabel(tr("Vous pouvez utiliser ce champ libre pour mentionner les auteurs du cartouche, sa licence, ou tout autre renseignement que vous jugerez utile."));
939  information_label -> setAlignment(Qt::AlignJustify | Qt::AlignVCenter);
940  information_label -> setWordWrap(true);
941  dialog_layout -> addWidget(information_label);
942 
943  // add a QTextEdit to the dialog
944  QTextEdit *text_field = new QTextEdit();
945  text_field -> setAcceptRichText(false);
946  text_field -> setPlainText(tb_template_ -> information());
947  text_field -> setReadOnly(read_only_);
948  dialog_layout -> addWidget(text_field);
949 
950  // add two buttons to the dialog
951  QDialogButtonBox *dialog_buttons = new QDialogButtonBox(read_only_ ? QDialogButtonBox::Ok : QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
952  dialog_layout -> addWidget(dialog_buttons);
953  connect(dialog_buttons, SIGNAL(accepted()), &dialog_author, SLOT(accept()));
954  connect(dialog_buttons, SIGNAL(rejected()), &dialog_author, SLOT(reject()));
955 
956  // run the dialog
957  if (dialog_author.exec() == QDialog::Accepted && !read_only_) {
958  QString new_info = text_field -> toPlainText().remove(QChar(13)); // CR-less text
959  if (new_info != tb_template_ -> information()) {
961  }
962  }
963 }
static QString customTitleBlockTemplatesDir()
Definition: qetapp.cpp:643
static TitleBlockTemplate * defaultTitleBlockTemplate()
Definition: qetapp.cpp:1088
void closeEvent(QCloseEvent *) override
bool editCopyOf(const TitleBlockTemplate *)
QIcon EditTableCellSplit
Definition: qeticons.cpp:74
QIcon EditTableInsertRowAbove
Definition: qeticons.cpp:79
bool read_only_
whether the currently edited template is considered read only
QString filepath_
Filepath of the currently edited template, if opened from a file.
void pushGridUndoCommand(TitleBlockTemplateCommand *)
void pushUndoCommand(QUndoCommand *)
QIcon EditRedo
Definition: qeticons.cpp:68
void setName(const QString &)
QIcon DocumentNew
Definition: qeticons.cpp:53
QIcon QETLogo
Definition: qeticons.cpp:151
QIcon EditTableInsertColumnRight
Definition: qeticons.cpp:78
QIcon ZoomOut
Definition: qeticons.cpp:181
TitleBlockTemplate * tb_template_
Template Object edited.
bool compareCanonicalFilePaths(const QString &, const QString &)
Definition: qet.cpp:519
QIcon EditUndo
Definition: qeticons.cpp:82
TitleBlockTemplateCellWidget * template_cell_editor_widget_
QMenu * settings_menu_
Settings menu.
Definition: qetmainwindow.h:65
bool isEditing(const QString &ilepath)
QIcon EditTableCellMerge
Definition: qeticons.cpp:73
bool event(QEvent *) override
QGraphicsScene * template_edition_area_scene_
Template preview.
QIcon ZoomIn
Definition: qeticons.cpp:179
QIcon EditCopy
Definition: qeticons.cpp:64
TitleBlockTemplateView * template_edition_area_view_
QIcon DocumentSave
Definition: qeticons.cpp:58
void savePreviewWidthToApplicationSettings(int, int)
QETTitleBlockTemplateEditor::savePreviewWidthToApplicationSettings Save the new preview width to appl...
QIcon InsertImage
Definition: qeticons.cpp:116
QDockWidget * template_cell_editor_dock_widget_
Individual cell widget edition.
TitleBlockTemplateLocation location() const
QIcon UserInformations
Definition: qeticons.cpp:169
void pushCellUndoCommand(ModifyTitleBlockCellCommand *)
void writeSettings()
QETTitleBlockTemplateEditor::writeSettings Write the settings.
QIcon tr
Definition: qeticons.cpp:204
bool edit(const TitleBlockTemplateLocation &)
void selectedCellsChanged(const QList< TitleBlockCell *> &)
QIcon EditPaste
Definition: qeticons.cpp:67
TitleBlockTemplate * getTemplate(const QString &) override
TitleBlockTemplateLocation getTitleBlockTemplateLocationFromUser(const QString &=QString(), bool existing_only=true)
void readSettings()
QETTitleBlockTemplateEditor::readSettings Read settings.
QIcon DocumentSaveAs
Definition: qeticons.cpp:60
QIcon DocumentOpen
Definition: qeticons.cpp:54
#define TITLEBLOCKS_FILE_EXTENSION
QMenu * file_menu_
menus TODO
QIcon ZoomOriginal
Definition: qeticons.cpp:180
TitleBlockTemplateLogoManager * logo_manager_
Logo manager widget.
QIcon EditCut
Definition: qeticons.cpp:65
void firstActivation(QEvent *) override
bool opened_from_file_
Whether to consider the location or the filepath.
void setParentCollection(TitleBlockTemplatesCollection *)
QIcon Cancel
Definition: qeticons.cpp:34
QIcon ApplicationExit
Definition: qeticons.cpp:27
QMessageBox::StandardButton question(QWidget *, const QString &, const QString &, QMessageBox::StandardButtons=QMessageBox::Ok, QMessageBox::StandardButton=QMessageBox::NoButton)
QUndoStack * undo_stack_
Undo interface.
QMessageBox::StandardButton information(QWidget *, const QString &, const QString &, QMessageBox::StandardButtons=QMessageBox::Ok, QMessageBox::StandardButton=QMessageBox::NoButton)
void insertMenu(QMenu *, QMenu *, bool=true)
QIcon ZoomFitBest
Definition: qeticons.cpp:178
QETTitleBlockTemplateEditor(QWidget *=nullptr)
TitleBlockTemplatesCollection * parentCollection() const
TitleBlockTemplate * getTemplate() const
TitleBlockTemplateLocation location_
Location of the currently edited template.
TitleBlockTemplatesProjectCollection * embeddedTitleBlockTemplatesCollection()
Definition: qetproject.cpp:236
static QETApp * instance()
Definition: qetapp.cpp:143
static QString realPath(const QString &)
Definition: qetapp.cpp:704