2011-12-25 17:45:39 +00:00
/*
2015-02-20 14:56:22 +00:00
Copyright 2006 - 2015 The QElectroTech Team
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 ) :
2012-02-13 22:28:26 +00:00
QETMainWindow ( parent ) ,
2012-01-12 07:04:09 +00:00
opened_from_file_ ( false ) ,
2012-01-22 14:35:57 +00:00
read_only_ ( false ) ,
2012-01-25 07:29:50 +00:00
duplicate_ ( 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-04-08 20:51:46 +00:00
initToolbars ( ) ;
2012-04-09 18:56:17 +00:00
readSettings ( ) ;
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-04-09 15:27:15 +00:00
/**
@ return true if the provided filepath matches the currently edited template .
@ param filepath path of a title block template on the filesystem
*/
bool QETTitleBlockTemplateEditor : : isEditing ( const QString & filepath ) {
QString current_filepath ;
if ( opened_from_file_ ) {
current_filepath = filepath_ ;
} else {
current_filepath = QETApp : : realPath ( location_ . toString ( ) ) ;
}
return (
QET : : compareCanonicalFilePaths (
current_filepath ,
filepath
)
) ;
}
2012-01-25 07:29:50 +00:00
/**
@ param true for this editor to prompt the user for a new template name as
soon as the window appears in order to duplicate the edited one .
*/
void QETTitleBlockTemplateEditor : : setOpenForDuplication ( bool duplicate ) {
duplicate_ = duplicate ;
}
/**
@ return true if this editor will prompt the user for a new template name as
soon as the window appears in order to duplicate the edited one .
*/
bool QETTitleBlockTemplateEditor : : openForDuplication ( ) const {
return ( duplicate_ ) ;
}
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 \350 le en cours ? " , " dialog title " ) ,
QString (
tr (
" Voulez-vous enregistrer le mod \350 le %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 ) ;
}
2012-01-25 07:29:50 +00:00
/**
@ param event Object describing the received event .
*/
2012-03-16 18:01:32 +00:00
void QETTitleBlockTemplateEditor : : firstActivation ( QEvent * event ) {
Q_UNUSED ( event )
if ( duplicate_ & & ! opened_from_file_ & & location_ . parentCollection ( ) ) {
// this editor is supposed to duplicate its current location
QTimer : : singleShot ( 250 , this , SLOT ( duplicateCurrentLocation ( ) ) ) ;
2012-01-25 07:29:50 +00:00
}
}
2012-01-10 18:53:48 +00:00
/**
Handle the closing of the main window
@ param qce The QCloseEvent event
*/
void QETTitleBlockTemplateEditor : : closeEvent ( QCloseEvent * qce ) {
if ( canClose ( ) ) {
2012-04-09 18:56:17 +00:00
writeSettings ( ) ;
2012-01-10 18:53:48 +00:00
setAttribute ( Qt : : WA_DeleteOnClose ) ;
qce - > accept ( ) ;
} else qce - > ignore ( ) ;
}
2012-01-25 07:29:50 +00:00
/**
Ask the user for a new template name in order to duplicate the currently
edited template .
*/
void QETTitleBlockTemplateEditor : : duplicateCurrentLocation ( ) {
// this method does not work for templates edited from the filesystem
if ( opened_from_file_ ) return ;
2012-01-25 18:02:17 +00:00
QString proposed_name ;
if ( location_ . name ( ) . isEmpty ( ) ) {
proposed_name = tr ( " nouveau_modele " , " template name suggestion when duplicating the default one " ) ;
} else {
proposed_name = QString ( " %1_copy " ) . arg ( location_ . name ( ) ) ;
}
2012-01-25 07:29:50 +00:00
bool accepted = false ;
QString new_template_name = QInputDialog : : getText (
this ,
tr ( " Dupliquer un mod \350 le de cartouche " , " input dialog title " ) ,
tr ( " Pour dupliquer ce mod \350 le, entrez le nom voulu pour sa copie " , " input dialog text " ) ,
QLineEdit : : Normal ,
2012-01-25 18:02:17 +00:00
proposed_name ,
2012-01-25 07:29:50 +00:00
& accepted
) ;
if ( accepted ) {
TitleBlockTemplateLocation new_template_location ( new_template_name , location_ . parentCollection ( ) ) ;
saveAs ( new_template_location ) ;
}
}
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-23 07:22:07 +00:00
setReadOnly ( location . isReadOnly ( ) ) ;
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-23 07:22:07 +00:00
setReadOnly ( project - > isReadOnly ( ) ) ;
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 ) ;
}
2012-01-23 07:22:07 +00:00
QFileInfo file_path_info ( file_path ) ;
2012-01-12 07:04:09 +00:00
filepath_ = file_path ;
opened_from_file_ = true ;
2012-01-23 07:22:07 +00:00
setReadOnly ( ! file_path_info . isWritable ( ) ) ;
2012-01-12 07:04:09 +00:00
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
}
2012-05-11 17:47:42 +00:00
logo_manager_ - > layout ( ) - > setContentsMargins ( 0 , 0 , 0 , 0 ) ;
QDialogButtonBox * buttons = new QDialogButtonBox ( QDialogButtonBox : : Close ) ;
QVBoxLayout * vlayout0 = new QVBoxLayout ( ) ;
vlayout0 - > addWidget ( logo_manager_ ) ;
vlayout0 - > addWidget ( buttons ) ;
QDialog d ( this ) ;
d . setWindowTitle ( logo_manager_ - > windowTitle ( ) ) ;
d . setLayout ( vlayout0 ) ;
connect ( buttons , SIGNAL ( rejected ( ) ) , & d , SLOT ( reject ( ) ) ) ;
d . exec ( ) ;
// prevent the logo manager from being deleted along with the dialog
logo_manager_ - > setParent ( this ) ;
2011-12-25 17:45:39 +00:00
}
}
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 ( ) ) ;
2012-04-09 18:56:17 +00:00
qet_template_editor - > show ( ) ;
2012-01-09 18:50:26 +00:00
}
2011-12-25 17:45:39 +00:00
/**
Initialize the various actions .
*/
void QETTitleBlockTemplateEditor : : initActions ( ) {
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 ) ;
2012-04-08 20:51:48 +00:00
save_as_ = new QAction ( QET : : Icons : : DocumentSaveAs , tr ( " Enregistrer sous " , " menu entry " ) , this ) ;
save_as_file_ = new QAction ( QET : : Icons : : DocumentSaveAs , 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 ) ;
2012-03-11 16:06:22 +00:00
cut_ = new QAction ( QET : : Icons : : EditCut , tr ( " Co&uper " , " menu entry " ) , this ) ;
copy_ = new QAction ( QET : : Icons : : EditCopy , tr ( " Cop&ier " , " menu entry " ) , this ) ;
paste_ = new QAction ( QET : : Icons : : EditPaste , tr ( " C&oller " , " menu entry " ) , this ) ;
2012-05-09 02:31:43 +00:00
edit_logos_ = new QAction ( QET : : Icons : : InsertImage , tr ( " G \351 rer les logos " , " menu entry " ) , this ) ;
2012-03-02 17:55:27 +00:00
edit_info_ = new QAction ( QET : : Icons : : UserInformations , tr ( " \311 diter les informations compl \351 mentaires " , " menu entry " ) , 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 \350 re " , " 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 ) ;
2012-04-08 20:51:43 +00:00
add_row_ = new QAction ( QET : : Icons : : EditTableInsertRowAbove , tr ( " Ajouter une &ligne " , " menu entry " ) , this ) ;
add_col_ = new QAction ( QET : : Icons : : EditTableInsertColumnRight , tr ( " Ajouter une &colonne " , " menu entry " ) , this ) ;
2012-02-17 07:26:46 +00:00
merge_cells_ = new QAction ( QET : : Icons : : EditTableCellMerge , tr ( " &Fusionner les cellules " , " menu entry " ) , this ) ;
split_cell_ = new QAction ( QET : : Icons : : EditTableCellSplit , tr ( " &S \351 parer 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 ) ;
2012-02-13 22:09:40 +00:00
open_from_file_ - > setShortcut ( tr ( " Ctrl+Shift+O " , " shortcut to open a template from a file " ) ) ;
2011-12-25 17:45:39 +00:00
save_ - > setShortcut ( QKeySequence : : Save ) ;
2012-02-13 22:09:40 +00:00
save_as_file_ - > setShortcut ( tr ( " Ctrl+Shift+S " , " shortcut to save a template to a file " ) ) ;
2011-12-25 17:45:39 +00:00
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 ) ;
2012-03-11 16:06:22 +00:00
cut_ - > setShortcut ( QKeySequence : : Cut ) ;
copy_ - > setShortcut ( QKeySequence : : Copy ) ;
paste_ - > setShortcut ( QKeySequence : : Paste ) ;
2012-05-09 02:31:43 +00:00
edit_logos_ - > setShortcut ( QKeySequence ( tr ( " Ctrl+T " , " shortcut to manage embedded logos " ) ) ) ;
2012-03-02 17:55:27 +00:00
edit_info_ - > setShortcut ( QKeySequence ( tr ( " Ctrl+Y " , " shortcut to edit extra information " ) ) ) ;
2012-05-09 02:31:43 +00:00
merge_cells_ - > setShortcut ( QKeySequence ( tr ( " Ctrl+J " , " shortcut to merge cells " ) ) ) ;
split_cell_ - > setShortcut ( QKeySequence ( tr ( " Ctrl+K " , " 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
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 ( ) ) ) ;
2012-03-11 16:06:22 +00:00
connect ( cut_ , SIGNAL ( triggered ( ) ) , template_edition_area_view_ , SLOT ( cut ( ) ) ) ;
connect ( copy_ , SIGNAL ( triggered ( ) ) , template_edition_area_view_ , SLOT ( copy ( ) ) ) ;
connect ( paste_ , SIGNAL ( triggered ( ) ) , template_edition_area_view_ , SLOT ( paste ( ) ) ) ;
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 ( ) ) ) ;
2012-05-09 02:31:43 +00:00
connect ( edit_logos_ , SIGNAL ( triggered ( ) ) , this , SLOT ( editLogos ( ) ) ) ;
2012-03-02 17:55:27 +00:00
connect ( edit_info_ , SIGNAL ( triggered ( ) ) , this , SLOT ( editTemplateInformation ( ) ) ) ;
2012-04-08 20:51:43 +00:00
connect ( add_row_ , SIGNAL ( triggered ( ) ) , template_edition_area_view_ , SLOT ( addRowAtEnd ( ) ) ) ;
connect ( add_col_ , SIGNAL ( triggered ( ) ) , template_edition_area_view_ , SLOT ( addColumnAtEnd ( ) ) ) ;
2011-12-25 17:45:39 +00:00
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 ( " & \311 dition " , " menu title " ) , this ) ;
2011-12-30 02:05:46 +00:00
display_menu_ = new QMenu ( tr ( " Afficha&ge " , " menu title " ) , this ) ;
2011-12-25 17:45:39 +00:00
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 ( ) ;
2012-03-11 16:06:22 +00:00
edit_menu_ - > addAction ( cut_ ) ;
edit_menu_ - > addAction ( copy_ ) ;
edit_menu_ - > addAction ( paste_ ) ;
edit_menu_ - > addSeparator ( ) ;
2012-04-08 20:51:43 +00:00
edit_menu_ - > addAction ( add_row_ ) ;
edit_menu_ - > addAction ( add_col_ ) ;
2011-12-25 17:45:39 +00:00
edit_menu_ - > addAction ( merge_cells_ ) ;
edit_menu_ - > addAction ( split_cell_ ) ;
2012-04-08 20:51:43 +00:00
edit_menu_ - > addSeparator ( ) ;
2012-05-09 02:31:43 +00:00
edit_menu_ - > addAction ( edit_logos_ ) ;
2012-03-02 17:55:27 +00:00
edit_menu_ - > addAction ( edit_info_ ) ;
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_ ) ;
2012-02-13 22:28:26 +00:00
insertMenu ( settings_menu_ , file_menu_ ) ;
insertMenu ( settings_menu_ , edit_menu_ ) ;
insertMenu ( settings_menu_ , display_menu_ ) ;
2011-12-25 17:45:39 +00:00
}
2012-04-08 20:51:46 +00:00
/**
Initalize toolbars .
*/
void QETTitleBlockTemplateEditor : : initToolbars ( ) {
QToolBar * main_toolbar = new QToolBar ( tr ( " Outils " , " toolbar title " ) , this ) ;
main_toolbar - > setObjectName ( " tbt_main_toolbar " ) ;
main_toolbar - > addAction ( new_ ) ;
main_toolbar - > addAction ( open_ ) ;
main_toolbar - > addAction ( save_ ) ;
main_toolbar - > addAction ( save_as_ ) ;
addToolBar ( Qt : : TopToolBarArea , main_toolbar ) ;
QToolBar * edit_toolbar = new QToolBar ( tr ( " \311 dition " , " toolbar title " ) , this ) ;
2012-04-09 18:56:17 +00:00
edit_toolbar - > setObjectName ( " tbt_edit_toolbar " ) ;
2012-04-08 20:51:46 +00:00
edit_toolbar - > addAction ( undo_ ) ;
edit_toolbar - > addAction ( redo_ ) ;
edit_toolbar - > addSeparator ( ) ;
edit_toolbar - > addAction ( merge_cells_ ) ;
edit_toolbar - > addAction ( split_cell_ ) ;
addToolBar ( Qt : : TopToolBarArea , edit_toolbar ) ;
QToolBar * display_toolbar = new QToolBar ( tr ( " Affichage " , " toolbar title " ) , this ) ;
display_toolbar - > setObjectName ( " tbt_display_toolbar " ) ;
display_toolbar - > addAction ( zoom_in_ ) ;
display_toolbar - > addAction ( zoom_out_ ) ;
display_toolbar - > addAction ( zoom_fit_ ) ;
display_toolbar - > addAction ( zoom_reset_ ) ;
addToolBar ( Qt : : TopToolBarArea , display_toolbar ) ;
}
2011-12-25 17:45:39 +00:00
/**
Initialize layouts and widgets
*/
void QETTitleBlockTemplateEditor : : initWidgets ( ) {
2012-02-27 18:20:33 +00:00
QSettings & settings = QETApp : : settings ( ) ;
2011-12-25 17:45:39 +00:00
// 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 " ) ) ;
2012-04-09 18:56:17 +00:00
undo_dock_widget_ - > setObjectName ( " tbt_undo_dock " ) ;
2011-12-25 17:45:39 +00:00
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 ) ;
2012-02-27 18:20:33 +00:00
template_edition_area_view_ = new TitleBlockTemplateView ( template_edition_area_scene_ ) ;
bool conv_ok ;
int conf_preview_width = settings . value ( " titleblocktemplateeditor/preview_width " , - 1 ) . toInt ( & conv_ok ) ;
if ( conv_ok & & conf_preview_width ! = - 1 ) {
template_edition_area_view_ - > setPreviewWidth ( conf_preview_width ) ;
}
2011-12-25 17:45:39 +00:00
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 \351 t \351 s de la cellule " , " dock title " ) , this ) ;
2012-04-09 18:56:17 +00:00
template_cell_editor_dock_widget_ - > setObjectName ( " tbt_celleditor_dock " ) ;
2011-12-25 17:45:39 +00:00
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-02-27 18:20:33 +00:00
connect (
template_edition_area_view_ ,
SIGNAL ( previewWidthChanged ( int , int ) ) ,
this ,
SLOT ( savePreviewWidthToApplicationSettings ( int , int ) )
) ;
2012-01-12 07:04:09 +00:00
connect ( undo_stack_ , SIGNAL ( cleanChanged ( bool ) ) , this , SLOT ( updateEditorTitle ( ) ) ) ;
2012-03-11 16:06:48 +00:00
connect ( QApplication : : clipboard ( ) , SIGNAL ( dataChanged ( ) ) , this , SLOT ( updateActions ( ) ) ) ;
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 ( ) {
2012-05-09 02:31:46 +00:00
logo_manager_ = new TitleBlockTemplateLogoManager ( tb_template_ , this ) ;
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 ) ;
}
2012-04-09 18:56:17 +00:00
/**
Load template editor - related parameters .
*/
void QETTitleBlockTemplateEditor : : readSettings ( ) {
QSettings & settings = QETApp : : settings ( ) ;
// window size and position
QVariant geometry = settings . value ( " titleblocktemplateeditor/geometry " ) ;
if ( geometry . isValid ( ) ) restoreGeometry ( geometry . toByteArray ( ) ) ;
// window state (toolbars, docks...)
QVariant state = settings . value ( " titleblocktemplateeditor/state " ) ;
if ( state . isValid ( ) ) restoreState ( state . toByteArray ( ) ) ;
}
/**
Save template editor - related parameters .
*/
void QETTitleBlockTemplateEditor : : writeSettings ( ) {
QSettings & settings = QETApp : : settings ( ) ;
settings . setValue ( " titleblocktemplateeditor/geometry " , saveGeometry ( ) ) ;
settings . setValue ( " titleblocktemplateeditor/state " , saveState ( ) ) ;
}
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 ) ;
}
2012-03-04 18:27:37 +00:00
updateActions ( ) ;
2011-12-25 17:45:39 +00:00
}
/**
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 - \311 diteur de mod \350 le 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 ( ) {
2012-01-23 07:22:07 +00:00
save_ - > setEnabled ( ! read_only_ ) ;
2012-03-04 18:27:37 +00:00
bool can_merge ;
bool can_split ;
2012-03-11 16:06:48 +00:00
int count ;
2012-03-04 18:27:37 +00:00
if ( ! read_only_ ) {
2012-03-11 16:06:48 +00:00
template_edition_area_view_ - > analyzeSelectedCells ( & can_merge , & can_split , & count ) ;
2012-03-04 18:27:37 +00:00
}
2012-03-11 16:06:48 +00:00
cut_ - > setEnabled ( ! read_only_ & & count ) ;
copy_ - > setEnabled ( count ) ;
paste_ - > setEnabled ( ! read_only_ & & count & & template_edition_area_view_ - > mayPaste ( ) ) ;
2012-04-08 20:51:43 +00:00
add_row_ - > setEnabled ( ! read_only_ ) ;
add_col_ - > setEnabled ( ! read_only_ ) ;
2012-03-04 18:27:37 +00:00
merge_cells_ - > setEnabled ( ! read_only_ & & can_merge ) ;
split_cell_ - > setEnabled ( ! read_only_ & & can_split ) ;
2012-01-22 14:35:57 +00:00
}
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-23 07:22:07 +00:00
setReadOnly ( false ) ;
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 ( ) ;
2012-01-23 07:22:07 +00:00
setReadOnly ( false ) ;
2012-01-12 07:04:09 +00:00
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 \350 le " , " 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 \350 les 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 ( ) ) {
2012-01-23 07:22:07 +00:00
QFileInfo file_path_info ( filepath_ ) ;
if ( file_path_info . isWritable ( ) ) {
return ( saveAs ( filepath_ ) ) ;
}
2012-01-12 07:04:09 +00:00
}
2012-01-23 07:22:07 +00:00
return ( saveAsFile ( ) ) ;
2011-12-26 05:42:48 +00:00
} else {
2012-01-12 07:04:09 +00:00
if ( location_ . isValid ( ) ) {
2012-01-23 07:22:07 +00:00
if ( ! location_ . isReadOnly ( ) ) {
return ( saveAs ( location_ ) ) ;
}
2012-01-12 07:04:09 +00:00
}
2012-01-23 07:22:07 +00:00
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 \350 le 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 \350 les 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 ) {
2012-01-25 07:29:50 +00:00
if ( read_only ! = read_only_ ) {
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_ ) ;
2012-01-22 14:35:57 +00:00
}
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 ( ) ;
}
2012-02-27 18:20:33 +00:00
/**
Save the new preview width to application settings
@ param former_preview_width Unused , former preview width
@ param new_preview_width New preview width
*/
void QETTitleBlockTemplateEditor : : savePreviewWidthToApplicationSettings ( int former_preview_width , int new_preview_width ) {
Q_UNUSED ( former_preview_width )
QETApp : : settings ( ) . setValue ( " titleblocktemplateeditor/preview_width " , new_preview_width ) ;
}
2012-03-02 17:55:27 +00:00
/**
Edit extra information attached to the template .
*/
void QETTitleBlockTemplateEditor : : editTemplateInformation ( ) {
if ( ! tb_template_ ) return ;
QDialog dialog_author ( this ) ;
dialog_author . setModal ( true ) ;
# ifdef Q_WS_MAC
dialog_author . setWindowFlags ( Qt : : Sheet ) ;
# endif
dialog_author . setMinimumSize ( 400 , 260 ) ;
dialog_author . setWindowTitle ( tr ( " \311 diter les informations compl \351 mentaires " , " window title " ) ) ;
QVBoxLayout * dialog_layout = new QVBoxLayout ( & dialog_author ) ;
// explanation label
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. " ) ) ;
information_label - > setAlignment ( Qt : : AlignJustify | Qt : : AlignVCenter ) ;
information_label - > setWordWrap ( true ) ;
dialog_layout - > addWidget ( information_label ) ;
// add a QTextEdit to the dialog
QTextEdit * text_field = new QTextEdit ( ) ;
text_field - > setAcceptRichText ( false ) ;
text_field - > setPlainText ( tb_template_ - > information ( ) ) ;
text_field - > setReadOnly ( read_only_ ) ;
dialog_layout - > addWidget ( text_field ) ;
// add two buttons to the dialog
QDialogButtonBox * dialog_buttons = new QDialogButtonBox ( read_only_ ? QDialogButtonBox : : Ok : QDialogButtonBox : : Ok | QDialogButtonBox : : Cancel ) ;
dialog_layout - > addWidget ( dialog_buttons ) ;
connect ( dialog_buttons , SIGNAL ( accepted ( ) ) , & dialog_author , SLOT ( accept ( ) ) ) ;
connect ( dialog_buttons , SIGNAL ( rejected ( ) ) , & dialog_author , SLOT ( reject ( ) ) ) ;
// run the dialog
if ( dialog_author . exec ( ) = = QDialog : : Accepted & & ! read_only_ ) {
2012-04-09 01:03:11 +00:00
QString new_info = text_field - > toPlainText ( ) . remove ( QChar ( 13 ) ) ; // CR-less text
2012-03-02 17:55:27 +00:00
if ( new_info ! = tb_template_ - > information ( ) ) {
pushUndoCommand ( new ChangeTemplateInformationsCommand ( tb_template_ , tb_template_ - > information ( ) , new_info ) ) ;
}
}
}