2007-12-01 10:47:15 +00:00
/*
2012-01-01 22:51:51 +00:00
Copyright 2006 - 2012 Xavier Guerrin
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-01-29 00:41:12 +00:00
# include "diagramview.h"
# include "diagram.h"
2007-01-30 22:32:21 +00:00
# include "customelement.h"
2009-05-17 02:13:40 +00:00
# include "ghostelement.h"
2007-10-03 17:02:39 +00:00
# include "conductor.h"
2007-09-25 23:24:36 +00:00
# include "diagramcommands.h"
2009-05-20 21:29:17 +00:00
# include "diagramposition.h"
2007-10-14 10:09:46 +00:00
# include "conductorpropertieswidget.h"
2010-04-18 17:59:54 +00:00
# include "conductortextitem.h"
2009-11-29 21:56:48 +00:00
# include "elementtextitem.h"
2010-04-18 17:59:54 +00:00
# include "independenttextitem.h"
2010-12-20 02:45:36 +00:00
# include "titleblockpropertieswidget.h"
2012-01-22 10:40:37 +00:00
# include "templatelocation.h"
2009-04-03 19:30:25 +00:00
# include "qetapp.h"
# include "qetproject.h"
2008-08-14 22:51:08 +00:00
# include "borderpropertieswidget.h"
2009-04-03 19:30:25 +00:00
# include "integrationmoveelementshandler.h"
2012-01-22 10:40:37 +00:00
# include "integrationmovetemplateshandler.h"
2009-04-03 19:30:25 +00:00
# include "qetdiagrameditor.h"
2009-05-01 14:41:33 +00:00
# include "qeticons.h"
2009-08-09 16:02:14 +00:00
# include "qetmessagebox.h"
2010-02-11 23:35:04 +00:00
# include "qtextorientationspinboxwidget.h"
2013-04-10 09:31:51 +00:00
# include "htmleditor/htmleditor.h"
# include "conductorautonumerotation.h"
2013-04-01 13:49:34 +00:00
2006-10-27 15:47:22 +00:00
/**
2007-09-29 12:54:01 +00:00
Constructeur
2009-11-22 16:12:22 +00:00
@ param diagram Schema a afficher ; si diagram vaut 0 , un nouveau Diagram est utilise
2008-08-10 15:07:59 +00:00
@ param parent Le QWidget parent de cette vue de schema
2006-10-27 15:47:22 +00:00
*/
2012-03-24 14:34:25 +00:00
DiagramView : : DiagramView ( Diagram * diagram , QWidget * parent ) : QGraphicsView ( parent ) , is_adding_text ( false ) , is_moving_view_ ( false ) {
2008-07-17 22:57:50 +00:00
setAttribute ( Qt : : WA_DeleteOnClose , true ) ;
2006-10-27 15:47:22 +00:00
setInteractive ( true ) ;
2007-02-17 18:59:18 +00:00
2012-04-28 16:45:13 +00:00
QString whatsthis = tr (
2012-05-10 06:13:23 +00:00
" Ceci est la zone dans laquelle vous concevez vos sch \351 mas en y ajoutant "
" des \351 l \351 ments et en posant des conducteurs entre leurs bornes. Il est "
" \351 galement possible d'ajouter des textes ind \351 pendants. " ,
2012-04-28 16:45:13 +00:00
" \" What's this? \" tip "
) ;
setWhatsThis ( whatsthis ) ;
2007-02-17 18:59:18 +00:00
// active l'antialiasing
setRenderHint ( QPainter : : Antialiasing , true ) ;
setRenderHint ( QPainter : : TextAntialiasing , true ) ;
setRenderHint ( QPainter : : SmoothPixmapTransform , true ) ;
2009-04-03 19:30:25 +00:00
scene = diagram ? diagram : new Diagram ( this ) ;
setScene ( scene ) ;
2007-09-29 09:52:35 +00:00
scene - > undoStack ( ) . setClean ( ) ;
2009-05-01 14:41:33 +00:00
setWindowIcon ( QET : : Icons : : QETLogo ) ;
2007-01-28 00:53:17 +00:00
setTransformationAnchor ( QGraphicsView : : AnchorUnderMouse ) ;
setResizeAnchor ( QGraphicsView : : AnchorUnderMouse ) ;
setAlignment ( Qt : : AlignLeft | Qt : : AlignTop ) ;
2009-04-03 19:30:25 +00:00
setSelectionMode ( ) ;
2007-03-03 23:35:14 +00:00
adjustSceneRect ( ) ;
2007-09-29 09:52:35 +00:00
updateWindowTitle ( ) ;
2007-11-02 18:04:13 +00:00
context_menu = new QMenu ( this ) ;
2009-05-01 14:41:33 +00:00
paste_here = new QAction ( QET : : Icons : : EditPaste , tr ( " Coller ici " , " context menu action " ) , this ) ;
2007-11-02 18:04:13 +00:00
connect ( paste_here , SIGNAL ( triggered ( ) ) , this , SLOT ( pasteHere ( ) ) ) ;
2009-04-18 15:30:44 +00:00
connect ( scene , SIGNAL ( selectionChanged ( ) ) , this , SIGNAL ( selectionChanged ( ) ) ) ;
2009-04-03 19:30:25 +00:00
connect ( scene , SIGNAL ( readOnlyChanged ( bool ) ) , this , SLOT ( applyReadOnly ( ) ) ) ;
2010-12-20 02:45:36 +00:00
connect ( & ( scene - > border_and_titleblock ) , SIGNAL ( borderChanged ( QRectF , QRectF ) ) , this , SLOT ( adjustSceneRect ( ) ) ) ;
connect ( & ( scene - > border_and_titleblock ) , SIGNAL ( displayChanged ( ) ) , this , SLOT ( adjustSceneRect ( ) ) ) ;
connect ( & ( scene - > border_and_titleblock ) , SIGNAL ( diagramTitleChanged ( const QString & ) ) , this , SLOT ( updateWindowTitle ( ) ) ) ;
2007-09-29 09:52:35 +00:00
connect ( & ( scene - > undoStack ( ) ) , SIGNAL ( cleanChanged ( bool ) ) , this , SLOT ( updateWindowTitle ( ) ) ) ;
2009-04-03 19:30:25 +00:00
connect ( this , SIGNAL ( aboutToAddElement ( ) ) , this , SLOT ( addDroppedElement ( ) ) , Qt : : QueuedConnection ) ;
2012-01-22 10:40:37 +00:00
connect (
this , SIGNAL ( aboutToSetDroppedTitleBlockTemplate ( const TitleBlockTemplateLocation & ) ) ,
this , SLOT ( setDroppedTitleBlockTemplate ( const TitleBlockTemplateLocation & ) ) ,
Qt : : QueuedConnection
) ;
2011-08-22 11:17:10 +00:00
QShortcut * edit_conductor_color_shortcut = new QShortcut ( QKeySequence ( Qt : : Key_F2 ) , this ) ;
connect ( edit_conductor_color_shortcut , SIGNAL ( activated ( ) ) , this , SLOT ( editSelectedConductorColor ( ) ) ) ;
2006-10-27 15:47:22 +00:00
}
2007-04-12 03:13:13 +00:00
/**
Destructeur
*/
DiagramView : : ~ DiagramView ( ) {
}
2006-10-27 15:47:22 +00:00
/**
2009-04-18 15:30:44 +00:00
Selectionne tous les objets du schema
2006-10-27 15:47:22 +00:00
*/
2007-01-29 00:41:12 +00:00
void DiagramView : : selectAll ( ) {
2009-04-18 15:30:44 +00:00
scene - > selectAll ( ) ;
2006-10-27 15:47:22 +00:00
}
/**
2009-04-18 15:30:44 +00:00
Deslectionne tous les objets selectionnes
2006-10-27 15:47:22 +00:00
*/
2007-01-29 00:41:12 +00:00
void DiagramView : : selectNothing ( ) {
2009-04-18 15:30:44 +00:00
scene - > deselectAll ( ) ;
2006-10-27 15:47:22 +00:00
}
/**
2009-04-18 15:30:44 +00:00
Inverse l ' etat de selection de tous les objets du schema
*/
2007-01-29 00:41:12 +00:00
void DiagramView : : selectInvert ( ) {
2009-04-18 15:30:44 +00:00
scene - > invertSelection ( ) ;
2006-10-27 15:47:22 +00:00
}
/**
Supprime les composants selectionnes
*/
2007-09-29 12:54:01 +00:00
void DiagramView : : deleteSelection ( ) {
2009-04-03 19:30:25 +00:00
if ( scene - > isReadOnly ( ) ) return ;
2007-11-09 13:06:51 +00:00
DiagramContent removed_content = scene - > selectedContent ( ) ;
2006-10-27 15:47:22 +00:00
scene - > clearSelection ( ) ;
2007-11-09 13:06:51 +00:00
scene - > undoStack ( ) . push ( new DeleteElementsCommand ( scene , removed_content ) ) ;
2007-12-22 14:59:38 +00:00
adjustSceneRect ( ) ;
2006-10-27 15:47:22 +00:00
}
/**
Pivote les composants selectionnes
*/
2007-09-29 12:54:01 +00:00
void DiagramView : : rotateSelection ( ) {
2009-04-03 19:30:25 +00:00
if ( scene - > isReadOnly ( ) ) return ;
2009-11-29 21:56:48 +00:00
// recupere les elements et les champs de texte a pivoter
2007-09-27 15:36:15 +00:00
QHash < Element * , QET : : Orientation > elements_to_rotate ;
2009-11-29 21:56:48 +00:00
QList < DiagramTextItem * > texts_to_rotate ;
2006-10-27 15:47:22 +00:00
foreach ( QGraphicsItem * item , scene - > selectedItems ( ) ) {
2007-09-27 15:36:15 +00:00
if ( Element * e = qgraphicsitem_cast < Element * > ( item ) ) {
elements_to_rotate . insert ( e , e - > orientation ( ) . current ( ) ) ;
2010-04-18 17:59:54 +00:00
} else if ( ConductorTextItem * cti = qgraphicsitem_cast < ConductorTextItem * > ( item ) ) {
texts_to_rotate < < cti ;
} else if ( IndependentTextItem * iti = qgraphicsitem_cast < IndependentTextItem * > ( item ) ) {
texts_to_rotate < < iti ;
2009-12-13 22:12:52 +00:00
} else if ( ElementTextItem * eti = qgraphicsitem_cast < ElementTextItem * > ( item ) ) {
// on ne pivote un texte d'element que si son parent n'est pas selectionne
if ( eti - > parentItem ( ) & & ! eti - > parentItem ( ) - > isSelected ( ) ) {
texts_to_rotate < < eti ;
}
}
2006-10-27 15:47:22 +00:00
}
2009-11-29 21:56:48 +00:00
// effectue les rotations s'il y a quelque chose a pivoter
if ( elements_to_rotate . isEmpty ( ) & & texts_to_rotate . isEmpty ( ) ) return ;
scene - > undoStack ( ) . push ( new RotateElementsCommand ( elements_to_rotate , texts_to_rotate ) ) ;
2006-10-27 15:47:22 +00:00
}
2010-02-11 23:35:04 +00:00
void DiagramView : : rotateTexts ( ) {
if ( scene - > isReadOnly ( ) ) return ;
// recupere les champs de texte a orienter
QList < DiagramTextItem * > texts_to_rotate ;
foreach ( QGraphicsItem * item , scene - > selectedItems ( ) ) {
2010-04-18 17:59:54 +00:00
if ( ConductorTextItem * cti = qgraphicsitem_cast < ConductorTextItem * > ( item ) ) {
texts_to_rotate < < cti ;
} else if ( IndependentTextItem * iti = qgraphicsitem_cast < IndependentTextItem * > ( item ) ) {
texts_to_rotate < < iti ;
2010-02-11 23:35:04 +00:00
} else if ( ElementTextItem * eti = qgraphicsitem_cast < ElementTextItem * > ( item ) ) {
// ici, on pivote un texte d'element meme si son parent est selectionne
texts_to_rotate < < eti ;
}
}
// effectue les rotations s'il y a quelque chose a pivoter
if ( texts_to_rotate . isEmpty ( ) ) return ;
// demande un angle a l'utilisateur
QDialog ori_text_dialog ( diagramEditor ( ) ) ;
ori_text_dialog . setSizeGripEnabled ( false ) ;
# ifdef Q_WS_MAC
ori_text_dialog . setWindowFlags ( Qt : : Sheet ) ;
# endif
ori_text_dialog . setWindowTitle ( tr ( " Orienter les textes s \351 lectionn \351 s " , " window title " ) ) ;
// ori_text_dialog.setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
QTextOrientationSpinBoxWidget * ori_widget = QETApp : : createTextOrientationSpinBoxWidget ( ) ;
ori_widget - > setParent ( & ori_text_dialog ) ;
if ( texts_to_rotate . count ( ) = = 1 ) {
ori_widget - > setOrientation ( texts_to_rotate . at ( 0 ) - > rotationAngle ( ) ) ;
}
ori_widget - > spinBox ( ) - > selectAll ( ) ;
// boutons
QDialogButtonBox buttons ( QDialogButtonBox : : Ok | QDialogButtonBox : : Cancel ) ;
connect ( & buttons , SIGNAL ( accepted ( ) ) , & ori_text_dialog , SLOT ( accept ( ) ) ) ;
connect ( & buttons , SIGNAL ( rejected ( ) ) , & ori_text_dialog , SLOT ( reject ( ) ) ) ;
// ajout dans une disposition verticale
QVBoxLayout layout_v ( & ori_text_dialog ) ;
layout_v . setSizeConstraint ( QLayout : : SetFixedSize ) ;
layout_v . addWidget ( ori_widget ) ;
layout_v . addStretch ( ) ;
layout_v . addWidget ( & buttons ) ;
// si le dialogue est accepte
if ( ori_text_dialog . exec ( ) = = QDialog : : Accepted ) {
scene - > undoStack ( ) . push ( new RotateTextsCommand ( texts_to_rotate , ori_widget - > orientation ( ) ) ) ;
}
}
2006-10-27 15:47:22 +00:00
/**
2008-08-10 15:07:59 +00:00
Accepte ou refuse le drag ' n drop en fonction du type de donnees entrant
2006-10-27 15:47:22 +00:00
@ param e le QDragEnterEvent correspondant au drag ' n drop tente
*/
2007-01-29 00:41:12 +00:00
void DiagramView : : dragEnterEvent ( QDragEnterEvent * e ) {
2009-04-03 19:30:25 +00:00
if ( e - > mimeData ( ) - > hasFormat ( " application/x-qet-element-uri " ) ) {
e - > acceptProposedAction ( ) ;
2012-01-22 10:40:37 +00:00
} else if ( e - > mimeData ( ) - > hasFormat ( " application/x-qet-titleblock-uri " ) ) {
e - > acceptProposedAction ( ) ;
2009-04-03 19:30:25 +00:00
} else {
e - > ignore ( ) ;
}
2006-10-27 15:47:22 +00:00
}
/**
2008-08-10 15:07:59 +00:00
Gere les dragleaveevent
2006-10-27 15:47:22 +00:00
@ param e le QDragEnterEvent correspondant au drag ' n drop sortant
*/
2009-11-22 16:12:22 +00:00
void DiagramView : : dragLeaveEvent ( QDragLeaveEvent * e ) {
Q_UNUSED ( e ) ;
2007-09-25 23:24:36 +00:00
}
2006-10-27 15:47:22 +00:00
/**
2008-08-10 15:07:59 +00:00
Accepte ou refuse le drag ' n drop en fonction du type de donnees entrant
2006-10-27 15:47:22 +00:00
@ param e le QDragMoveEvent correspondant au drag ' n drop tente
*/
2007-01-29 00:41:12 +00:00
void DiagramView : : dragMoveEvent ( QDragMoveEvent * e ) {
2006-10-27 15:47:22 +00:00
if ( e - > mimeData ( ) - > hasFormat ( " text/plain " ) ) e - > acceptProposedAction ( ) ;
else e - > ignore ( ) ;
}
/**
2012-01-22 10:40:37 +00:00
Handle the drops accepted on diagram ( elements and title block templates ) .
@ param e the QDropEvent describing the current drag ' n drop
2006-10-27 15:47:22 +00:00
*/
2007-01-29 00:41:12 +00:00
void DiagramView : : dropEvent ( QDropEvent * e ) {
2012-01-22 10:40:37 +00:00
if ( e - > mimeData ( ) - > hasFormat ( " application/x-qet-element-uri " ) ) {
handleElementDrop ( e ) ;
} else if ( e - > mimeData ( ) - > hasFormat ( " application/x-qet-titleblock-uri " ) ) {
handleTitleBlockDrop ( e ) ;
}
}
/**
Handle the drop of an element .
@ param e the QDropEvent describing the current drag ' n drop
*/
void DiagramView : : handleElementDrop ( QDropEvent * e ) {
// fetch the element location from the drop event
2009-04-03 19:30:25 +00:00
QString elmt_path = e - > mimeData ( ) - > text ( ) ;
2012-01-22 10:40:37 +00:00
2009-04-03 19:30:25 +00:00
ElementsLocation location ( ElementsLocation : : locationFromString ( elmt_path ) ) ;
// verifie qu'il existe un element correspondant a cet emplacement
ElementsCollectionItem * dropped_item = QETApp : : collectionItem ( location ) ;
if ( ! dropped_item ) return ;
next_location_ = location ;
next_position_ = e - > pos ( ) ;
emit ( aboutToAddElement ( ) ) ;
2006-10-27 15:47:22 +00:00
}
2012-01-22 10:40:37 +00:00
/**
Handle the drop of an element .
@ param e the QDropEvent describing the current drag ' n drop
*/
void DiagramView : : handleTitleBlockDrop ( QDropEvent * e ) {
// fetch the title block template location from the drop event
TitleBlockTemplateLocation tbt_loc ;
tbt_loc . fromString ( e - > mimeData ( ) - > text ( ) ) ;
if ( tbt_loc . isValid ( ) ) {
emit ( aboutToSetDroppedTitleBlockTemplate ( tbt_loc ) ) ;
}
}
2006-10-27 15:47:22 +00:00
/**
2007-01-29 00:41:12 +00:00
Passe le Diagram en mode visualisation
2006-10-27 15:47:22 +00:00
*/
2007-01-29 00:41:12 +00:00
void DiagramView : : setVisualisationMode ( ) {
2006-10-27 15:47:22 +00:00
setDragMode ( ScrollHandDrag ) ;
2009-04-03 19:30:25 +00:00
applyReadOnly ( ) ;
2007-09-08 19:09:59 +00:00
setInteractive ( false ) ;
2006-10-27 15:47:22 +00:00
emit ( modeChanged ( ) ) ;
}
/**
2007-01-29 00:41:12 +00:00
Passe le Diagram en mode Selection
2006-10-27 15:47:22 +00:00
*/
2007-01-29 00:41:12 +00:00
void DiagramView : : setSelectionMode ( ) {
2006-10-27 15:47:22 +00:00
setDragMode ( RubberBandDrag ) ;
2007-09-08 19:09:59 +00:00
setInteractive ( true ) ;
2009-04-03 19:30:25 +00:00
applyReadOnly ( ) ;
2006-10-27 15:47:22 +00:00
emit ( modeChanged ( ) ) ;
}
/**
Agrandit le schema ( + 33 % = inverse des - 25 % de zoomMoins ( ) )
*/
2007-09-29 12:54:01 +00:00
void DiagramView : : zoomIn ( ) {
2006-10-27 15:47:22 +00:00
scale ( 4.0 / 3.0 , 4.0 / 3.0 ) ;
2007-09-04 18:15:41 +00:00
adjustGridToZoom ( ) ;
2006-10-27 15:47:22 +00:00
}
/**
Retrecit le schema ( - 25 % = inverse des + 33 % de zoomPlus ( ) )
*/
2007-09-29 12:54:01 +00:00
void DiagramView : : zoomOut ( ) {
2006-10-27 15:47:22 +00:00
scale ( 0.75 , 0.75 ) ;
2007-09-04 18:15:41 +00:00
adjustGridToZoom ( ) ;
2006-10-27 15:47:22 +00:00
}
/**
Agrandit ou rectrecit le schema de facon a ce que tous les elements du
schema soient visibles a l ' ecran . S ' il n ' y a aucun element sur le schema ,
le zoom est reinitialise
*/
2007-01-29 00:41:12 +00:00
void DiagramView : : zoomFit ( ) {
2007-03-03 23:35:14 +00:00
adjustSceneRect ( ) ;
fitInView ( sceneRect ( ) , Qt : : KeepAspectRatio ) ;
2007-09-04 18:15:41 +00:00
adjustGridToZoom ( ) ;
2006-10-27 15:47:22 +00:00
}
2012-08-12 11:46:42 +00:00
/**
Adjust zoom to fit all elements in the view , regardless of diagram borders .
*/
void DiagramView : : zoomContent ( ) {
fitInView ( scene - > itemsBoundingRect ( ) , Qt : : KeepAspectRatio ) ;
adjustGridToZoom ( ) ;
}
2006-10-27 15:47:22 +00:00
/**
Reinitialise le zoom
*/
2007-01-29 00:41:12 +00:00
void DiagramView : : zoomReset ( ) {
2006-10-27 15:47:22 +00:00
resetMatrix ( ) ;
2007-09-04 18:15:41 +00:00
adjustGridToZoom ( ) ;
2006-10-27 15:47:22 +00:00
}
/**
2008-08-10 15:07:59 +00:00
Copie les elements selectionnes du schema dans le presse - papier puis les supprime
2006-10-27 15:47:22 +00:00
*/
2007-09-29 12:54:01 +00:00
void DiagramView : : cut ( ) {
copy ( ) ;
2007-11-11 16:12:45 +00:00
DiagramContent cut_content = scene - > selectedContent ( ) ;
2007-09-26 12:36:31 +00:00
scene - > clearSelection ( ) ;
2007-11-11 16:12:45 +00:00
scene - > undoStack ( ) . push ( new CutDiagramCommand ( scene , cut_content ) ) ;
2006-10-27 15:47:22 +00:00
}
/**
2008-08-10 15:07:59 +00:00
Copie les elements selectionnes du schema dans le presse - papier
2006-10-27 15:47:22 +00:00
*/
2007-09-29 12:54:01 +00:00
void DiagramView : : copy ( ) {
2006-10-27 15:47:22 +00:00
QClipboard * presse_papier = QApplication : : clipboard ( ) ;
QString contenu_presse_papier = scene - > toXml ( false ) . toString ( 4 ) ;
if ( presse_papier - > supportsSelection ( ) ) presse_papier - > setText ( contenu_presse_papier , QClipboard : : Selection ) ;
presse_papier - > setText ( contenu_presse_papier ) ;
}
/**
2007-11-02 18:04:13 +00:00
Importe les elements contenus dans le presse - papier dans le schema
@ param pos coin superieur gauche ( en coordonnees de la scene ) du rectangle
englobant le contenu colle
@ param clipboard_mode Type de presse - papier a prendre en compte
2006-10-27 15:47:22 +00:00
*/
2007-11-02 18:04:13 +00:00
void DiagramView : : paste ( const QPointF & pos , QClipboard : : Mode clipboard_mode ) {
2012-03-24 14:34:25 +00:00
if ( ! isInteractive ( ) | | scene - > isReadOnly ( ) ) return ;
2009-04-03 19:30:25 +00:00
2007-11-02 18:04:13 +00:00
QString texte_presse_papier = QApplication : : clipboard ( ) - > text ( clipboard_mode ) ;
if ( ( texte_presse_papier ) . isEmpty ( ) ) return ;
2006-10-27 15:47:22 +00:00
QDomDocument document_xml ;
if ( ! document_xml . setContent ( texte_presse_papier ) ) return ;
2007-09-26 12:36:31 +00:00
2007-11-09 13:06:51 +00:00
// objet pour recuperer le contenu ajoute au schema par le coller
DiagramContent content_pasted ;
scene - > fromXml ( document_xml , pos , false , & content_pasted ) ;
2007-09-26 12:36:31 +00:00
2007-11-02 18:04:13 +00:00
// si quelque chose a effectivement ete ajoute au schema, on cree un objet d'annulation
2007-11-09 13:06:51 +00:00
if ( content_pasted . count ( ) ) {
2007-09-26 12:36:31 +00:00
scene - > clearSelection ( ) ;
2007-11-09 13:06:51 +00:00
scene - > undoStack ( ) . push ( new PasteDiagramCommand ( scene , content_pasted ) ) ;
2007-12-22 14:59:38 +00:00
adjustSceneRect ( ) ;
2007-09-26 12:36:31 +00:00
}
2006-10-27 15:47:22 +00:00
}
2009-04-13 01:35:01 +00:00
/**
Colle le contenu du presse - papier sur le schema a la position de la souris
*/
2007-11-02 18:04:13 +00:00
void DiagramView : : pasteHere ( ) {
paste ( mapToScene ( paste_here_pos ) ) ;
}
2006-10-27 15:47:22 +00:00
/**
2013-04-10 09:31:51 +00:00
Gere les clics et plus particulierement :
* le clic du milieu ( = coller pour X11 )
* le clic pour ajouter un champ de texte independant
2006-10-27 15:47:22 +00:00
*/
2007-01-29 00:41:12 +00:00
void DiagramView : : mousePressEvent ( QMouseEvent * e ) {
2012-03-24 14:34:25 +00:00
if ( fresh_focus_in_ ) {
switchToVisualisationModeIfNeeded ( e ) ;
fresh_focus_in_ = false ;
}
2013-04-08 19:46:11 +00:00
if ( isInteractive ( ) & & ! scene - > isReadOnly ( ) ) {
2013-04-10 09:31:51 +00:00
if ( e - > buttons ( ) = = Qt : : MidButton ) {
paste ( mapToScene ( e - > pos ( ) ) , QClipboard : : Selection ) ;
} else {
if ( is_adding_text & & e - > buttons ( ) = = Qt : : LeftButton ) {
addDiagramTextAtPos ( mapToScene ( e - > pos ( ) ) ) ;
is_adding_text = false ;
}
2013-04-08 19:38:50 +00:00
}
2013-04-08 19:46:11 +00:00
}
2012-03-24 14:34:25 +00:00
QGraphicsView : : mousePressEvent ( e ) ;
2006-10-27 15:47:22 +00:00
}
2007-10-04 14:30:52 +00:00
/**
2013-04-10 09:31:51 +00:00
Gere les actions liees a la rollette de la souris
@ param e QWheelEvent decrivant l ' evenement rollette
2007-10-04 14:30:52 +00:00
*/
void DiagramView : : wheelEvent ( QWheelEvent * e ) {
2013-04-10 09:31:51 +00:00
// si la touche Ctrl est enfoncee, on zoome / dezoome
if ( e - > modifiers ( ) & Qt : : ControlModifier ) {
if ( e - > delta ( ) > 0 ) {
zoomIn ( ) ;
} else {
zoomOut ( ) ;
2013-04-08 14:39:50 +00:00
}
2013-04-10 09:31:51 +00:00
} else {
QAbstractScrollArea : : wheelEvent ( e ) ;
2007-10-04 14:30:52 +00:00
}
}
2012-03-24 14:34:25 +00:00
/**
Handles " Focus in " events . Reimplemented here to store the fact the focus
was freshly acquired again using the mouse . This information is later used
in DiagramView : : mousePressEvent ( ) .
*/
void DiagramView : : focusInEvent ( QFocusEvent * e ) {
if ( e - > reason ( ) = = Qt : : MouseFocusReason ) {
fresh_focus_in_ = true ;
}
}
/**
Handles " key press " events . Reimplemented here to switch to visualisation
mode if needed .
*/
void DiagramView : : keyPressEvent ( QKeyEvent * e ) {
switchToVisualisationModeIfNeeded ( e ) ;
QGraphicsView : : keyPressEvent ( e ) ;
}
/**
Handles " key release " events . Reimplemented here to switch to selection
mode if needed .
*/
void DiagramView : : keyReleaseEvent ( QKeyEvent * e ) {
switchToSelectionModeIfNeeded ( e ) ;
QGraphicsView : : keyReleaseEvent ( e ) ;
}
2006-10-27 15:47:22 +00:00
/**
2009-04-03 19:30:25 +00:00
@ return le titre de cette vue ; cela correspond au titre du schema
visualise precede de la mention " Schema " . Si le titre du schema est vide ,
la mention " Schema sans titre " est utilisee
@ see Diagram : : title ( )
2007-04-09 02:56:47 +00:00
*/
2009-04-03 19:30:25 +00:00
QString DiagramView : : title ( ) const {
QString view_title ;
QString diagram_title ( scene - > title ( ) ) ;
if ( diagram_title . isEmpty ( ) ) {
2013-03-03 17:07:05 +00:00
view_title = tr ( " Sans titre " , " what to display for untitled diagrams " ) ;
2008-02-24 20:13:45 +00:00
} else {
2013-03-03 16:59:52 +00:00
view_title = diagram_title ;
2007-02-01 01:07:26 +00:00
}
2009-04-03 19:30:25 +00:00
return ( view_title ) ;
2007-02-01 01:07:26 +00:00
}
2007-04-09 02:56:47 +00:00
/**
Edite les informations du schema .
*/
2009-04-03 19:30:25 +00:00
void DiagramView : : editDiagramProperties ( ) {
2010-02-28 16:13:45 +00:00
bool diagram_is_read_only = scene - > isReadOnly ( ) ;
2009-04-03 19:30:25 +00:00
2008-08-14 22:51:08 +00:00
// recupere le cartouche et les dimensions du schema
2010-12-20 02:45:36 +00:00
TitleBlockProperties titleblock = scene - > border_and_titleblock . exportTitleBlock ( ) ;
BorderProperties border = scene - > border_and_titleblock . exportBorder ( ) ;
2010-12-28 08:21:45 +00:00
ConductorProperties conductors = scene - > defaultConductorProperties ;
2007-10-12 12:54:25 +00:00
2007-02-01 01:07:26 +00:00
// construit le dialogue
2008-08-17 20:41:37 +00:00
QDialog popup ( diagramEditor ( ) ) ;
2012-01-25 07:29:50 +00:00
popup . setWindowModality ( Qt : : WindowModal ) ;
2009-08-09 16:43:03 +00:00
# ifdef Q_WS_MAC
popup . setWindowFlags ( Qt : : Sheet ) ;
# endif
2010-12-28 08:21:45 +00:00
popup . setMinimumWidth ( 786 ) ;
popup . setMinimumHeight ( 500 ) ;
2009-04-03 19:30:25 +00:00
popup . setWindowTitle ( tr ( " Propri \351 t \351 s du sch \351 ma " , " window title " ) ) ;
2007-10-12 12:54:25 +00:00
2008-08-14 22:51:08 +00:00
BorderPropertiesWidget * border_infos = new BorderPropertiesWidget ( border , & popup ) ;
2010-02-28 16:13:45 +00:00
border_infos - > setReadOnly ( diagram_is_read_only ) ;
2010-12-24 23:35:40 +00:00
2010-12-20 02:45:36 +00:00
TitleBlockPropertiesWidget * titleblock_infos = new TitleBlockPropertiesWidget ( titleblock , false , & popup ) ;
2010-12-24 23:35:40 +00:00
if ( QETProject * parent_project = scene - > project ( ) ) {
2012-01-25 18:02:17 +00:00
titleblock_infos - > setTitleBlockTemplatesCollection ( parent_project - > embeddedTitleBlockTemplatesCollection ( ) ) ;
2010-12-24 23:35:40 +00:00
titleblock_infos - > setTitleBlockTemplatesVisible ( true ) ;
// we have to parse again the TitleBlockProperties object, since the
// first parsing did not know of our templates
titleblock_infos - > setTitleBlockProperties ( titleblock ) ;
2012-01-25 07:29:50 +00:00
// relay the signal that requires a title block template edition
connect ( titleblock_infos , SIGNAL ( editTitleBlockTemplate ( QString , bool ) ) , this , SIGNAL ( editTitleBlockTemplate ( QString , bool ) ) ) ;
2010-12-24 23:35:40 +00:00
}
2010-12-20 02:45:36 +00:00
titleblock_infos - > setReadOnly ( diagram_is_read_only ) ;
2007-02-01 01:07:26 +00:00
2010-12-28 08:21:45 +00:00
ConductorPropertiesWidget * cpw = new ConductorPropertiesWidget ( conductors ) ;
cpw - > setReadOnly ( diagram_is_read_only ) ;
2007-02-01 01:07:26 +00:00
// boutons
2010-02-28 16:13:45 +00:00
QDialogButtonBox boutons ( diagram_is_read_only ? QDialogButtonBox : : Ok : QDialogButtonBox : : Ok | QDialogButtonBox : : Cancel ) ;
2007-02-01 01:07:26 +00:00
connect ( & boutons , SIGNAL ( accepted ( ) ) , & popup , SLOT ( accept ( ) ) ) ;
2007-11-18 00:22:19 +00:00
connect ( & boutons , SIGNAL ( rejected ( ) ) , & popup , SLOT ( reject ( ) ) ) ;
2007-02-01 01:07:26 +00:00
2010-12-28 08:21:45 +00:00
// usual layout for these three widgets
QHBoxLayout * hlayout1 = new QHBoxLayout ( ) ;
QVBoxLayout * vlayout2 = new QVBoxLayout ( ) ;
vlayout2 - > addWidget ( border_infos ) ;
vlayout2 - > addWidget ( titleblock_infos ) ;
vlayout2 - > setSpacing ( 5 ) ;
hlayout1 - > addLayout ( vlayout2 ) ;
hlayout1 - > addWidget ( cpw ) ;
hlayout1 - > setAlignment ( cpw , Qt : : AlignTop ) ;
2007-02-01 01:07:26 +00:00
// ajout dans une disposition verticale
QVBoxLayout layout_v ( & popup ) ;
2010-12-28 08:21:45 +00:00
layout_v . addLayout ( hlayout1 ) ;
2007-12-19 21:44:43 +00:00
layout_v . addStretch ( ) ;
2007-02-01 01:07:26 +00:00
layout_v . addWidget ( & boutons ) ;
2007-09-28 17:39:30 +00:00
// si le dialogue est accepte
2010-02-28 16:13:45 +00:00
if ( popup . exec ( ) = = QDialog : : Accepted & & ! diagram_is_read_only ) {
2010-12-20 02:45:36 +00:00
TitleBlockProperties new_titleblock = titleblock_infos - > titleBlockProperties ( ) ;
2008-08-14 22:51:08 +00:00
BorderProperties new_border = border_infos - > borderProperties ( ) ;
2010-12-28 08:21:45 +00:00
ConductorProperties new_conductors = cpw - > conductorProperties ( ) ;
2011-12-30 02:17:26 +00:00
bool adjust_scene = false ;
2007-10-12 12:54:25 +00:00
// s'il y a des modifications au cartouche
2010-12-20 02:45:36 +00:00
if ( new_titleblock ! = titleblock ) {
scene - > undoStack ( ) . push ( new ChangeTitleBlockCommand ( scene , titleblock , new_titleblock ) ) ;
2011-12-30 02:17:26 +00:00
adjust_scene = true ;
2007-09-28 17:39:30 +00:00
}
2007-10-12 12:54:25 +00:00
2007-12-01 10:29:03 +00:00
// s'il y a des modifications aux dimensions du schema
2008-08-14 22:51:08 +00:00
if ( new_border ! = border ) {
2008-08-15 12:46:22 +00:00
scene - > undoStack ( ) . push ( new ChangeBorderCommand ( scene , border , new_border ) ) ;
2011-12-30 02:17:26 +00:00
adjust_scene = true ;
2007-10-12 12:54:25 +00:00
}
2010-12-28 08:21:45 +00:00
// if modifcations have been made to the conductors properties
if ( new_conductors ! = conductors ) {
/// TODO implement an undo command to allow the user to undo/redo this action
scene - > defaultConductorProperties = new_conductors ;
}
2011-12-30 02:17:26 +00:00
if ( adjust_scene ) adjustSceneRect ( ) ;
2007-02-01 01:07:26 +00:00
}
}
2007-04-09 02:56:47 +00:00
/**
2010-04-24 22:37:45 +00:00
@ return true s ' il y a des items selectionnes sur le schema , false sinon
2007-04-09 02:56:47 +00:00
*/
2007-02-01 01:07:26 +00:00
bool DiagramView : : hasSelectedItems ( ) {
return ( scene - > selectedItems ( ) . size ( ) > 0 ) ;
}
2010-04-24 22:37:45 +00:00
/**
@ return true s ' il y a des items selectionnes sur le schema et que ceux - ci
peuvent etre copies dans le presse - papier , false sinon
*/
bool DiagramView : : hasCopiableItems ( ) {
foreach ( QGraphicsItem * qgi , scene - > selectedItems ( ) ) {
if (
qgraphicsitem_cast < Element * > ( qgi ) | |
qgraphicsitem_cast < IndependentTextItem * > ( qgi )
) {
return ( true ) ;
}
}
return ( false ) ;
}
/**
@ return true s ' il y a des items selectionnes sur le schema et que ceux - ci
peuvent etre supprimes , false sinon
*/
bool DiagramView : : hasDeletableItems ( ) {
foreach ( QGraphicsItem * qgi , scene - > selectedItems ( ) ) {
if (
qgraphicsitem_cast < Element * > ( qgi ) | |
qgraphicsitem_cast < Conductor * > ( qgi ) | |
qgraphicsitem_cast < IndependentTextItem * > ( qgi )
) {
return ( true ) ;
}
}
return ( false ) ;
}
2007-04-09 02:56:47 +00:00
/**
Ajoute une colonne au schema .
*/
2007-02-01 01:07:26 +00:00
void DiagramView : : addColumn ( ) {
2009-04-03 19:30:25 +00:00
if ( scene - > isReadOnly ( ) ) return ;
2010-12-20 02:45:36 +00:00
BorderProperties old_bp = scene - > border_and_titleblock . exportBorder ( ) ;
BorderProperties new_bp = scene - > border_and_titleblock . exportBorder ( ) ;
2008-08-15 12:46:22 +00:00
new_bp . columns_count + = 1 ;
scene - > undoStack ( ) . push ( new ChangeBorderCommand ( scene , old_bp , new_bp ) ) ;
2007-02-01 01:07:26 +00:00
}
2007-04-09 02:56:47 +00:00
/**
Enleve une colonne au schema .
*/
2007-02-01 01:07:26 +00:00
void DiagramView : : removeColumn ( ) {
2009-04-03 19:30:25 +00:00
if ( scene - > isReadOnly ( ) ) return ;
2010-12-20 02:45:36 +00:00
BorderProperties old_bp = scene - > border_and_titleblock . exportBorder ( ) ;
BorderProperties new_bp = scene - > border_and_titleblock . exportBorder ( ) ;
2008-08-15 12:46:22 +00:00
new_bp . columns_count - = 1 ;
scene - > undoStack ( ) . push ( new ChangeBorderCommand ( scene , old_bp , new_bp ) ) ;
2007-02-01 01:07:26 +00:00
}
2007-02-03 02:00:18 +00:00
2007-04-09 02:56:47 +00:00
/**
Agrandit le schema en hauteur
*/
2008-08-10 15:07:59 +00:00
void DiagramView : : addRow ( ) {
2009-04-03 19:30:25 +00:00
if ( scene - > isReadOnly ( ) ) return ;
2010-12-20 02:45:36 +00:00
BorderProperties old_bp = scene - > border_and_titleblock . exportBorder ( ) ;
BorderProperties new_bp = scene - > border_and_titleblock . exportBorder ( ) ;
2008-08-15 12:46:22 +00:00
new_bp . rows_count + = 1 ;
scene - > undoStack ( ) . push ( new ChangeBorderCommand ( scene , old_bp , new_bp ) ) ;
2007-03-03 23:35:14 +00:00
}
2007-04-09 02:56:47 +00:00
/**
Retrecit le schema en hauteur
*/
2008-08-10 15:07:59 +00:00
void DiagramView : : removeRow ( ) {
2009-04-03 19:30:25 +00:00
if ( scene - > isReadOnly ( ) ) return ;
2010-12-20 02:45:36 +00:00
BorderProperties old_bp = scene - > border_and_titleblock . exportBorder ( ) ;
BorderProperties new_bp = scene - > border_and_titleblock . exportBorder ( ) ;
2008-08-15 12:46:22 +00:00
new_bp . rows_count - = 1 ;
scene - > undoStack ( ) . push ( new ChangeBorderCommand ( scene , old_bp , new_bp ) ) ;
2007-02-03 02:00:18 +00:00
}
2007-03-03 23:35:14 +00:00
/**
Ajuste le sceneRect ( zone du schema visualisee par le DiagramView ) afin que
celui inclut a la fois les elements dans et en dehors du cadre et le cadre
lui - meme .
*/
void DiagramView : : adjustSceneRect ( ) {
2007-09-28 21:02:53 +00:00
QRectF old_scene_rect = sceneRect ( ) ;
2007-03-03 23:35:14 +00:00
// rectangle delimitant l'ensemble des elements
QRectF elements_bounding_rect = scene - > itemsBoundingRect ( ) ;
2007-02-03 02:00:18 +00:00
2007-03-03 23:35:14 +00:00
// rectangle contenant le cadre = colonnes + cartouche
2007-10-10 22:35:32 +00:00
QRectF border_bounding_rect = scene - > border ( ) . adjusted ( - Diagram : : margin , - Diagram : : margin , Diagram : : margin , Diagram : : margin ) ;
2007-03-03 23:35:14 +00:00
// ajuste la sceneRect
2007-09-28 21:02:53 +00:00
QRectF new_scene_rect = elements_bounding_rect . united ( border_bounding_rect ) ;
setSceneRect ( new_scene_rect ) ;
// met a jour la scene
scene - > update ( old_scene_rect . united ( new_scene_rect ) ) ;
2007-02-03 02:00:18 +00:00
}
2007-09-04 18:15:41 +00:00
2007-10-10 17:50:26 +00:00
/**
Met a jour le titre du widget
*/
2007-09-29 09:52:35 +00:00
void DiagramView : : updateWindowTitle ( ) {
2009-04-03 19:30:25 +00:00
QString view_title ( title ( ) ) ;
// verifie si le document a ete modifie
bool modified_diagram = ! ( scene - > undoStack ( ) . isClean ( ) ) ;
// specifie le titre du widget
setWindowTitle ( view_title + " [*] " ) ;
setWindowModified ( modified_diagram ) ;
// emet le signal titleChanged en ajoutant manuellement [*] si le schema a ete modifie
QString emitted_title = view_title ;
if ( modified_diagram ) emitted_title + = " [*] " ;
emit ( titleChanged ( this , emitted_title ) ) ;
2007-09-29 09:52:35 +00:00
}
2007-10-10 17:50:26 +00:00
/**
2013-04-10 09:31:51 +00:00
Active ou desactive le dessin de grille selon la quantite de pixels affichee
2007-10-10 17:50:26 +00:00
*/
2007-09-04 18:15:41 +00:00
void DiagramView : : adjustGridToZoom ( ) {
QRectF viewed_scene = viewedSceneRect ( ) ;
scene - > setDisplayGrid ( viewed_scene . width ( ) < 2000 | | viewed_scene . height ( ) < 2000 ) ;
}
2007-10-10 17:50:26 +00:00
/**
@ return le rectangle du schema ( classe Diagram ) visualise par ce DiagramView
*/
2007-09-04 18:15:41 +00:00
QRectF DiagramView : : viewedSceneRect ( ) const {
// recupere la taille du widget viewport
QSize viewport_size = viewport ( ) - > size ( ) ;
// recupere la transformation viewport -> scene
QTransform view_to_scene = viewportTransform ( ) . inverted ( ) ;
// mappe le coin superieur gauche et le coin inferieur droit de la viewport sur la scene
QPointF scene_left_top = view_to_scene . map ( QPointF ( 0.0 , 0.0 ) ) ;
QPointF scene_right_bottom = view_to_scene . map ( QPointF ( viewport_size . width ( ) , viewport_size . height ( ) ) ) ;
// en deduit le rectangle visualise par la scene
return ( QRectF ( scene_left_top , scene_right_bottom ) ) ;
}
2007-10-03 13:11:47 +00:00
2009-04-03 19:30:25 +00:00
/**
Cette methode permet de determiner s ' il faut ou non integrer au projet un
element dont on connait l ' emplacement .
L ' element droppe est integre a la collection du projet :
* s ' il appartient a un autre projet , quelque soit la specification de
l ' utilisateur a ce propos ;
* s ' il appartient a la collection commune ou a la collection
personnelle ET que l ' utilisateur a autorise l ' integration automatique
des elements dans les projets .
@ param location Emplacement de l ' element
@ return true si l ' element doit etre integre , false sinon
*/
bool DiagramView : : mustIntegrateElement ( const ElementsLocation & location ) const {
// l'utilisateur a-t-il autorise l'integration automatique des elements dans les projets ?
bool auto_integration_enabled = QETApp : : settings ( ) . value ( " diagrameditor/integrate-elements " , true ) . toBool ( ) ;
// l'element appartient-il a un projet et si oui, est-ce un autre projet ?
bool elmt_from_project = location . project ( ) ;
bool elmt_from_another_project = elmt_from_project & & location . project ( ) ! = scene - > project ( ) ;
// faut-il integrer l'element ?
bool must_integrate_element = ( elmt_from_another_project | | ( auto_integration_enabled & & ! elmt_from_project ) ) ;
return ( must_integrate_element ) ;
}
2012-01-22 10:40:37 +00:00
/**
@ param tbt_loc A title block template location
@ return true if the title block template needs to be integrated in the
parent project before being applied to the current diagram , or false if it
can be directly applied
*/
bool DiagramView : : mustIntegrateTitleBlockTemplate ( const TitleBlockTemplateLocation & tbt_loc ) const {
2012-04-04 16:13:08 +00:00
// unlike elements, the integration of title block templates is mandatory, so we simply check whether the parent project of the template is also the parent project of the diagram
2012-01-22 10:40:37 +00:00
QETProject * tbt_parent_project = tbt_loc . parentProject ( ) ;
if ( ! tbt_parent_project ) return ( true ) ;
return ( tbt_parent_project ! = scene - > project ( ) ) ;
}
2009-04-03 19:30:25 +00:00
/**
@ param location Emplacement de l ' element a ajouter sur le schema
@ param pos Position ( dans les coordonnees de la vue ) a laquelle l ' element sera ajoute
*/
bool DiagramView : : addElementAtPos ( const ElementsLocation & location , const QPoint & pos ) {
// construit une instance de l'element correspondant a l'emplacement
2009-04-13 01:35:01 +00:00
int state ;
Element * el = new CustomElement ( location , 0 , 0 , & state ) ;
if ( state ) {
2009-04-03 19:30:25 +00:00
delete el ;
return ( false ) ;
}
// pose de l'element sur le schema
diagram ( ) - > undoStack ( ) . push ( new AddElementCommand ( diagram ( ) , el , mapToScene ( pos ) ) ) ;
return ( true ) ;
}
/**
Fait en sorte que le schema ne soit editable que s ' il n ' est pas en lecture
seule
*/
void DiagramView : : applyReadOnly ( ) {
if ( ! scene ) return ;
bool is_writable = ! scene - > isReadOnly ( ) ;
setInteractive ( is_writable ) ;
setAcceptDrops ( is_writable ) ;
}
2009-05-17 02:13:40 +00:00
/**
Edite les proprietes des objets selectionnes
*/
void DiagramView : : editSelectionProperties ( ) {
// recupere la selection
DiagramContent selection = scene - > selectedContent ( ) ;
// s'il n'y a rien de selectionne, cette methode ne fait rien
int selected_items_count = selection . count ( DiagramContent : : All | DiagramContent : : SelectedOnly ) ;
if ( ! selected_items_count ) return ;
// si la selection ne comprend qu'un seul objet, on l'edite via un dialogue approprie
if ( selected_items_count = = 1 ) {
// cas d'un conducteur selectionne
QList < Conductor * > selected_conductors = selection . conductors ( DiagramContent : : AnyConductor | DiagramContent : : SelectedOnly ) ;
if ( selected_conductors . count ( ) = = 1 ) {
editConductor ( selected_conductors . at ( 0 ) ) ;
return ;
}
// cas d'un element selectionne
if ( selection . elements . count ( ) = = 1 ) {
2010-05-08 21:24:43 +00:00
editElement ( selection . elements . toList ( ) . at ( 0 ) ) ;
2009-05-17 02:13:40 +00:00
return ;
}
// cas d'un champ de texte selectionne : pour le moment, on traite comme une selection multiple
}
// sinon on affiche un simple listing des elements selectionnes
2009-08-09 16:02:14 +00:00
QET : : MessageBox : : information (
2009-05-17 02:13:40 +00:00
this ,
tr ( " Propri \351 t \351 s de la s \351 lection " ) ,
QString (
tr (
" La s \351 lection contient %1. " ,
" %1 is a sentence listing the selected objects "
)
) . arg ( selection . sentence ( DiagramContent : : All | DiagramContent : : SelectedOnly ) )
) ;
}
2011-08-22 11:17:10 +00:00
/**
Edit the color of the selected conductor ; does nothing if multiple conductors are selected
*/
void DiagramView : : editSelectedConductorColor ( ) {
// retrieve selected content
DiagramContent selection = scene - > selectedContent ( ) ;
// we'll focus on the selected conductor (we do not handle multiple conductors edition)
QList < Conductor * > selected_conductors = selection . conductors ( DiagramContent : : AnyConductor | DiagramContent : : SelectedOnly ) ;
if ( selected_conductors . count ( ) = = 1 ) {
editConductorColor ( selected_conductors . at ( 0 ) ) ;
}
}
2009-05-17 02:13:40 +00:00
/**
Affiche des informations sur un element
@ param element Element a afficher
*/
void DiagramView : : editElement ( Element * element ) {
if ( ! element ) return ;
CustomElement * custom_element = qobject_cast < CustomElement * > ( element ) ;
GhostElement * ghost_element = qobject_cast < GhostElement * > ( element ) ;
// type de l'element
QString description_string ;
if ( ghost_element ) {
description_string + = tr ( " \311 l \351 ment manquant " ) ;
} else {
description_string + = tr ( " \311 l \351 ment " ) ;
}
description_string + = " \n " ;
2011-09-08 19:03:13 +00:00
// nom, nombre de bornes, dimensions
2009-05-17 02:13:40 +00:00
description_string + = QString ( tr ( " Nom \240 : %1 \n " ) ) . arg ( element - > name ( ) ) ;
2011-09-08 19:03:13 +00:00
int folio_index = scene - > folioIndex ( ) ;
if ( folio_index ! = - 1 ) {
description_string + = QString ( tr ( " Folio \240 : %1 \n " ) ) . arg ( folio_index + 1 ) ;
}
2009-05-20 21:29:17 +00:00
description_string + = QString ( tr ( " Position \240 : %1 \n " ) ) . arg ( scene - > convertPosition ( element - > scenePos ( ) ) . toString ( ) ) ;
2009-05-17 02:13:40 +00:00
description_string + = QString ( tr ( " Dimensions \240 : %1 \327 %2 \n " ) ) . arg ( element - > size ( ) . width ( ) ) . arg ( element - > size ( ) . height ( ) ) ;
description_string + = QString ( tr ( " Bornes \240 : %1 \n " ) ) . arg ( element - > terminals ( ) . count ( ) ) ;
description_string + = QString ( tr ( " Connexions internes \240 : %1 \n " ) ) . arg ( element - > internalConnections ( ) ? tr ( " Autoris \351 es " ) : tr ( " Interdites " ) ) ;
description_string + = QString ( tr ( " Champs de texte \240 : %1 \n " ) ) . arg ( element - > texts ( ) . count ( ) ) ;
if ( custom_element ) {
description_string + = QString ( tr ( " Emplacement \240 : %1 \n " ) ) . arg ( custom_element - > location ( ) . toString ( ) ) ;
}
2009-05-19 19:00:37 +00:00
// titre et boutons du dialogue
QString description_title = tr ( " Propri \351 t \351 s de l' \351 l \351 ment s \351 lectionn \351 " ) ;
QPushButton * find_in_panel = new QPushButton ( tr ( " Retrouver dans le panel " ) ) ;
2009-08-16 12:19:46 +00:00
QPushButton * edit_element = new QPushButton ( tr ( " \311 diter l' \351 l \351 ment " ) ) ;
2009-11-22 16:12:22 +00:00
edit_element - > setIcon ( QET : : Icons : : ElementEdit ) ;
2009-05-19 19:00:37 +00:00
// dialogue en lui-meme
2009-08-09 19:20:21 +00:00
QMessageBox edit_element_dialog ( diagramEditor ( ) ) ;
# ifdef Q_WS_MAC
edit_element_dialog . setWindowFlags ( Qt : : Sheet ) ;
# endif
2009-05-19 19:00:37 +00:00
edit_element_dialog . setIcon ( QMessageBox : : Information ) ;
edit_element_dialog . setWindowTitle ( description_title ) ;
edit_element_dialog . setText ( description_title ) ;
edit_element_dialog . setInformativeText ( description_string ) ;
edit_element_dialog . addButton ( find_in_panel , QMessageBox : : ApplyRole ) ;
2009-07-08 09:41:20 +00:00
edit_element_dialog . addButton ( edit_element , QMessageBox : : ApplyRole ) ;
2009-05-19 19:00:37 +00:00
edit_element_dialog . addButton ( QMessageBox : : Ok ) ;
edit_element_dialog . setDefaultButton ( QMessageBox : : Ok ) ;
2009-07-11 22:13:50 +00:00
edit_element_dialog . setEscapeButton ( QMessageBox : : Ok ) ;
2009-05-19 19:00:37 +00:00
edit_element_dialog . exec ( ) ;
2009-07-08 09:41:20 +00:00
// Permet de trouver l'element dans la collection
2009-05-19 19:00:37 +00:00
if ( edit_element_dialog . clickedButton ( ) = = find_in_panel ) {
emit ( findElementRequired ( custom_element - > location ( ) ) ) ;
}
2009-07-08 09:41:20 +00:00
// Trouve l'element dans la collection et l'edite
if ( edit_element_dialog . clickedButton ( ) = = edit_element ) {
emit ( findElementRequired ( custom_element - > location ( ) ) ) ;
emit ( editElementRequired ( custom_element - > location ( ) ) ) ;
}
2009-05-17 02:13:40 +00:00
}
2007-10-10 17:50:26 +00:00
/**
Affiche un dialogue permettant d ' editer le conducteur selectionne .
Ne fait rien s ' il y a 0 ou plusieurs conducteurs selectionnes .
*/
2007-10-03 17:02:39 +00:00
void DiagramView : : editConductor ( ) {
QList < Conductor * > selected_conductors ( scene - > selectedConductors ( ) . toList ( ) ) ;
2007-10-03 13:11:47 +00:00
// on ne peut editer qu'un conducteur a la fois
2007-10-03 17:02:39 +00:00
if ( selected_conductors . count ( ) ! = 1 ) return ;
Conductor * edited_conductor = selected_conductors . first ( ) ;
2007-10-03 13:11:47 +00:00
2007-12-02 20:41:19 +00:00
editConductor ( edited_conductor ) ;
}
/**
Edite le conducteur passe en parametre
@ param edited_conductor Conducteur a editer
*/
void DiagramView : : editConductor ( Conductor * edited_conductor ) {
2009-04-03 19:30:25 +00:00
if ( scene - > isReadOnly ( ) ) return ;
2007-12-02 20:41:19 +00:00
if ( ! edited_conductor ) return ;
2007-10-03 13:11:47 +00:00
// initialise l'editeur de proprietes pour le conducteur
2007-10-14 14:44:33 +00:00
ConductorProperties old_properties = edited_conductor - > properties ( ) ;
ConductorPropertiesWidget * cpw = new ConductorPropertiesWidget ( old_properties ) ;
2007-10-03 15:51:04 +00:00
2007-10-03 13:11:47 +00:00
// l'insere dans un dialogue
2008-08-17 20:41:37 +00:00
QDialog conductor_dialog ( diagramEditor ( ) ) ;
2009-08-09 19:20:21 +00:00
# ifdef Q_WS_MAC
conductor_dialog . setWindowFlags ( Qt : : Sheet ) ;
# endif
2009-04-03 19:30:25 +00:00
conductor_dialog . setWindowTitle ( tr ( " \311 diter les propri \351 t \351 s d'un conducteur " , " window title " ) ) ;
2007-10-03 17:02:39 +00:00
QVBoxLayout * dialog_layout = new QVBoxLayout ( & conductor_dialog ) ;
2007-10-03 13:11:47 +00:00
dialog_layout - > addWidget ( cpw ) ;
2007-12-19 21:44:43 +00:00
dialog_layout - > addStretch ( ) ;
2007-10-03 13:11:47 +00:00
QDialogButtonBox * dbb = new QDialogButtonBox ( QDialogButtonBox : : Ok | QDialogButtonBox : : Cancel ) ;
dialog_layout - > addWidget ( dbb ) ;
2007-10-03 17:02:39 +00:00
connect ( dbb , SIGNAL ( accepted ( ) ) , & conductor_dialog , SLOT ( accept ( ) ) ) ;
connect ( dbb , SIGNAL ( rejected ( ) ) , & conductor_dialog , SLOT ( reject ( ) ) ) ;
2011-03-01 23:26:31 +00:00
cpw - > setFocus ( Qt : : ActiveWindowFocusReason ) ;
2007-10-03 13:11:47 +00:00
// execute le dialogue et met a jour le conducteur
2007-10-03 17:02:39 +00:00
if ( conductor_dialog . exec ( ) = = QDialog : : Accepted ) {
2007-10-14 15:16:37 +00:00
// recupere les nouvelles proprietes
2007-10-14 14:44:33 +00:00
ConductorProperties new_properties = cpw - > conductorProperties ( ) ;
if ( new_properties ! = old_properties ) {
2013-04-10 09:31:51 +00:00
int qmbreturn = 0 ;
//if conductor isn't alone at this potential
//ask user to apply text on every conductors of this potential
if ( edited_conductor - > relatedPotentialConductors ( ) . size ( ) > = 1 ) {
qmbreturn = QMessageBox : : question ( diagramEditor ( ) , tr ( " Textes de conducteurs " ) ,
tr ( " Voulez-vous appliquer le nouveau texte \n "
" \340 l'ensemble des conducteurs de ce potentiel ? " ) ,
QMessageBox : : No | QMessageBox : : Yes , QMessageBox : : Yes ) ;
if ( qmbreturn = = QMessageBox : : Yes ) {
ConductorAutoNumerotation can ( edited_conductor ) ;
can . setText ( new_properties . text ) ;
}
}
if ( qmbreturn = = 0 | | qmbreturn = = QMessageBox : : No ) {
// initialise l'objet UndoCommand correspondant
ChangeConductorPropertiesCommand * ccpc = new ChangeConductorPropertiesCommand ( edited_conductor ) ;
ccpc - > setOldSettings ( old_properties ) ;
ccpc - > setNewSettings ( new_properties ) ;
diagram ( ) - > undoStack ( ) . push ( ccpc ) ;
}
2007-10-14 14:44:33 +00:00
}
2011-08-22 11:17:10 +00:00
}
}
/**
Edit the color of the given conductor
@ param edited_conductor Conductor we want to change the color
*/
void DiagramView : : editConductorColor ( Conductor * edited_conductor ) {
if ( scene - > isReadOnly ( ) ) return ;
if ( ! edited_conductor ) return ;
// store the initial properties of the provided conductor
ConductorProperties initial_properties = edited_conductor - > properties ( ) ;
// prepare a color dialog showing the initial conductor color
QColorDialog * color_dialog = new QColorDialog ( this ) ;
color_dialog - > setWindowTitle ( tr ( " Choisir la nouvelle couleur de ce conducteur " ) ) ;
# ifdef Q_WS_MAC
2012-04-10 17:22:49 +00:00
color_dialog - > setWindowFlags ( Qt : : Sheet ) ;
2011-08-22 11:17:10 +00:00
# endif
color_dialog - > setCurrentColor ( initial_properties . color ) ;
// asks the user what color he wishes to apply
if ( color_dialog - > exec ( ) = = QDialog : : Accepted ) {
QColor new_color = color_dialog - > selectedColor ( ) ;
if ( new_color ! = initial_properties . color ) {
// the user chose a different color
ConductorProperties new_properties = initial_properties ;
new_properties . color = new_color ;
ChangeConductorPropertiesCommand * ccpc = new ChangeConductorPropertiesCommand ( edited_conductor ) ;
ccpc - > setOldSettings ( initial_properties ) ;
ccpc - > setNewSettings ( new_properties ) ;
diagram ( ) - > undoStack ( ) . push ( ccpc ) ;
}
2007-10-03 13:11:47 +00:00
}
}
2007-10-06 18:37:21 +00:00
/**
Reinitialise le profil des conducteurs selectionnes
*/
void DiagramView : : resetConductors ( ) {
2009-04-03 19:30:25 +00:00
if ( scene - > isReadOnly ( ) ) return ;
2007-10-06 18:37:21 +00:00
// recupere les conducteurs selectionnes
QSet < Conductor * > selected_conductors = scene - > selectedConductors ( ) ;
// repere les conducteurs modifies (= profil non nul)
2007-10-22 20:27:39 +00:00
QHash < Conductor * , ConductorProfilesGroup > conductors_and_profiles ;
2007-10-06 18:37:21 +00:00
foreach ( Conductor * conductor , selected_conductors ) {
2007-10-22 20:27:39 +00:00
ConductorProfilesGroup profile = conductor - > profiles ( ) ;
if (
! profile [ Qt : : TopLeftCorner ] . isNull ( ) | | \
! profile [ Qt : : TopRightCorner ] . isNull ( ) | | \
! profile [ Qt : : BottomLeftCorner ] . isNull ( ) | | \
! profile [ Qt : : BottomRightCorner ] . isNull ( )
) {
conductors_and_profiles . insert ( conductor , profile ) ;
}
2007-10-06 18:37:21 +00:00
}
if ( conductors_and_profiles . isEmpty ( ) ) return ;
scene - > undoStack ( ) . push ( new ResetConductorCommand ( conductors_and_profiles ) ) ;
}
2007-10-12 10:58:57 +00:00
/**
Gere les evenements de la DiagramView
@ param e Evenement
*/
bool DiagramView : : event ( QEvent * e ) {
// fait en sorte que les raccourcis clavier arrivent prioritairement sur la
// vue plutot que de remonter vers les QMenu / QAction
2010-03-28 16:27:48 +00:00
if (
e - > type ( ) = = QEvent : : ShortcutOverride & &
2012-03-24 14:34:25 +00:00
selectedItemHasFocus ( )
2010-03-28 16:27:48 +00:00
) {
2007-10-12 10:58:57 +00:00
e - > accept ( ) ;
return ( true ) ;
}
return ( QGraphicsView : : event ( e ) ) ;
2007-10-12 12:54:25 +00:00
}
2007-10-27 13:18:17 +00:00
2012-03-24 14:34:25 +00:00
/**
Switch to visualisation mode if the user is pressing Ctrl and Shift .
@ return true if the view was switched to visualisation mode , false
otherwise .
*/
bool DiagramView : : switchToVisualisationModeIfNeeded ( QInputEvent * e ) {
if ( isCtrlShifting ( e ) & & ! selectedItemHasFocus ( ) ) {
if ( dragMode ( ) ! = QGraphicsView : : ScrollHandDrag ) {
is_moving_view_ = true ;
setVisualisationMode ( ) ;
return ( true ) ;
}
}
return ( false ) ;
}
/**
Switch back to selection mode if the user is not pressing Ctrl and Shift .
@ return true if the view was switched to selection mode , false
otherwise .
*/
bool DiagramView : : switchToSelectionModeIfNeeded ( QInputEvent * e ) {
if ( is_moving_view_ & & ! selectedItemHasFocus ( ) & & ! isCtrlShifting ( e ) ) {
setSelectionMode ( ) ;
is_moving_view_ = false ;
return ( true ) ;
}
return ( false ) ;
}
/**
@ return true if the user is pressing Ctrl and Shift simultaneously .
*/
bool DiagramView : : isCtrlShifting ( QInputEvent * e ) {
bool result = false ;
// note: QInputEvent::modifiers and QKeyEvent::modifiers() do not return the
// same values, hence the casts
if ( e - > type ( ) = = QEvent : : KeyPress | | e - > type ( ) = = QEvent : : KeyRelease ) {
if ( QKeyEvent * ke = static_cast < QKeyEvent * > ( e ) ) {
result = ( ke - > modifiers ( ) = = ( Qt : : ControlModifier | Qt : : ShiftModifier ) ) ;
}
} else if ( e - > type ( ) > = QEvent : : MouseButtonPress & & e - > type ( ) < = QEvent : : MouseMove ) {
if ( QMouseEvent * me = static_cast < QMouseEvent * > ( e ) ) {
result = ( me - > modifiers ( ) = = ( Qt : : ControlModifier | Qt : : ShiftModifier ) ) ;
}
}
return ( result ) ;
}
/**
@ return true if there is a selected item and that item has the focus .
*/
bool DiagramView : : selectedItemHasFocus ( ) {
return (
scene - > hasFocus ( ) & &
scene - > focusItem ( ) & &
scene - > focusItem ( ) - > isSelected ( )
) ;
}
2007-12-16 13:21:28 +00:00
/**
Passe le DiagramView en mode " ajout de texte " . Un clic cree alors un
nouveau champ de texte .
*/
2007-10-27 13:18:17 +00:00
void DiagramView : : addText ( ) {
2009-04-03 19:30:25 +00:00
if ( scene - > isReadOnly ( ) ) return ;
2007-10-27 13:18:17 +00:00
is_adding_text = true ;
}
2007-11-02 18:04:13 +00:00
2013-04-01 13:49:34 +00:00
/**
To edit the text through the htmlEditor
*/
void DiagramView : : editText ( ) {
if ( scene - > isReadOnly ( ) ) return ;
// Get text to edit
QList < DiagramTextItem * > texts_to_edit ;
foreach ( QGraphicsItem * item , scene - > selectedItems ( ) ) {
2013-04-01 23:40:03 +00:00
if ( IndependentTextItem * iti = qgraphicsitem_cast < IndependentTextItem * > ( item ) ) {
2013-04-01 13:49:34 +00:00
texts_to_edit < < iti ;
} else if ( ElementTextItem * eti = qgraphicsitem_cast < ElementTextItem * > ( item ) ) {
// here...
texts_to_edit < < eti ;
}
}
// Test if any text existe..
if ( texts_to_edit . isEmpty ( ) ) return ;
else texts_to_edit . at ( 0 ) - > edit ( ) ;
}
2008-07-09 21:14:30 +00:00
/**
Cree un nouveau champ de texte et le place a la position pos
en gerant l ' annulation ; enfin , le signal textAdded est emis .
@ param pos Position du champ de texte ajoute
@ return le champ de texte ajoute
*/
2010-04-18 17:59:54 +00:00
IndependentTextItem * DiagramView : : addDiagramTextAtPos ( const QPointF & pos ) {
2012-03-24 14:34:25 +00:00
if ( ! isInteractive ( ) | | scene - > isReadOnly ( ) ) return ( 0 ) ;
2008-07-09 21:14:30 +00:00
// cree un nouveau champ de texte
2010-04-18 17:59:54 +00:00
IndependentTextItem * iti = new IndependentTextItem ( " _ " ) ;
2008-07-09 21:14:30 +00:00
// le place a la position pos en gerant l'annulation
2010-04-18 17:59:54 +00:00
scene - > undoStack ( ) . push ( new AddTextCommand ( scene , iti , pos ) ) ;
2008-07-09 21:14:30 +00:00
adjustSceneRect ( ) ;
2010-04-18 17:59:54 +00:00
2008-07-09 21:14:30 +00:00
// emet le signal textAdded
emit ( textAdded ( false ) ) ;
2010-04-18 17:59:54 +00:00
return ( iti ) ;
2008-07-09 21:14:30 +00:00
}
2007-11-02 18:04:13 +00:00
/**
Gere le menu contextuel
@ param e Evenement decrivant la demande de menu contextuel
*/
void DiagramView : : contextMenuEvent ( QContextMenuEvent * e ) {
if ( QGraphicsItem * qgi = scene - > itemAt ( mapToScene ( e - > pos ( ) ) ) ) {
if ( ! qgi - > isSelected ( ) ) scene - > clearSelection ( ) ;
qgi - > setSelected ( true ) ;
}
if ( QETDiagramEditor * qde = diagramEditor ( ) ) {
context_menu - > clear ( ) ;
if ( scene - > selectedItems ( ) . isEmpty ( ) ) {
paste_here_pos = e - > pos ( ) ;
2007-11-03 20:20:34 +00:00
paste_here - > setEnabled ( Diagram : : clipboardMayContainDiagram ( ) ) ;
2007-11-02 18:04:13 +00:00
context_menu - > addAction ( paste_here ) ;
context_menu - > addSeparator ( ) ;
context_menu - > addAction ( qde - > infos_diagram ) ;
context_menu - > addAction ( qde - > add_column ) ;
context_menu - > addAction ( qde - > remove_column ) ;
2008-08-10 15:07:59 +00:00
context_menu - > addAction ( qde - > add_row ) ;
context_menu - > addAction ( qde - > remove_row ) ;
2007-11-02 18:04:13 +00:00
} else {
context_menu - > addAction ( qde - > cut ) ;
context_menu - > addAction ( qde - > copy ) ;
context_menu - > addSeparator ( ) ;
2009-05-17 02:13:40 +00:00
context_menu - > addAction ( qde - > conductor_reset ) ;
context_menu - > addSeparator ( ) ;
2007-11-02 18:04:13 +00:00
context_menu - > addAction ( qde - > delete_selection ) ;
context_menu - > addAction ( qde - > rotate_selection ) ;
2012-04-09 17:48:54 +00:00
context_menu - > addAction ( qde - > rotate_texts ) ;
2013-03-31 18:13:30 +00:00
context_menu - > addAction ( qde - > add_edittext ) ;
2013-02-12 18:37:08 +00:00
context_menu - > addAction ( qde - > find_element ) ;
context_menu - > addAction ( qde - > edit_element ) ;
2009-05-17 02:13:40 +00:00
context_menu - > addAction ( qde - > selection_prop ) ;
2007-11-02 18:04:13 +00:00
}
// affiche le menu contextuel
context_menu - > popup ( e - > globalPos ( ) ) ;
}
e - > accept ( ) ;
}
2009-04-13 01:35:01 +00:00
/**
@ return l ' editeur de schemas parent ou 0
*/
2007-11-02 18:04:13 +00:00
QETDiagramEditor * DiagramView : : diagramEditor ( ) const {
// remonte la hierarchie des widgets
QWidget * w = const_cast < DiagramView * > ( this ) ;
while ( w - > parentWidget ( ) & & ! w - > isWindow ( ) ) {
w = w - > parentWidget ( ) ;
}
// la fenetre est supposee etre un QETDiagramEditor
return ( qobject_cast < QETDiagramEditor * > ( w ) ) ;
}
2007-12-01 12:42:31 +00:00
/**
Gere les double - clics sur le schema
*/
void DiagramView : : mouseDoubleClickEvent ( QMouseEvent * e ) {
2010-12-20 02:45:36 +00:00
BorderTitleBlock & bi = scene - > border_and_titleblock ;
2007-12-01 12:42:31 +00:00
// recupere le rectangle corespondant au cartouche
2010-12-20 02:45:36 +00:00
QRectF titleblock_rect (
2007-12-01 12:42:31 +00:00
Diagram : : margin ,
2008-08-10 15:07:59 +00:00
Diagram : : margin + bi . diagramHeight ( ) ,
2010-12-20 02:45:36 +00:00
bi . titleBlockWidth ( ) ,
bi . titleBlockHeight ( )
2007-12-01 12:42:31 +00:00
) ;
// recupere le rectangle correspondant aux en-tetes des colonnes
QRectF columns_rect (
Diagram : : margin ,
Diagram : : margin ,
bi . borderWidth ( ) ,
bi . columnsHeaderHeight ( )
) ;
2008-08-10 15:07:59 +00:00
// recupere le rectangle correspondant aux en-tetes des lignes
QRectF rows_rect (
Diagram : : margin ,
Diagram : : margin ,
bi . rowsHeaderWidth ( ) ,
bi . diagramHeight ( )
) ;
2007-12-01 12:42:31 +00:00
// coordonnees du clic par rapport au schema
QPointF click_pos = viewportTransform ( ) . inverted ( ) . map ( e - > pos ( ) ) ;
// detecte le double-clic sur le cartouche ou les colonnes
2007-12-21 23:53:36 +00:00
if ( QGraphicsItem * qgi = itemAt ( e - > pos ( ) ) ) {
2007-12-02 20:41:19 +00:00
if ( Conductor * c = qgraphicsitem_cast < Conductor * > ( qgi ) ) {
editConductor ( c ) ;
2009-05-17 02:13:40 +00:00
} else if ( Element * element = qgraphicsitem_cast < Element * > ( qgi ) ) {
editElement ( element ) ;
2007-12-21 23:53:36 +00:00
} else {
QGraphicsView : : mouseDoubleClickEvent ( e ) ;
2007-12-02 20:41:19 +00:00
}
2010-12-20 02:45:36 +00:00
} else if ( titleblock_rect . contains ( click_pos ) | | columns_rect . contains ( click_pos ) | | rows_rect . contains ( click_pos ) ) {
2007-12-21 23:53:36 +00:00
// edite les proprietes du schema
2009-04-03 19:30:25 +00:00
editDiagramProperties ( ) ;
2007-12-01 12:42:31 +00:00
} else {
QGraphicsView : : mouseDoubleClickEvent ( e ) ;
}
}
2009-04-03 19:30:25 +00:00
/**
2012-01-22 10:40:37 +00:00
Cette methode ajoute l ' element designe par l ' emplacement location a la
2009-04-03 19:30:25 +00:00
position pos . Si necessaire , elle demande l ' integration de l ' element au
projet .
@ see mustIntegrateElement
*/
void DiagramView : : addDroppedElement ( ) {
ElementsLocation location = next_location_ ;
QPoint pos = next_position_ ;
if ( ! mustIntegrateElement ( location ) ) {
addElementAtPos ( location , pos ) ;
} else {
QString error_msg ;
IntegrationMoveElementsHandler * integ_handler = new IntegrationMoveElementsHandler ( this ) ;
QString integ_path = scene - > project ( ) - > integrateElement ( location . toString ( ) , integ_handler , error_msg ) ;
delete integ_handler ;
if ( integ_path . isEmpty ( ) ) {
2009-04-13 01:35:01 +00:00
qDebug ( ) < < " DiagramView::addDroppedElement : Impossible d'ajouter l'element. Motif : " < < qPrintable ( error_msg ) ;
2009-04-03 19:30:25 +00:00
return ;
}
addElementAtPos ( ElementsLocation : : locationFromString ( integ_path ) , pos ) ;
}
adjustSceneRect ( ) ;
}
2012-01-22 10:40:37 +00:00
/**
@ param tbt TitleBlockTemplateLocation
*/
void DiagramView : : setDroppedTitleBlockTemplate ( const TitleBlockTemplateLocation & tbt ) {
// fetch the current title block properties
TitleBlockProperties titleblock_properties_before = scene - > border_and_titleblock . exportTitleBlock ( ) ;
// check the provided template is not already applied
QETProject * tbt_parent_project = tbt . parentProject ( ) ;
if ( tbt_parent_project & & tbt_parent_project = = scene - > project ( ) ) {
// same parent project and same name = same title block template
if ( tbt . name ( ) = = titleblock_properties_before . template_name ) return ;
}
// integrate the provided template into the project if needed
QString integrated_template_name = tbt . name ( ) ;
if ( mustIntegrateTitleBlockTemplate ( tbt ) ) {
IntegrationMoveTitleBlockTemplatesHandler * handler = new IntegrationMoveTitleBlockTemplatesHandler ( this ) ;
//QString error_message;
integrated_template_name = scene - > project ( ) - > integrateTitleBlockTemplate ( tbt , handler ) ;
if ( integrated_template_name . isEmpty ( ) ) return ;
}
// apply the provided title block template
if ( titleblock_properties_before . template_name = = integrated_template_name ) return ;
TitleBlockProperties titleblock_properties_after = titleblock_properties_before ;
titleblock_properties_after . template_name = integrated_template_name ;
scene - > undoStack ( ) . push ( new ChangeTitleBlockCommand ( scene , titleblock_properties_before , titleblock_properties_after ) ) ;
adjustSceneRect ( ) ;
}