2011-12-25 17:45:39 +00:00
|
|
|
/*
|
2012-01-01 22:51:51 +00:00
|
|
|
Copyright 2006-2012 Xavier Guerrin
|
2011-12-25 17:45:39 +00:00
|
|
|
This file is part of QElectroTech.
|
|
|
|
|
|
|
|
QElectroTech is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
QElectroTech is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#include "qettemplateeditor.h"
|
2012-01-10 18:53:48 +00:00
|
|
|
#include "qetmessagebox.h"
|
2011-12-25 17:45:39 +00:00
|
|
|
#include "qeticons.h"
|
|
|
|
#include "qetapp.h"
|
|
|
|
#include "qetproject.h"
|
|
|
|
#include "templatecellwidget.h"
|
|
|
|
#include "templatecommands.h"
|
|
|
|
#include "templateview.h"
|
2012-01-10 07:07:48 +00:00
|
|
|
#include "templatelocationsaver.h"
|
2011-12-25 17:45:39 +00:00
|
|
|
#include "templatelogomanager.h"
|
|
|
|
#include "templatecellwidget.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
@param parent parent QWidget of this window
|
|
|
|
*/
|
|
|
|
QETTitleBlockTemplateEditor::QETTitleBlockTemplateEditor(QWidget *parent) :
|
|
|
|
QMainWindow(parent),
|
2012-01-12 07:04:09 +00:00
|
|
|
opened_from_file_(false),
|
2012-01-22 14:35:57 +00:00
|
|
|
read_only_(false),
|
2011-12-25 17:45:39 +00:00
|
|
|
tb_template_(0),
|
|
|
|
logo_manager_(0)
|
|
|
|
{
|
2011-12-27 01:39:45 +00:00
|
|
|
setWindowIcon(QET::Icons::QETLogo);
|
|
|
|
setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
|
2011-12-25 17:45:39 +00:00
|
|
|
initWidgets();
|
|
|
|
initActions();
|
|
|
|
initMenus();
|
2012-01-12 07:04:09 +00:00
|
|
|
|
2011-12-25 17:45:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Destructor
|
|
|
|
*/
|
|
|
|
QETTitleBlockTemplateEditor::~QETTitleBlockTemplateEditor() {
|
|
|
|
}
|
|
|
|
|
2011-12-26 05:42:48 +00:00
|
|
|
/**
|
|
|
|
@return the location of the currently edited template
|
|
|
|
*/
|
|
|
|
TitleBlockTemplateLocation QETTitleBlockTemplateEditor::location() const {
|
2012-01-08 17:04:34 +00:00
|
|
|
return(location_);
|
|
|
|
}
|
|
|
|
|
2012-01-10 18:53:48 +00:00
|
|
|
/**
|
|
|
|
@return true if the currently edited template can be closed. A template can be
|
|
|
|
closed if it has not been modified. If the template has been modified, this
|
|
|
|
method asks the user what he wants to do.
|
|
|
|
*/
|
|
|
|
bool QETTitleBlockTemplateEditor::canClose() {
|
|
|
|
if (undo_stack_ -> isClean()) return(true);
|
|
|
|
// ask the user whether he wants to save the current template
|
|
|
|
QMessageBox::StandardButton answer = QET::MessageBox::question(
|
|
|
|
this,
|
|
|
|
tr("Enregistrer le mod\350le en cours ?", "dialog title"),
|
|
|
|
QString(
|
|
|
|
tr(
|
|
|
|
"Voulez-vous enregistrer le mod\350le %1 ?",
|
|
|
|
"dialog content - %1 is a title block template name"
|
|
|
|
)
|
|
|
|
).arg(location_.name()),
|
|
|
|
QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
|
|
|
|
QMessageBox::Cancel
|
|
|
|
);
|
|
|
|
bool result;
|
|
|
|
switch(answer) {
|
|
|
|
case QMessageBox::Cancel: result = false; break; // the user hits Cancel or closes the dialog: abort the closing
|
|
|
|
case QMessageBox::Yes: result = save(); break; // the user hits Yes: la reussite depend de l'enregistrement
|
|
|
|
default: result = true; // the user hits no: the editor can be closed
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Handle the closing of the main window
|
|
|
|
@param qce The QCloseEvent event
|
|
|
|
*/
|
|
|
|
void QETTitleBlockTemplateEditor::closeEvent(QCloseEvent *qce) {
|
|
|
|
if (canClose()) {
|
|
|
|
setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
qce -> accept();
|
|
|
|
} else qce -> ignore();
|
|
|
|
}
|
|
|
|
|
2012-01-08 17:04:34 +00:00
|
|
|
/**
|
|
|
|
@param location Location of the tile block template to be edited.
|
|
|
|
*/
|
|
|
|
bool QETTitleBlockTemplateEditor::edit(const TitleBlockTemplateLocation &location) {
|
|
|
|
// the template name may be empty to create a new one
|
|
|
|
const TitleBlockTemplate *tb_template_orig;
|
|
|
|
if (location.name().isEmpty()) {
|
|
|
|
// loads the default title block template provided by the application
|
|
|
|
// it will be used as a start point to design the title block
|
|
|
|
tb_template_orig = QETApp::defaultTitleBlockTemplate();
|
|
|
|
} else {
|
|
|
|
tb_template_orig = location.getTemplate();
|
|
|
|
}
|
|
|
|
if (!tb_template_orig) {
|
|
|
|
/// TODO The TBT does not exist, manage error
|
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
|
2012-01-12 07:04:09 +00:00
|
|
|
opened_from_file_ = false;
|
2012-01-08 17:04:34 +00:00
|
|
|
location_ = location;
|
2012-01-12 07:04:09 +00:00
|
|
|
updateEditorTitle();
|
2012-01-08 17:04:34 +00:00
|
|
|
editCopyOf(tb_template_orig);
|
|
|
|
return(true);
|
2011-12-26 05:42:48 +00:00
|
|
|
}
|
|
|
|
|
2011-12-25 17:45:39 +00:00
|
|
|
/**
|
|
|
|
Edit the given template.
|
|
|
|
@param project Parent project of the template to edit.
|
|
|
|
@param template_name Name of the template to edit within its parent project.
|
|
|
|
@return true if this editor was able to edit the given template, false otherwise
|
|
|
|
*/
|
|
|
|
bool QETTitleBlockTemplateEditor::edit(QETProject *project, const QString &template_name) {
|
|
|
|
// we require a project we will rattach templates to
|
|
|
|
if (!project) return(false);
|
|
|
|
|
|
|
|
// the template name may be empty to create a new one
|
|
|
|
const TitleBlockTemplate *tb_template_orig;
|
|
|
|
if (template_name.isEmpty()) {
|
|
|
|
// loads the default title block template provided by the application
|
|
|
|
// it will be used as a start point to design the title block
|
|
|
|
tb_template_orig = QETApp::defaultTitleBlockTemplate();
|
|
|
|
} else {
|
|
|
|
tb_template_orig = project -> getTemplateByName(template_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!tb_template_orig) {
|
|
|
|
/// TODO The TBT does not exist, manage error
|
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
|
2012-01-12 07:04:09 +00:00
|
|
|
opened_from_file_ = false;
|
2012-01-08 17:04:34 +00:00
|
|
|
location_.setParentCollection(project -> embeddedTitleBlockTemplatesCollection());
|
|
|
|
location_.setName(template_name);
|
2012-01-12 07:04:09 +00:00
|
|
|
updateEditorTitle();
|
2012-01-08 17:04:34 +00:00
|
|
|
return(editCopyOf(tb_template_orig));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@param file_path Path of the template file to edit.
|
|
|
|
@return false if a problem occured while opening the template, true otherwise.
|
|
|
|
*/
|
|
|
|
bool QETTitleBlockTemplateEditor::edit(const QString &file_path) {
|
|
|
|
// get title block template object from the file, edit it
|
|
|
|
TitleBlockTemplate *tbt = new TitleBlockTemplate();
|
|
|
|
bool loading = tbt -> loadFromXmlFile(file_path);
|
|
|
|
if (!loading) {
|
|
|
|
/// TODO the file opening failed, warn the user?
|
|
|
|
return(false);
|
|
|
|
}
|
2012-01-12 07:04:09 +00:00
|
|
|
|
|
|
|
bool editing = edit(tbt);
|
|
|
|
if (!editing) {
|
|
|
|
/// TODO the file editing failed, warn the user?
|
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
filepath_ = file_path;
|
|
|
|
opened_from_file_ = true;
|
|
|
|
updateEditorTitle();
|
|
|
|
|
|
|
|
return(true);
|
2012-01-08 17:04:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@param tbt Title block template to be edited
|
|
|
|
@return false if a problem occured while opening the template, true otherwise.
|
|
|
|
*/
|
|
|
|
bool QETTitleBlockTemplateEditor::editCopyOf(const TitleBlockTemplate *tbt) {
|
|
|
|
if (!tbt) return(false);
|
|
|
|
return(edit(tbt -> clone()));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@param tbt Title block template to be directly edited
|
|
|
|
@return false if a problem occured while opening the template, true otherwise.
|
|
|
|
*/
|
|
|
|
bool QETTitleBlockTemplateEditor::edit(TitleBlockTemplate *tbt) {
|
|
|
|
if (!tbt) return(false);
|
|
|
|
tb_template_ = tbt;
|
2011-12-25 17:45:39 +00:00
|
|
|
template_edition_area_view_ -> setTitleBlockTemplate(tb_template_);
|
|
|
|
template_cell_editor_widget_ -> updateLogosComboBox(tb_template_);
|
|
|
|
updateEditorTitle();
|
|
|
|
return(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Launches the logo manager widget, which allows the user to manage the
|
|
|
|
logos embedded within the edited template.
|
|
|
|
*/
|
|
|
|
void QETTitleBlockTemplateEditor::editLogos() {
|
|
|
|
if (tb_template_) {
|
|
|
|
if (!logo_manager_) {
|
2011-12-30 02:42:50 +00:00
|
|
|
initLogoManager();
|
2011-12-25 17:45:39 +00:00
|
|
|
}
|
|
|
|
logo_manager_ -> show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-09 18:50:26 +00:00
|
|
|
/**
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2011-12-25 17:45:39 +00:00
|
|
|
/**
|
|
|
|
Initialize the various actions.
|
|
|
|
*/
|
|
|
|
void QETTitleBlockTemplateEditor::initActions() {
|
|
|
|
QETApp *qet_app = QETApp::instance();
|
|
|
|
|
2012-01-09 18:50:26 +00:00
|
|
|
new_ = new QAction(QET::Icons::DocumentNew, tr("&Nouveau", "menu entry"), this);
|
2012-01-10 18:53:48 +00:00
|
|
|
open_ = new QAction(QET::Icons::DocumentOpen, tr("&Ouvrir", "menu entry"), this);
|
2012-01-12 07:04:09 +00:00
|
|
|
open_from_file_ = new QAction(QET::Icons::DocumentOpen, tr("Ouvrir depuis un fichier", "menu entry"), this);
|
2011-12-25 18:22:39 +00:00
|
|
|
save_ = new QAction(QET::Icons::DocumentSave, tr("&Enregistrer", "menu entry"), this);
|
2011-12-26 05:42:48 +00:00
|
|
|
save_as_ = new QAction(QET::Icons::DocumentSave, tr("Enregistrer sous", "menu entry"), this);
|
2012-01-12 07:04:09 +00:00
|
|
|
save_as_file_ = new QAction(QET::Icons::DocumentSave, tr("Enregistrer vers un fichier", "menu entry"), this);
|
2011-12-25 18:22:39 +00:00
|
|
|
quit_ = new QAction(QET::Icons::ApplicationExit, tr("&Quitter", "menu entry"), this);
|
2012-01-15 00:33:03 +00:00
|
|
|
undo_ = undo_stack_ -> createUndoAction(this);
|
|
|
|
redo_ = undo_stack_ -> createRedoAction(this);
|
2011-12-30 02:05:46 +00:00
|
|
|
zoom_in_ = new QAction(QET::Icons::ZoomIn, tr("Zoom avant", "menu entry"), this);
|
|
|
|
zoom_out_ = new QAction(QET::Icons::ZoomOut, tr("Zoom arri\350re", "menu entry"), this);
|
|
|
|
zoom_fit_ = new QAction(QET::Icons::ZoomFitBest, tr("Zoom adapt\351", "menu entry"), this);
|
|
|
|
zoom_reset_ = new QAction(QET::Icons::ZoomOriginal, tr("Pas de zoom", "menu entry"), this);
|
2011-12-25 18:22:39 +00:00
|
|
|
configure_ = new QAction(QET::Icons::Configure, tr("&Configurer QElectroTech", "menu entry"), this);
|
|
|
|
about_qet_ = new QAction(QET::Icons::QETLogo, tr("\300 &propos de QElectroTech", "menu entry"), this);
|
|
|
|
about_qt_ = new QAction(QET::Icons::QtLogo, tr("\300 propos de &Qt", "menu entry"), this);
|
|
|
|
merge_cells_ = new QAction( tr("&Fusionner les cellules", "menu entry"), this);
|
|
|
|
split_cell_ = new QAction( tr("&S\351parer les cellules", "menu entry"), this);
|
2011-12-25 17:45:39 +00:00
|
|
|
|
2012-01-15 00:33:03 +00:00
|
|
|
undo_ -> setIcon(QET::Icons::EditUndo);
|
|
|
|
redo_ -> setIcon(QET::Icons::EditRedo);
|
|
|
|
|
2012-01-09 18:50:26 +00:00
|
|
|
new_ -> setShortcut(QKeySequence::New);
|
2012-01-10 18:53:48 +00:00
|
|
|
open_ -> setShortcut(QKeySequence::Open);
|
2011-12-25 17:45:39 +00:00
|
|
|
save_ -> setShortcut(QKeySequence::Save);
|
|
|
|
quit_ -> setShortcut(QKeySequence(tr("Ctrl+Q", "shortcut to quit")));
|
2012-01-15 00:33:03 +00:00
|
|
|
undo_ -> setShortcut(QKeySequence::Undo);
|
|
|
|
redo_ -> setShortcut(QKeySequence::Redo);
|
2011-12-25 17:45:39 +00:00
|
|
|
merge_cells_ -> setShortcut(QKeySequence(tr("Ctrl+K", "shortcut to merge cells")));
|
|
|
|
split_cell_ -> setShortcut(QKeySequence(tr("Ctrl+J", "shortcut to split merged cell")));
|
2011-12-30 02:05:46 +00:00
|
|
|
zoom_in_ -> setShortcut(QKeySequence::ZoomIn);
|
|
|
|
zoom_out_ -> setShortcut(QKeySequence::ZoomOut);
|
|
|
|
zoom_fit_ -> setShortcut(QKeySequence(tr("Ctrl+9", "shortcut to enable fit zoom")));
|
|
|
|
zoom_reset_ -> setShortcut(QKeySequence(tr("Ctrl+0", "shortcut to reset zoom")));
|
2011-12-25 17:45:39 +00:00
|
|
|
|
|
|
|
configure_ -> setStatusTip(tr("Permet de r\351gler diff\351rents param\350tres de QElectroTech", "status bar tip"));
|
|
|
|
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"));
|
|
|
|
|
2012-01-09 18:50:26 +00:00
|
|
|
connect(new_, SIGNAL(triggered()), this, SLOT(newTemplate()));
|
2012-01-10 18:53:48 +00:00
|
|
|
connect(open_, SIGNAL(triggered()), this, SLOT(open()));
|
2012-01-12 07:04:09 +00:00
|
|
|
connect(open_from_file_, SIGNAL(triggered()), this, SLOT(openFromFile()));
|
2011-12-25 17:45:39 +00:00
|
|
|
connect(save_, SIGNAL(triggered()), this, SLOT(save()));
|
2011-12-26 05:42:48 +00:00
|
|
|
connect(save_as_, SIGNAL(triggered()), this, SLOT(saveAs()));
|
2012-01-12 07:04:09 +00:00
|
|
|
connect(save_as_file_, SIGNAL(triggered()), this, SLOT(saveAsFile()));
|
2011-12-25 17:45:39 +00:00
|
|
|
connect(quit_, SIGNAL(triggered()), this, SLOT(quit()));
|
2011-12-30 02:05:46 +00:00
|
|
|
connect(zoom_in_, SIGNAL(triggered()), template_edition_area_view_, SLOT(zoomIn()));
|
|
|
|
connect(zoom_out_, SIGNAL(triggered()), template_edition_area_view_, SLOT(zoomOut()));
|
|
|
|
connect(zoom_fit_, SIGNAL(triggered()), template_edition_area_view_, SLOT(zoomFit()));
|
|
|
|
connect(zoom_reset_, SIGNAL(triggered()), template_edition_area_view_, SLOT(zoomReset()));
|
2011-12-25 17:45:39 +00:00
|
|
|
connect(configure_, SIGNAL(triggered()), qet_app, SLOT(configureQET()));
|
|
|
|
connect(about_qet_, SIGNAL(triggered()), qet_app, SLOT(aboutQET()));
|
|
|
|
connect(about_qt_, SIGNAL(triggered()), qet_app, SLOT(aboutQt()));
|
|
|
|
connect(merge_cells_, SIGNAL(triggered()), template_edition_area_view_, SLOT(mergeSelectedCells()));
|
|
|
|
connect(split_cell_, SIGNAL(triggered()), template_edition_area_view_, SLOT(splitSelectedCell()));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Initialize the various menus.
|
|
|
|
*/
|
|
|
|
void QETTitleBlockTemplateEditor::initMenus() {
|
2011-12-25 18:22:39 +00:00
|
|
|
file_menu_ = new QMenu(tr("&Fichier", "menu title"), this);
|
|
|
|
edit_menu_ = new QMenu(tr("&\311dition", "menu title"), this);
|
2011-12-30 02:05:46 +00:00
|
|
|
display_menu_ = new QMenu(tr("Afficha&ge", "menu title"), this);
|
2011-12-25 18:22:39 +00:00
|
|
|
config_menu_ = new QMenu(tr("&Configuration", "menu title"), this);
|
|
|
|
help_menu_ = new QMenu(tr("&Aide", "menu title"), this);
|
2011-12-25 17:45:39 +00:00
|
|
|
|
|
|
|
file_menu_ -> setTearOffEnabled(true);
|
|
|
|
edit_menu_ -> setTearOffEnabled(true);
|
|
|
|
config_menu_ -> setTearOffEnabled(true);
|
2011-12-30 02:05:46 +00:00
|
|
|
display_menu_ -> setTearOffEnabled(true);
|
2011-12-25 17:45:39 +00:00
|
|
|
help_menu_ -> setTearOffEnabled(true);
|
|
|
|
|
2012-01-09 18:50:26 +00:00
|
|
|
file_menu_ -> addAction(new_);
|
2012-01-10 18:53:48 +00:00
|
|
|
file_menu_ -> addAction(open_);
|
2012-01-12 07:04:09 +00:00
|
|
|
file_menu_ -> addAction(open_from_file_);
|
2011-12-25 17:45:39 +00:00
|
|
|
file_menu_ -> addAction(save_);
|
2011-12-26 05:42:48 +00:00
|
|
|
file_menu_ -> addAction(save_as_);
|
2012-01-12 07:04:09 +00:00
|
|
|
file_menu_ -> addAction(save_as_file_);
|
2011-12-25 17:45:39 +00:00
|
|
|
file_menu_ -> addSeparator();
|
|
|
|
file_menu_ -> addAction(quit_);
|
|
|
|
|
2012-01-15 00:33:03 +00:00
|
|
|
edit_menu_ -> addAction(undo_);
|
|
|
|
edit_menu_ -> addAction(redo_);
|
|
|
|
edit_menu_ -> addSeparator();
|
2011-12-25 17:45:39 +00:00
|
|
|
edit_menu_ -> addAction(merge_cells_);
|
|
|
|
edit_menu_ -> addAction(split_cell_);
|
|
|
|
|
2011-12-30 02:05:46 +00:00
|
|
|
display_menu_ -> addAction(zoom_in_);
|
|
|
|
display_menu_ -> addAction(zoom_out_);
|
|
|
|
display_menu_ -> addAction(zoom_fit_);
|
|
|
|
display_menu_ -> addAction(zoom_reset_);
|
|
|
|
|
2011-12-25 17:45:39 +00:00
|
|
|
config_menu_ -> addAction(configure_);
|
|
|
|
|
|
|
|
help_menu_ -> addAction(about_qet_);
|
|
|
|
help_menu_ -> addAction(about_qt_);
|
|
|
|
|
|
|
|
menuBar() -> addMenu(file_menu_);
|
|
|
|
menuBar() -> addMenu(edit_menu_);
|
2011-12-30 02:05:46 +00:00
|
|
|
menuBar() -> addMenu(display_menu_);
|
2011-12-25 17:45:39 +00:00
|
|
|
menuBar() -> addMenu(config_menu_);
|
|
|
|
menuBar() -> addMenu(help_menu_);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Initialize layouts and widgets
|
|
|
|
*/
|
|
|
|
void QETTitleBlockTemplateEditor::initWidgets() {
|
|
|
|
// undo list on the right
|
|
|
|
undo_stack_ = new QUndoStack(this);
|
|
|
|
undo_view_ = new QUndoView(undo_stack_);
|
|
|
|
undo_view_ -> setEmptyLabel(tr("Aucune modification", "label displayed in the undo list when empty"));
|
|
|
|
|
|
|
|
undo_dock_widget_ = new QDockWidget(tr("Annulations", "dock title"));
|
|
|
|
undo_dock_widget_ -> setFeatures(QDockWidget::AllDockWidgetFeatures);
|
|
|
|
undo_dock_widget_ -> setWidget(undo_view_);
|
|
|
|
undo_dock_widget_ -> setMinimumWidth(290);
|
|
|
|
addDockWidget(Qt::RightDockWidgetArea, undo_dock_widget_);
|
|
|
|
|
|
|
|
// WYSIWYG editor as central widget
|
|
|
|
template_edition_area_scene_ = new QGraphicsScene(this);
|
|
|
|
template_edition_area_view_ = new TitleBlockTemplateView(template_edition_area_scene_);
|
|
|
|
setCentralWidget(template_edition_area_view_);
|
|
|
|
|
|
|
|
// cell edition widget at the bottom
|
|
|
|
template_cell_editor_widget_ = new TitleBlockTemplateCellWidget(tb_template_);
|
|
|
|
template_cell_editor_dock_widget_ = new QDockWidget(tr("Propri\351t\351s de la cellule", "dock title"), this);
|
|
|
|
template_cell_editor_dock_widget_ -> setFeatures(QDockWidget::AllDockWidgetFeatures);
|
|
|
|
template_cell_editor_dock_widget_ -> setWidget(template_cell_editor_widget_);
|
|
|
|
template_cell_editor_dock_widget_ -> setMinimumWidth(180);
|
|
|
|
template_cell_editor_dock_widget_ -> setMinimumHeight(250);
|
|
|
|
addDockWidget(Qt::BottomDockWidgetArea, template_cell_editor_dock_widget_);
|
|
|
|
template_cell_editor_widget_ -> setVisible(false);
|
|
|
|
|
|
|
|
connect(
|
|
|
|
template_edition_area_view_,
|
|
|
|
SIGNAL(selectedCellsChanged(QList<TitleBlockCell *>)),
|
|
|
|
this,
|
|
|
|
SLOT(selectedCellsChanged(QList<TitleBlockCell *>))
|
|
|
|
);
|
|
|
|
connect(template_cell_editor_widget_, SIGNAL(logoEditionRequested()), this, SLOT(editLogos()));
|
|
|
|
connect(
|
|
|
|
template_cell_editor_widget_,
|
|
|
|
SIGNAL(cellModified(ModifyTitleBlockCellCommand *)),
|
|
|
|
this,
|
|
|
|
SLOT(pushCellUndoCommand(ModifyTitleBlockCellCommand *))
|
|
|
|
);
|
|
|
|
connect(
|
|
|
|
template_edition_area_view_,
|
|
|
|
SIGNAL(gridModificationRequested(TitleBlockTemplateCommand *)),
|
|
|
|
this,
|
|
|
|
SLOT(pushGridUndoCommand(TitleBlockTemplateCommand *))
|
|
|
|
);
|
2012-01-12 07:04:09 +00:00
|
|
|
connect(undo_stack_, SIGNAL(cleanChanged(bool)), this, SLOT(updateEditorTitle()));
|
2011-12-25 17:45:39 +00:00
|
|
|
}
|
|
|
|
|
2012-01-08 17:04:34 +00:00
|
|
|
/**
|
|
|
|
Initialize the logo manager
|
|
|
|
*/
|
2011-12-30 02:42:50 +00:00
|
|
|
void QETTitleBlockTemplateEditor::initLogoManager() {
|
|
|
|
logo_manager_ = new TitleBlockTemplateLogoManager(tb_template_);
|
2012-01-22 14:35:57 +00:00
|
|
|
logo_manager_ -> setReadOnly(read_only_);
|
2011-12-30 02:42:50 +00:00
|
|
|
connect(
|
|
|
|
logo_manager_,
|
|
|
|
SIGNAL(logosChanged(const TitleBlockTemplate *)),
|
|
|
|
template_cell_editor_widget_,
|
|
|
|
SLOT(updateLogosComboBox(const TitleBlockTemplate *))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-01-12 07:24:21 +00:00
|
|
|
/**
|
|
|
|
@return a string describing what is being edited, along with [Changed] or
|
|
|
|
[Read only] tags. Useful to compose the window title.
|
|
|
|
*/
|
|
|
|
QString QETTitleBlockTemplateEditor::currentlyEditedTitle() const {
|
|
|
|
QString titleblock_title;
|
|
|
|
if (opened_from_file_) {
|
|
|
|
titleblock_title = filepath_;
|
|
|
|
} else {
|
|
|
|
titleblock_title = location_.name();
|
|
|
|
}
|
|
|
|
|
|
|
|
// if a (file)name has been added, also add a "[Changed]" tag if needed
|
|
|
|
if (!titleblock_title.isEmpty()) {
|
|
|
|
QString tag;
|
|
|
|
if (!undo_stack_ -> isClean()) {
|
|
|
|
tag = tr("[Modifi\351]", "window title tag");
|
|
|
|
}
|
2012-01-22 14:35:57 +00:00
|
|
|
if (read_only_) {
|
|
|
|
tag = tr("[Lecture seule]", "window title tag");
|
|
|
|
}
|
2012-01-12 07:24:21 +00:00
|
|
|
titleblock_title = QString(
|
|
|
|
tr(
|
|
|
|
"%1 %2",
|
|
|
|
"part of the window title - %1 is the filepath or template name, %2 is the [Changed] or [Read only] tag"
|
|
|
|
)
|
|
|
|
).arg(titleblock_title).arg(tag);
|
|
|
|
}
|
|
|
|
|
|
|
|
return(titleblock_title);
|
|
|
|
}
|
|
|
|
|
2011-12-25 17:45:39 +00:00
|
|
|
/**
|
|
|
|
Update various things when user changes the selected cells.
|
|
|
|
@param selected_cells List of selected cells.
|
|
|
|
*/
|
|
|
|
void QETTitleBlockTemplateEditor::selectedCellsChanged(QList<TitleBlockCell *> selected_cells) {
|
|
|
|
if (selected_cells.count() == 1) {
|
|
|
|
template_cell_editor_widget_ -> edit(selected_cells.at(0));
|
|
|
|
template_cell_editor_widget_ -> setVisible(true);
|
|
|
|
} else {
|
|
|
|
template_cell_editor_widget_ -> setVisible(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Configure an undo Command before adding it to the undo stack.
|
|
|
|
@param command to be added to the undo stack
|
|
|
|
*/
|
|
|
|
void QETTitleBlockTemplateEditor::pushCellUndoCommand(ModifyTitleBlockCellCommand *command) {
|
|
|
|
command -> setView(template_edition_area_view_);
|
|
|
|
pushUndoCommand(command);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Add an undo Command to the undo stack.
|
|
|
|
@param command QUndoCommand to be added to the undo stack
|
|
|
|
*/
|
|
|
|
void QETTitleBlockTemplateEditor::pushGridUndoCommand(TitleBlockTemplateCommand *command) {
|
|
|
|
pushUndoCommand(command);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Add an undo Command to the undo stack.
|
|
|
|
@param command QUndoCommand to be added to the undo stack
|
|
|
|
*/
|
|
|
|
void QETTitleBlockTemplateEditor::pushUndoCommand(QUndoCommand *command) {
|
|
|
|
undo_stack_ -> push(command);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Set the title of this editor.
|
|
|
|
*/
|
|
|
|
void QETTitleBlockTemplateEditor::updateEditorTitle() {
|
2012-01-12 07:24:21 +00:00
|
|
|
// base title
|
2011-12-25 17:45:39 +00:00
|
|
|
QString min_title(
|
|
|
|
tr(
|
|
|
|
"QElectroTech - \311diteur de mod\350le de cartouche",
|
|
|
|
"titleblock template editor: base window title"
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2012-01-12 07:24:21 +00:00
|
|
|
// get the currently edited template (file)name
|
|
|
|
QString titleblock_title = currentlyEditedTitle();
|
2012-01-12 07:04:09 +00:00
|
|
|
|
2012-01-12 07:24:21 +00:00
|
|
|
// generate the final window title
|
2011-12-25 17:45:39 +00:00
|
|
|
QString title;
|
2012-01-12 07:04:09 +00:00
|
|
|
if (titleblock_title.isEmpty()) {
|
2011-12-25 17:45:39 +00:00
|
|
|
title = min_title;
|
|
|
|
} else {
|
|
|
|
title = QString(
|
|
|
|
tr(
|
|
|
|
"%1 - %2",
|
|
|
|
"window title: %1 is the base window title, %2 is a template name"
|
|
|
|
)
|
2012-01-12 07:04:09 +00:00
|
|
|
).arg(min_title).arg(titleblock_title);
|
2011-12-25 17:45:39 +00:00
|
|
|
}
|
|
|
|
setWindowTitle(title);
|
|
|
|
}
|
|
|
|
|
2012-01-22 14:35:57 +00:00
|
|
|
/**
|
|
|
|
Ensure the user interface remains consistent by enabling or disabling
|
|
|
|
adequate actions.
|
|
|
|
*/
|
|
|
|
void QETTitleBlockTemplateEditor::updateActions() {
|
|
|
|
/// TODO complete this method
|
|
|
|
merge_cells_ -> setEnabled(!read_only_);
|
|
|
|
split_cell_ -> setEnabled(!read_only_);
|
|
|
|
}
|
|
|
|
|
2011-12-25 17:45:39 +00:00
|
|
|
/**
|
2012-01-08 17:04:34 +00:00
|
|
|
Save the template under the provided location.
|
2011-12-26 05:42:48 +00:00
|
|
|
@see QETProject::setTemplateXmlDescription()
|
2012-01-08 17:04:34 +00:00
|
|
|
@param location Location where the title block template should be saved.
|
2011-12-25 17:45:39 +00:00
|
|
|
*/
|
2012-01-10 18:53:48 +00:00
|
|
|
bool QETTitleBlockTemplateEditor::saveAs(const TitleBlockTemplateLocation &location) {
|
2012-01-08 17:04:34 +00:00
|
|
|
TitleBlockTemplatesCollection *collection = location.parentCollection();
|
2012-01-10 18:53:48 +00:00
|
|
|
if (!collection) return(false);
|
2011-12-26 05:42:48 +00:00
|
|
|
|
2011-12-25 17:45:39 +00:00
|
|
|
QDomDocument doc;
|
|
|
|
QDomElement elmt = doc.createElement("root");
|
|
|
|
tb_template_ -> saveToXmlElement(elmt);
|
2012-01-08 17:04:34 +00:00
|
|
|
elmt.setAttribute("name", location.name());
|
2011-12-25 17:45:39 +00:00
|
|
|
doc.appendChild(elmt);
|
|
|
|
|
2012-01-08 17:04:34 +00:00
|
|
|
collection -> setTemplateXmlDescription(location.name(), elmt);
|
2011-12-26 05:42:48 +00:00
|
|
|
|
2012-01-12 07:04:09 +00:00
|
|
|
opened_from_file_ = false;
|
2012-01-08 17:04:34 +00:00
|
|
|
location_ = location;
|
2012-01-10 18:53:48 +00:00
|
|
|
undo_stack_ -> setClean();
|
2012-01-12 07:04:09 +00:00
|
|
|
updateEditorTitle();
|
2012-01-10 18:53:48 +00:00
|
|
|
return(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-01-12 07:04:09 +00:00
|
|
|
Save the template in the provided filepath.
|
|
|
|
@see TitleBlockTemplate::saveToXmlFile()
|
|
|
|
@param filepath location Location where the title block template should be saved.
|
|
|
|
*/
|
|
|
|
bool QETTitleBlockTemplateEditor::saveAs(const QString &filepath) {
|
|
|
|
bool saving = tb_template_ -> saveToXmlFile(filepath);
|
|
|
|
if (!saving) return(false);
|
2012-01-10 18:53:48 +00:00
|
|
|
|
2012-01-12 07:04:09 +00:00
|
|
|
opened_from_file_ = true;
|
|
|
|
filepath_ = filepath;
|
|
|
|
undo_stack_ -> setClean();
|
|
|
|
updateEditorTitle();
|
|
|
|
return(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Ask the user to choose a title block template from the known collections
|
|
|
|
then open it for edition.
|
2012-01-10 18:53:48 +00:00
|
|
|
*/
|
|
|
|
void QETTitleBlockTemplateEditor::open() {
|
|
|
|
TitleBlockTemplateLocation location = getTitleBlockTemplateLocationFromUser(
|
|
|
|
tr("Ouvrir un mod\350le", "File > open dialog window title"),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
if (location.isValid()) {
|
|
|
|
QETApp::instance() -> openTitleBlockTemplate(location);
|
|
|
|
}
|
2011-12-26 05:42:48 +00:00
|
|
|
}
|
|
|
|
|
2012-01-12 07:04:09 +00:00
|
|
|
/**
|
|
|
|
Ask the user to choose a file supposed to contain a title block template,
|
|
|
|
then open it for edition.
|
|
|
|
*/
|
|
|
|
void QETTitleBlockTemplateEditor::openFromFile() {
|
|
|
|
// directory to show
|
|
|
|
QString initial_dir = filepath_.isEmpty() ? QETApp::customTitleBlockTemplatesDir() : QDir(filepath_).absolutePath();
|
|
|
|
|
|
|
|
// ask the user to choose a filepath
|
|
|
|
QString user_filepath = QFileDialog::getOpenFileName(
|
|
|
|
this,
|
|
|
|
tr("Ouvrir un fichier", "dialog title"),
|
|
|
|
initial_dir,
|
|
|
|
tr(
|
|
|
|
"Mod\350les de cartouches QElectroTech (*%1);;"
|
|
|
|
"Fichiers XML (*.xml);;"
|
|
|
|
"Tous les fichiers (*)",
|
|
|
|
"filetypes allowed when opening a title block template file - %1 is the .titleblock extension"
|
|
|
|
).arg(QString(TITLEBLOCKS_FILE_EXTENSION))
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
if (!user_filepath.isEmpty()) QETApp::instance() -> openTitleBlockTemplate(user_filepath);
|
|
|
|
}
|
|
|
|
|
2011-12-26 05:42:48 +00:00
|
|
|
/**
|
|
|
|
Save the currently edited title block template back to its parent project.
|
|
|
|
*/
|
2012-01-10 18:53:48 +00:00
|
|
|
bool QETTitleBlockTemplateEditor::save() {
|
2012-01-12 07:04:09 +00:00
|
|
|
if (opened_from_file_) {
|
|
|
|
if (!filepath_.isEmpty()) {
|
|
|
|
return(saveAs(filepath_));
|
|
|
|
} else {
|
|
|
|
// Actually, this should never happen since opened_from_file_ is always set
|
|
|
|
// along with a valid path. There is a dedicated menu item to call this.s
|
|
|
|
return(saveAsFile());
|
|
|
|
}
|
2011-12-26 05:42:48 +00:00
|
|
|
} else {
|
2012-01-12 07:04:09 +00:00
|
|
|
if (location_.isValid()) {
|
|
|
|
return(saveAs(location_));
|
|
|
|
} else {
|
|
|
|
return(saveAs());
|
|
|
|
}
|
2011-12-26 05:42:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Ask the user where he wishes to save the currently edited template.
|
|
|
|
*/
|
2012-01-10 18:53:48 +00:00
|
|
|
bool QETTitleBlockTemplateEditor::saveAs() {
|
|
|
|
TitleBlockTemplateLocation location = getTitleBlockTemplateLocationFromUser(
|
|
|
|
tr("Enregistrer le mod\350le sous", "dialog window title"),
|
|
|
|
false
|
|
|
|
);
|
2011-12-26 05:42:48 +00:00
|
|
|
if (location.isValid()) {
|
2012-01-10 18:53:48 +00:00
|
|
|
return(saveAs(location));
|
2011-12-26 05:42:48 +00:00
|
|
|
}
|
2012-01-10 18:53:48 +00:00
|
|
|
return(false);
|
2011-12-26 05:42:48 +00:00
|
|
|
}
|
|
|
|
|
2012-01-12 07:04:09 +00:00
|
|
|
/**
|
|
|
|
Ask the user where on the filesystem he wishes to save the currently edited template.
|
|
|
|
*/
|
|
|
|
bool QETTitleBlockTemplateEditor::saveAsFile() {
|
|
|
|
// directory to show
|
|
|
|
QString initial_dir = filepath_.isEmpty() ? QETApp::customTitleBlockTemplatesDir() : QDir(filepath_).absolutePath();
|
|
|
|
|
|
|
|
// ask the user to choose a target file
|
|
|
|
QString filepath = QFileDialog::getSaveFileName(
|
|
|
|
this,
|
|
|
|
tr("Enregistrer sous", "dialog title"),
|
|
|
|
initial_dir,
|
|
|
|
tr(
|
|
|
|
"Mod\350les de cartouches QElectroTech (*%1)",
|
|
|
|
"filetypes allowed when saving a title block template file - %1 is the .titleblock extension"
|
|
|
|
).arg(QString(TITLEBLOCKS_FILE_EXTENSION))
|
|
|
|
);
|
|
|
|
|
|
|
|
// if no name was entered, return false
|
|
|
|
if (filepath.isEmpty()) return(false);
|
|
|
|
|
|
|
|
// if the name does not end with ".titleblock", add it
|
|
|
|
if (!filepath.endsWith(".titleblock", Qt::CaseInsensitive)) filepath += ".titleblock";
|
|
|
|
|
|
|
|
// attempts to save the file
|
|
|
|
bool saving = saveAs(filepath);
|
|
|
|
|
|
|
|
// retourne un booleen representatif de la reussite de l'enregistrement
|
|
|
|
return(saving);
|
|
|
|
}
|
|
|
|
|
2012-01-22 14:35:57 +00:00
|
|
|
/**
|
|
|
|
@param read_only True to restrict this editor to visualization of the
|
|
|
|
currently edited template, false to allow full edition.
|
|
|
|
*/
|
|
|
|
void QETTitleBlockTemplateEditor::setReadOnly(bool read_only) {
|
|
|
|
if (read_only == read_only_) return;
|
|
|
|
read_only_ = read_only;
|
|
|
|
if (logo_manager_) {
|
|
|
|
logo_manager_ -> setReadOnly(read_only_);
|
|
|
|
}
|
|
|
|
template_cell_editor_widget_ -> setReadOnly(read_only_);
|
|
|
|
template_edition_area_view_ -> setReadOnly(read_only_);
|
|
|
|
updateActions();
|
|
|
|
updateEditorTitle();
|
|
|
|
}
|
|
|
|
|
2011-12-26 05:42:48 +00:00
|
|
|
/**
|
2012-01-10 18:53:48 +00:00
|
|
|
Ask the user for a title block template location
|
|
|
|
@param title Title displayed by the dialog window
|
|
|
|
@param existing_only True for the user to be forced to choose an existing
|
|
|
|
template, false if he may specify the template name
|
|
|
|
@return The location chosen by the user, or an empty
|
|
|
|
TitleBlockTemplateLocation if the user cancelled the dialog
|
2011-12-26 05:42:48 +00:00
|
|
|
*/
|
2012-01-10 18:53:48 +00:00
|
|
|
TitleBlockTemplateLocation QETTitleBlockTemplateEditor::getTitleBlockTemplateLocationFromUser(const QString &title, bool existing_only) {
|
|
|
|
TitleBlockTemplateLocationChooser *widget;
|
|
|
|
if (existing_only) {
|
|
|
|
widget = new TitleBlockTemplateLocationChooser(location());
|
|
|
|
} else {
|
|
|
|
widget = new TitleBlockTemplateLocationSaver(location());
|
|
|
|
}
|
2011-12-26 05:42:48 +00:00
|
|
|
QDialogButtonBox *buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
|
|
|
|
|
|
|
QVBoxLayout *dialog_layout = new QVBoxLayout();
|
2012-01-10 18:53:48 +00:00
|
|
|
dialog_layout -> addWidget(widget);
|
2011-12-26 05:42:48 +00:00
|
|
|
dialog_layout -> addWidget(buttons);
|
|
|
|
|
|
|
|
QDialog dialog;
|
2012-01-10 18:53:48 +00:00
|
|
|
dialog.setWindowTitle(title);
|
2011-12-26 05:42:48 +00:00
|
|
|
dialog.setLayout(dialog_layout);
|
|
|
|
|
|
|
|
connect(buttons, SIGNAL(accepted()), &dialog, SLOT(accept()));
|
|
|
|
connect(buttons, SIGNAL(rejected()), &dialog, SLOT(reject()));
|
|
|
|
|
|
|
|
if (dialog.exec() == QDialog::Accepted) {
|
2012-01-10 18:53:48 +00:00
|
|
|
return(widget -> location());
|
2011-12-25 17:45:39 +00:00
|
|
|
}
|
2011-12-26 05:42:48 +00:00
|
|
|
return TitleBlockTemplateLocation();
|
2011-12-25 17:45:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Close the current editor.
|
|
|
|
*/
|
|
|
|
void QETTitleBlockTemplateEditor::quit() {
|
|
|
|
close();
|
|
|
|
}
|