mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-19 14:50:53 +01:00
Handled window closing and added File > Open in the title block template editor.
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/branches/0.3@1453 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#include "qettemplateeditor.h"
|
#include "qettemplateeditor.h"
|
||||||
|
#include "qetmessagebox.h"
|
||||||
#include "qeticons.h"
|
#include "qeticons.h"
|
||||||
#include "qetapp.h"
|
#include "qetapp.h"
|
||||||
#include "qetproject.h"
|
#include "qetproject.h"
|
||||||
@@ -56,6 +57,46 @@ TitleBlockTemplateLocation QETTitleBlockTemplateEditor::location() const {
|
|||||||
return(location_);
|
return(location_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@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();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@param location Location of the tile block template to be edited.
|
@param location Location of the tile block template to be edited.
|
||||||
*/
|
*/
|
||||||
@@ -175,6 +216,7 @@ void QETTitleBlockTemplateEditor::initActions() {
|
|||||||
QETApp *qet_app = QETApp::instance();
|
QETApp *qet_app = QETApp::instance();
|
||||||
|
|
||||||
new_ = new QAction(QET::Icons::DocumentNew, tr("&Nouveau", "menu entry"), this);
|
new_ = new QAction(QET::Icons::DocumentNew, tr("&Nouveau", "menu entry"), this);
|
||||||
|
open_ = new QAction(QET::Icons::DocumentOpen, tr("&Ouvrir", "menu entry"), this);
|
||||||
save_ = new QAction(QET::Icons::DocumentSave, tr("&Enregistrer", "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);
|
save_as_ = new QAction(QET::Icons::DocumentSave, tr("Enregistrer sous", "menu entry"), this);
|
||||||
quit_ = new QAction(QET::Icons::ApplicationExit, tr("&Quitter", "menu entry"), this);
|
quit_ = new QAction(QET::Icons::ApplicationExit, tr("&Quitter", "menu entry"), this);
|
||||||
@@ -189,6 +231,7 @@ void QETTitleBlockTemplateEditor::initActions() {
|
|||||||
split_cell_ = new QAction( tr("&S\351parer les cellules", "menu entry"), this);
|
split_cell_ = new QAction( tr("&S\351parer les cellules", "menu entry"), this);
|
||||||
|
|
||||||
new_ -> setShortcut(QKeySequence::New);
|
new_ -> setShortcut(QKeySequence::New);
|
||||||
|
open_ -> setShortcut(QKeySequence::Open);
|
||||||
save_ -> setShortcut(QKeySequence::Save);
|
save_ -> setShortcut(QKeySequence::Save);
|
||||||
quit_ -> setShortcut(QKeySequence(tr("Ctrl+Q", "shortcut to quit")));
|
quit_ -> setShortcut(QKeySequence(tr("Ctrl+Q", "shortcut to quit")));
|
||||||
merge_cells_ -> setShortcut(QKeySequence(tr("Ctrl+K", "shortcut to merge cells")));
|
merge_cells_ -> setShortcut(QKeySequence(tr("Ctrl+K", "shortcut to merge cells")));
|
||||||
@@ -203,6 +246,7 @@ void QETTitleBlockTemplateEditor::initActions() {
|
|||||||
about_qt_ -> setStatusTip(tr("Affiche des informations sur la biblioth\350que Qt", "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(new_, SIGNAL(triggered()), this, SLOT(newTemplate()));
|
||||||
|
connect(open_, SIGNAL(triggered()), this, SLOT(open()));
|
||||||
connect(save_, SIGNAL(triggered()), this, SLOT(save()));
|
connect(save_, SIGNAL(triggered()), this, SLOT(save()));
|
||||||
connect(save_as_, SIGNAL(triggered()), this, SLOT(saveAs()));
|
connect(save_as_, SIGNAL(triggered()), this, SLOT(saveAs()));
|
||||||
connect(quit_, SIGNAL(triggered()), this, SLOT(quit()));
|
connect(quit_, SIGNAL(triggered()), this, SLOT(quit()));
|
||||||
@@ -234,6 +278,7 @@ void QETTitleBlockTemplateEditor::initMenus() {
|
|||||||
help_menu_ -> setTearOffEnabled(true);
|
help_menu_ -> setTearOffEnabled(true);
|
||||||
|
|
||||||
file_menu_ -> addAction(new_);
|
file_menu_ -> addAction(new_);
|
||||||
|
file_menu_ -> addAction(open_);
|
||||||
file_menu_ -> addAction(save_);
|
file_menu_ -> addAction(save_);
|
||||||
file_menu_ -> addAction(save_as_);
|
file_menu_ -> addAction(save_as_);
|
||||||
file_menu_ -> addSeparator();
|
file_menu_ -> addSeparator();
|
||||||
@@ -391,9 +436,9 @@ void QETTitleBlockTemplateEditor::updateEditorTitle() {
|
|||||||
@see QETProject::setTemplateXmlDescription()
|
@see QETProject::setTemplateXmlDescription()
|
||||||
@param location Location where the title block template should be saved.
|
@param location Location where the title block template should be saved.
|
||||||
*/
|
*/
|
||||||
void QETTitleBlockTemplateEditor::saveAs(const TitleBlockTemplateLocation &location) {
|
bool QETTitleBlockTemplateEditor::saveAs(const TitleBlockTemplateLocation &location) {
|
||||||
TitleBlockTemplatesCollection *collection = location.parentCollection();
|
TitleBlockTemplatesCollection *collection = location.parentCollection();
|
||||||
if (!collection) return;
|
if (!collection) return(false);
|
||||||
|
|
||||||
QDomDocument doc;
|
QDomDocument doc;
|
||||||
QDomElement elmt = doc.createElement("root");
|
QDomElement elmt = doc.createElement("root");
|
||||||
@@ -404,51 +449,78 @@ void QETTitleBlockTemplateEditor::saveAs(const TitleBlockTemplateLocation &locat
|
|||||||
collection -> setTemplateXmlDescription(location.name(), elmt);
|
collection -> setTemplateXmlDescription(location.name(), elmt);
|
||||||
|
|
||||||
location_ = location;
|
location_ = location;
|
||||||
|
undo_stack_ -> setClean();
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
|
||||||
|
*/
|
||||||
|
void QETTitleBlockTemplateEditor::open() {
|
||||||
|
TitleBlockTemplateLocation location = getTitleBlockTemplateLocationFromUser(
|
||||||
|
tr("Ouvrir un mod\350le", "File > open dialog window title"),
|
||||||
|
true
|
||||||
|
);
|
||||||
|
if (location.isValid()) {
|
||||||
|
QETApp::instance() -> openTitleBlockTemplate(location);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Save the currently edited title block template back to its parent project.
|
Save the currently edited title block template back to its parent project.
|
||||||
*/
|
*/
|
||||||
void QETTitleBlockTemplateEditor::save() {
|
bool QETTitleBlockTemplateEditor::save() {
|
||||||
if (location_.isValid()) {
|
if (location_.isValid()) {
|
||||||
saveAs(location_);
|
return(saveAs(location_));
|
||||||
} else {
|
} else {
|
||||||
saveAs();
|
return(saveAs());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Ask the user where he wishes to save the currently edited template.
|
Ask the user where he wishes to save the currently edited template.
|
||||||
*/
|
*/
|
||||||
void QETTitleBlockTemplateEditor::saveAs() {
|
bool QETTitleBlockTemplateEditor::saveAs() {
|
||||||
TitleBlockTemplateLocation location = getTitleBlockTemplateLocationFromUser();
|
TitleBlockTemplateLocation location = getTitleBlockTemplateLocationFromUser(
|
||||||
|
tr("Enregistrer le mod\350le sous", "dialog window title"),
|
||||||
|
false
|
||||||
|
);
|
||||||
if (location.isValid()) {
|
if (location.isValid()) {
|
||||||
saveAs(location);
|
return(saveAs(location));
|
||||||
}
|
}
|
||||||
|
return(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Ask the user for a title block template location @return The location chosen
|
Ask the user for a title block template location
|
||||||
by the user, or an empty TitleBlockTemplateLocation if the user cancelled the
|
@param title Title displayed by the dialog window
|
||||||
dialog
|
@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
|
||||||
*/
|
*/
|
||||||
TitleBlockTemplateLocation QETTitleBlockTemplateEditor::getTitleBlockTemplateLocationFromUser() {
|
TitleBlockTemplateLocation QETTitleBlockTemplateEditor::getTitleBlockTemplateLocationFromUser(const QString &title, bool existing_only) {
|
||||||
TitleBlockTemplateLocationSaver *saver = new TitleBlockTemplateLocationSaver(location());
|
TitleBlockTemplateLocationChooser *widget;
|
||||||
|
if (existing_only) {
|
||||||
|
widget = new TitleBlockTemplateLocationChooser(location());
|
||||||
|
} else {
|
||||||
|
widget = new TitleBlockTemplateLocationSaver(location());
|
||||||
|
}
|
||||||
QDialogButtonBox *buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
QDialogButtonBox *buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||||
|
|
||||||
QVBoxLayout *dialog_layout = new QVBoxLayout();
|
QVBoxLayout *dialog_layout = new QVBoxLayout();
|
||||||
dialog_layout -> addWidget(saver);
|
dialog_layout -> addWidget(widget);
|
||||||
dialog_layout -> addWidget(buttons);
|
dialog_layout -> addWidget(buttons);
|
||||||
|
|
||||||
QDialog dialog;
|
QDialog dialog;
|
||||||
dialog.setWindowTitle(tr("Enregistrer le mod\350le sous", "dialog window title"));
|
dialog.setWindowTitle(title);
|
||||||
dialog.setLayout(dialog_layout);
|
dialog.setLayout(dialog_layout);
|
||||||
|
|
||||||
connect(buttons, SIGNAL(accepted()), &dialog, SLOT(accept()));
|
connect(buttons, SIGNAL(accepted()), &dialog, SLOT(accept()));
|
||||||
connect(buttons, SIGNAL(rejected()), &dialog, SLOT(reject()));
|
connect(buttons, SIGNAL(rejected()), &dialog, SLOT(reject()));
|
||||||
|
|
||||||
if (dialog.exec() == QDialog::Accepted) {
|
if (dialog.exec() == QDialog::Accepted) {
|
||||||
return(saver -> location());
|
return(widget -> location());
|
||||||
}
|
}
|
||||||
return TitleBlockTemplateLocation();
|
return TitleBlockTemplateLocation();
|
||||||
}
|
}
|
||||||
@@ -457,6 +529,5 @@ TitleBlockTemplateLocation QETTitleBlockTemplateEditor::getTitleBlockTemplateLoc
|
|||||||
Close the current editor.
|
Close the current editor.
|
||||||
*/
|
*/
|
||||||
void QETTitleBlockTemplateEditor::quit() {
|
void QETTitleBlockTemplateEditor::quit() {
|
||||||
/// TODO save if needed
|
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ class QETTitleBlockTemplateEditor : public QMainWindow {
|
|||||||
/// menus TODO
|
/// menus TODO
|
||||||
QMenu *file_menu_, *edit_menu_,/* *paste_from_menu_, */*display_menu_,/* *tools_menu_,*/ *config_menu_, *help_menu_;
|
QMenu *file_menu_, *edit_menu_,/* *paste_from_menu_, */*display_menu_,/* *tools_menu_,*/ *config_menu_, *help_menu_;
|
||||||
/// actions
|
/// actions
|
||||||
QAction *new_, *save_, *save_as_, *quit_, *configure_, *about_qt_, *about_qet_, *merge_cells_, *split_cell_;
|
QAction *new_, *open_, *save_, *save_as_, *quit_, *configure_, *about_qt_, *about_qet_, *merge_cells_, *split_cell_;
|
||||||
QAction *zoom_in_, *zoom_out_, *zoom_fit_, *zoom_reset_;
|
QAction *zoom_in_, *zoom_out_, *zoom_fit_, *zoom_reset_;
|
||||||
/// Location of the currently edited template
|
/// Location of the currently edited template
|
||||||
TitleBlockTemplateLocation location_;
|
TitleBlockTemplateLocation location_;
|
||||||
@@ -73,6 +73,8 @@ class QETTitleBlockTemplateEditor : public QMainWindow {
|
|||||||
TitleBlockTemplateLocation location() const;
|
TitleBlockTemplateLocation location() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
bool canClose();
|
||||||
|
void closeEvent(QCloseEvent *);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void initActions();
|
void initActions();
|
||||||
@@ -89,17 +91,18 @@ class QETTitleBlockTemplateEditor : public QMainWindow {
|
|||||||
bool edit(TitleBlockTemplate *);
|
bool edit(TitleBlockTemplate *);
|
||||||
void editLogos();
|
void editLogos();
|
||||||
void newTemplate();
|
void newTemplate();
|
||||||
void save();
|
void open();
|
||||||
void saveAs();
|
bool save();
|
||||||
|
bool saveAs();
|
||||||
void quit();
|
void quit();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
TitleBlockTemplateLocation getTitleBlockTemplateLocationFromUser();
|
TitleBlockTemplateLocation getTitleBlockTemplateLocationFromUser(const QString & = QString(), bool existing_only = true);
|
||||||
void pushCellUndoCommand(ModifyTitleBlockCellCommand *);
|
void pushCellUndoCommand(ModifyTitleBlockCellCommand *);
|
||||||
void pushGridUndoCommand(TitleBlockTemplateCommand *);
|
void pushGridUndoCommand(TitleBlockTemplateCommand *);
|
||||||
void pushUndoCommand(QUndoCommand *);
|
void pushUndoCommand(QUndoCommand *);
|
||||||
void updateEditorTitle();
|
void updateEditorTitle();
|
||||||
void saveAs(const TitleBlockTemplateLocation &);
|
bool saveAs(const TitleBlockTemplateLocation &);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user