2007-12-01 10:47:15 +00:00
/*
2015-02-20 14:56:22 +00:00
Copyright 2006 - 2015 The QElectroTech Team
2007-12-01 10:47:15 +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/>.
*/
2007-09-21 12:35:28 +00:00
# include "qetdiagrameditor.h"
2007-09-21 13:22:18 +00:00
# include "qetapp.h"
2013-02-12 18:37:08 +00:00
# include "diagramcontent.h"
2007-01-29 00:41:12 +00:00
# include "diagramview.h"
2007-09-25 23:24:36 +00:00
# include "diagram.h"
2013-11-14 10:11:22 +00:00
# include "qetgraphicsitem/element.h"
2007-02-26 22:42:46 +00:00
# include "elementspanelwidget.h"
2007-10-14 10:09:46 +00:00
# include "conductorpropertieswidget.h"
2013-11-14 10:11:22 +00:00
# include "qetgraphicsitem/customelement.h"
2009-04-03 19:30:25 +00:00
# include "qetproject.h"
# include "projectview.h"
2008-07-30 11:51:27 +00:00
# include "recentfiles.h"
2009-05-01 14:41:33 +00:00
# include "qeticons.h"
2009-07-08 09:41:20 +00:00
# include "qetelementeditor.h"
2009-08-09 16:02:14 +00:00
# include "qetmessagebox.h"
2012-07-13 07:21:19 +00:00
# include "qetresult.h"
2012-02-06 21:21:43 +00:00
# include "genericpanel.h"
2013-04-11 09:35:10 +00:00
# include "nomenclature.h"
2014-02-08 18:17:10 +00:00
# include "diagramfoliolist.h"
2014-09-24 09:38:16 +00:00
# include "qetshapeitem.h"
# include "dveventaddimage.h"
# include "dveventaddshape.h"
# include "dveventaddtext.h"
2014-10-26 11:57:38 +00:00
# include "reportproperties.h"
2013-04-11 09:35:10 +00:00
2013-05-07 13:17:57 +00:00
# include "ui/dialogautonum.h"
2008-08-14 22:51:08 +00:00
2013-01-03 17:26:08 +00:00
# include <QMessageBox>
2014-12-26 19:41:00 +00:00
2006-10-27 15:47:22 +00:00
/**
2014-12-26 19:41:00 +00:00
* @ brief QETDiagramEditor : : QETDiagramEditor
* Constructor
* @ param files , list of files to open
* @ param parent , parent widget
2006-10-27 15:47:22 +00:00
*/
2009-04-03 19:30:25 +00:00
QETDiagramEditor : : QETDiagramEditor ( const QStringList & files , QWidget * parent ) :
2012-02-13 22:12:37 +00:00
QETMainWindow ( parent ) ,
2014-10-19 11:25:03 +00:00
m_add_item_actions_group ( this ) ,
m_zoom_actions_group ( this ) ,
m_select_actions_group ( this ) ,
m_selection_actions_group ( this ) ,
m_row_column_actions_group ( this ) ,
m_file_actions_group ( this ) ,
2014-11-27 18:46:30 +00:00
open_dialog_dir ( QDesktopServices : : storageLocation ( QDesktopServices : : DesktopLocation ) )
2009-04-03 19:30:25 +00:00
{
2014-12-26 19:41:00 +00:00
//Setup the mdi area at center of application
2006-10-27 15:47:22 +00:00
setCentralWidget ( & workspace ) ;
2009-05-24 17:46:44 +00:00
2014-12-26 19:41:00 +00:00
//Set object name to be retrieved by the stylesheets
2009-04-03 19:30:25 +00:00
workspace . setBackground ( QBrush ( Qt : : NoBrush ) ) ;
workspace . setObjectName ( " mdiarea " ) ;
2006-10-27 15:47:22 +00:00
2012-07-08 13:32:38 +00:00
# if QT_VERSION >= 0x040800
workspace . setTabsClosable ( true ) ;
# endif
2014-12-26 19:41:00 +00:00
//Set the signal mapper
2009-04-03 19:30:25 +00:00
connect ( & windowMapper , SIGNAL ( mapped ( QWidget * ) ) , this , SLOT ( activateWidget ( QWidget * ) ) ) ;
2006-10-27 15:47:22 +00:00
2014-12-26 19:41:00 +00:00
setWindowTitle ( tr ( " QElectroTech " , " window title " ) ) ;
2009-05-01 14:41:33 +00:00
setWindowIcon ( QET : : Icons : : QETLogo ) ;
2009-04-03 19:30:25 +00:00
statusBar ( ) - > showMessage ( tr ( " QElectroTech " , " status bar message " ) ) ;
2006-10-27 15:47:22 +00:00
2014-10-26 11:57:38 +00:00
setUpElementsPanel ( ) ;
setUpUndoStack ( ) ;
setUpActions ( ) ;
setUpToolBar ( ) ;
setUpMenu ( ) ;
2014-11-28 18:14:33 +00:00
tabifyDockWidget ( qdw_undo , qdw_pa ) ;
2006-10-27 15:47:22 +00:00
2014-12-26 19:41:00 +00:00
//By default the windows is maximised
2007-11-12 15:21:14 +00:00
setMinimumSize ( QSize ( 500 , 350 ) ) ;
2006-10-27 15:47:22 +00:00
setWindowState ( Qt : : WindowMaximized ) ;
2014-12-26 19:41:00 +00:00
connect ( & workspace , SIGNAL ( subWindowActivated ( QMdiSubWindow * ) ) , this , SLOT ( subWindowActivated ( QMdiSubWindow * ) ) ) ;
2014-12-10 17:00:08 +00:00
connect ( QApplication : : clipboard ( ) , SIGNAL ( dataChanged ( ) ) , this , SLOT ( slot_updatePasteAction ( ) ) ) ;
connect ( & undo_group , SIGNAL ( cleanChanged ( bool ) ) , this , SLOT ( activeUndoStackCleanChanged ( bool ) ) ) ;
2007-09-22 13:27:14 +00:00
2007-11-12 15:21:14 +00:00
readSettings ( ) ;
2007-09-22 13:27:14 +00:00
show ( ) ;
2008-08-23 12:54:16 +00:00
2014-12-26 19:41:00 +00:00
//If valid file path is given as arguments
2009-04-03 19:30:25 +00:00
uint opened_projects = 0 ;
2014-12-26 19:41:00 +00:00
if ( files . count ( ) )
{
//So we open this files
foreach ( QString file , files )
if ( openAndAddProject ( file , false ) )
2009-04-03 19:30:25 +00:00
+ + opened_projects ;
2008-08-23 12:54:16 +00:00
}
2014-10-26 11:57:38 +00:00
slot_updateActions ( ) ;
2006-10-27 15:47:22 +00:00
}
2007-04-12 03:13:13 +00:00
/**
Destructeur
*/
2007-09-21 12:35:28 +00:00
QETDiagramEditor : : ~ QETDiagramEditor ( ) {
2007-04-12 03:13:13 +00:00
}
2006-10-27 15:47:22 +00:00
/**
2014-10-26 11:57:38 +00:00
* @ brief QETDiagramEditor : : setUpElementsPanel
* Setup the element panel and element panel widget
*/
void QETDiagramEditor : : setUpElementsPanel ( ) {
//Add the element panel as a QDockWidget
qdw_pa = new QDockWidget ( tr ( " Panel d' \351 l \351 ments " , " dock title " ) , this ) ;
qdw_pa - > setObjectName ( " elements panel " ) ;
qdw_pa - > setAllowedAreas ( Qt : : LeftDockWidgetArea | Qt : : RightDockWidgetArea ) ;
qdw_pa - > setFeatures ( QDockWidget : : AllDockWidgetFeatures ) ;
qdw_pa - > setMinimumWidth ( 160 ) ;
qdw_pa - > setWidget ( pa = new ElementsPanelWidget ( qdw_pa ) ) ;
2014-11-28 18:14:33 +00:00
addDockWidget ( Qt : : LeftDockWidgetArea , qdw_pa ) ;
2014-10-26 11:57:38 +00:00
connect ( pa , SIGNAL ( requestForProject ( QETProject * ) ) , this , SLOT ( activateProject ( QETProject * ) ) ) ;
connect ( pa , SIGNAL ( requestForProjectClosing ( QETProject * ) ) , this , SLOT ( closeProject ( QETProject * ) ) ) ;
connect ( pa , SIGNAL ( requestForProjectPropertiesEdition ( QETProject * ) ) , this , SLOT ( editProjectProperties ( QETProject * ) ) ) ;
connect ( pa , SIGNAL ( requestForNewDiagram ( QETProject * ) ) , this , SLOT ( addDiagramToProject ( QETProject * ) ) ) ;
connect ( pa , SIGNAL ( requestForDiagram ( Diagram * ) ) , this , SLOT ( activateDiagram ( Diagram * ) ) ) ;
connect ( pa , SIGNAL ( requestForDiagramPropertiesEdition ( Diagram * ) ) , this , SLOT ( editDiagramProperties ( Diagram * ) ) ) ;
connect ( pa , SIGNAL ( requestForDiagramDeletion ( Diagram * ) ) , this , SLOT ( removeDiagram ( Diagram * ) ) ) ;
connect ( pa , SIGNAL ( requestForDiagramMoveUp ( Diagram * ) ) , this , SLOT ( moveDiagramUp ( Diagram * ) ) ) ;
connect ( pa , SIGNAL ( requestForDiagramMoveDown ( Diagram * ) ) , this , SLOT ( moveDiagramDown ( Diagram * ) ) ) ;
2014-12-14 17:01:11 +00:00
connect ( pa , SIGNAL ( requestForDiagramMoveUpx10 ( Diagram * ) ) , this , SLOT ( moveDiagramUpx10 ( Diagram * ) ) ) ;
connect ( pa , SIGNAL ( requestForDiagramMoveDownx10 ( Diagram * ) ) , this , SLOT ( moveDiagramDownx10 ( Diagram * ) ) ) ;
2006-10-27 15:47:22 +00:00
}
/**
2014-10-26 11:57:38 +00:00
* @ brief QETDiagramEditor : : setUpUndoStack
* Setup the undostack and undo stack widget
*/
void QETDiagramEditor : : setUpUndoStack ( ) {
QUndoView * undo_view = new QUndoView ( & undo_group , this ) ;
undo_view - > setEmptyLabel ( tr ( " Aucune modification " ) ) ;
undo_view - > setStatusTip ( tr ( " Cliquez sur une action pour revenir en arri \350 re dans l' \351 dition de votre sch \351 ma " , " Status tip " ) ) ;
undo_view - > setWhatsThis ( tr ( " Ce panneau liste les diff \351 rentes actions effectu \351 es sur le sch \351 ma courant. Cliquer sur une action permet de revenir \340 l' \351 tat du sch \351 ma juste apr \350 s son application. " , " \" What's this \" tip " ) ) ;
qdw_undo = new QDockWidget ( tr ( " Annulations " , " dock title " ) , this ) ;
qdw_undo - > setObjectName ( " diagram_undo " ) ;
qdw_undo - > setAllowedAreas ( Qt : : LeftDockWidgetArea | Qt : : RightDockWidgetArea ) ;
qdw_undo - > setFeatures ( QDockWidget : : AllDockWidgetFeatures ) ;
qdw_undo - > setMinimumWidth ( 160 ) ;
qdw_undo - > setWidget ( undo_view ) ;
2014-11-28 18:14:33 +00:00
addDockWidget ( Qt : : LeftDockWidgetArea , qdw_undo ) ;
2014-10-26 11:57:38 +00:00
}
/**
* @ brief QETDiagramEditor : : setUpActions
* Set up all Qaction
*/
void QETDiagramEditor : : setUpActions ( ) {
2006-10-27 15:47:22 +00:00
// icones et labels
2013-10-26 11:51:46 +00:00
export_diagram = new QAction ( QET : : Icons : : DocumentExport , tr ( " E&xporter " ) , this ) ;
print = new QAction ( QET : : Icons : : DocumentPrint , tr ( " Imprimer " ) , this ) ;
quit_editor = new QAction ( QET : : Icons : : ApplicationExit , tr ( " &Quitter " ) , this ) ;
2014-10-26 11:57:38 +00:00
2007-09-29 12:54:01 +00:00
undo = undo_group . createUndoAction ( this , tr ( " Annuler " ) ) ;
2013-10-26 11:51:46 +00:00
undo - > setIcon ( QET : : Icons : : EditUndo ) ;
2007-09-29 12:54:01 +00:00
redo = undo_group . createRedoAction ( this , tr ( " Refaire " ) ) ;
2013-10-26 11:51:46 +00:00
redo - > setIcon ( QET : : Icons : : EditRedo ) ;
cut = new QAction ( QET : : Icons : : EditCut , tr ( " Co&uper " ) , this ) ;
copy = new QAction ( QET : : Icons : : EditCopy , tr ( " Cop&ier " ) , this ) ;
paste = new QAction ( QET : : Icons : : EditPaste , tr ( " C&oller " ) , this ) ;
2009-05-01 14:41:33 +00:00
conductor_reset = new QAction ( QET : : Icons : : ConductorSettings , tr ( " R \351 initialiser les conducteurs " ) , this ) ;
2015-01-11 11:10:57 +00:00
2015-01-14 11:52:41 +00:00
m_auto_conductor = new QAction ( QET : : Icons : : Autoconnect , tr ( " Cr \351 ation automatique de conducteur(s) " , " Tool tip of auto conductor " ) , this ) ;
2015-01-11 11:10:57 +00:00
m_auto_conductor - > setStatusTip ( tr ( " Utiliser la cr \351 ation automatique de conducteur(s) quand cela est possible " , " Status tip of auto conductor " ) ) ;
m_auto_conductor - > setCheckable ( true ) ;
m_auto_conductor - > setDisabled ( true ) ;
connect ( m_auto_conductor , SIGNAL ( triggered ( bool ) ) , this , SLOT ( slot_autoConductor ( bool ) ) ) ;
2013-10-26 11:51:46 +00:00
infos_diagram = new QAction ( QET : : Icons : : DialogInformation , tr ( " Propri \351 t \351 s du sch \351 ma " ) , this ) ;
prj_edit_prop = new QAction ( QET : : Icons : : DialogInformation , tr ( " Propri \351 t \351 s du projet " ) , this ) ;
2009-05-01 14:41:33 +00:00
prj_add_diagram = new QAction ( QET : : Icons : : DiagramAdd , tr ( " Ajouter un sch \351 ma " ) , this ) ;
prj_del_diagram = new QAction ( QET : : Icons : : DiagramDelete , tr ( " Supprimer le sch \351 ma " ) , this ) ;
2013-10-26 11:51:46 +00:00
prj_clean = new QAction ( QET : : Icons : : EditClear , tr ( " Nettoyer le projet " ) , this ) ;
2014-02-06 23:55:02 +00:00
prj_diagramList = new QAction ( QET : : Icons : : listDrawings , tr ( " Ajouter un sommaire " ) , this ) ;
2014-10-05 14:38:34 +00:00
prj_nomenclature = new QAction ( QET : : Icons : : DocumentExport , tr ( " Exporter une nomenclature " ) , this ) ;
2009-05-01 14:41:33 +00:00
tabbed_view_mode = new QAction ( tr ( " en utilisant des onglets " ) , this ) ;
windowed_view_mode = new QAction ( tr ( " en utilisant des fen \352 tres " ) , this ) ;
mode_selection = new QAction ( QET : : Icons : : PartSelect , tr ( " Mode Selection " ) , this ) ;
mode_visualise = new QAction ( QET : : Icons : : ViewMove , tr ( " Mode Visualisation " ) , this ) ;
2015-01-11 11:10:57 +00:00
tile_window = new QAction ( tr ( " &Mosa \357 que " ) , this ) ;
cascade_window = new QAction ( tr ( " &Cascade " ) , this ) ;
next_window = new QAction ( tr ( " Projet suivant " ) , this ) ;
prev_window = new QAction ( tr ( " Projet pr \351 c \351 dent " ) , this ) ;
2014-10-26 11:57:38 +00:00
2014-06-07 21:03:49 +00:00
///Files action///
QAction * new_file = m_file_actions_group . addAction ( QET : : Icons : : DocumentNew , tr ( " &Nouveau " ) ) ;
QAction * open_file = m_file_actions_group . addAction ( QET : : Icons : : DocumentOpen , tr ( " &Ouvrir " ) ) ;
save_file = m_file_actions_group . addAction ( QET : : Icons : : DocumentSave , tr ( " &Enregistrer " ) ) ;
save_file_as = m_file_actions_group . addAction ( QET : : Icons : : DocumentSaveAs , tr ( " Enregistrer sous " ) ) ;
close_file = m_file_actions_group . addAction ( QET : : Icons : : DocumentClose , tr ( " &Fermer " ) ) ;
new_file - > setShortcut ( QKeySequence : : New ) ;
open_file - > setShortcut ( QKeySequence : : Open ) ;
close_file - > setShortcut ( QKeySequence : : Close ) ;
save_file - > setShortcut ( QKeySequence : : Save ) ;
new_file - > setStatusTip ( tr ( " Cr \351 e un nouveau sch \351 ma " , " status bar tip " ) ) ;
open_file - > setStatusTip ( tr ( " Ouvre un sch \351 ma existant " , " status bar tip " ) ) ;
close_file - > setStatusTip ( tr ( " Ferme le sch \351 ma courant " , " status bar tip " ) ) ;
save_file - > setStatusTip ( tr ( " Enregistre le projet courant et tous ses sch \351 mas " , " status bar tip " ) ) ;
save_file_as - > setStatusTip ( tr ( " Enregistre le project courant avec un autre nom de fichier " , " status bar tip " ) ) ;
connect ( save_file_as , SIGNAL ( triggered ( ) ) , this , SLOT ( saveAs ( ) ) ) ;
connect ( save_file , SIGNAL ( triggered ( ) ) , this , SLOT ( save ( ) ) ) ;
connect ( new_file , SIGNAL ( triggered ( ) ) , this , SLOT ( newProject ( ) ) ) ;
connect ( open_file , SIGNAL ( triggered ( ) ) , this , SLOT ( openProject ( ) ) ) ;
connect ( close_file , SIGNAL ( triggered ( ) ) , this , SLOT ( closeCurrentProject ( ) ) ) ;
///Row Column action///
QAction * add_column = m_row_column_actions_group . addAction ( QET : : Icons : : EditTableInsertColumnRight , tr ( " Ajouter une colonne " ) ) ;
QAction * remove_column = m_row_column_actions_group . addAction ( QET : : Icons : : EditTableDeleteColumn , tr ( " Enlever une colonne " ) ) ;
QAction * add_row = m_row_column_actions_group . addAction ( QET : : Icons : : EditTableInsertRowUnder , tr ( " Ajouter une ligne " ) ) ;
QAction * remove_row = m_row_column_actions_group . addAction ( QET : : Icons : : EditTableDeleteRow , tr ( " Enlever une ligne " ) ) ;
add_column - > setStatusTip ( tr ( " Ajoute une colonne au sch \351 ma " , " status bar tip " ) ) ;
remove_column - > setStatusTip ( tr ( " Enl \350 ve une colonne au sch \351 ma " , " status bar tip " ) ) ;
add_row - > setStatusTip ( tr ( " Agrandit le sch \351 ma en hauteur " , " status bar tip " ) ) ;
remove_row - > setStatusTip ( tr ( " R \351 tr \351 cit le sch \351 ma en hauteur " , " status bar tip " ) ) ;
connect ( add_column , SIGNAL ( triggered ( ) ) , this , SLOT ( slot_addColumn ( ) ) ) ;
connect ( remove_column , SIGNAL ( triggered ( ) ) , this , SLOT ( slot_removeColumn ( ) ) ) ;
connect ( add_row , SIGNAL ( triggered ( ) ) , this , SLOT ( slot_addRow ( ) ) ) ;
connect ( remove_row , SIGNAL ( triggered ( ) ) , this , SLOT ( slot_removeRow ( ) ) ) ;
///Selections Actions (related to a selected item)///
delete_selection = m_selection_actions_group . addAction ( QET : : Icons : : EditDelete , tr ( " Supprimer " ) ) ;
rotate_selection = m_selection_actions_group . addAction ( QET : : Icons : : ObjectRotateRight , tr ( " Pivoter " ) ) ;
rotate_texts = m_selection_actions_group . addAction ( QET : : Icons : : ObjectRotateRight , tr ( " Orienter les textes " ) ) ;
find_element = m_selection_actions_group . addAction ( tr ( " Retrouver dans le panel " ) ) ;
edit_selection = m_selection_actions_group . addAction ( QET : : Icons : : ElementEdit , tr ( " \311 diter l'item s \351 lectionn \351 " ) ) ;
# ifndef Q_WS_MAC
delete_selection - > setShortcut ( QKeySequence ( Qt : : Key_Delete ) ) ;
# else
delete_selection - > setShortcut ( QKeySequence ( tr ( " Backspace " ) ) ) ;
# endif
rotate_selection - > setShortcut ( QKeySequence ( tr ( " Space " ) ) ) ;
rotate_texts - > setShortcut ( QKeySequence ( tr ( " Ctrl+Space " ) ) ) ;
conductor_reset - > setShortcut ( QKeySequence ( tr ( " Ctrl+K " ) ) ) ;
infos_diagram - > setShortcut ( QKeySequence ( tr ( " Ctrl+L " ) ) ) ;
edit_selection - > setShortcut ( QKeySequence ( tr ( " Ctrl+E " ) ) ) ;
delete_selection - > setStatusTip ( tr ( " Enl \350 ve les \351 l \351 ments s \351 lectionn \351 s du sch \351 ma " , " status bar tip " ) ) ;
rotate_selection - > setStatusTip ( tr ( " Pivote les \351 l \351 ments et textes s \351 lectionn \351 s " , " status bar tip " ) ) ;
rotate_texts - > setStatusTip ( tr ( " Pivote les textes s \351 lectionn \351 s \340 un angle pr \351 cis " , " status bar tip " ) ) ;
find_element - > setStatusTip ( tr ( " Retrouve l' \351 l \351 ment s \351 lectionn \351 dans le panel " , " status bar tip " ) ) ;
connect ( delete_selection , SIGNAL ( triggered ( ) ) , this , SLOT ( slot_delete ( ) ) ) ;
connect ( rotate_selection , SIGNAL ( triggered ( ) ) , this , SLOT ( slot_rotate ( ) ) ) ;
connect ( rotate_texts , SIGNAL ( triggered ( ) ) , this , SLOT ( slot_rotateTexts ( ) ) ) ;
connect ( find_element , SIGNAL ( triggered ( ) ) , this , SLOT ( findSelectedElementInPanel ( ) ) ) ;
connect ( edit_selection , SIGNAL ( triggered ( ) ) , this , SLOT ( slot_editSelection ( ) ) ) ;
///Select Action///
QAction * select_all = m_select_actions_group . addAction ( QET : : Icons : : EditSelectAll , tr ( " Tout s \351 lectionner " ) ) ;
QAction * select_nothing = m_select_actions_group . addAction ( tr ( " D \351 s \351 lectionner tout " ) ) ;
QAction * select_invert = m_select_actions_group . addAction ( tr ( " Inverser la s \351 lection " ) ) ;
select_all - > setShortcut ( QKeySequence : : SelectAll ) ;
select_nothing - > setShortcut ( QKeySequence ( tr ( " Ctrl+Shift+A " ) ) ) ;
select_invert - > setShortcut ( QKeySequence ( tr ( " Ctrl+I " ) ) ) ;
select_all - > setStatusTip ( tr ( " S \351 lectionne tous les \351 l \351 ments du sch \351 ma " , " status bar tip " ) ) ;
select_nothing - > setStatusTip ( tr ( " D \351 s \351 lectionne tous les \351 l \351 ments du sch \351 ma " , " status bar tip " ) ) ;
select_invert - > setStatusTip ( tr ( " D \351 s \351 lectionne les \351 l \351 ments s \351 lectionn \351 s et s \351 lectionne les \351 l \351 ments non s \351 lectionn \351 s " , " status bar tip " ) ) ;
connect ( select_all , SIGNAL ( triggered ( ) ) , this , SLOT ( slot_selectAll ( ) ) ) ;
connect ( select_nothing , SIGNAL ( triggered ( ) ) , this , SLOT ( slot_selectNothing ( ) ) ) ;
connect ( select_invert , SIGNAL ( triggered ( ) ) , this , SLOT ( slot_selectInvert ( ) ) ) ;
///Zoom actions///
QAction * zoom_in = m_zoom_actions_group . addAction ( QET : : Icons : : ZoomIn , tr ( " Zoom avant " ) ) ;
QAction * zoom_out = m_zoom_actions_group . addAction ( QET : : Icons : : ZoomOut , tr ( " Zoom arri \350 re " ) ) ;
QAction * zoom_content = m_zoom_actions_group . addAction ( QET : : Icons : : ZoomDraw , tr ( " Zoom sur le contenu " ) ) ;
QAction * zoom_fit = m_zoom_actions_group . addAction ( QET : : Icons : : ZoomFitBest , tr ( " Zoom adapt \351 " ) ) ;
QAction * zoom_reset = m_zoom_actions_group . addAction ( QET : : Icons : : ZoomOriginal , tr ( " Pas de zoom " ) ) ;
m_zoom_action_toolBar < < zoom_content < < zoom_fit < < zoom_reset ;
zoom_in - > setShortcut ( QKeySequence : : ZoomIn ) ;
zoom_out - > setShortcut ( QKeySequence : : ZoomOut ) ;
zoom_content - > setShortcut ( QKeySequence ( tr ( " Ctrl+8 " ) ) ) ;
zoom_fit - > setShortcut ( QKeySequence ( tr ( " Ctrl+9 " ) ) ) ;
zoom_reset - > setShortcut ( QKeySequence ( tr ( " Ctrl+0 " ) ) ) ;
zoom_in - > setStatusTip ( tr ( " Agrandit le sch \351 ma " , " status bar tip " ) ) ;
zoom_out - > setStatusTip ( tr ( " R \351 tr \351 cit le sch \351 ma " , " status bar tip " ) ) ;
zoom_content - > setStatusTip ( tr ( " Adapte le zoom de fa \347 on \340 afficher tout le contenu ind \351 pendamment du cadre " ) ) ;
zoom_fit - > setStatusTip ( tr ( " Adapte la taille du sch \351 ma afin qu'il soit enti \350 rement visible " , " status bar tip " ) ) ;
zoom_reset - > setStatusTip ( tr ( " Restaure le zoom par d \351 faut " , " status bar tip " ) ) ;
connect ( zoom_in , SIGNAL ( triggered ( ) ) , this , SLOT ( slot_zoomIn ( ) ) ) ;
connect ( zoom_out , SIGNAL ( triggered ( ) ) , this , SLOT ( slot_zoomOut ( ) ) ) ;
connect ( zoom_content , SIGNAL ( triggered ( ) ) , this , SLOT ( slot_zoomContent ( ) ) ) ;
connect ( zoom_fit , SIGNAL ( triggered ( ) ) , this , SLOT ( slot_zoomFit ( ) ) ) ;
connect ( zoom_reset , SIGNAL ( triggered ( ) ) , this , SLOT ( slot_zoomReset ( ) ) ) ;
///Adding action (add text, image, shape...)///
m_add_item_actions_group . setExclusive ( true ) ;
QAction * add_text = m_add_item_actions_group . addAction ( QET : : Icons : : PartTextField , tr ( " Ajouter un champ de texte " ) ) ;
QAction * add_image = m_add_item_actions_group . addAction ( QET : : Icons : : adding_image , tr ( " Ajouter une image " ) ) ;
QAction * add_line = m_add_item_actions_group . addAction ( QET : : Icons : : PartLine , tr ( " Ajouter une liaison mecanique " ) ) ;
QAction * add_rectangle = m_add_item_actions_group . addAction ( QET : : Icons : : PartRectangle , tr ( " Ajouter une zone rectangle " ) ) ;
QAction * add_ellipse = m_add_item_actions_group . addAction ( QET : : Icons : : PartEllipse , tr ( " Ajouter une zone ellipse " ) ) ;
2014-06-17 09:08:41 +00:00
QAction * add_polyline = m_add_item_actions_group . addAction ( QET : : Icons : : PartPolygon , tr ( " Ajouter une zone polyligne " ) ) ;
2014-06-07 21:03:49 +00:00
connect ( add_text , SIGNAL ( triggered ( ) ) , this , SLOT ( slot_addText ( ) ) ) ;
connect ( add_image , SIGNAL ( triggered ( ) ) , this , SLOT ( slot_addImage ( ) ) ) ;
connect ( add_line , SIGNAL ( triggered ( ) ) , this , SLOT ( slot_addLine ( ) ) ) ;
connect ( add_rectangle , SIGNAL ( triggered ( ) ) , this , SLOT ( slot_addRectangle ( ) ) ) ;
connect ( add_ellipse , SIGNAL ( triggered ( ) ) , this , SLOT ( slot_addEllipse ( ) ) ) ;
2014-06-17 09:08:41 +00:00
connect ( add_polyline , SIGNAL ( triggered ( ) ) , this , SLOT ( slot_addPolyline ( ) ) ) ;
2014-06-07 21:03:49 +00:00
foreach ( QAction * action , m_add_item_actions_group . actions ( ) ) action - > setCheckable ( true ) ;
///Keyboard shortcut
2007-09-29 12:54:01 +00:00
export_diagram - > setShortcut ( QKeySequence ( tr ( " Ctrl+Shift+X " ) ) ) ;
print - > setShortcut ( QKeySequence ( QKeySequence : : Print ) ) ;
quit_editor - > setShortcut ( QKeySequence ( tr ( " Ctrl+Q " ) ) ) ;
undo - > setShortcut ( QKeySequence : : Undo ) ;
redo - > setShortcut ( QKeySequence : : Redo ) ;
cut - > setShortcut ( QKeySequence : : Cut ) ;
copy - > setShortcut ( QKeySequence : : Copy ) ;
paste - > setShortcut ( QKeySequence : : Paste ) ;
2014-10-26 11:57:38 +00:00
2009-04-03 19:30:25 +00:00
prj_add_diagram - > setShortcut ( QKeySequence ( tr ( " Ctrl+T " ) ) ) ;
2014-10-26 11:57:38 +00:00
2007-09-29 12:54:01 +00:00
next_window - > setShortcut ( QKeySequence : : NextChild ) ;
prev_window - > setShortcut ( QKeySequence : : PreviousChild ) ;
2014-10-26 11:57:38 +00:00
2006-10-28 11:17:14 +00:00
// affichage dans la barre de statut
2009-04-03 19:30:25 +00:00
export_diagram - > setStatusTip ( tr ( " Exporte le sch \351 ma courant dans un autre format " , " status bar tip " ) ) ;
print - > setStatusTip ( tr ( " Imprime le sch \351 ma courant " , " status bar tip " ) ) ;
quit_editor - > setStatusTip ( tr ( " Ferme l'application QElectroTech " , " status bar tip " ) ) ;
undo - > setStatusTip ( tr ( " Annule l'action pr \351 c \351 dente " , " status bar tip " ) ) ;
redo - > setStatusTip ( tr ( " Restaure l'action annul \351 e " , " status bar tip " ) ) ;
cut - > setStatusTip ( tr ( " Transf \350 re les \351 l \351 ments s \351 lectionn \351 s dans le presse-papier " , " status bar tip " ) ) ;
copy - > setStatusTip ( tr ( " Copie les \351 l \351 ments s \351 lectionn \351 s dans le presse-papier " , " status bar tip " ) ) ;
paste - > setStatusTip ( tr ( " Place les \351 l \351 ments du presse-papier sur le sch \351 ma " , " status bar tip " ) ) ;
conductor_reset - > setStatusTip ( tr ( " Recalcule les chemins des conducteurs sans tenir compte des modifications " , " status bar tip " ) ) ;
infos_diagram - > setStatusTip ( tr ( " \311 dite les informations affich \351 es par le cartouche " , " status bar tip " ) ) ;
2014-10-26 11:57:38 +00:00
2009-04-03 19:30:25 +00:00
windowed_view_mode - > setStatusTip ( tr ( " Pr \351 sente les diff \351 rents projets ouverts dans des sous-fen \352 tres " , " status bar tip " ) ) ;
tabbed_view_mode - > setStatusTip ( tr ( " Pr \351 sente les diff \351 rents projets ouverts des onglets " , " status bar tip " ) ) ;
2014-10-26 11:57:38 +00:00
2009-04-03 19:30:25 +00:00
mode_selection - > setStatusTip ( tr ( " Permet de s \351 lectionner les \351 l \351 ments " , " status bar tip " ) ) ;
mode_visualise - > setStatusTip ( tr ( " Permet de visualiser le sch \351 ma sans pouvoir le modifier " , " status bar tip " ) ) ;
2014-10-26 11:57:38 +00:00
2009-04-03 19:30:25 +00:00
tile_window - > setStatusTip ( tr ( " Dispose les fen \352 tres en mosa \357 que " , " status bar tip " ) ) ;
cascade_window - > setStatusTip ( tr ( " Dispose les fen \352 tres en cascade " , " status bar tip " ) ) ;
2009-04-06 03:56:56 +00:00
next_window - > setStatusTip ( tr ( " Active le projet suivant " , " status bar tip " ) ) ;
prev_window - > setStatusTip ( tr ( " Active le projet pr \351 c \351 dent " , " status bar tip " ) ) ;
2014-10-30 15:03:58 +00:00
//mode_visualise -> setShortcut( QKeySequence( tr("Ctrl+Shift") ) );
2014-10-26 11:57:38 +00:00
2006-10-27 15:47:22 +00:00
// traitements speciaux
2009-04-03 19:30:25 +00:00
windowed_view_mode - > setCheckable ( true ) ;
tabbed_view_mode - > setCheckable ( true ) ;
mode_selection - > setCheckable ( true ) ;
mode_visualise - > setCheckable ( true ) ;
mode_selection - > setChecked ( true ) ;
2014-10-26 11:57:38 +00:00
2007-10-28 00:16:32 +00:00
grp_visu_sel = new QActionGroup ( this ) ;
2006-10-27 15:47:22 +00:00
grp_visu_sel - > addAction ( mode_selection ) ;
grp_visu_sel - > addAction ( mode_visualise ) ;
grp_visu_sel - > setExclusive ( true ) ;
2014-10-26 11:57:38 +00:00
2009-04-03 19:30:25 +00:00
grp_view_mode = new QActionGroup ( this ) ;
grp_view_mode - > addAction ( windowed_view_mode ) ;
grp_view_mode - > addAction ( tabbed_view_mode ) ;
grp_view_mode - > setExclusive ( true ) ;
2014-10-26 11:57:38 +00:00
2006-10-27 15:47:22 +00:00
// connexion a des slots
2009-04-03 19:30:25 +00:00
connect ( quit_editor , SIGNAL ( triggered ( ) ) , this , SLOT ( close ( ) ) ) ;
connect ( windowed_view_mode , SIGNAL ( triggered ( ) ) , this , SLOT ( setWindowedMode ( ) ) ) ;
connect ( tabbed_view_mode , SIGNAL ( triggered ( ) ) , this , SLOT ( setTabbedMode ( ) ) ) ;
connect ( mode_selection , SIGNAL ( triggered ( ) ) , this , SLOT ( slot_setSelectionMode ( ) ) ) ;
connect ( mode_visualise , SIGNAL ( triggered ( ) ) , this , SLOT ( slot_setVisualisationMode ( ) ) ) ;
connect ( prj_edit_prop , SIGNAL ( triggered ( ) ) , this , SLOT ( editCurrentProjectProperties ( ) ) ) ;
connect ( prj_add_diagram , SIGNAL ( triggered ( ) ) , this , SLOT ( addDiagramToProject ( ) ) ) ;
connect ( prj_del_diagram , SIGNAL ( triggered ( ) ) , this , SLOT ( removeDiagramFromProject ( ) ) ) ;
connect ( prj_clean , SIGNAL ( triggered ( ) ) , this , SLOT ( cleanCurrentProject ( ) ) ) ;
2014-02-07 07:54:54 +00:00
connect ( prj_diagramList , SIGNAL ( triggered ( ) ) , this , SLOT ( addDiagramFolioListToProject ( ) ) ) ;
2013-04-11 09:35:10 +00:00
connect ( prj_nomenclature , SIGNAL ( triggered ( ) ) , this , SLOT ( nomenclatureProject ( ) ) ) ;
2009-04-03 19:30:25 +00:00
connect ( print , SIGNAL ( triggered ( ) ) , this , SLOT ( printDialog ( ) ) ) ;
connect ( export_diagram , SIGNAL ( triggered ( ) ) , this , SLOT ( exportDialog ( ) ) ) ;
connect ( cut , SIGNAL ( triggered ( ) ) , this , SLOT ( slot_cut ( ) ) ) ;
connect ( copy , SIGNAL ( triggered ( ) ) , this , SLOT ( slot_copy ( ) ) ) ;
connect ( paste , SIGNAL ( triggered ( ) ) , this , SLOT ( slot_paste ( ) ) ) ;
connect ( tile_window , SIGNAL ( triggered ( ) ) , & workspace , SLOT ( tileSubWindows ( ) ) ) ;
connect ( cascade_window , SIGNAL ( triggered ( ) ) , & workspace , SLOT ( cascadeSubWindows ( ) ) ) ;
connect ( next_window , SIGNAL ( triggered ( ) ) , & workspace , SLOT ( activateNextSubWindow ( ) ) ) ;
connect ( prev_window , SIGNAL ( triggered ( ) ) , & workspace , SLOT ( activatePreviousSubWindow ( ) ) ) ;
connect ( conductor_reset , SIGNAL ( triggered ( ) ) , this , SLOT ( slot_resetConductors ( ) ) ) ;
connect ( infos_diagram , SIGNAL ( triggered ( ) ) , this , SLOT ( editCurrentDiagramProperties ( ) ) ) ;
}
/**
2014-10-26 11:57:38 +00:00
* @ brief QETDiagramEditor : : setUpToolBar
*/
void QETDiagramEditor : : setUpToolBar ( ) {
main_bar = new QToolBar ( tr ( " Outils " ) , this ) ;
main_bar - > setObjectName ( " toolbar " ) ;
view_bar = new QToolBar ( tr ( " Affichage " ) , this ) ;
view_bar - > setObjectName ( " display " ) ;
diagram_bar = new QToolBar ( tr ( " Sch \351 ma " ) , this ) ;
diagram_bar - > setObjectName ( " diagram " ) ;
main_bar - > addActions ( m_file_actions_group . actions ( ) ) ;
main_bar - > addAction ( print ) ;
main_bar - > addSeparator ( ) ;
main_bar - > addAction ( undo ) ;
main_bar - > addAction ( redo ) ;
main_bar - > addSeparator ( ) ;
main_bar - > addAction ( cut ) ;
main_bar - > addAction ( copy ) ;
main_bar - > addAction ( paste ) ;
main_bar - > addSeparator ( ) ;
main_bar - > addAction ( delete_selection ) ;
main_bar - > addAction ( rotate_selection ) ;
// Modes selection / visualisation et zoom
view_bar - > addAction ( mode_selection ) ;
view_bar - > addAction ( mode_visualise ) ;
view_bar - > addSeparator ( ) ;
view_bar - > addActions ( m_zoom_action_toolBar ) ;
2015-01-11 11:10:57 +00:00
diagram_bar - > addAction ( infos_diagram ) ;
diagram_bar - > addAction ( conductor_reset ) ;
diagram_bar - > addAction ( m_auto_conductor ) ;
2014-10-26 11:57:38 +00:00
m_add_item_toolBar = new QToolBar ( tr ( " Ajouter " ) , this ) ;
m_add_item_toolBar - > setObjectName ( " adding " ) ;
m_add_item_toolBar - > addActions ( m_add_item_actions_group . actions ( ) ) ;
// ajout de la barre d'outils a la fenetre principale
addToolBar ( Qt : : TopToolBarArea , main_bar ) ;
addToolBar ( Qt : : TopToolBarArea , view_bar ) ;
addToolBar ( Qt : : TopToolBarArea , diagram_bar ) ;
addToolBar ( Qt : : TopToolBarArea , m_add_item_toolBar ) ;
2006-10-27 15:47:22 +00:00
}
/**
2014-10-26 11:57:38 +00:00
* @ brief QETDiagramEditor : : setUpMenu
*/
void QETDiagramEditor : : setUpMenu ( ) {
2012-02-13 22:12:37 +00:00
QMenu * menu_fichier = new QMenu ( tr ( " &Fichier " ) ) ;
QMenu * menu_edition = new QMenu ( tr ( " & \311 dition " ) ) ;
QMenu * menu_project = new QMenu ( tr ( " &Projet " ) ) ;
QMenu * menu_affichage = new QMenu ( tr ( " Afficha&ge " ) ) ;
//QMenu *menu_outils = new QMenu(tr("O&utils"));
windows_menu = new QMenu ( tr ( " Fe&n \352 tres " ) ) ;
2014-10-26 11:57:38 +00:00
2012-02-13 22:12:37 +00:00
insertMenu ( settings_menu_ , menu_fichier ) ;
insertMenu ( settings_menu_ , menu_edition ) ;
insertMenu ( settings_menu_ , menu_project ) ;
insertMenu ( settings_menu_ , menu_affichage ) ;
insertMenu ( help_menu_ , windows_menu ) ;
2014-10-26 11:57:38 +00:00
2014-06-07 21:03:49 +00:00
// File menu
2014-06-02 01:38:02 +00:00
QMenu * recentfile = menu_fichier - > addMenu ( QET : : Icons : : DocumentOpenRecent , tr ( " &R \351 cemment ouverts " ) ) ;
2014-05-05 17:32:10 +00:00
recentfile - > addActions ( QETApp : : projectsRecentFiles ( ) - > menu ( ) - > actions ( ) ) ;
2008-07-30 11:51:27 +00:00
connect ( QETApp : : projectsRecentFiles ( ) , SIGNAL ( fileOpeningRequested ( const QString & ) ) , this , SLOT ( openRecentFile ( const QString & ) ) ) ;
2014-06-07 21:03:49 +00:00
menu_fichier - > addActions ( m_file_actions_group . actions ( ) ) ;
2006-10-27 15:47:22 +00:00
menu_fichier - > addSeparator ( ) ;
2007-09-29 12:54:01 +00:00
//menu_fichier -> addAction(import_diagram);
menu_fichier - > addAction ( export_diagram ) ;
2007-09-22 13:27:14 +00:00
//menu_fichier -> addSeparator();
2007-09-29 12:54:01 +00:00
menu_fichier - > addAction ( print ) ;
2006-10-27 15:47:22 +00:00
menu_fichier - > addSeparator ( ) ;
2007-09-29 12:54:01 +00:00
menu_fichier - > addAction ( quit_editor ) ;
2014-10-26 11:57:38 +00:00
2006-10-27 15:47:22 +00:00
// menu Edition
2007-09-29 12:54:01 +00:00
menu_edition - > addAction ( undo ) ;
menu_edition - > addAction ( redo ) ;
2006-10-27 15:47:22 +00:00
menu_edition - > addSeparator ( ) ;
2007-09-29 12:54:01 +00:00
menu_edition - > addAction ( cut ) ;
menu_edition - > addAction ( copy ) ;
menu_edition - > addAction ( paste ) ;
2006-10-27 15:47:22 +00:00
menu_edition - > addSeparator ( ) ;
2014-06-07 21:03:49 +00:00
menu_edition - > addActions ( m_select_actions_group . actions ( ) ) ;
2006-10-27 15:47:22 +00:00
menu_edition - > addSeparator ( ) ;
2014-06-07 21:03:49 +00:00
menu_edition - > addActions ( m_selection_actions_group . actions ( ) ) ;
2006-11-19 18:40:03 +00:00
menu_edition - > addSeparator ( ) ;
2007-10-06 18:37:21 +00:00
menu_edition - > addAction ( conductor_reset ) ;
2007-10-03 13:11:47 +00:00
menu_edition - > addSeparator ( ) ;
2007-01-29 00:41:12 +00:00
menu_edition - > addAction ( infos_diagram ) ;
2014-06-07 21:03:49 +00:00
menu_edition - > addActions ( m_row_column_actions_group . actions ( ) ) ;
2014-10-26 11:57:38 +00:00
2009-04-03 19:30:25 +00:00
// menu Projet
menu_project - > addAction ( prj_edit_prop ) ;
menu_project - > addAction ( prj_add_diagram ) ;
menu_project - > addAction ( prj_del_diagram ) ;
menu_project - > addAction ( prj_clean ) ;
2013-04-11 09:35:10 +00:00
menu_project - > addSeparator ( ) ;
2014-02-06 23:55:02 +00:00
menu_project - > addAction ( prj_diagramList ) ;
2013-04-11 09:35:10 +00:00
menu_project - > addAction ( prj_nomenclature ) ;
2014-10-26 11:57:38 +00:00
2007-11-09 15:16:54 +00:00
main_bar - > toggleViewAction ( ) - > setStatusTip ( tr ( " Affiche ou non la barre d'outils principale " ) ) ;
view_bar - > toggleViewAction ( ) - > setStatusTip ( tr ( " Affiche ou non la barre d'outils Affichage " ) ) ;
2007-10-13 17:04:52 +00:00
diagram_bar - > toggleViewAction ( ) - > setStatusTip ( tr ( " Affiche ou non la barre d'outils Sch \351 ma " ) ) ;
2007-11-09 15:16:54 +00:00
qdw_pa - > toggleViewAction ( ) - > setStatusTip ( tr ( " Affiche ou non le panel d'appareils " ) ) ;
qdw_undo - > toggleViewAction ( ) - > setStatusTip ( tr ( " Affiche ou non la liste des modifications " ) ) ;
2014-10-26 11:57:38 +00:00
2006-10-27 15:47:22 +00:00
// menu Affichage
2009-04-03 19:30:25 +00:00
QMenu * projects_view_mode = menu_affichage - > addMenu ( tr ( " Afficher les projets " ) ) ;
projects_view_mode - > setTearOffEnabled ( true ) ;
projects_view_mode - > addAction ( windowed_view_mode ) ;
projects_view_mode - > addAction ( tabbed_view_mode ) ;
2014-10-26 11:57:38 +00:00
2009-04-03 19:30:25 +00:00
menu_affichage - > addSeparator ( ) ;
2007-10-13 17:04:52 +00:00
menu_affichage - > addAction ( mode_selection ) ;
menu_affichage - > addAction ( mode_visualise ) ;
2006-10-27 15:47:22 +00:00
menu_affichage - > addSeparator ( ) ;
2014-06-07 21:03:49 +00:00
menu_affichage - > addActions ( m_zoom_actions_group . actions ( ) ) ;
2013-08-24 15:18:45 +00:00
2007-01-29 00:41:12 +00:00
// menu Fenetres
2007-09-29 12:54:01 +00:00
slot_updateWindowsMenu ( ) ;
2006-10-27 15:47:22 +00:00
}
/**
2014-10-26 11:57:38 +00:00
Permet de quitter l ' application lors de la fermeture de la fenetre principale
@ param qce Le QCloseEvent correspondant a l ' evenement de fermeture
2006-10-27 15:47:22 +00:00
*/
2014-10-26 11:57:38 +00:00
void QETDiagramEditor : : closeEvent ( QCloseEvent * qce ) {
// quitte directement s'il n'y a aucun projet ouvert
bool can_quit = true ;
if ( openedProjects ( ) . count ( ) ) {
// s'assure que la fenetre soit visible s'il y a des projets a fermer
if ( ! isVisible ( ) | | isMinimized ( ) ) {
if ( isMaximized ( ) ) showMaximized ( ) ;
else showNormal ( ) ;
}
// sinon demande la permission de fermer chaque projet
foreach ( ProjectView * project , openedProjects ( ) ) {
if ( ! closeProject ( project ) ) {
can_quit = false ;
qce - > ignore ( ) ;
break ;
}
}
}
if ( can_quit ) {
writeSettings ( ) ;
setAttribute ( Qt : : WA_DeleteOnClose ) ;
qce - > accept ( ) ;
}
}
2013-03-27 21:20:53 +00:00
2014-10-26 11:57:38 +00:00
/**
Gere les evenements du l ' editeur de schema
Reimplemente ici pour :
* eviter un conflit sur le raccourci clavier " Ctrl+W " ( QKeySequence : : Close )
@ param e Evenement
*/
bool QETDiagramEditor : : event ( QEvent * e ) {
if ( e - > type ( ) = = QEvent : : ShortcutOverride ) {
QKeyEvent * shortcut_event = static_cast < QKeyEvent * > ( e ) ;
if ( shortcut_event & & shortcut_event - > matches ( QKeySequence : : Close ) ) {
close_file - > trigger ( ) ;
e - > accept ( ) ;
return ( true ) ;
}
}
return ( QETMainWindow : : event ( e ) ) ;
2006-10-27 15:47:22 +00:00
}
/**
2007-02-01 01:07:26 +00:00
Imprime le schema courant
2006-10-27 15:47:22 +00:00
*/
2007-09-29 12:54:01 +00:00
void QETDiagramEditor : : printDialog ( ) {
2009-04-03 19:30:25 +00:00
ProjectView * current_project = currentProject ( ) ;
if ( ! current_project ) return ;
current_project - > printProject ( ) ;
2006-10-27 15:47:22 +00:00
}
2006-11-11 13:56:40 +00:00
/**
2007-02-01 01:07:26 +00:00
Gere l ' export de schema sous forme d ' image
2006-11-11 13:56:40 +00:00
*/
2007-09-29 12:54:01 +00:00
void QETDiagramEditor : : exportDialog ( ) {
2009-04-03 19:30:25 +00:00
ProjectView * current_project = currentProject ( ) ;
if ( ! current_project ) return ;
current_project - > exportProject ( ) ;
2006-10-27 15:47:22 +00:00
}
/**
2014-12-12 13:27:13 +00:00
* @ brief QETDiagramEditor : : save
* Ask the current active project to save
*/
2012-07-13 07:21:19 +00:00
void QETDiagramEditor : : save ( ) {
2009-04-03 19:30:25 +00:00
if ( ProjectView * project_view = currentProject ( ) ) {
2014-10-26 11:57:38 +00:00
QETResult saved = project_view - > save ( ) ;
2014-12-12 13:27:13 +00:00
2014-10-26 11:57:38 +00:00
if ( saved . isOk ( ) ) {
2014-12-12 13:27:13 +00:00
save_file - > setDisabled ( true ) ;
2009-04-03 19:30:25 +00:00
QETApp : : projectsRecentFiles ( ) - > fileWasOpened ( project_view - > project ( ) - > filePath ( ) ) ;
2014-12-12 13:27:13 +00:00
2014-11-24 02:51:08 +00:00
QString title = ( project_view - > project ( ) - > title ( ) ) ;
if ( title . isEmpty ( ) ) title = " QElectroTech " ;
QString filePath = ( project_view - > project ( ) - > filePath ( ) ) ;
2014-11-26 18:48:24 +00:00
statusBar ( ) - > showMessage ( tr ( " Projet %1 enregistr \351 dans le repertoire: %2. " ) . arg ( title ) . arg ( filePath ) , 2000 ) ;
2014-12-12 13:27:13 +00:00
}
else {
2014-10-26 11:57:38 +00:00
showError ( saved ) ;
2009-04-03 19:30:25 +00:00
}
}
2006-10-27 15:47:22 +00:00
}
/**
2014-12-12 13:27:13 +00:00
* @ brief QETDiagramEditor : : saveAs
* Ask the current active project to save as
*/
2012-07-13 07:21:19 +00:00
void QETDiagramEditor : : saveAs ( ) {
2009-04-03 19:30:25 +00:00
if ( ProjectView * project_view = currentProject ( ) ) {
2012-07-13 07:21:19 +00:00
QETResult save_file = project_view - > saveAs ( ) ;
if ( save_file . isOk ( ) ) {
2009-04-03 19:30:25 +00:00
QETApp : : projectsRecentFiles ( ) - > fileWasOpened ( project_view - > project ( ) - > filePath ( ) ) ;
2014-12-12 13:27:13 +00:00
2014-11-24 02:51:08 +00:00
QString title = ( project_view - > project ( ) - > title ( ) ) ;
if ( title . isEmpty ( ) ) title = " QElectroTech " ;
QString filePath = ( project_view - > project ( ) - > filePath ( ) ) ;
statusBar ( ) - > showMessage ( tr ( " Projet %1 enregistr \351 dans le repertoire: %2. " ) . arg ( title ) . arg ( filePath ) , 2000 ) ;
2014-12-12 13:27:13 +00:00
}
else {
2012-07-13 07:21:19 +00:00
showError ( save_file ) ;
2008-08-23 18:17:00 +00:00
}
}
2006-10-27 15:47:22 +00:00
}
2009-04-03 19:30:25 +00:00
/**
2014-04-11 09:51:21 +00:00
* @ brief QETDiagramEditor : : newProject
* Create an empty project
* @ return
*/
2009-04-03 19:30:25 +00:00
bool QETDiagramEditor : : newProject ( ) {
2014-04-11 09:51:21 +00:00
// create new project without diagram
2009-04-03 19:30:25 +00:00
QETProject * new_project = new QETProject ( 0 ) ;
2014-04-11 09:51:21 +00:00
// Set default properties for new diagram
2014-10-26 11:57:38 +00:00
new_project - > setDefaultBorderProperties ( BorderProperties : : defaultProperties ( ) ) ;
new_project - > setDefaultConductorProperties ( ConductorProperties : : defaultProperties ( ) ) ;
new_project - > setDefaultTitleBlockProperties ( TitleBlockProperties : : defaultProperties ( ) ) ;
new_project - > setDefaultReportProperties ( ReportProperties : : defaultProperties ( ) ) ;
new_project - > setDefaultXRefProperties ( XRefProperties : : defaultProperties ( ) ) ;
2009-04-03 19:30:25 +00:00
2014-02-11 05:10:16 +00:00
// add new diagram
2014-02-08 23:54:15 +00:00
new_project - > addNewDiagram ( ) ;
2009-04-03 19:30:25 +00:00
return ( addProject ( new_project ) ) ;
2006-10-27 15:47:22 +00:00
}
2008-07-30 11:51:27 +00:00
/**
Slot utilise pour ouvrir un fichier recent .
Transfere filepath au slot openAndAddDiagram seulement si cet editeur est
actif
@ param filepath Fichier a ouvrir
@ see openAndAddDiagram
*/
bool QETDiagramEditor : : openRecentFile ( const QString & filepath ) {
2013-01-03 21:53:26 +00:00
// small hack to prevent all diagram editors from trying to topen the required
// recent file at the same time
2008-07-30 11:51:27 +00:00
if ( qApp - > activeWindow ( ) ! = this ) return ( false ) ;
2009-04-03 19:30:25 +00:00
return ( openAndAddProject ( filepath ) ) ;
2008-07-30 11:51:27 +00:00
}
2006-10-27 15:47:22 +00:00
/**
Cette fonction demande un nom de fichier a ouvrir a l ' utilisateur
@ return true si l ' ouverture a reussi , false sinon
*/
2009-04-03 19:30:25 +00:00
bool QETDiagramEditor : : openProject ( ) {
// demande un chemin de fichier a ouvrir a l'utilisateur
QString filepath = QFileDialog : : getOpenFileName (
2006-10-27 15:47:22 +00:00
this ,
tr ( " Ouvrir un fichier " ) ,
2007-10-21 12:53:57 +00:00
open_dialog_dir . absolutePath ( ) ,
2007-02-23 01:51:13 +00:00
tr ( " Sch \351 mas QElectroTech (*.qet);;Fichiers XML (*.xml);;Tous les fichiers (*) " )
2006-10-27 15:47:22 +00:00
) ;
2009-04-03 19:30:25 +00:00
if ( filepath . isEmpty ( ) ) return ( false ) ;
// retient le dossier contenant le dernier projet ouvert
open_dialog_dir = QDir ( filepath ) ;
2008-07-17 19:25:57 +00:00
2009-04-03 19:30:25 +00:00
// ouvre le fichier
return ( openAndAddProject ( filepath ) ) ;
}
/**
Ferme un projet
@ param project_view Projet a fermer
@ return true si la fermeture du projet a reussi , false sinon
Note : cette methode renvoie true si project est nul
*/
bool QETDiagramEditor : : closeProject ( ProjectView * project_view ) {
if ( project_view ) {
activateProject ( project_view ) ;
if ( QMdiSubWindow * sub_window = subWindowForWidget ( project_view ) ) {
return ( sub_window - > close ( ) ) ;
}
}
return ( true ) ;
}
/**
Ferme un projet
@ param project projet a fermer
@ return true si la fermeture du fichier a reussi , false sinon
Note : cette methode renvoie true si project est nul
*/
bool QETDiagramEditor : : closeProject ( QETProject * project ) {
if ( ProjectView * project_view = findProject ( project ) ) {
return ( closeProject ( project_view ) ) ;
}
return ( true ) ;
2008-07-17 19:25:57 +00:00
}
/**
2009-04-03 19:30:25 +00:00
Ferme le projet courant
@ return true si la fermeture du fichier a reussi , false sinon
Note : cette methode renvoie true s ' il n ' y a pas de projet courant
*/
bool QETDiagramEditor : : closeCurrentProject ( ) {
if ( ProjectView * project_view = currentProject ( ) ) {
return ( closeProject ( project_view ) ) ;
}
return ( true ) ;
}
/**
Ouvre un projet depuis un fichier et l ' ajoute a cet editeur
@ param filepath Chemin du projet a ouvrir
@ param interactive true pour afficher des messages a l ' utilisateur , false sinon
2011-03-15 20:06:40 +00:00
@ param update_panel Whether the elements panel should be warned this
project has been added . Defaults to true .
2008-07-17 19:25:57 +00:00
@ return true si l ' ouverture a reussi , false sinon
*/
2011-03-15 20:06:40 +00:00
bool QETDiagramEditor : : openAndAddProject ( const QString & filepath , bool interactive , bool update_panel ) {
2009-04-03 19:30:25 +00:00
if ( filepath . isEmpty ( ) ) return ( false ) ;
2006-10-27 15:47:22 +00:00
2009-04-03 19:30:25 +00:00
QFileInfo filepath_info ( filepath ) ;
// verifie que le projet n'est pas deja ouvert dans un editeur
QString my_filepath = filepath_info . canonicalFilePath ( ) ;
if ( QETDiagramEditor * diagram_editor = QETApp : : diagramEditorForFile ( filepath ) ) {
2008-07-20 11:37:31 +00:00
if ( diagram_editor = = this ) {
2009-04-03 19:30:25 +00:00
if ( ProjectView * project_view = viewForFile ( filepath ) ) {
activateWidget ( project_view ) ;
2008-07-20 11:37:31 +00:00
show ( ) ;
activateWindow ( ) ;
}
2006-10-27 15:47:22 +00:00
return ( false ) ;
2008-07-20 11:37:31 +00:00
} else {
// demande a l'autre editeur d'afficher le fichier
2009-04-03 19:30:25 +00:00
return ( diagram_editor - > openAndAddProject ( filepath ) ) ;
2006-10-27 15:47:22 +00:00
}
}
2013-01-03 21:53:26 +00:00
// check the file exists
if ( ! filepath_info . exists ( ) ) {
if ( interactive ) {
QET : : MessageBox : : critical (
this ,
tr ( " Impossible d'ouvrir le fichier " , " message box title " ) ,
QString (
tr ( " Il semblerait que le fichier %1 que vous essayez d'ouvrir "
" n'existe pas ou plus. " )
) . arg ( filepath )
) ;
}
2013-01-04 14:11:03 +00:00
return ( false ) ;
2013-01-03 21:53:26 +00:00
}
2009-04-03 19:30:25 +00:00
// verifie que le fichier est accessible en lecture
if ( ! filepath_info . isReadable ( ) ) {
if ( interactive ) {
2009-08-09 16:02:14 +00:00
QET : : MessageBox : : critical (
2009-04-03 19:30:25 +00:00
this ,
2013-01-03 21:53:26 +00:00
tr ( " Impossible d'ouvrir le fichier " , " message box title " ) ,
2009-04-03 19:30:25 +00:00
tr ( " Il semblerait que le fichier que vous essayez d'ouvrir ne "
" soit pas accessible en lecture. Il est donc impossible de "
" l'ouvrir. Veuillez v \351 rifier les permissions du fichier. " )
) ;
}
return ( false ) ;
}
// gere le fait que le fichier puisse etre en lecture seule
if ( ! filepath_info . isWritable ( ) ) {
if ( interactive ) {
2009-08-09 16:02:14 +00:00
QET : : MessageBox : : warning (
2009-04-03 19:30:25 +00:00
this ,
2013-01-03 21:53:26 +00:00
tr ( " Ouverture du projet en lecture seule " , " message box title " ) ,
2009-04-03 19:30:25 +00:00
tr ( " Il semblerait que le projet que vous essayez d'ouvrir ne "
" soit pas accessible en \351 criture. Il sera donc ouvert en "
" lecture seule. " )
) ;
}
}
// cree le projet a partir du fichier
QETProject * project = new QETProject ( filepath ) ;
if ( project - > state ( ) ! = QETProject : : Ok ) {
2011-08-26 19:06:35 +00:00
if ( interactive & & project - > state ( ) ! = QETProject : : FileOpenDiscard ) {
2009-08-09 16:02:14 +00:00
QET : : MessageBox : : warning (
2009-04-03 19:30:25 +00:00
this ,
tr ( " \311 chec de l'ouverture du projet " , " message box title " ) ,
QString (
tr (
" Il semblerait que le fichier %1 ne soit pas un fichier "
" projet QElectroTech. Il ne peut donc \352 tre ouvert. " ,
" message box content "
)
) . arg ( filepath )
) ;
2006-10-27 15:47:22 +00:00
}
2011-08-26 19:06:35 +00:00
delete project ;
2006-10-27 15:47:22 +00:00
return ( false ) ;
}
2013-04-11 09:35:10 +00:00
2009-04-03 19:30:25 +00:00
// a ce stade, l'ouverture du fichier a reussi
// on l'ajoute a la liste des fichiers recents
QETApp : : projectsRecentFiles ( ) - > fileWasOpened ( filepath ) ;
// ... et on l'ajoute dans l'application
2011-03-15 20:06:40 +00:00
// Note: we require the panel not to be updated when the project is added
// because it will update itself as soon as it becomes visible
return ( addProject ( project ) , update_panel ) ;
2006-10-27 15:47:22 +00:00
}
/**
2014-02-08 23:54:15 +00:00
Ajoute un projetmoveDiagramUp (
2009-04-03 19:30:25 +00:00
@ param project projet a ajouter
2011-03-15 20:06:40 +00:00
@ param update_panel Whether the elements panel should be warned this
project has been added . Defaults to true .
2006-10-27 15:47:22 +00:00
*/
2011-03-15 20:06:40 +00:00
bool QETDiagramEditor : : addProject ( QETProject * project , bool update_panel ) {
2009-04-03 19:30:25 +00:00
// enregistre le projet
QETApp : : registerProject ( project ) ;
// cree un ProjectView pour visualiser le projet
ProjectView * project_view = new ProjectView ( project ) ;
addProjectView ( project_view ) ;
2014-11-27 18:46:30 +00:00
undo_group . addStack ( project - > undoStack ( ) ) ;
2009-04-03 19:30:25 +00:00
// met a jour le panel d'elements
2011-03-15 20:06:40 +00:00
if ( update_panel ) {
pa - > elementsPanel ( ) . projectWasOpened ( project ) ;
}
2009-04-03 19:30:25 +00:00
return ( true ) ;
}
/**
@ return la liste des projets ouverts dans cette fenetre
*/
QList < ProjectView * > QETDiagramEditor : : openedProjects ( ) const {
QList < ProjectView * > result ;
QList < QMdiSubWindow * > window_list ( workspace . subWindowList ( ) ) ;
foreach ( QMdiSubWindow * window , window_list ) {
if ( ProjectView * project_view = qobject_cast < ProjectView * > ( window - > widget ( ) ) ) {
result < < project_view ;
}
}
return ( result ) ;
}
/**
@ return Le projet actuellement edite ( = qui a le focus dans l ' interface
MDI ) ou 0 s ' il n ' y en a pas
*/
ProjectView * QETDiagramEditor : : currentProject ( ) const {
QMdiSubWindow * current_window = workspace . activeSubWindow ( ) ;
if ( ! current_window ) return ( 0 ) ;
QWidget * current_widget = current_window - > widget ( ) ;
if ( ! current_widget ) return ( 0 ) ;
if ( ProjectView * project_view = qobject_cast < ProjectView * > ( current_widget ) ) {
return ( project_view ) ;
}
return ( 0 ) ;
2006-10-27 15:47:22 +00:00
}
/**
2009-04-03 19:30:25 +00:00
@ return Le schema actuellement edite ( = l ' onglet ouvert dans le projet
courant ) ou 0 s ' il n ' y en a pas
2006-10-27 15:47:22 +00:00
*/
2007-09-25 23:24:36 +00:00
DiagramView * QETDiagramEditor : : currentDiagram ( ) const {
2009-04-03 19:30:25 +00:00
if ( ProjectView * project_view = currentProject ( ) ) {
return ( project_view - > currentDiagram ( ) ) ;
}
return ( 0 ) ;
}
2013-02-12 18:37:08 +00:00
/**
@ return the selected element in the current diagram view , or 0 if :
* no diagram is being viewed in this editor .
* no element is selected
* more than one element is selected
*/
Element * QETDiagramEditor : : currentElement ( ) const {
DiagramView * dv = currentDiagram ( ) ;
if ( ! dv ) return ( 0 ) ;
QList < Element * > selected_elements = dv - > diagram ( ) - > selectedContent ( ) . elements . toList ( ) ;
if ( selected_elements . count ( ) ! = 1 ) return ( 0 ) ;
return ( selected_elements . first ( ) ) ;
}
/**
@ return the selected element in the current diagram view , or 0 if :
* no diagram is being viewed in this editor .
* no element is selected
* more than one element is selected
* the selected element is not a custom element
*/
CustomElement * QETDiagramEditor : : currentCustomElement ( ) const {
return ( dynamic_cast < CustomElement * > ( currentElement ( ) ) ) ;
}
2009-04-03 19:30:25 +00:00
/**
Cette methode permet de retrouver le projet contenant un schema donne .
@ param diagram_view Schema dont il faut retrouver
@ return la vue sur le projet contenant ce schema ou 0 s ' il n ' y en a pas
*/
ProjectView * QETDiagramEditor : : findProject ( DiagramView * diagram_view ) const {
foreach ( ProjectView * project_view , openedProjects ( ) ) {
if ( project_view - > diagrams ( ) . contains ( diagram_view ) ) {
return ( project_view ) ;
}
}
return ( 0 ) ;
}
/**
Cette methode permet de retrouver le projet contenant un schema donne .
@ param diagram Schema dont il faut retrouver
@ return la vue sur le projet contenant ce schema ou 0 s ' il n ' y en a pas
*/
ProjectView * QETDiagramEditor : : findProject ( Diagram * diagram ) const {
foreach ( ProjectView * project_view , openedProjects ( ) ) {
foreach ( DiagramView * diagram_view , project_view - > diagrams ( ) ) {
if ( diagram_view - > diagram ( ) = = diagram ) {
return ( project_view ) ;
}
}
}
return ( 0 ) ;
}
/**
@ param project Projet dont il faut trouver la vue
@ return la vue du projet passe en parametre
*/
ProjectView * QETDiagramEditor : : findProject ( QETProject * project ) const {
foreach ( ProjectView * opened_project , openedProjects ( ) ) {
if ( opened_project - > project ( ) = = project ) {
return ( opened_project ) ;
}
}
return ( 0 ) ;
}
/**
@ param filepath Chemin de fichier d ' un projet
@ return le ProjectView correspondant au chemin passe en parametre , ou 0 si
celui - ci n ' a pas ete trouve
*/
ProjectView * QETDiagramEditor : : findProject ( const QString & filepath ) const {
foreach ( ProjectView * opened_project , openedProjects ( ) ) {
if ( QETProject * project = opened_project - > project ( ) ) {
if ( project - > filePath ( ) = = filepath ) {
return ( opened_project ) ;
}
}
}
return ( 0 ) ;
}
/**
@ param widget Widget a rechercher dans la zone MDI
@ return La sous - fenetre accueillant le widget passe en parametre , ou 0 si
celui - ci n ' a pas ete trouve .
*/
QMdiSubWindow * QETDiagramEditor : : subWindowForWidget ( QWidget * widget ) const {
foreach ( QMdiSubWindow * sub_window , workspace . subWindowList ( ) ) {
if ( sub_window - > widget ( ) = = widget ) {
return ( sub_window ) ;
}
}
return ( 0 ) ;
}
/**
@ param widget Widget a activer
*/
void QETDiagramEditor : : activateWidget ( QWidget * widget ) {
QMdiSubWindow * sub_window = subWindowForWidget ( widget ) ;
if ( sub_window ) {
workspace . setActiveSubWindow ( sub_window ) ;
}
}
2006-11-11 13:56:40 +00:00
/**
Effectue l ' action " couper " sur le schema en cours
*/
2007-09-29 12:54:01 +00:00
void QETDiagramEditor : : slot_cut ( ) {
if ( currentDiagram ( ) ) currentDiagram ( ) - > cut ( ) ;
2006-10-27 15:47:22 +00:00
}
2006-11-11 13:56:40 +00:00
/**
2007-01-29 00:41:12 +00:00
Effectue l ' action " copier " sur le diagram en cours
2006-11-11 13:56:40 +00:00
*/
2007-09-29 12:54:01 +00:00
void QETDiagramEditor : : slot_copy ( ) {
if ( currentDiagram ( ) ) currentDiagram ( ) - > copy ( ) ;
2006-10-27 15:47:22 +00:00
}
2006-11-11 13:56:40 +00:00
/**
Effectue l ' action " coller " sur le schema en cours
*/
2007-09-29 12:54:01 +00:00
void QETDiagramEditor : : slot_paste ( ) {
if ( currentDiagram ( ) ) currentDiagram ( ) - > paste ( ) ;
2006-10-27 15:47:22 +00:00
}
2006-11-11 13:56:40 +00:00
/**
2007-01-29 00:41:12 +00:00
Effectue l ' action " zoom avant " sur le diagram en cours
2006-11-11 13:56:40 +00:00
*/
2007-09-29 12:54:01 +00:00
void QETDiagramEditor : : slot_zoomIn ( ) {
if ( currentDiagram ( ) ) currentDiagram ( ) - > zoomIn ( ) ;
2006-10-27 15:47:22 +00:00
}
2006-11-11 13:56:40 +00:00
/**
Effectue l ' action " zoom arriere " sur le schema en cours
*/
2007-09-29 12:54:01 +00:00
void QETDiagramEditor : : slot_zoomOut ( ) {
if ( currentDiagram ( ) ) currentDiagram ( ) - > zoomOut ( ) ;
2006-10-27 15:47:22 +00:00
}
2006-11-11 13:56:40 +00:00
/**
2007-01-29 00:41:12 +00:00
Effectue l ' action " zoom arriere " sur le diagram en cours
2006-11-11 13:56:40 +00:00
*/
2007-09-21 12:35:28 +00:00
void QETDiagramEditor : : slot_zoomFit ( ) {
2007-09-25 23:24:36 +00:00
if ( currentDiagram ( ) ) currentDiagram ( ) - > zoomFit ( ) ;
2006-10-27 15:47:22 +00:00
}
2012-08-12 11:46:42 +00:00
/**
Call the " zoom content " action for the current diagram .
*/
void QETDiagramEditor : : slot_zoomContent ( ) {
if ( currentDiagram ( ) ) currentDiagram ( ) - > zoomContent ( ) ;
}
2006-11-11 13:56:40 +00:00
/**
Effectue l ' action " zoom par defaut " sur le schema en cours
*/
2007-09-21 12:35:28 +00:00
void QETDiagramEditor : : slot_zoomReset ( ) {
2007-09-25 23:24:36 +00:00
if ( currentDiagram ( ) ) currentDiagram ( ) - > zoomReset ( ) ;
2006-10-27 15:47:22 +00:00
}
2006-11-11 13:56:40 +00:00
/**
Effectue l ' action " selectionner tout " sur le schema en cours
*/
2007-09-21 12:35:28 +00:00
void QETDiagramEditor : : slot_selectAll ( ) {
2007-09-25 23:24:36 +00:00
if ( currentDiagram ( ) ) currentDiagram ( ) - > selectAll ( ) ;
2006-10-27 15:47:22 +00:00
}
2006-11-11 13:56:40 +00:00
/**
Effectue l ' action " deselectionenr tout " sur le schema en cours
*/
2007-09-21 12:35:28 +00:00
void QETDiagramEditor : : slot_selectNothing ( ) {
2007-09-25 23:24:36 +00:00
if ( currentDiagram ( ) ) currentDiagram ( ) - > selectNothing ( ) ;
2006-10-27 15:47:22 +00:00
}
2006-11-11 13:56:40 +00:00
/**
Effectue l ' action " inverser la selection " sur le schema en cours
*/
2007-09-21 12:35:28 +00:00
void QETDiagramEditor : : slot_selectInvert ( ) {
2007-09-25 23:24:36 +00:00
if ( currentDiagram ( ) ) currentDiagram ( ) - > selectInvert ( ) ;
2006-10-27 15:47:22 +00:00
}
2006-11-11 13:56:40 +00:00
/**
Effectue l ' action " supprimer " sur le schema en cours
*/
2007-09-29 12:54:01 +00:00
void QETDiagramEditor : : slot_delete ( ) {
if ( currentDiagram ( ) ) currentDiagram ( ) - > deleteSelection ( ) ;
2006-10-27 15:47:22 +00:00
}
2006-11-11 13:56:40 +00:00
/**
Effectue l ' action " pivoter " sur le schema en cours
*/
2007-09-29 12:54:01 +00:00
void QETDiagramEditor : : slot_rotate ( ) {
if ( currentDiagram ( ) ) currentDiagram ( ) - > rotateSelection ( ) ;
2006-10-27 15:47:22 +00:00
}
2010-02-11 23:35:04 +00:00
/**
Effectue l ' action " Orienter les textes selectionnes " sur le schema en cours
*/
void QETDiagramEditor : : slot_rotateTexts ( ) {
if ( currentDiagram ( ) ) currentDiagram ( ) - > rotateTexts ( ) ;
}
2006-11-11 13:56:40 +00:00
/**
2015-01-11 08:50:36 +00:00
* @ brief QETDiagramEditor : : slot_setSelectionMode
* Set all diagram view of the current project to selection mode
*/
void QETDiagramEditor : : slot_setSelectionMode ( )
{
if ( ProjectView * pv = currentProject ( ) )
foreach ( DiagramView * dv , pv - > diagrams ( ) )
dv - > setSelectionMode ( ) ;
2006-10-27 15:47:22 +00:00
}
2006-11-11 13:56:40 +00:00
/**
2015-01-11 08:50:36 +00:00
* @ brief QETDiagramEditor : : slot_setVisualisationMode
* Set all diagram view of the current project to visualisation mode
*/
void QETDiagramEditor : : slot_setVisualisationMode ( )
{
if ( ProjectView * pv = currentProject ( ) )
foreach ( DiagramView * dv , pv - > diagrams ( ) )
dv - > setVisualisationMode ( ) ;
2006-10-27 15:47:22 +00:00
}
/**
2014-12-26 19:41:00 +00:00
* @ brief QETDiagramEditor : : slot_updateActions
* Manage actions
*/
void QETDiagramEditor : : slot_updateActions ( )
{
2009-04-03 19:30:25 +00:00
DiagramView * dv = currentDiagram ( ) ;
ProjectView * pv = currentProject ( ) ;
2014-10-26 11:57:38 +00:00
2009-04-03 19:30:25 +00:00
bool opened_project = pv ;
bool opened_diagram = dv ;
bool editable_project = ( pv & & ! pv - > project ( ) - > isReadOnly ( ) ) ;
2014-02-08 18:51:06 +00:00
2014-12-26 19:41:00 +00:00
close_file - > setEnabled ( opened_project ) ;
save_file_as - > setEnabled ( opened_project ) ;
prj_edit_prop - > setEnabled ( opened_project ) ;
prj_add_diagram - > setEnabled ( editable_project ) ;
prj_del_diagram - > setEnabled ( editable_project ) ;
prj_clean - > setEnabled ( editable_project ) ;
prj_diagramList - > setEnabled ( opened_project ) ;
prj_nomenclature - > setEnabled ( editable_project ) ;
export_diagram - > setEnabled ( opened_diagram ) ;
print - > setEnabled ( opened_diagram ) ;
infos_diagram - > setEnabled ( opened_diagram ) ;
prj_nomenclature - > setEnabled ( editable_project ) ;
m_zoom_actions_group . setEnabled ( opened_diagram ) ;
m_select_actions_group . setEnabled ( opened_diagram ) ;
m_add_item_actions_group . setEnabled ( editable_project ) ;
m_row_column_actions_group . setEnabled ( editable_project ) ;
2015-01-11 11:10:57 +00:00
2014-12-26 19:41:00 +00:00
slot_updateUndoStack ( ) ;
2007-10-28 00:16:32 +00:00
slot_updateModeActions ( ) ;
slot_updatePasteAction ( ) ;
slot_updateComplexActions ( ) ;
}
2014-01-05 15:00:46 +00:00
/**
* @ brief QETDiagramEditor : : slot_updateUndoStack
* Update the undo stack view
*/
2014-12-26 19:41:00 +00:00
void QETDiagramEditor : : slot_updateUndoStack ( )
{
2014-01-05 15:00:46 +00:00
ProjectView * pv = currentProject ( ) ;
2014-12-26 19:41:00 +00:00
if ( pv )
{
2014-01-05 15:00:46 +00:00
undo_group . setActiveStack ( pv - > project ( ) - > undoStack ( ) ) ;
2014-12-26 19:41:00 +00:00
save_file - > setEnabled ( undo_group . activeStack ( ) - > count ( ) & & ! pv - > project ( ) - > isReadOnly ( ) ) ;
}
else
{
save_file - > setDisabled ( true ) ;
2014-01-05 15:00:46 +00:00
}
}
2007-10-28 00:16:32 +00:00
/**
2015-02-20 18:44:44 +00:00
* @ brief QETDiagramEditor : : slot_updateComplexActions
* Manage the actions who need some conditions to be enable or not .
* This method does nothing if there is no project opened
*/
2007-10-28 00:16:32 +00:00
void QETDiagramEditor : : slot_updateComplexActions ( ) {
DiagramView * dv = currentDiagram ( ) ;
2009-04-03 19:30:25 +00:00
bool editable_diagram = ( dv & & ! dv - > diagram ( ) - > isReadOnly ( ) ) ;
2007-10-28 00:16:32 +00:00
2015-02-20 18:44:44 +00:00
//Number of selected conductors
2009-04-03 19:30:25 +00:00
int selected_conductors_count = dv ? dv - > diagram ( ) - > selectedConductors ( ) . count ( ) : 0 ;
conductor_reset - > setEnabled ( editable_diagram & & selected_conductors_count ) ;
2007-10-28 00:16:32 +00:00
2015-02-20 18:44:44 +00:00
// number of selected elements
2013-02-12 18:37:08 +00:00
int selected_elements_count = dv ? dv - > diagram ( ) - > selectedContent ( ) . count ( DiagramContent : : Elements ) : 0 ;
find_element - > setEnabled ( selected_elements_count = = 1 ) ;
2015-02-20 18:44:44 +00:00
//Action that need items (elements, conductors, texts...) selected, to be enabled
2010-04-24 22:37:45 +00:00
bool copiable_items = dv ? ( dv - > hasCopiableItems ( ) ) : false ;
bool deletable_items = dv ? ( dv - > hasDeletableItems ( ) ) : false ;
2013-08-25 10:38:26 +00:00
cut - > setEnabled ( editable_diagram & & copiable_items ) ;
copy - > setEnabled ( copiable_items ) ;
2010-04-24 22:37:45 +00:00
delete_selection - > setEnabled ( editable_diagram & & deletable_items ) ;
rotate_selection - > setEnabled ( editable_diagram & & dv - > diagram ( ) - > canRotateSelection ( ) ) ;
2014-02-06 23:55:02 +00:00
2015-02-20 18:44:44 +00:00
//Action that need selected texts
2013-05-28 16:50:35 +00:00
int selected_texts = dv ? ( dv - > diagram ( ) - > selectedTexts ( ) . count ( ) ) : 0 ;
int selected_conductor_texts = dv ? ( dv - > diagram ( ) - > selectedConductorTexts ( ) . count ( ) ) : 0 ;
2014-12-23 01:51:17 +00:00
int selected_element_texts = dv ? ( dv - > diagram ( ) - > selectedElementTexts ( ) . count ( ) ) : 0 ;
2010-04-24 22:37:45 +00:00
rotate_texts - > setEnabled ( editable_diagram & & selected_texts ) ;
2013-09-10 14:44:25 +00:00
2015-02-20 18:44:44 +00:00
// actions need only one editable item
2013-09-10 14:44:25 +00:00
int selected_image = dv ? dv - > diagram ( ) - > selectedContent ( ) . count ( DiagramContent : : Images ) : 0 ;
2014-03-06 14:04:19 +00:00
int selected_shape = dv ? dv - > diagram ( ) - > selectedContent ( ) . count ( DiagramContent : : Shapes ) : 0 ;
2015-02-20 18:44:44 +00:00
int selected_editable = selected_elements_count +
( selected_texts - selected_conductor_texts - selected_element_texts ) +
selected_image +
selected_shape +
selected_conductors_count ;
2013-09-10 14:44:25 +00:00
2015-02-20 18:44:44 +00:00
if ( selected_editable = = 1 )
{
2013-09-10 14:44:25 +00:00
edit_selection - > setEnabled ( true ) ;
2015-02-20 18:44:44 +00:00
//edit element
if ( selected_elements_count )
{
2013-09-10 14:44:25 +00:00
edit_selection - > setText ( tr ( " \311 diter l' \351 lement " , " edit element " ) ) ;
edit_selection - > setIcon ( QET : : Icons : : ElementEdit ) ;
}
2015-02-20 18:44:44 +00:00
//edit text field
else if ( selected_texts )
{
2013-09-10 14:44:25 +00:00
edit_selection - > setText ( tr ( " \311 diter le champ de texte " , " edit text field " ) ) ;
edit_selection - > setIcon ( QET : : Icons : : EditText ) ;
}
2015-02-20 18:44:44 +00:00
//edit image
else if ( selected_image )
{
2013-09-10 14:44:25 +00:00
edit_selection - > setText ( tr ( " \311 diter l'image " , " edit image " ) ) ;
2013-09-11 15:30:49 +00:00
edit_selection - > setIcon ( QET : : Icons : : resize_image ) ;
2013-09-10 14:44:25 +00:00
}
2015-02-20 18:44:44 +00:00
//edit conductor
else if ( selected_conductors_count )
{
edit_selection - > setText ( tr ( " \311 diter le conducteur " , " edit conductor " ) ) ;
edit_selection - > setIcon ( QET : : Icons : : ElementEdit ) ;
}
2013-09-10 14:44:25 +00:00
}
2015-02-20 18:44:44 +00:00
//not an editable item
else
{
2013-09-10 14:44:25 +00:00
edit_selection - > setText ( tr ( " \311 diter l'objet s \351 lectionn \351 " , " edit selected item " ) ) ;
edit_selection - > setIcon ( QET : : Icons : : ElementEdit ) ;
edit_selection - > setEnabled ( false ) ;
}
2009-04-03 19:30:25 +00:00
}
2007-10-28 00:16:32 +00:00
/**
2015-01-11 11:10:57 +00:00
* @ brief QETDiagramEditor : : slot_updateModeActions
* Manage action who need an opened diagram or project to be updated
*/
2007-10-28 00:16:32 +00:00
void QETDiagramEditor : : slot_updateModeActions ( ) {
DiagramView * dv = currentDiagram ( ) ;
2006-10-27 15:47:22 +00:00
2015-01-11 11:10:57 +00:00
if ( ! dv )
{
2007-10-28 00:16:32 +00:00
grp_visu_sel - > setEnabled ( false ) ;
2015-01-11 11:10:57 +00:00
}
else
{
switch ( ( int ) ( dv - > dragMode ( ) ) )
{
2006-10-27 15:47:22 +00:00
case QGraphicsView : : NoDrag :
2007-10-28 00:16:32 +00:00
grp_visu_sel - > setEnabled ( false ) ;
2006-10-27 15:47:22 +00:00
break ;
case QGraphicsView : : ScrollHandDrag :
2007-10-28 00:16:32 +00:00
grp_visu_sel - > setEnabled ( true ) ;
2006-10-27 15:47:22 +00:00
mode_visualise - > setChecked ( true ) ;
break ;
case QGraphicsView : : RubberBandDrag :
2007-10-28 00:16:32 +00:00
grp_visu_sel - > setEnabled ( true ) ;
2006-10-27 15:47:22 +00:00
mode_selection - > setChecked ( true ) ;
break ;
}
}
2015-01-11 11:10:57 +00:00
if ( ProjectView * pv = currentProject ( ) )
{
m_auto_conductor - > setEnabled ( true ) ;
m_auto_conductor - > setChecked ( pv - > project ( ) - > autoConductor ( ) ) ;
}
else
m_auto_conductor - > setDisabled ( true ) ;
2007-10-28 00:16:32 +00:00
}
/**
Gere les actions ayant besoin du presse - papier
*/
void QETDiagramEditor : : slot_updatePasteAction ( ) {
2009-04-03 19:30:25 +00:00
DiagramView * dv = currentDiagram ( ) ;
bool editable_diagram = ( dv & & ! dv - > diagram ( ) - > isReadOnly ( ) ) ;
2007-11-03 20:20:34 +00:00
// pour coller, il faut un schema ouvert et un schema dans le presse-papier
2009-04-03 19:30:25 +00:00
paste - > setEnabled ( editable_diagram & & Diagram : : clipboardMayContainDiagram ( ) ) ;
2006-10-27 15:47:22 +00:00
}
2006-11-11 13:56:40 +00:00
/**
2014-12-26 19:41:00 +00:00
* @ brief QETDiagramEditor : : addProjectView
* Add a new project view to workspace and
* build the connection between the projectview / project and this QETDiagramEditor .
* @ param project_view , project view to add
*/
void QETDiagramEditor : : addProjectView ( ProjectView * project_view )
{
2009-04-03 19:30:25 +00:00
if ( ! project_view ) return ;
2014-10-26 11:57:38 +00:00
2014-12-26 19:41:00 +00:00
foreach ( DiagramView * dv , project_view - > diagrams ( ) )
2009-04-03 19:30:25 +00:00
diagramWasAdded ( dv ) ;
2007-01-29 00:41:12 +00:00
2014-12-26 19:41:00 +00:00
//Manage the close event of project
2009-04-03 19:30:25 +00:00
connect ( project_view , SIGNAL ( projectClosed ( ProjectView * ) ) , this , SLOT ( projectWasClosed ( ProjectView * ) ) ) ;
2014-12-26 19:41:00 +00:00
//Manage the adding of diagram
connect ( project_view , SIGNAL ( diagramAdded ( DiagramView * ) ) , this , SLOT ( diagramWasAdded ( DiagramView * ) ) ) ;
if ( QETProject * project = project_view - > project ( ) )
2009-04-03 19:30:25 +00:00
connect ( project , SIGNAL ( readOnlyChanged ( QETProject * , bool ) ) , this , SLOT ( slot_updateActions ( ) ) ) ;
2014-12-26 19:41:00 +00:00
//Manage request for edit or find element and titleblock
connect ( project_view , SIGNAL ( findElementRequired ( const ElementsLocation & ) ) , this , SLOT ( findElementInPanel ( const ElementsLocation & ) ) ) ;
connect ( project_view , SIGNAL ( editElementRequired ( const ElementsLocation & ) ) , this , SLOT ( editElementInEditor ( const ElementsLocation & ) ) ) ;
connect ( project_view , SIGNAL ( editTitleBlockTemplate ( const TitleBlockTemplateLocation & , bool ) ) , QETApp : : instance ( ) , SLOT ( openTitleBlockTemplate ( TitleBlockTemplateLocation , bool ) ) ) ;
2012-01-25 07:29:50 +00:00
2014-12-26 19:41:00 +00:00
// display error messages sent by the project view
2012-07-13 07:21:19 +00:00
connect ( project_view , SIGNAL ( errorEncountered ( QString ) ) , this , SLOT ( showError ( const QString & ) ) ) ;
2014-01-18 19:04:39 +00:00
2014-12-26 19:41:00 +00:00
//We maximise the new window if the current window is inexistent or maximized
QWidget * current_window = workspace . activeSubWindow ( ) ;
bool maximise = ( ( ! current_window ) | | ( current_window - > windowState ( ) & Qt : : WindowMaximized ) ) ;
//Add the new window
QMdiSubWindow * sub_window = workspace . addSubWindow ( project_view ) ;
sub_window - > setWindowIcon ( project_view - > windowIcon ( ) ) ;
sub_window - > systemMenu ( ) - > clear ( ) ;
//Display the new window
if ( maximise ) project_view - > showMaximized ( ) ;
else project_view - > show ( ) ;
2008-07-20 11:37:31 +00:00
}
/**
@ return la liste des fichiers edites par cet editeur de schemas
*/
QList < QString > QETDiagramEditor : : editedFiles ( ) const {
QList < QString > edited_files_list ;
2009-04-03 19:30:25 +00:00
foreach ( ProjectView * project_view , openedProjects ( ) ) {
QString diagram_file ( project_view - > project ( ) - > filePath ( ) ) ;
2008-07-20 11:37:31 +00:00
if ( ! diagram_file . isEmpty ( ) ) {
edited_files_list < < QFileInfo ( diagram_file ) . canonicalFilePath ( ) ;
}
}
return ( edited_files_list ) ;
}
/**
@ param filepath Un chemin de fichier
Note : si filepath est une chaine vide , cette methode retourne 0.
2009-04-03 19:30:25 +00:00
@ return le ProjectView editant le fichier filepath , ou 0 si ce fichier n ' est
2008-07-20 11:37:31 +00:00
pas edite par cet editeur de schemas .
*/
2009-04-03 19:30:25 +00:00
ProjectView * QETDiagramEditor : : viewForFile ( const QString & filepath ) const {
2008-07-20 11:37:31 +00:00
if ( filepath . isEmpty ( ) ) return ( 0 ) ;
QString searched_can_file_path = QFileInfo ( filepath ) . canonicalFilePath ( ) ;
2013-01-04 14:11:03 +00:00
if ( searched_can_file_path . isEmpty ( ) ) {
// QFileInfo returns an empty path for non-existent files
return ( 0 ) ;
}
2009-04-03 19:30:25 +00:00
foreach ( ProjectView * project_view , openedProjects ( ) ) {
QString project_can_file_path = QFileInfo ( project_view - > project ( ) - > filePath ( ) ) . canonicalFilePath ( ) ;
if ( project_can_file_path = = searched_can_file_path ) {
return ( project_view ) ;
2008-07-20 11:37:31 +00:00
}
}
return ( 0 ) ;
}
2006-11-11 13:56:40 +00:00
/**
met a jour le menu " Fenetres "
*/
2007-09-29 12:54:01 +00:00
void QETDiagramEditor : : slot_updateWindowsMenu ( ) {
2006-10-27 15:47:22 +00:00
// nettoyage du menu
2007-09-29 12:54:01 +00:00
foreach ( QAction * a , windows_menu - > actions ( ) ) windows_menu - > removeAction ( a ) ;
2006-10-27 15:47:22 +00:00
// actions de fermeture
2007-09-29 12:54:01 +00:00
windows_menu - > addAction ( close_file ) ;
//windows_menu -> addAction(closeAllAct);
2006-10-27 15:47:22 +00:00
// actions de reorganisation des fenetres
2007-09-29 12:54:01 +00:00
windows_menu - > addSeparator ( ) ;
windows_menu - > addAction ( tile_window ) ;
windows_menu - > addAction ( cascade_window ) ;
2006-10-27 15:47:22 +00:00
2007-10-28 00:16:32 +00:00
// actions de deplacement entre les fenetres
2007-09-29 12:54:01 +00:00
windows_menu - > addSeparator ( ) ;
windows_menu - > addAction ( next_window ) ;
windows_menu - > addAction ( prev_window ) ;
2006-10-27 15:47:22 +00:00
// liste des fenetres
2009-04-03 19:30:25 +00:00
QList < ProjectView * > windows = openedProjects ( ) ;
2007-09-29 12:54:01 +00:00
2009-04-03 19:30:25 +00:00
tile_window - > setEnabled ( ! windows . isEmpty ( ) & & workspace . viewMode ( ) = = QMdiArea : : SubWindowView ) ;
cascade_window - > setEnabled ( ! windows . isEmpty ( ) & & workspace . viewMode ( ) = = QMdiArea : : SubWindowView ) ;
2007-10-28 00:16:32 +00:00
next_window - > setEnabled ( windows . count ( ) > 1 ) ;
prev_window - > setEnabled ( windows . count ( ) > 1 ) ;
2007-09-29 12:54:01 +00:00
if ( ! windows . isEmpty ( ) ) windows_menu - > addSeparator ( ) ;
2007-11-01 23:56:19 +00:00
QActionGroup * windows_actions = new QActionGroup ( this ) ;
2009-04-03 19:30:25 +00:00
foreach ( ProjectView * project_view , windows ) {
QString pv_title = project_view - > windowTitle ( ) ;
QAction * action = windows_menu - > addAction ( pv_title ) ;
2007-11-01 23:56:19 +00:00
windows_actions - > addAction ( action ) ;
2009-04-06 03:56:56 +00:00
action - > setStatusTip ( QString ( tr ( " Active le projet \253 \240 %1 \240 \273 " ) ) . arg ( pv_title ) ) ;
2006-10-27 15:47:22 +00:00
action - > setCheckable ( true ) ;
2009-04-03 19:30:25 +00:00
action - > setChecked ( project_view = = currentProject ( ) ) ;
2006-10-27 15:47:22 +00:00
connect ( action , SIGNAL ( triggered ( ) ) , & windowMapper , SLOT ( map ( ) ) ) ;
2009-04-03 19:30:25 +00:00
windowMapper . setMapping ( action , project_view ) ;
2006-10-27 15:47:22 +00:00
}
}
2006-10-28 19:39:43 +00:00
2007-02-01 01:07:26 +00:00
/**
Edite les informations du schema en cours
*/
2009-04-03 19:30:25 +00:00
void QETDiagramEditor : : editCurrentDiagramProperties ( ) {
if ( ProjectView * project_view = currentProject ( ) ) {
activateProject ( project_view ) ;
project_view - > editCurrentDiagramProperties ( ) ;
}
}
/**
Edite les proprietes du schema diagram
@ param diagram_view schema dont il faut editer les proprietes
*/
void QETDiagramEditor : : editDiagramProperties ( DiagramView * diagram_view ) {
if ( ProjectView * project_view = findProject ( diagram_view ) ) {
activateProject ( project_view ) ;
project_view - > editDiagramProperties ( diagram_view ) ;
}
}
/**
Edite les proprietes du schema diagram
@ param diagram schema dont il faut editer les proprietes
*/
void QETDiagramEditor : : editDiagramProperties ( Diagram * diagram ) {
if ( ProjectView * project_view = findProject ( diagram ) ) {
activateProject ( project_view ) ;
project_view - > editDiagramProperties ( diagram ) ;
2008-08-10 15:07:59 +00:00
}
2006-11-19 18:40:03 +00:00
}
2007-01-28 00:53:17 +00:00
2007-02-01 01:07:26 +00:00
/**
Ajoute une colonne au schema en cours
*/
2007-09-21 12:35:28 +00:00
void QETDiagramEditor : : slot_addColumn ( ) {
2008-08-10 15:07:59 +00:00
if ( DiagramView * dv = currentDiagram ( ) ) {
dv - > addColumn ( ) ;
}
2007-01-28 00:53:17 +00:00
}
2007-02-01 01:07:26 +00:00
/**
Enleve une colonne au schema en cours
*/
2007-09-21 12:35:28 +00:00
void QETDiagramEditor : : slot_removeColumn ( ) {
2008-08-10 15:07:59 +00:00
if ( DiagramView * dv = currentDiagram ( ) ) {
dv - > removeColumn ( ) ;
}
2007-01-28 00:53:17 +00:00
}
2007-02-03 02:00:18 +00:00
/**
Allonge le schema en cours en hauteur
*/
2008-08-10 15:07:59 +00:00
void QETDiagramEditor : : slot_addRow ( ) {
if ( DiagramView * dv = currentDiagram ( ) ) {
dv - > addRow ( ) ;
}
2007-02-03 02:00:18 +00:00
}
/**
Retrecit le schema en cours en hauteur
*/
2008-08-10 15:07:59 +00:00
void QETDiagramEditor : : slot_removeRow ( ) {
if ( DiagramView * dv = currentDiagram ( ) ) {
dv - > removeRow ( ) ;
}
2007-02-03 02:00:18 +00:00
}
2007-10-03 13:11:47 +00:00
2009-05-17 02:13:40 +00:00
/**
Edite les proprietes des objets selectionnes
*/
void QETDiagramEditor : : editSelectionProperties ( ) {
if ( DiagramView * dv = currentDiagram ( ) ) {
dv - > editSelectionProperties ( ) ;
}
}
2007-10-06 18:37:21 +00:00
/**
Reinitialise les conducteurs selectionnes
*/
void QETDiagramEditor : : slot_resetConductors ( ) {
if ( DiagramView * dv = currentDiagram ( ) ) {
dv - > resetConductors ( ) ;
}
}
2007-10-14 15:16:37 +00:00
2015-01-11 11:10:57 +00:00
/**
* @ brief QETDiagramEditor : : slot_autoConductor
* @ param ac
* Update the auto conductor status of current project ;
*/
void QETDiagramEditor : : slot_autoConductor ( bool ac )
{
if ( ProjectView * pv = currentProject ( ) )
pv - > project ( ) - > setAutoConductor ( ac ) ;
}
2007-10-27 13:18:17 +00:00
/**
2014-06-07 21:03:49 +00:00
* @ brief QETDiagramEditor : : slot_addText
* add text to curent diagram
*/
2007-10-27 13:18:17 +00:00
void QETDiagramEditor : : slot_addText ( ) {
2014-09-24 09:38:16 +00:00
if ( DiagramView * dv = currentDiagram ( ) )
dv - > setEventInterface ( new DVEventAddText ( dv ) ) ;
2007-10-14 15:16:37 +00:00
}
2014-06-07 21:03:49 +00:00
2013-08-24 15:18:45 +00:00
/**
2014-06-07 21:03:49 +00:00
* @ brief QETDiagramEditor : : slot_addImage
* add image to curent diagram
*/
2013-08-24 15:18:45 +00:00
void QETDiagramEditor : : slot_addImage ( ) {
2014-09-24 09:38:16 +00:00
if ( DiagramView * dv = currentDiagram ( ) ) {
DVEventAddImage * event = new DVEventAddImage ( dv ) ;
if ( event - > isNull ( ) ) {
delete event ;
m_add_item_actions_group . checkedAction ( ) - > setChecked ( false ) ;
} else {
dv - > setEventInterface ( event ) ;
}
}
2013-08-24 15:18:45 +00:00
}
2013-09-10 14:44:25 +00:00
2014-06-07 21:03:49 +00:00
/**
* @ brief QETDiagramEditor : : slot_addLine
* add line to curent diagram
*/
2014-02-23 18:55:26 +00:00
void QETDiagramEditor : : slot_addLine ( ) {
2014-09-24 09:38:16 +00:00
if ( DiagramView * dv = currentDiagram ( ) )
dv - > setEventInterface ( new DVEventAddShape ( dv , QetShapeItem : : Line ) ) ;
2014-02-23 18:55:26 +00:00
}
2014-06-07 21:03:49 +00:00
/**
* @ brief QETDiagramEditor : : slot_addRectangle
2014-09-24 09:38:16 +00:00
* add rectangle to curent diagram
2014-06-07 21:03:49 +00:00
*/
2014-02-23 18:55:26 +00:00
void QETDiagramEditor : : slot_addRectangle ( ) {
2014-09-24 09:38:16 +00:00
if ( DiagramView * dv = currentDiagram ( ) ) dv - > setEventInterface ( new DVEventAddShape ( dv , QetShapeItem : : Rectangle ) ) ;
2014-02-23 18:55:26 +00:00
}
2014-06-07 21:03:49 +00:00
/**
* @ brief QETDiagramEditor : : slot_addEllipse
* add ellipse to curent diagram
*/
2014-02-23 18:55:26 +00:00
void QETDiagramEditor : : slot_addEllipse ( ) {
2014-09-24 09:38:16 +00:00
if ( DiagramView * dv = currentDiagram ( ) ) dv - > setEventInterface ( new DVEventAddShape ( dv , QetShapeItem : : Ellipse ) ) ;
2014-02-23 18:55:26 +00:00
}
2014-06-17 09:08:41 +00:00
/**
* @ brief QETDiagramEditor : : slot_addPolyline
* add polyline to current diagram
*/
void QETDiagramEditor : : slot_addPolyline ( ) {
2014-09-24 09:38:16 +00:00
if ( DiagramView * dv = currentDiagram ( ) ) dv - > setEventInterface ( new DVEventAddShape ( dv , QetShapeItem : : Polyline ) ) ;
2014-06-17 09:08:41 +00:00
}
2013-04-01 13:49:34 +00:00
/**
2013-09-10 14:44:25 +00:00
* @ brief QETDiagramEditor : : slot_editSelection
* edit the selected item if he can be edited and if only one item is selected
*/
void QETDiagramEditor : : slot_editSelection ( ) {
2013-04-01 13:49:34 +00:00
if ( DiagramView * dv = currentDiagram ( ) ) {
2013-09-10 14:44:25 +00:00
DiagramContent dc = dv - > diagram ( ) - > selectedContent ( ) ;
2013-09-26 09:27:55 +00:00
if ( dc . count ( DiagramContent : : SelectedOnly | DiagramContent : : All ) ! = 1 ) return ;
2014-09-25 09:44:41 +00:00
dv - > editSelection ( ) ;
2013-04-01 13:49:34 +00:00
}
}
2009-04-03 19:30:25 +00:00
/**
Affiche les projets dans des fenetres .
*/
void QETDiagramEditor : : setWindowedMode ( ) {
workspace . setViewMode ( QMdiArea : : SubWindowView ) ;
windowed_view_mode - > setChecked ( true ) ;
slot_updateWindowsMenu ( ) ;
}
/**
Affiche les projets dans des onglets .
*/
void QETDiagramEditor : : setTabbedMode ( ) {
workspace . setViewMode ( QMdiArea : : TabbedView ) ;
tabbed_view_mode - > setChecked ( true ) ;
slot_updateWindowsMenu ( ) ;
}
2007-11-12 15:21:14 +00:00
/// Lit les parametres de l'editeur de schemas
void QETDiagramEditor : : readSettings ( ) {
QSettings & settings = QETApp : : settings ( ) ;
// dimensions et position de la fenetre
QVariant geometry = settings . value ( " diagrameditor/geometry " ) ;
if ( geometry . isValid ( ) ) restoreGeometry ( geometry . toByteArray ( ) ) ;
// etat de la fenetre (barres d'outils, docks...)
QVariant state = settings . value ( " diagrameditor/state " ) ;
if ( state . isValid ( ) ) restoreState ( state . toByteArray ( ) ) ;
2009-04-03 19:30:25 +00:00
// gestion des projets (onglets ou fenetres)
2009-04-05 12:33:20 +00:00
bool tabbed = settings . value ( " diagrameditor/viewmode " , " tabbed " ) = = " tabbed " ;
2009-04-03 19:30:25 +00:00
if ( tabbed ) {
setTabbedMode ( ) ;
} else {
setWindowedMode ( ) ;
}
2007-11-12 15:21:14 +00:00
}
/// Enregistre les parametres de l'editeur de schemas
void QETDiagramEditor : : writeSettings ( ) {
QSettings & settings = QETApp : : settings ( ) ;
settings . setValue ( " diagrameditor/geometry " , saveGeometry ( ) ) ;
settings . setValue ( " diagrameditor/state " , saveState ( ) ) ;
}
2007-11-18 00:22:19 +00:00
2009-04-03 19:30:25 +00:00
/**
Active le schema passe en parametre
@ param diagram Schema a activer
*/
void QETDiagramEditor : : activateDiagram ( Diagram * diagram ) {
if ( QETProject * project = diagram - > project ( ) ) {
if ( ProjectView * project_view = findProject ( project ) ) {
activateWidget ( project_view ) ;
project_view - > showDiagram ( diagram ) ;
}
} else {
/// @todo gerer ce cas
}
}
/**
Active le projet passe en parametre
@ param project Projet a activer
*/
void QETDiagramEditor : : activateProject ( QETProject * project ) {
activateProject ( findProject ( project ) ) ;
}
/**
Active le projet passe en parametre
@ param project_view Projet a activer
*/
void QETDiagramEditor : : activateProject ( ProjectView * project_view ) {
if ( ! project_view ) return ;
activateWidget ( project_view ) ;
}
/**
Gere la fermeture d ' une ProjectView
@ param project_view ProjectView fermee
*/
void QETDiagramEditor : : projectWasClosed ( ProjectView * project_view ) {
QETProject * project = project_view - > project ( ) ;
if ( project ) {
pa - > elementsPanel ( ) . projectWasClosed ( project ) ;
2014-11-27 18:46:30 +00:00
undo_group . removeStack ( project - > undoStack ( ) ) ;
2009-04-03 19:30:25 +00:00
QETApp : : unregisterProject ( project ) ;
}
project_view - > deleteLater ( ) ;
project - > deleteLater ( ) ;
}
/**
Edite les proprietes du projet courant .
*/
void QETDiagramEditor : : editCurrentProjectProperties ( ) {
editProjectProperties ( currentProject ( ) ) ;
}
/**
Edite les proprietes du projet project_view .
@ param project_view Vue sur le projet dont il faut editer les proprietes
*/
void QETDiagramEditor : : editProjectProperties ( ProjectView * project_view ) {
if ( ! project_view ) return ;
activateProject ( project_view ) ;
project_view - > editProjectProperties ( ) ;
}
/**
Edite les proprietes du projet project .
@ param project Projet dont il faut editer les proprietes
*/
void QETDiagramEditor : : editProjectProperties ( QETProject * project ) {
editProjectProperties ( findProject ( project ) ) ;
}
/**
Ajoute un nouveau schema au projet courant
*/
void QETDiagramEditor : : addDiagramToProject ( ) {
if ( ProjectView * current_project = currentProject ( ) ) {
current_project - > addNewDiagram ( ) ;
}
}
2014-09-18 18:12:05 +00:00
/**
* @ brief QETDiagramEditor : : addDiagramFolioListToProject
* Add new folio list to project
*/
2014-02-07 07:54:54 +00:00
void QETDiagramEditor : : addDiagramFolioListToProject ( ) {
2014-09-18 18:12:05 +00:00
if ( ProjectView * current_project = currentProject ( ) )
2014-12-12 13:27:13 +00:00
current_project - > addNewDiagramFolioList ( ) ;
2014-02-07 07:54:54 +00:00
}
2009-04-03 19:30:25 +00:00
/**
Ajoute un nouveau schema a un projet
@ param project Projet auquel il faut ajouter un schema
*/
void QETDiagramEditor : : addDiagramToProject ( QETProject * project ) {
if ( ! project ) return ;
// recupere le ProjectView visualisant ce projet
if ( ProjectView * project_view = findProject ( project ) ) {
// affiche le projet en question
activateProject ( project ) ;
// ajoute un schema au projet
project_view - > addNewDiagram ( ) ;
}
}
/**
Supprime un schema de son projet
@ param diagram Schema a supprimer
*/
void QETDiagramEditor : : removeDiagram ( Diagram * diagram ) {
if ( ! diagram ) return ;
// recupere le projet contenant le schema
if ( QETProject * diagram_project = diagram - > project ( ) ) {
// recupere la vue sur ce projet
if ( ProjectView * project_view = findProject ( diagram_project ) ) {
// affiche le schema en question
project_view - > showDiagram ( diagram ) ;
// supprime le schema
project_view - > removeDiagram ( diagram ) ;
}
}
}
2010-02-28 16:13:45 +00:00
/**
Change l ' ordre des schemas d ' un projet , en decalant le schema vers le haut /
la gauche
@ param diagram Schema a decaler vers le haut / la gauche
*/
void QETDiagramEditor : : moveDiagramUp ( Diagram * diagram ) {
if ( ! diagram ) return ;
// recupere le projet contenant le schema
if ( QETProject * diagram_project = diagram - > project ( ) ) {
if ( diagram_project - > isReadOnly ( ) ) return ;
// recupere la vue sur ce projet
if ( ProjectView * project_view = findProject ( diagram_project ) ) {
project_view - > moveDiagramUp ( diagram ) ;
}
}
}
/**
Change l ' ordre des schemas d ' un projet , en decalant le schema vers le bas /
la droite
@ param diagram Schema a decaler vers le bas / la droite
*/
void QETDiagramEditor : : moveDiagramDown ( Diagram * diagram ) {
if ( ! diagram ) return ;
// recupere le projet contenant le schema
if ( QETProject * diagram_project = diagram - > project ( ) ) {
if ( diagram_project - > isReadOnly ( ) ) return ;
// recupere la vue sur ce projet
if ( ProjectView * project_view = findProject ( diagram_project ) ) {
project_view - > moveDiagramDown ( diagram ) ;
}
}
}
2014-12-14 17:01:11 +00:00
/**
Change l ' ordre des schemas d ' un projet , en decalant le schema vers le haut /
la gauche x10
@ param diagram Schema a decaler vers le haut / la gauche x10
*/
void QETDiagramEditor : : moveDiagramUpx10 ( Diagram * diagram ) {
if ( ! diagram ) return ;
// recupere le projet contenant le schema
if ( QETProject * diagram_project = diagram - > project ( ) ) {
if ( diagram_project - > isReadOnly ( ) ) return ;
// recupere la vue sur ce projet
if ( ProjectView * project_view = findProject ( diagram_project ) ) {
project_view - > moveDiagramUpx10 ( diagram ) ;
}
}
}
/**
Change l ' ordre des schemas d ' un projet , en decalant le schema vers le bas /
la droite x10
@ param diagram Schema a decaler vers le bas / la droite x10
*/
void QETDiagramEditor : : moveDiagramDownx10 ( Diagram * diagram ) {
if ( ! diagram ) return ;
// recupere le projet contenant le schema
if ( QETProject * diagram_project = diagram - > project ( ) ) {
if ( diagram_project - > isReadOnly ( ) ) return ;
// recupere la vue sur ce projet
if ( ProjectView * project_view = findProject ( diagram_project ) ) {
project_view - > moveDiagramDownx10 ( diagram ) ;
}
}
}
2009-04-03 19:30:25 +00:00
/**
Nettoie le projet courant
*/
void QETDiagramEditor : : cleanCurrentProject ( ) {
if ( ProjectView * current_project = currentProject ( ) ) {
int clean_count = current_project - > cleanProject ( ) ;
if ( clean_count ) pa - > reloadAndFilter ( ) ;
}
}
2013-04-11 09:35:10 +00:00
/**
* @ brief export nomemclature of schema
*/
void QETDiagramEditor : : nomenclatureProject ( ) {
//TODO: Test nomenclature CYRIL F.
2014-10-05 13:35:01 +00:00
nomenclature nomencl ( currentProject ( ) - > project ( ) , this ) ;
nomencl . saveToCSVFile ( ) ;
2013-04-11 09:35:10 +00:00
}
2009-04-03 19:30:25 +00:00
/**
Supprime le schema courant du projet courant
*/
void QETDiagramEditor : : removeDiagramFromProject ( ) {
if ( ProjectView * current_project = currentProject ( ) ) {
if ( DiagramView * current_diagram = current_project - > currentDiagram ( ) ) {
2014-02-10 11:48:05 +00:00
bool isFolioList = false ;
2014-02-11 05:10:16 +00:00
// if diagram to remove is a "folio list sheet", then set a flag.
2014-10-19 11:25:03 +00:00
if ( dynamic_cast < DiagramFolioList * > ( current_diagram - > diagram ( ) ) )
2014-02-10 11:48:05 +00:00
isFolioList = true ;
2014-02-11 05:10:16 +00:00
2009-04-03 19:30:25 +00:00
current_project - > removeDiagram ( current_diagram ) ;
2014-02-11 05:10:16 +00:00
// if the removed diagram was a folio sheet, then delete all the remaining folio sheets also.
2014-02-10 11:48:05 +00:00
if ( isFolioList ) {
foreach ( DiagramView * diag , current_project - > diagrams ( ) ) {
2014-10-19 11:25:03 +00:00
if ( dynamic_cast < DiagramFolioList * > ( diag - > diagram ( ) ) ) {
2014-02-10 11:48:05 +00:00
current_project - > removeDiagram ( diag ) ;
}
}
2014-02-11 05:10:16 +00:00
// else if after diagram removal, the total diagram quantity becomes a factor of 58, then
// remove one (last) folio sheet.
2014-02-10 11:48:05 +00:00
} else if ( current_project - > diagrams ( ) . size ( ) % 58 = = 0 ) {
foreach ( DiagramView * diag , current_project - > diagrams ( ) ) {
DiagramFolioList * ptr = dynamic_cast < DiagramFolioList * > ( diag - > diagram ( ) ) ;
2014-02-10 13:58:30 +00:00
if ( ptr & & ptr - > getId ( ) = = current_project - > project ( ) - > getFolioSheetsQuantity ( ) - 1 ) {
2014-02-10 11:48:05 +00:00
current_project - > removeDiagram ( diag ) ;
}
}
}
2009-04-03 19:30:25 +00:00
}
}
}
/**
2014-12-26 19:41:00 +00:00
* @ brief QETDiagramEditor : : diagramWasAdded
* Manage the adding of diagram view in a project
* @ param dv , added diagram view
*/
void QETDiagramEditor : : diagramWasAdded ( DiagramView * dv )
{
connect ( dv , SIGNAL ( selectionChanged ( ) ) , this , SLOT ( slot_updateComplexActions ( ) ) ) ;
connect ( dv , SIGNAL ( modeChanged ( ) ) , this , SLOT ( slot_updateModeActions ( ) ) ) ;
connect ( dv , SIGNAL ( itemAdded ( ) ) , this , SLOT ( addItemFinish ( ) ) ) ;
2009-04-03 19:30:25 +00:00
}
2009-05-19 19:00:37 +00:00
/**
@ param location Emplacement de l ' element a retrouver dans le panel
d ' elements .
*/
void QETDiagramEditor : : findElementInPanel ( const ElementsLocation & location ) {
bool element_found = pa - > elementsPanel ( ) . scrollToElement ( location ) ;
if ( ! element_found ) {
// l'element n'a pas ete trouve
ElementsCollectionItem * element = QETApp : : collectionItem ( location ) ;
if ( element ) {
// mais il semble exister tout de meme
// peut-etre vient-il d'un projet ouvert dans un autre editeur ?
if ( location . project ( ) & & ! findProject ( location . project ( ) ) ) {
statusBar ( ) - > showMessage (
tr ( " Impossible de retrouver cet \351 l \351 ment dans le panel car il semble \351 dit \351 dans une autre fen \352 tre " ) ,
10000
) ;
} else {
// il devrait etre affiche : on tente de recharger le panel
statusBar ( ) - > showMessage (
tr ( " Impossible de retrouver cet \351 l \351 ment dans le panel... rechargement du panel... " ) ,
10000
) ;
pa - > reloadAndFilter ( ) ;
statusBar ( ) - > clearMessage ( ) ;
element_found = pa - > elementsPanel ( ) . scrollToElement ( location ) ;
}
}
}
if ( ! element_found ) {
statusBar ( ) - > showMessage (
tr ( " Impossible de retrouver cet \351 l \351 ment dans le panel " ) ,
10000
) ;
}
}
2013-02-12 18:37:08 +00:00
/**
Search the panel for the definition for the selected element in the current
diagram view .
*/
void QETDiagramEditor : : findSelectedElementInPanel ( ) {
if ( CustomElement * selected_element = currentCustomElement ( ) ) {
findElementInPanel ( selected_element - > location ( ) ) ;
}
}
2009-07-08 09:41:20 +00:00
/**
Lance l ' editeur d ' element pour l ' element filename
@ param location Emplacement de l ' element a editer
*/
void QETDiagramEditor : : editElementInEditor ( const ElementsLocation & location ) {
2010-03-28 16:27:48 +00:00
QETApp : : instance ( ) - > openElementLocations ( QList < ElementsLocation > ( ) < < location ) ;
2009-07-08 09:41:20 +00:00
}
2013-02-12 18:37:08 +00:00
/**
Launch an element editor to edit the selected element in the current
diagram view .
*/
void QETDiagramEditor : : editSelectedElementInEditor ( ) {
if ( CustomElement * selected_element = currentCustomElement ( ) ) {
editElementInEditor ( selected_element - > location ( ) ) ;
}
}
2012-07-13 07:21:19 +00:00
/**
Show the error message contained in \ a result .
*/
void QETDiagramEditor : : showError ( const QETResult & result ) {
if ( result . isOk ( ) ) return ;
showError ( result . errorMessage ( ) ) ;
}
/**
Show the \ a error message .
*/
void QETDiagramEditor : : showError ( const QString & error ) {
if ( error . isEmpty ( ) ) return ;
QET : : MessageBox : : critical ( this , tr ( " Erreur " , " message box title " ) , error ) ;
}
2014-06-07 21:03:49 +00:00
/**
* @ brief QETDiagramEditor : : addItemFinish
* Uncheck all action in m_add_item_actions_group
*/
void QETDiagramEditor : : addItemFinish ( ) {
2014-09-24 09:38:16 +00:00
m_add_item_actions_group . checkedAction ( ) - > setChecked ( false ) ;
2014-06-07 21:03:49 +00:00
}
2014-12-10 17:00:08 +00:00
2014-12-26 19:41:00 +00:00
/**
* @ brief QETDiagramEditor : : subWindowActivated
* Slot used to update menu and undo stack when subwindows of MDIarea was activated
* @ param subWindows
*/
void QETDiagramEditor : : subWindowActivated ( QMdiSubWindow * subWindows )
{
Q_UNUSED ( subWindows ) ;
slot_updateActions ( ) ;
slot_updateWindowsMenu ( ) ;
}
2014-12-10 17:00:08 +00:00
/**
* @ brief QETDiagramEditor : : activeUndoStackCleanChanged
* Enable the QAction save_file when @ clean is set to false
* @ clean at true do nothing ;
* @ param clean
*/
void QETDiagramEditor : : activeUndoStackCleanChanged ( bool clean ) {
if ( ! clean ) {
save_file - > setEnabled ( true ) ;
}
}