diff --git a/sources/titleblock/qettemplateeditor.cpp b/sources/titleblock/qettemplateeditor.cpp index a5ccc39d4..f4c97bc66 100644 --- a/sources/titleblock/qettemplateeditor.cpp +++ b/sources/titleblock/qettemplateeditor.cpp @@ -159,12 +159,23 @@ void QETTitleBlockTemplateEditor::editLogos() { } } +/** + Launch a new title block template editor. +*/ +void QETTitleBlockTemplateEditor::newTemplate() { + QETTitleBlockTemplateEditor *qet_template_editor = new QETTitleBlockTemplateEditor(); + qet_template_editor -> edit(TitleBlockTemplateLocation()); + qet_template_editor -> showMaximized(); + +} + /** Initialize the various actions. */ void QETTitleBlockTemplateEditor::initActions() { QETApp *qet_app = QETApp::instance(); + new_ = new QAction(QET::Icons::DocumentNew, tr("&Nouveau", "menu entry"), this); save_ = new QAction(QET::Icons::DocumentSave, tr("&Enregistrer", "menu entry"), this); save_as_ = new QAction(QET::Icons::DocumentSave, tr("Enregistrer sous", "menu entry"), this); quit_ = new QAction(QET::Icons::ApplicationExit, tr("&Quitter", "menu entry"), this); @@ -178,6 +189,7 @@ void QETTitleBlockTemplateEditor::initActions() { merge_cells_ = new QAction( tr("&Fusionner les cellules", "menu entry"), this); split_cell_ = new QAction( tr("&S\351parer les cellules", "menu entry"), this); + new_ -> setShortcut(QKeySequence::New); save_ -> setShortcut(QKeySequence::Save); quit_ -> setShortcut(QKeySequence(tr("Ctrl+Q", "shortcut to quit"))); merge_cells_ -> setShortcut(QKeySequence(tr("Ctrl+K", "shortcut to merge cells"))); @@ -191,6 +203,7 @@ void QETTitleBlockTemplateEditor::initActions() { about_qet_ -> setStatusTip(tr("Affiche des informations sur QElectroTech", "status bar tip")); about_qt_ -> setStatusTip(tr("Affiche des informations sur la biblioth\350que Qt", "status bar tip")); + connect(new_, SIGNAL(triggered()), this, SLOT(newTemplate())); connect(save_, SIGNAL(triggered()), this, SLOT(save())); connect(save_as_, SIGNAL(triggered()), this, SLOT(saveAs())); connect(quit_, SIGNAL(triggered()), this, SLOT(quit())); @@ -221,6 +234,7 @@ void QETTitleBlockTemplateEditor::initMenus() { display_menu_ -> setTearOffEnabled(true); help_menu_ -> setTearOffEnabled(true); + file_menu_ -> addAction(new_); file_menu_ -> addAction(save_); file_menu_ -> addAction(save_as_); file_menu_ -> addSeparator(); diff --git a/sources/titleblock/qettemplateeditor.h b/sources/titleblock/qettemplateeditor.h index 722d8e5c9..7d18d1593 100644 --- a/sources/titleblock/qettemplateeditor.h +++ b/sources/titleblock/qettemplateeditor.h @@ -49,7 +49,7 @@ class QETTitleBlockTemplateEditor : public QMainWindow { /// menus TODO QMenu *file_menu_, *edit_menu_,/* *paste_from_menu_, */*display_menu_,/* *tools_menu_,*/ *config_menu_, *help_menu_; /// actions - QAction *save_, *save_as_, *quit_, *configure_, *about_qt_, *about_qet_, *merge_cells_, *split_cell_; + QAction *new_, *save_, *save_as_, *quit_, *configure_, *about_qt_, *about_qet_, *merge_cells_, *split_cell_; QAction *zoom_in_, *zoom_out_, *zoom_fit_, *zoom_reset_; /// Location of the currently edited template TitleBlockTemplateLocation location_; @@ -88,6 +88,7 @@ class QETTitleBlockTemplateEditor : public QMainWindow { bool editCopyOf(const TitleBlockTemplate *); bool edit(TitleBlockTemplate *); void editLogos(); + void newTemplate(); void save(); void saveAs(); void quit(); diff --git a/sources/titleblock/templatelocationchooser.cpp b/sources/titleblock/templatelocationchooser.cpp index bb95faad5..083a99c1c 100644 --- a/sources/titleblock/templatelocationchooser.cpp +++ b/sources/titleblock/templatelocationchooser.cpp @@ -51,7 +51,10 @@ QString TitleBlockTemplateLocationChooser::name() const { @param location to be displayed by this widget */ void TitleBlockTemplateLocationChooser::setLocation(const TitleBlockTemplateLocation &location) { - collections_ -> setCurrentIndex(collections_index_.keys(location.parentCollection()).first()); + // hack: if o suitable index was found, set it to 1, which is supposed to be the user collection + int index = indexForCollection(location.parentCollection()); + if (index == -1 && collections_ -> count() > 1) index = 1; + collections_ -> setCurrentIndex(index); if (!location.name().isEmpty()) { int template_index = templates_ -> findText(location.name()); @@ -83,6 +86,16 @@ void TitleBlockTemplateLocationChooser::init() { setLayout(form_layout); } +/** + @param coll A Title block templates collection which we want to know the index within the combo box of this dialog. + @return -1 if the collection is unknown to this dialog, or the index of \a coll +*/ +int TitleBlockTemplateLocationChooser::indexForCollection(TitleBlockTemplatesCollection *coll) const { + QList indexes = collections_index_.keys(coll); + if (indexes.count()) return(indexes.first()); + return(-1); +} + /** Update the collections list */ diff --git a/sources/titleblock/templatelocationchooser.h b/sources/titleblock/templatelocationchooser.h index 717a9870e..39eef7e3f 100644 --- a/sources/titleblock/templatelocationchooser.h +++ b/sources/titleblock/templatelocationchooser.h @@ -40,8 +40,10 @@ class TitleBlockTemplateLocationChooser : public QWidget { TitleBlockTemplatesCollection *collection() const; QString name() const; void setLocation(const TitleBlockTemplateLocation &); + private: void init(); + int indexForCollection(TitleBlockTemplatesCollection *) const; // slots private slots: