2007-12-01 10:47:15 +00:00
/*
2025-01-04 13:37:40 +01:00
Copyright 2006 - 2025 The QElectroTech Team
2007-12-01 10:47:15 +00:00
This file is part of QElectroTech .
2016-05-13 15:00:22 +00:00
2007-12-01 10:47:15 +00:00
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 .
2016-05-13 15:00:22 +00:00
2007-12-01 10:47:15 +00:00
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 .
2016-05-13 15:00:22 +00:00
2007-12-01 10:47:15 +00:00
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"
2020-10-02 18:38:24 +02:00
2020-12-08 19:57:35 +01:00
# include "QPropertyUndoCommand/qpropertyundocommand.h"
# include "diagramcommands.h"
# include "diagramevent/diagrameventaddelement.h"
# include "dvevent/dveventinterface.h"
2016-05-13 15:00:22 +00:00
# include "projectview.h"
2009-04-03 19:30:25 +00:00
# include "qetdiagrameditor.h"
2020-12-08 19:57:35 +01:00
# include "qetgraphicsitem/conductor.h"
# include "qetgraphicsitem/conductortextitem.h"
# include "qetgraphicsitem/independenttextitem.h"
2009-05-01 14:41:33 +00:00
# include "qeticons.h"
2020-12-08 19:57:35 +01:00
# include "titleblock/integrationmovetemplateshandler.h"
# include "ui/diagrampropertiesdialog.h"
# include "ui/multipastedialog.h"
# include "undocommand/changetitleblockcommand.h"
# include "utils/conductorcreator.h"
2021-02-07 16:20:55 +01:00
# include "undocommand/addgraphicsobjectcommand.h"
2021-02-07 20:44:17 +01:00
# include "diagram.h"
2013-04-10 11:10:02 +00:00
2020-10-03 15:42:58 +02:00
# include <QDropEvent>
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
*/
2014-12-21 12:15:45 +00:00
DiagramView : : DiagramView ( Diagram * diagram , QWidget * parent ) :
2017-08-03 17:36:08 +00:00
QGraphicsView ( parent ) ,
m_diagram ( diagram )
2014-12-21 12:15:45 +00:00
{
2014-08-18 18:26:38 +00:00
grabGesture ( Qt : : PinchGesture ) ;
2008-07-17 22:57:50 +00:00
setAttribute ( Qt : : WA_DeleteOnClose , true ) ;
2006-10-27 15:47:22 +00:00
setInteractive ( true ) ;
2013-08-24 15:18:45 +00:00
2012-04-28 16:45:13 +00:00
QString whatsthis = tr (
2015-03-02 20:14:56 +00:00
" Ceci est la zone dans laquelle vous concevez vos schémas en y ajoutant "
" des éléments et en posant des conducteurs entre leurs bornes. Il est "
" également possible d'ajouter des textes indépendants. " ,
2012-04-28 16:45:13 +00:00
" \" What's this? \" tip "
) ;
setWhatsThis ( whatsthis ) ;
2016-05-13 15:00:22 +00:00
2007-02-17 18:59:18 +00:00
// active l'antialiasing
setRenderHint ( QPainter : : Antialiasing , true ) ;
setRenderHint ( QPainter : : TextAntialiasing , true ) ;
setRenderHint ( QPainter : : SmoothPixmapTransform , true ) ;
2016-05-13 15:00:22 +00:00
2017-08-03 17:36:08 +00:00
setScene ( m_diagram ) ;
m_diagram - > 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 ( ) ;
2017-08-03 17:36:08 +00:00
m_diagram - > loadElmtFolioSeq ( ) ;
m_diagram - > loadCndFolioSeq ( ) ;
2020-09-25 22:06:11 +02:00
2017-08-03 17:36:08 +00:00
m_paste_here = new QAction ( QET : : Icons : : EditPaste , tr ( " Coller ici " , " context menu action " ) , this ) ;
connect ( m_paste_here , SIGNAL ( triggered ( ) ) , this , SLOT ( pasteHere ( ) ) ) ;
2020-09-25 22:06:11 +02:00
2018-04-08 16:50:52 +00:00
m_multi_paste = new QAction ( QET : : Icons : : EditPaste , tr ( " Collage multiple " ) , this ) ;
connect ( m_multi_paste , & QAction : : triggered , [ this ] ( ) {
MultiPasteDialog d ( this - > m_diagram , this ) ;
d . exec ( ) ;
} ) ;
2020-09-25 22:06:11 +02:00
2018-07-02 13:48:47 +00:00
//setup three separators, to be use in context menu
for ( int i = 0 ; i < 3 ; + + i )
{
m_separators < < new QAction ( this ) ;
m_separators . last ( ) - > setSeparator ( true ) ;
}
2016-05-13 15:00:22 +00:00
2017-08-03 17:36:08 +00:00
connect ( m_diagram , SIGNAL ( showDiagram ( Diagram * ) ) , this , SIGNAL ( showDiagram ( Diagram * ) ) ) ;
connect ( m_diagram , SIGNAL ( sceneRectChanged ( QRectF ) ) , this , SLOT ( adjustSceneRect ( ) ) ) ;
connect ( & ( m_diagram - > border_and_titleblock ) , SIGNAL ( diagramTitleChanged ( const QString & ) ) , this , SLOT ( updateWindowTitle ( ) ) ) ;
2013-11-29 14:42:03 +00:00
connect ( diagram , SIGNAL ( findElementRequired ( ElementsLocation ) ) , this , SIGNAL ( findElementRequired ( ElementsLocation ) ) ) ;
2016-05-13 15:00:22 +00:00
2011-08-22 11:17:10 +00:00
QShortcut * edit_conductor_color_shortcut = new QShortcut ( QKeySequence ( Qt : : Key_F2 ) , this ) ;
2020-10-02 18:57:11 +02:00
connect ( edit_conductor_color_shortcut , & QShortcut : : activated , [ this ] ( )
{
if ( m_diagram - > isReadOnly ( ) ) {
return ;
}
DiagramContent dc ( m_diagram ) ;
auto cond_list = dc . conductors ( DiagramContent : : AnyConductor ) ;
if ( cond_list . size ( ) ! = 1 ) {
return ;
}
auto edited_conductor = cond_list . first ( ) ;
// 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_OS_MACOS
color_dialog - > setWindowFlags ( Qt : : Sheet ) ;
# 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
QVariant old_value , new_value ;
old_value . setValue ( initial_properties ) ;
initial_properties . color = new_color ;
new_value . setValue ( initial_properties ) ;
QPropertyUndoCommand * undo = new QPropertyUndoCommand ( edited_conductor , " properties " , old_value , new_value ) ;
undo - > setText ( tr ( " Modifier les propriétés d'un conducteur " , " undo caption " ) ) ;
m_diagram - > undoStack ( ) . push ( undo ) ;
}
}
} ) ;
2006-10-27 15:47:22 +00:00
}
2007-04-12 03:13:13 +00:00
/**
Destructeur
*/
2020-09-07 22:03:40 +02:00
DiagramView : : ~ DiagramView ( )
2020-10-02 18:38:24 +02: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 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 ( ) ;
2013-10-26 11:46:59 +00:00
} else if ( e - > mimeData ( ) - > hasText ( ) ) {
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
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 ( ) ;
}
/**
2016-05-13 15:00:22 +00:00
Handle the drops accepted on diagram ( elements and title block templates ) .
2012-01-22 10:40:37 +00:00
@ 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 ) ;
2013-10-26 11:46:59 +00:00
} else if ( e - > mimeData ( ) - > hasText ( ) ) {
handleTextDrop ( e ) ;
2012-01-22 10:40:37 +00:00
}
}
/**
2020-08-20 21:57:35 +02:00
@ brief DiagramView : : handleElementDrop
2012-01-22 10:40:37 +00:00
Handle the drop of an element .
2020-08-20 21:57:35 +02:00
@ param event the QDropEvent describing the current drag ' n drop
2012-01-22 10:40:37 +00:00
*/
2016-05-05 13:31:04 +00:00
void DiagramView : : handleElementDrop ( QDropEvent * event )
2016-03-20 15:54:28 +00:00
{
2016-05-05 13:31:04 +00:00
//Build an element from the text of the mime data
ElementsLocation location ( event - > mimeData ( ) - > text ( ) ) ;
if ( ! ( location . isElement ( ) & & location . exist ( ) ) )
{
qDebug ( ) < < " DiagramView::handleElementDrop, location can't be use : " < < location ;
return ;
}
2015-03-04 21:13:13 +00:00
2020-10-03 15:42:58 +02:00
# if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // ### Qt 6: remove
diagram ( ) - > setEventInterface (
new DiagramEventAddElement (
location , diagram ( ) , mapToScene ( event - > pos ( ) ) ) ) ;
# else
# if TODO_LIST
# pragma message("@TODO remove code for QT 6 or later")
# endif
diagram ( ) - > setEventInterface (
new DiagramEventAddElement (
location , diagram ( ) , event - > position ( ) ) ) ;
# endif
2015-03-04 21:13:13 +00:00
//Set focus to the view to get event
this - > setFocus ( ) ;
2006-10-27 15:47:22 +00:00
}
2012-01-22 10:40:37 +00:00
/**
2020-08-16 11:19:36 +02:00
@ brief DiagramView : : handleTitleBlockDrop
Handle the dropEvent that contain data of a titleblock
@ param e
*/
2012-01-22 10:40:37 +00:00
void DiagramView : : handleTitleBlockDrop ( QDropEvent * e ) {
2016-10-20 17:48:10 +00:00
// fetch the title block template location from the drop event
2012-01-22 10:40:37 +00:00
TitleBlockTemplateLocation tbt_loc ;
2016-10-20 17:48:10 +00:00
tbt_loc . fromString ( e - > mimeData ( ) - > text ( ) ) ;
if ( tbt_loc . isValid ( ) )
{
// fetch the current title block properties
2017-08-03 17:36:08 +00:00
TitleBlockProperties titleblock_properties_before = m_diagram - > border_and_titleblock . exportTitleBlock ( ) ;
2016-10-20 17:48:10 +00:00
// check the provided template is not already applied
QETProject * tbt_parent_project = tbt_loc . parentProject ( ) ;
2017-08-03 17:36:08 +00:00
if ( tbt_parent_project & & tbt_parent_project = = m_diagram - > project ( ) )
2016-10-20 17:48:10 +00:00
{
// same parent project and same name = same title block template
if ( tbt_loc . name ( ) = = titleblock_properties_before . template_name )
return ;
}
// integrate the provided template into the project if needed
QString integrated_template_name = tbt_loc . name ( ) ;
if ( mustIntegrateTitleBlockTemplate ( tbt_loc ) )
{
2018-07-30 15:24:29 +00:00
IntegrationMoveTitleBlockTemplatesHandler * handler = new IntegrationMoveTitleBlockTemplatesHandler ( this ) ;
2016-10-20 17:48:10 +00:00
//QString error_message;
2017-08-03 17:36:08 +00:00
integrated_template_name = m_diagram - > project ( ) - > integrateTitleBlockTemplate ( tbt_loc , handler ) ;
2016-10-20 17:48:10 +00:00
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 ;
2017-08-03 17:36:08 +00:00
m_diagram - > undoStack ( ) . push ( new ChangeTitleBlockCommand ( m_diagram , titleblock_properties_before , titleblock_properties_after ) ) ;
2016-10-20 17:48:10 +00:00
adjustSceneRect ( ) ;
2012-01-22 10:40:37 +00:00
}
}
2013-10-26 11:46:59 +00:00
/**
2020-08-16 11:19:36 +02:00
@ brief DiagramView : : handleTextDrop
2014-09-24 09:38:16 +00:00
* handle the drop of text
2020-08-16 11:19:36 +02:00
@ param e the QDropEvent describing the current drag ' n drop
*/
2013-10-26 11:46:59 +00:00
void DiagramView : : handleTextDrop ( QDropEvent * e ) {
2017-08-03 17:36:08 +00:00
if ( m_diagram - > isReadOnly ( ) | | ( e - > mimeData ( ) - > hasText ( ) = = false ) ) return ;
2014-10-30 13:29:58 +00:00
2014-12-14 13:06:21 +00:00
IndependentTextItem * iti = new IndependentTextItem ( e - > mimeData ( ) - > text ( ) ) ;
2014-10-30 13:29:58 +00:00
if ( e - > mimeData ( ) - > hasHtml ( ) ) {
iti - > setHtml ( e - > mimeData ( ) - > text ( ) ) ;
}
2020-10-03 15:42:58 +02:00
# if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // ### Qt 6: remove
2021-02-07 16:20:55 +01:00
m_diagram - > undoStack ( ) . push ( new AddGraphicsObjectCommand (
iti , m_diagram , mapToScene ( e - > pos ( ) ) ) ) ;
2020-10-03 15:42:58 +02:00
# else
# if TODO_LIST
# pragma message("@TODO remove code for QT 6 or later")
# endif
2021-02-07 16:20:55 +01:00
m_diagram - > undoStack ( ) . push ( new AddGraphicsObjectCommand (
iti , m_diagram , e - > position ( ) ) ) ;
2020-10-03 15:42:58 +02:00
# endif
2013-10-26 11:46:59 +00:00
}
2006-10-27 15:47:22 +00:00
/**
2013-04-16 12:00:41 +00:00
Set the Diagram in visualisation mode
2006-10-27 15:47:22 +00:00
*/
2020-09-07 22:03:40 +02: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 ( ) ) ;
}
/**
2013-04-16 12:00:41 +00:00
Set the Diagram in Selection mode
2006-10-27 15:47:22 +00:00
*/
2020-09-07 22:03:40 +02: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 ( ) ) ;
}
/**
2020-08-16 11:19:36 +02:00
@ brief DiagramView : : zoom
Zomm the view .
A zoom_factor > 1 zoom in .
A zoom_factor < 1 zoom out
@ param zoom_factor
*/
2015-11-18 09:51:53 +00:00
void DiagramView : : zoom ( const qreal zoom_factor )
2015-09-16 15:11:13 +00:00
{
2016-06-09 20:46:27 +00:00
if ( zoom_factor > = 1 ) {
2015-11-18 09:51:53 +00:00
scale ( zoom_factor , zoom_factor ) ;
2016-06-09 20:46:27 +00:00
}
2015-11-18 09:51:53 +00:00
else
{
QSettings settings ;
if ( settings . value ( " diagrameditor/zoom-out-beyond-of-folio " , false ) . toBool ( ) | |
( horizontalScrollBar ( ) - > maximum ( ) | | verticalScrollBar ( ) - > maximum ( ) ) )
2018-02-10 16:32:57 +00:00
if ( zoom_factor > = 0 ) {
scale ( zoom_factor , zoom_factor ) ;
}
2015-11-18 09:51:53 +00:00
}
2017-08-03 17:36:08 +00:00
m_diagram - > adjustSceneRect ( ) ;
2014-08-18 18:26:38 +00:00
adjustGridToZoom ( ) ;
2017-08-16 14:32:34 +00:00
adjustSceneRect ( ) ;
2014-08-18 18:26:38 +00:00
}
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
*/
2020-09-07 22:03:40 +02:00
void DiagramView : : zoomFit ( )
{
2007-03-03 23:35:14 +00:00
adjustSceneRect ( ) ;
2017-08-03 17:36:08 +00:00
fitInView ( m_diagram - > 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 .
*/
2020-09-07 22:03:40 +02:00
void DiagramView : : zoomContent ( )
{
2017-08-03 17:36:08 +00:00
fitInView ( m_diagram - > itemsBoundingRect ( ) , Qt : : KeepAspectRatio ) ;
2012-08-12 11:46:42 +00:00
adjustGridToZoom ( ) ;
}
2006-10-27 15:47:22 +00:00
/**
Reinitialise le zoom
*/
2020-09-07 22:03:40 +02:00
void DiagramView : : zoomReset ( )
{
2020-06-10 19:53:10 +02:00
resetTransform ( ) ;
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
*/
2020-09-07 22:03:40 +02:00
void DiagramView : : cut ( )
{
2007-09-29 12:54:01 +00:00
copy ( ) ;
2017-12-05 20:51:54 +00:00
DiagramContent cut_content ( m_diagram ) ;
2017-08-03 17:36:08 +00:00
m_diagram - > clearSelection ( ) ;
m_diagram - > undoStack ( ) . push ( new CutDiagramCommand ( m_diagram , 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
*/
2020-09-07 22:03:40 +02:00
void DiagramView : : copy ( )
{
2006-10-27 15:47:22 +00:00
QClipboard * presse_papier = QApplication : : clipboard ( ) ;
2017-08-03 17:36:08 +00:00
QString contenu_presse_papier = m_diagram - > toXml ( false ) . toString ( 4 ) ;
2006-10-27 15:47:22 +00:00
if ( presse_papier - > supportsSelection ( ) ) presse_papier - > setText ( contenu_presse_papier , QClipboard : : Selection ) ;
presse_papier - > setText ( contenu_presse_papier ) ;
}
/**
2020-08-16 11:19:36 +02:00
@ brief DiagramView : : paste
Import the element stored in the clipboard to the diagram .
@ param pos : top left corner of the bounding rect of imported elements
@ param clipboard_mode
*/
2007-11-02 18:04:13 +00:00
void DiagramView : : paste ( const QPointF & pos , QClipboard : : Mode clipboard_mode ) {
2017-08-03 17:36:08 +00:00
if ( ! isInteractive ( ) | | m_diagram - > isReadOnly ( ) ) return ;
2016-05-13 15:00:22 +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 ;
2016-05-13 15:00:22 +00:00
2006-10-27 15:47:22 +00:00
QDomDocument document_xml ;
if ( ! document_xml . setContent ( texte_presse_papier ) ) return ;
2016-05-13 15:00:22 +00:00
2007-11-09 13:06:51 +00:00
DiagramContent content_pasted ;
2019-03-21 19:42:16 +00:00
m_diagram - > fromXml ( document_xml , pos , false , & content_pasted ) ;
2016-05-13 15:00:22 +00:00
2019-03-21 19:42:16 +00:00
//If something was really added to diagram, we create an undo object.
if ( content_pasted . count ( ) )
{
2017-08-03 17:36:08 +00:00
m_diagram - > clearSelection ( ) ;
m_diagram - > undoStack ( ) . push ( new PasteDiagramCommand ( m_diagram , 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
*/
2020-09-07 22:03:40 +02:00
void DiagramView : : pasteHere ( )
{
2017-08-03 17:36:08 +00:00
paste ( mapToScene ( m_paste_here_pos ) ) ;
2007-11-02 18:04:13 +00:00
}
2006-10-27 15:47:22 +00:00
/**
2015-03-24 22:21:58 +00:00
Manage the events press click :
2013-04-10 11:10:02 +00:00
* click to add an independent text field
2006-10-27 15:47:22 +00:00
*/
2015-09-19 13:27:06 +00:00
void DiagramView : : mousePressEvent ( QMouseEvent * e )
{
2019-02-04 19:00:46 +00:00
e - > ignore ( ) ;
2020-09-25 22:06:11 +02:00
2017-08-03 17:36:08 +00:00
if ( m_fresh_focus_in )
2015-09-19 13:27:06 +00:00
{
2012-03-24 14:34:25 +00:00
switchToVisualisationModeIfNeeded ( e ) ;
2017-08-03 17:36:08 +00:00
m_fresh_focus_in = false ;
2012-03-24 14:34:25 +00:00
}
2014-03-18 16:12:51 +00:00
2015-09-19 13:27:06 +00:00
if ( m_event_interface & & m_event_interface - > mousePressEvent ( e ) ) return ;
2014-06-17 09:08:41 +00:00
2015-03-24 22:21:58 +00:00
//Start drag view when hold the middle button
2020-12-04 18:13:48 +01:00
# if QT_VERSION < QT_VERSION_CHECK(5, 15, 1) // ### Qt 6: remove
2015-03-24 22:21:58 +00:00
if ( e - > button ( ) = = Qt : : MidButton )
2020-10-03 09:17:40 +02:00
# else
# if TODO_LIST
# pragma message("@TODO remove code for QT 6 or later")
# endif
if ( e - > button ( ) = = Qt : : MiddleButton )
# endif
2015-03-24 22:21:58 +00:00
{
2019-01-23 17:08:04 +00:00
m_drag_last_pos = e - > pos ( ) ;
2015-09-16 15:30:25 +00:00
viewport ( ) - > setCursor ( Qt : : ClosedHandCursor ) ;
2019-02-04 19:00:46 +00:00
e - > accept ( ) ;
return ;
}
2020-09-25 22:06:11 +02:00
2019-02-04 19:00:46 +00:00
//There is a good luck that user want to do a free selection
//In this case we temporally disable the dragmode because if the QGraphicsScene don't accept the event,
//and the drag mode is set to rubberbanddrag, the QGraphicsView start rubber band drag, and accept the event.
if ( e - > button ( ) = = Qt : : LeftButton & &
e - > modifiers ( ) = = Qt : : CTRL )
{
QGraphicsView : : DragMode dm = dragMode ( ) ;
setDragMode ( QGraphicsView : : NoDrag ) ;
QGraphicsView : : mousePressEvent ( e ) ;
setDragMode ( dm ) ;
} else {
QGraphicsView : : mousePressEvent ( e ) ;
2013-04-15 13:17:06 +00:00
}
2020-09-25 22:06:11 +02:00
2019-02-04 19:00:46 +00:00
if ( e - > isAccepted ( ) ) {
return ;
}
2020-09-25 22:06:11 +02:00
2019-02-04 19:00:46 +00:00
if ( e - > button ( ) = = Qt : : LeftButton & &
e - > modifiers ( ) = = Qt : : CTRL )
2019-01-23 17:08:04 +00:00
{
m_free_rubberbanding = true ;
m_free_rubberband = QPolygon ( ) ;
2019-02-04 19:00:46 +00:00
e - > accept ( ) ;
return ;
2019-01-23 17:08:04 +00:00
}
2020-09-25 22:06:11 +02:00
2019-02-04 19:00:46 +00:00
if ( ! e - > isAccepted ( ) ) {
QGraphicsView : : mousePressEvent ( e ) ;
2020-09-25 22:06:11 +02:00
}
2013-04-15 13:17:06 +00:00
}
2013-05-11 18:20:26 +00:00
/**
2020-08-16 11:19:36 +02:00
@ brief DiagramView : : mouseMoveEvent
Manage the event move mouse
*/
2015-09-19 13:27:06 +00:00
void DiagramView : : mouseMoveEvent ( QMouseEvent * e )
{
2021-02-23 00:51:50 +01:00
setToolTip ( tr ( " X: %1 Y: %2 " ) . arg ( e - > pos ( ) . x ( ) ) . arg ( e - > pos ( ) . y ( ) ) ) ;
2015-09-19 13:27:06 +00:00
if ( m_event_interface & & m_event_interface - > mouseMoveEvent ( e ) ) return ;
2015-03-24 22:21:58 +00:00
2020-12-04 18:13:48 +01:00
// Drag the view
# if QT_VERSION < QT_VERSION_CHECK(5, 15, 1) // ### Qt 6: remove
2020-10-04 16:03:09 +02:00
if ( e - > buttons ( ) = = Qt : : MidButton )
2020-10-03 09:17:40 +02:00
# else
# if TODO_LIST
# pragma message("@TODO remove code for QT 6 or later")
# endif
2020-10-08 16:16:59 +02:00
if ( e - > buttons ( ) = = Qt : : MiddleButton )
2020-10-03 09:17:40 +02:00
# endif
2015-03-24 22:21:58 +00:00
{
QScrollBar * h = horizontalScrollBar ( ) ;
QScrollBar * v = verticalScrollBar ( ) ;
2019-01-23 17:08:04 +00:00
QPointF pos = m_drag_last_pos - e - > pos ( ) ;
m_drag_last_pos = e - > pos ( ) ;
2015-03-24 22:21:58 +00:00
h - > setValue ( h - > value ( ) + pos . x ( ) ) ;
v - > setValue ( v - > value ( ) + pos . y ( ) ) ;
2017-08-16 14:32:34 +00:00
adjustSceneRect ( ) ;
2013-05-11 18:20:26 +00:00
}
2019-01-23 17:08:04 +00:00
else if ( m_free_rubberbanding )
{
//Update old free rubberband
if ( viewportUpdateMode ( ) ! = QGraphicsView : : NoViewportUpdate & & ! m_free_rubberband . isEmpty ( ) )
{
if ( viewportUpdateMode ( ) ! = QGraphicsView : : FullViewportUpdate ) {
2019-01-27 17:04:13 +00:00
viewport ( ) - > update ( m_free_rubberband . boundingRect ( ) . toRect ( ) . adjusted ( - 10 , - 10 , 10 , 10 ) ) ;
2019-01-23 17:08:04 +00:00
}
else {
update ( ) ;
}
}
2020-09-25 22:06:11 +02:00
2019-01-23 17:08:04 +00:00
//Stop polygon rubberbanding if user has let go of all buttons (even
//if we didn't get the release events)
if ( ! e - > buttons ( ) ) {
m_free_rubberbanding = false ;
m_free_rubberband = QPolygon ( ) ;
return ;
}
m_free_rubberband . append ( mapToScene ( e - > pos ( ) ) ) ;
emit freeRubberBandChanged ( m_free_rubberband ) ;
2020-09-25 22:06:11 +02:00
2019-01-23 17:08:04 +00:00
if ( viewportUpdateMode ( ) ! = QGraphicsView : : NoViewportUpdate )
{
if ( viewportUpdateMode ( ) ! = QGraphicsView : : FullViewportUpdate ) {
2019-01-27 17:04:13 +00:00
viewport ( ) - > update ( mapFromScene ( m_free_rubberband . boundingRect ( ) . adjusted ( - 10 , - 10 , 10 , 10 ) ) ) ;
2019-01-23 17:08:04 +00:00
}
else {
update ( ) ;
}
}
2020-09-25 22:06:11 +02:00
2019-01-23 17:08:04 +00:00
//Set the new selection area
QPainterPath selection_area ;
selection_area . addPolygon ( m_free_rubberband ) ;
m_diagram - > setSelectionArea ( selection_area ) ;
}
2014-06-17 09:08:41 +00:00
2014-03-18 16:12:51 +00:00
else QGraphicsView : : mouseMoveEvent ( e ) ;
2013-05-11 18:20:26 +00:00
}
/**
2020-08-16 11:19:36 +02:00
@ brief DiagramView : : mouseReleaseEvent
Manage event release click mouse
*/
2015-09-19 13:27:06 +00:00
void DiagramView : : mouseReleaseEvent ( QMouseEvent * e )
{
if ( m_event_interface & & m_event_interface - > mouseReleaseEvent ( e ) ) return ;
2014-06-17 09:08:41 +00:00
2020-12-04 18:13:48 +01:00
// Stop drag view
# if QT_VERSION < QT_VERSION_CHECK(5, 15, 1) // ### Qt 6: remove
2020-10-03 09:17:40 +02:00
if ( e - > button ( ) = = Qt : : MidButton )
# else
# if TODO_LIST
# pragma message("@TODO remove code for QT 6 or later")
# endif
if ( e - > button ( ) = = Qt : : MiddleButton )
# endif
2019-01-27 17:04:13 +00:00
{
2019-01-23 17:08:04 +00:00
viewport ( ) - > setCursor ( Qt : : ArrowCursor ) ;
}
else if ( m_free_rubberbanding & & ! e - > buttons ( ) )
{
if ( viewportUpdateMode ( ) ! = QGraphicsView : : NoViewportUpdate )
{
2019-01-27 17:04:13 +00:00
if ( viewportUpdateMode ( ) ! = QGraphicsView : : FullViewportUpdate )
{
2019-01-23 17:08:04 +00:00
QRectF r ( mapFromScene ( m_free_rubberband ) . boundingRect ( ) ) ;
2019-01-27 17:04:13 +00:00
r . adjust ( - 10 , - 10 , 10 , 10 ) ;
2019-01-23 17:08:04 +00:00
viewport ( ) - > update ( r . toRect ( ) ) ;
2019-01-27 17:04:13 +00:00
}
else
{
2019-01-23 17:08:04 +00:00
update ( ) ;
}
}
2020-09-25 22:06:11 +02:00
2019-02-04 20:43:58 +00:00
if ( m_free_rubberband . count ( ) > 3 )
2019-01-27 17:04:13 +00:00
{
2019-02-04 20:43:58 +00:00
//Popup a menu with an action to create conductors between
//all selected terminals.
2019-02-20 23:35:37 +00:00
QAction * act = new QAction ( tr ( " Connecter les bornes sélectionnées " ) , this ) ;
2019-02-04 20:43:58 +00:00
QPolygonF polygon_ = m_free_rubberband ;
connect ( act , & QAction : : triggered , [ this , polygon_ ] ( )
{
ConductorCreator : : create ( m_diagram , polygon_ ) ;
diagram ( ) - > clearSelection ( ) ;
} ) ;
QMenu * menu = new QMenu ( this ) ;
menu - > addAction ( act ) ;
2020-10-03 15:42:58 +02:00
# if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // ### Qt 6: remove
2019-02-04 20:43:58 +00:00
menu - > popup ( e - > globalPos ( ) ) ;
2020-10-03 15:42:58 +02:00
# else
# if TODO_LIST
# pragma message("@TODO remove code for QT 6 or later")
# endif
menu - > popup ( e - > pos ( ) ) ;
# endif
2019-02-04 20:43:58 +00:00
}
2020-09-25 22:06:11 +02:00
2019-01-23 17:08:04 +00:00
m_free_rubberbanding = false ;
m_free_rubberband = QPolygon ( ) ;
emit freeRubberBandChanged ( m_free_rubberband ) ;
2019-01-27 17:04:13 +00:00
e - > accept ( ) ;
2019-01-23 17:08:04 +00:00
}
else
QGraphicsView : : mouseReleaseEvent ( e ) ;
2013-05-11 18:20:26 +00:00
}
2014-08-29 02:33:38 +00:00
/**
2020-08-16 11:19:36 +02:00
@ brief DiagramView : : gestures
@ return
*/
2015-09-16 15:11:13 +00:00
bool DiagramView : : gestures ( ) const
{
QSettings settings ;
return ( settings . value ( " diagramview/gestures " , false ) . toBool ( ) ) ;
2014-08-31 09:45:01 +00:00
}
2014-08-29 02:33:38 +00:00
2007-10-04 14:30:52 +00:00
/**
2020-08-20 21:57:35 +02:00
@ brief DiagramView : : wheelEvent
2013-04-13 14:02:47 +00:00
Manage wheel event of mouse
2020-08-20 21:57:35 +02:00
@ param event QWheelEvent
2007-10-04 14:30:52 +00:00
*/
2015-11-18 09:51:53 +00:00
void DiagramView : : wheelEvent ( QWheelEvent * event )
2015-09-19 13:27:06 +00:00
{
2015-11-18 09:51:53 +00:00
if ( m_event_interface & & m_event_interface - > wheelEvent ( event ) ) return ;
2014-09-24 09:38:16 +00:00
2015-11-12 17:01:08 +00:00
//Zoom and scrolling
2015-11-18 09:51:53 +00:00
QPoint angle = event - > angleDelta ( ) ;
if ( gestures ( ) ) //When gesture mode is enable, we suppose the wheel event are made from a trackpad.
{
if ( event - > modifiers ( ) = = Qt : : ControlModifier ) //zoom
{
qreal value = angle . y ( ) ;
zoom ( 1 + value / 1000 ) ;
}
else //scroll
{
horizontalScrollBar ( ) - > setValue ( horizontalScrollBar ( ) - > value ( ) - angle . x ( ) ) ;
verticalScrollBar ( ) - > setValue ( verticalScrollBar ( ) - > value ( ) - angle . y ( ) ) ;
}
}
else if ( event - > modifiers ( ) = = Qt : : NoModifier ) //Else we suppose the wheel event are made from a mouse.
{
qreal value = angle . y ( ) ;
zoom ( 1 + value / 1000 ) ;
}
2015-11-12 17:01:08 +00:00
else
2015-11-18 09:51:53 +00:00
QGraphicsView : : wheelEvent ( event ) ;
2014-08-18 18:26:38 +00:00
}
/**
2020-08-16 11:19:36 +02:00
@ brief DiagramView : : gestureEvent
Use the pinch of the trackpad for zoom
@ param event
@ return
*/
2015-11-18 09:51:53 +00:00
bool DiagramView : : gestureEvent ( QGestureEvent * event )
{
if ( QGesture * gesture = event - > gesture ( Qt : : PinchGesture ) )
{
2018-07-30 15:24:29 +00:00
QPinchGesture * pinch = static_cast < QPinchGesture * > ( gesture ) ;
2015-11-18 09:51:53 +00:00
if ( pinch - > changeFlags ( ) & QPinchGesture : : ScaleFactorChanged )
{
2014-08-18 18:26:38 +00:00
qreal value = gesture - > property ( " scaleFactor " ) . toReal ( ) ;
2015-11-18 09:51:53 +00:00
value > 1 ? zoom ( 1.02 ) : zoom ( 0.98 ) ;
2013-04-10 11:10:02 +00:00
}
}
2014-08-18 18:26:38 +00:00
return true ;
2007-10-04 14:30:52 +00:00
}
2014-08-18 18:26:38 +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 ) {
2017-08-03 17:36:08 +00:00
m_fresh_focus_in = true ;
2012-03-24 14:34:25 +00:00
}
}
/**
2020-08-16 11:19:36 +02:00
@ brief DiagramView : : keyPressEvent
Handles " key press " events . Reimplemented here to switch to visualisation
mode if needed .
@ param e
*/
2017-08-09 09:03:04 +00:00
void DiagramView : : keyPressEvent ( QKeyEvent * e )
{
if ( m_event_interface & & m_event_interface - > keyPressEvent ( e ) )
return ;
2020-09-25 22:06:11 +02:00
2018-09-25 16:05:24 +00:00
ProjectView * current_project = this - > diagramEditor ( ) - > currentProjectView ( ) ;
2017-12-05 20:51:54 +00:00
DiagramContent dc ( m_diagram ) ;
2017-08-09 09:03:04 +00:00
switch ( e - > key ( ) )
2016-05-13 15:00:22 +00:00
{
case Qt : : Key_PageUp :
current_project - > changeTabUp ( ) ;
return ;
case Qt : : Key_PageDown :
current_project - > changeTabDown ( ) ;
return ;
case Qt : : Key_Home :
2018-04-04 11:02:40 +00:00
if ( dc . selectedTexts ( ) . isEmpty ( ) ) {
2016-08-08 16:42:47 +00:00
if (
2017-08-03 17:36:08 +00:00
qgraphicsitem_cast < IndependentTextItem * > ( m_diagram - > focusItem ( ) ) | |
qgraphicsitem_cast < ConductorTextItem * > ( m_diagram - > focusItem ( ) ) | |
qgraphicsitem_cast < DiagramTextItem * > ( m_diagram - > focusItem ( ) )
2016-08-08 16:42:47 +00:00
)
break ;
current_project - > changeFirstTab ( ) ;
return ;
}
else break ;
2016-05-13 15:00:22 +00:00
case Qt : : Key_End :
2018-04-04 11:02:40 +00:00
if ( dc . selectedTexts ( ) . isEmpty ( ) ) {
2016-08-08 16:42:47 +00:00
if (
2017-08-03 17:36:08 +00:00
qgraphicsitem_cast < IndependentTextItem * > ( m_diagram - > focusItem ( ) ) | |
qgraphicsitem_cast < ConductorTextItem * > ( m_diagram - > focusItem ( ) ) | |
qgraphicsitem_cast < DiagramTextItem * > ( m_diagram - > focusItem ( ) )
2016-08-08 16:42:47 +00:00
)
break ;
current_project - > changeLastTab ( ) ;
return ;
}
else break ;
2016-07-13 04:57:02 +00:00
case Qt : : Key_ZoomOut :
2016-06-09 20:46:27 +00:00
zoom ( 0.85 ) ;
return ;
2016-07-13 04:57:02 +00:00
case Qt : : Key_ZoomIn :
2016-06-09 20:46:27 +00:00
zoom ( 1.15 ) ;
return ;
2017-08-09 09:03:04 +00:00
case Qt : : Key_Minus : {
2016-07-13 21:25:29 +00:00
if ( e - > modifiers ( ) & Qt : : ControlModifier )
zoom ( 0.85 ) ;
2017-08-09 09:03:04 +00:00
}
break ;
case Qt : : Key_Plus : {
2016-07-13 21:25:29 +00:00
if ( e - > modifiers ( ) & Qt : : ControlModifier )
zoom ( 1.15 ) ;
2017-08-09 09:03:04 +00:00
}
break ;
case Qt : : Key_Up : {
2019-03-16 11:34:52 +00:00
if ( ! dc . items ( DiagramContent : : All ) . isEmpty ( ) & & ! dc . hasTextEditing ( ) )
2016-06-09 20:46:27 +00:00
scrollOnMovement ( e ) ;
2017-08-09 09:03:04 +00:00
}
break ;
case Qt : : Key_Down : {
2019-03-16 11:34:52 +00:00
if ( ! dc . items ( DiagramContent : : All ) . isEmpty ( ) & & ! dc . hasTextEditing ( ) )
2016-06-09 20:46:27 +00:00
scrollOnMovement ( e ) ;
2017-08-09 09:03:04 +00:00
}
break ;
case Qt : : Key_Left : {
2019-03-16 11:34:52 +00:00
if ( ! dc . items ( DiagramContent : : All ) . isEmpty ( ) & & ! dc . hasTextEditing ( ) )
2016-06-09 20:46:27 +00:00
scrollOnMovement ( e ) ;
2017-08-09 09:03:04 +00:00
}
break ;
case Qt : : Key_Right : {
2019-03-16 11:34:52 +00:00
if ( ! dc . items ( DiagramContent : : All ) . isEmpty ( ) & & ! dc . hasTextEditing ( ) )
2016-06-09 20:46:27 +00:00
scrollOnMovement ( e ) ;
2017-08-09 09:03:04 +00:00
}
break ;
2016-05-13 15:00:22 +00:00
}
2020-09-25 22:06:11 +02:00
2012-03-24 14:34:25 +00:00
switchToVisualisationModeIfNeeded ( e ) ;
QGraphicsView : : keyPressEvent ( e ) ;
}
/**
Handles " key release " events . Reimplemented here to switch to selection
mode if needed .
*/
void DiagramView : : keyReleaseEvent ( QKeyEvent * e ) {
2015-09-19 13:27:06 +00:00
if ( m_event_interface & & m_event_interface - > KeyReleaseEvent ( e ) ) return ;
2012-03-24 14:34:25 +00:00
switchToSelectionModeIfNeeded ( e ) ;
QGraphicsView : : keyReleaseEvent ( e ) ;
}
2016-06-09 20:46:27 +00:00
/**
Handles element movement when editor is zoomed in and scrolls vertical
and horizontal bar . If element is moved to the right side of the editor
or below the editor SceneRect is expanded
*/
2017-12-05 20:51:54 +00:00
void DiagramView : : scrollOnMovement ( QKeyEvent * e )
{
2018-03-24 14:29:43 +00:00
const QList < QGraphicsItem * > selected_elmts = DiagramContent ( m_diagram ) . items ( DiagramContent : : All ) ;
2016-06-09 20:46:27 +00:00
QRectF viewed_scene = viewedSceneRect ( ) ;
2018-03-24 14:29:43 +00:00
for ( QGraphicsItem * qgi : selected_elmts )
{
if ( qgraphicsitem_cast < Conductor * > ( qgi ) )
continue ;
2024-12-31 15:52:17 +01:00
if ( qgi - > parentItem ( ) & & qgi - > parentItem ( ) - > isSelected ( ) )
2018-03-24 14:29:43 +00:00
continue ;
2020-09-25 22:06:11 +02:00
2016-06-09 20:46:27 +00:00
qreal x = qgi - > pos ( ) . x ( ) ;
qreal y = qgi - > pos ( ) . y ( ) ;
qreal bottom = viewed_scene . bottom ( ) ;
2024-12-31 15:52:17 +01:00
qreal top = viewed_scene . top ( ) ;
qreal left = viewed_scene . left ( ) ;
qreal right = viewed_scene . right ( ) ;
qreal elmt_top = y + qgi - > boundingRect ( ) . top ( ) ;
2016-06-09 20:46:27 +00:00
qreal elmt_bottom = y + qgi - > boundingRect ( ) . bottom ( ) ;
2024-12-31 15:52:17 +01:00
qreal elmt_right = x + qgi - > boundingRect ( ) . right ( ) ;
qreal elmt_left = x + qgi - > boundingRect ( ) . left ( ) ;
if ( qgi - > parentItem ( ) ) {
elmt_top + = qgi - > parentItem ( ) - > y ( ) ;
elmt_bottom + = qgi - > parentItem ( ) - > y ( ) ;
elmt_right + = qgi - > parentItem ( ) - > x ( ) ;
elmt_left + = qgi - > parentItem ( ) - > x ( ) ;
}
2020-09-25 22:06:11 +02:00
2016-06-09 20:46:27 +00:00
bool elmt_right_of_left_margin = elmt_left > = left ;
bool elmt_left_of_right_margin = elmt_right < = right ;
2018-03-24 14:29:43 +00:00
bool elmt_below_top_margin = elmt_top > = top ;
bool elmt_above_bottom_margin = elmt_bottom < = bottom ;
2020-09-25 22:06:11 +02:00
2016-06-09 20:46:27 +00:00
if ( ! ( elmt_right_of_left_margin & & elmt_left_of_right_margin ) | |
2024-12-31 16:01:47 +01:00
! ( elmt_below_top_margin & & elmt_above_bottom_margin ) )
2018-03-24 14:29:43 +00:00
{
2016-06-09 20:46:27 +00:00
QScrollBar * h = horizontalScrollBar ( ) ;
QScrollBar * v = verticalScrollBar ( ) ;
int h_increment = 0 ;
int v_increment = 0 ;
2016-08-08 16:42:47 +00:00
if ( e - > key ( ) = = Qt : : Key_Up & & elmt_above_bottom_margin ) {
2016-06-09 20:46:27 +00:00
v_increment = 2 * qgi - > boundingRect ( ) . top ( ) ;
2016-08-08 16:42:47 +00:00
if ( v_increment = = 0 ) v_increment = - 2 * qgi - > boundingRect ( ) . height ( ) ;
}
else if ( e - > key ( ) = = Qt : : Key_Down & & elmt_below_top_margin ) {
2016-06-09 20:46:27 +00:00
v_increment = 2 * qgi - > boundingRect ( ) . bottom ( ) ;
2016-08-08 16:42:47 +00:00
if ( v_increment = = 0 ) v_increment = - 2 * qgi - > boundingRect ( ) . height ( ) ;
2016-06-09 20:46:27 +00:00
}
2016-08-08 16:42:47 +00:00
else if ( e - > key ( ) = = Qt : : Key_Left & & elmt_left_of_right_margin ) {
2016-06-09 20:46:27 +00:00
h_increment = 2 * qgi - > boundingRect ( ) . left ( ) ;
2016-08-08 16:42:47 +00:00
if ( h_increment = = 0 ) h_increment = - 2 * qgi - > boundingRect ( ) . width ( ) ;
}
else if ( e - > key ( ) = = Qt : : Key_Right & & elmt_right_of_left_margin ) {
2016-06-09 20:46:27 +00:00
h_increment = 2 * qgi - > boundingRect ( ) . right ( ) ;
2016-08-08 16:42:47 +00:00
if ( h_increment = = 0 ) h_increment = - 2 * qgi - > boundingRect ( ) . width ( ) ;
2016-06-09 20:46:27 +00:00
}
2017-08-03 17:36:08 +00:00
if ( ( ( elmt_right > = m_diagram - > sceneRect ( ) . right ( ) - qgi - > boundingRect ( ) . right ( ) ) | |
( elmt_bottom > = m_diagram - > sceneRect ( ) . bottom ( ) - qgi - > boundingRect ( ) . bottom ( ) ) ) & &
2016-06-09 20:46:27 +00:00
( e - > key ( ) = = Qt : : Key_Right | | e - > key ( ) = = Qt : : Key_Down ) ) {
2017-08-03 17:36:08 +00:00
m_diagram - > adjustSceneRect ( ) ;
2016-06-09 20:46:27 +00:00
}
h - > setValue ( h - > value ( ) + h_increment ) ;
v - > setValue ( v - > value ( ) + v_increment ) ;
}
}
}
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
*/
2020-09-07 22:03:40 +02:00
QString DiagramView : : title ( ) const
{
2009-04-03 19:30:25 +00:00
QString view_title ;
2017-08-03 17:36:08 +00:00
QString diagram_title ( m_diagram - > title ( ) ) ;
2009-04-03 19:30:25 +00:00
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
/**
2020-08-16 11:19:36 +02:00
@ brief DiagramView : : editDiagramProperties
Edit the properties of the viewed digram
*/
2020-09-07 22:03:40 +02:00
void DiagramView : : editDiagramProperties ( )
{
2017-08-03 17:36:08 +00:00
DiagramPropertiesDialog : : diagramPropertiesDialog ( m_diagram , diagramEditor ( ) ) ;
2007-02-01 01:07:26 +00:00
}
2007-03-03 23:35:14 +00:00
/**
2020-08-16 11:19:36 +02:00
@ brief DiagramView : : adjustSceneRect
Calcul and set the area of the scene visualized by this view
*/
2015-03-27 09:45:19 +00:00
void DiagramView : : adjustSceneRect ( )
{
2017-08-03 17:36:08 +00:00
QRectF scene_rect = m_diagram - > sceneRect ( ) ;
2015-03-27 09:45:19 +00:00
scene_rect . adjust ( - Diagram : : margin , - Diagram : : margin , Diagram : : margin , Diagram : : margin ) ;
2020-09-25 22:06:11 +02:00
2017-08-16 14:32:34 +00:00
QSettings settings ;
if ( settings . value ( " diagrameditor/zoom-out-beyond-of-folio " , false ) . toBool ( ) )
{
2022-12-04 06:24:28 -05:00
//When zoom out beyond of folio is active,
2017-08-16 14:32:34 +00:00
//we always adjust the scene rect to be 1/3 bigger than the wiewport
QRectF vpbr = mapToScene ( viewport ( ) - > rect ( ) ) . boundingRect ( ) ;
vpbr . adjust ( 0 , 0 , vpbr . width ( ) / 3 , vpbr . height ( ) / 3 ) ;
scene_rect = scene_rect . united ( vpbr ) ;
}
2015-03-27 09:45:19 +00:00
setSceneRect ( 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
*/
2020-09-07 22:03:40 +02:00
void DiagramView : : updateWindowTitle ( )
{
2014-01-05 15:00:46 +00:00
emit ( titleChanged ( this , title ( ) ) ) ;
2007-09-29 09:52:35 +00:00
}
2007-10-10 17:50:26 +00:00
/**
2013-04-10 11:10:02 +00:00
Enables or disables the drawing grid according to the amount of pixels display
2007-10-10 17:50:26 +00:00
*/
2020-09-07 22:03:40 +02:00
void DiagramView : : adjustGridToZoom ( )
{
2007-09-04 18:15:41 +00:00
QRectF viewed_scene = viewedSceneRect ( ) ;
2016-08-18 16:30:24 +00:00
if ( diagramEditor ( ) - > drawGrid ( ) )
2017-08-03 17:36:08 +00:00
m_diagram - > setDisplayGrid ( viewed_scene . width ( ) < 2000 | | viewed_scene . height ( ) < 2000 ) ;
2016-08-18 16:30:24 +00:00
else
2017-08-03 17:36:08 +00:00
m_diagram - > setDisplayGrid ( false ) ;
2007-09-04 18:15:41 +00:00
}
2007-10-10 17:50:26 +00:00
/**
@ return le rectangle du schema ( classe Diagram ) visualise par ce DiagramView
*/
2020-09-07 22:03:40 +02:00
QRectF DiagramView : : viewedSceneRect ( ) const
{
2007-09-04 18:15:41 +00:00
// recupere la taille du widget viewport
QSize viewport_size = viewport ( ) - > size ( ) ;
2016-05-13 15:00:22 +00:00
2007-09-04 18:15:41 +00:00
// recupere la transformation viewport -> scene
QTransform view_to_scene = viewportTransform ( ) . inverted ( ) ;
2016-05-13 15:00:22 +00:00
2007-09-04 18:15:41 +00:00
// 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 ( ) ) ) ;
2016-05-13 15:00:22 +00:00
2007-09-04 18:15:41 +00:00
// en deduit le rectangle visualise par la scene
return ( QRectF ( scene_left_top , scene_right_bottom ) ) ;
}
2007-10-03 13:11:47 +00:00
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
*/
2020-09-07 22:03:40 +02:00
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 ) ;
2016-05-13 15:00:22 +00:00
2017-08-03 17:36:08 +00:00
return ( tbt_parent_project ! = m_diagram - > project ( ) ) ;
2012-01-22 10:40:37 +00:00
}
2009-04-03 19:30:25 +00:00
/**
Fait en sorte que le schema ne soit editable que s ' il n ' est pas en lecture
seule
*/
2020-09-07 22:03:40 +02:00
void DiagramView : : applyReadOnly ( )
{
2017-08-03 17:36:08 +00:00
if ( ! m_diagram ) return ;
2016-05-13 15:00:22 +00:00
2017-08-03 17:36:08 +00:00
bool is_writable = ! m_diagram - > isReadOnly ( ) ;
2009-04-03 19:30:25 +00:00
setInteractive ( is_writable ) ;
setAcceptDrops ( is_writable ) ;
}
2007-10-06 18:37:21 +00:00
/**
Reinitialise le profil des conducteurs selectionnes
*/
2020-09-07 22:03:40 +02:00
void DiagramView : : resetConductors ( )
{
2017-08-03 17:36:08 +00:00
if ( m_diagram - > isReadOnly ( ) ) return ;
2007-10-06 18:37:21 +00:00
// recupere les conducteurs selectionnes
2017-08-03 17:36:08 +00:00
QSet < Conductor * > selected_conductors = m_diagram - > selectedConductors ( ) ;
2016-05-13 15:00:22 +00:00
2007-10-06 18:37:21 +00:00
// repere les conducteurs modifies (= profil non nul)
2007-10-22 20:27:39 +00:00
QHash < Conductor * , ConductorProfilesGroup > conductors_and_profiles ;
2017-02-05 16:18:50 +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
}
2016-05-13 15:00:22 +00:00
2007-10-06 18:37:21 +00:00
if ( conductors_and_profiles . isEmpty ( ) ) return ;
2017-08-03 17:36:08 +00:00
m_diagram - > undoStack ( ) . push ( new ResetConductorCommand ( conductors_and_profiles ) ) ;
2007-10-06 18:37:21 +00:00
}
2007-10-12 10:58:57 +00:00
2015-03-27 09:45:19 +00:00
/**
2020-08-16 11:19:36 +02:00
@ brief DiagramView : : event
Manage the event on this diagram view .
- At first activation ( QEvent : : WindowActivate or QEvent : : Show ) we zoomFit .
- Convert event interpreted to mouse event to gesture event if needed .
- send Shortcut to view ( by default send to QMenu / QAction )
2020-08-20 22:35:25 +02:00
Gere les evenements de la DiagramView
2020-08-20 21:57:35 +02:00
@ param e : the event .
2020-08-16 11:19:36 +02:00
@ return
*/
2007-10-12 10:58:57 +00:00
bool DiagramView : : event ( QEvent * e ) {
2015-03-27 09:45:19 +00:00
if ( Q_UNLIKELY ( m_first_activation ) ) {
if ( e - > type ( ) = = QEvent : : Show ) {
zoomFit ( ) ;
m_first_activation = false ;
}
}
2014-08-18 18:26:38 +00:00
// By default touch events are converted to mouse events. So
// after this event we will get a mouse event also but we want
// to handle touch events as gestures only. So we need this safeguard
// to block mouse events that are actually generated from touch.
if ( e - > type ( ) = = QEvent : : Gesture )
return gestureEvent ( static_cast < QGestureEvent * > ( e ) ) ;
2019-01-23 17:08:04 +00:00
// 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
2019-01-27 17:04:13 +00:00
/**
2020-08-16 11:19:36 +02:00
@ brief DiagramView : : paintEvent
Reimplemented from QGraphicsView
@ param event
*/
2019-01-23 17:08:04 +00:00
void DiagramView : : paintEvent ( QPaintEvent * event )
{
QGraphicsView : : paintEvent ( event ) ;
2020-09-25 22:06:11 +02:00
2019-01-23 17:08:04 +00:00
if ( m_free_rubberbanding & & m_free_rubberband . count ( ) > = 3 )
{
QPainter painter ( viewport ( ) ) ;
painter . setRenderHint ( QPainter : : Antialiasing ) ;
QPen pen ( Qt : : darkGreen ) ;
pen . setWidth ( 1 ) ;
painter . setPen ( pen ) ;
QColor color ( Qt : : darkGreen ) ;
color . setAlpha ( 50 ) ;
QBrush brush ( color ) ;
painter . setBrush ( brush ) ;
painter . drawPolygon ( mapFromScene ( m_free_rubberband ) ) ;
}
}
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 ) {
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 ) {
2014-09-24 09:38:16 +00:00
if ( ! selectedItemHasFocus ( ) & & ! isCtrlShifting ( e ) ) {
2012-03-24 14:34:25 +00:00
setSelectionMode ( ) ;
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 ) {
2018-07-30 15:24:29 +00:00
if ( QKeyEvent * ke = static_cast < QKeyEvent * > ( e ) ) {
2012-03-24 14:34:25 +00:00
result = ( ke - > modifiers ( ) = = ( Qt : : ControlModifier | Qt : : ShiftModifier ) ) ;
}
} else if ( e - > type ( ) > = QEvent : : MouseButtonPress & & e - > type ( ) < = QEvent : : MouseMove ) {
2018-07-30 15:24:29 +00:00
if ( QMouseEvent * me = static_cast < QMouseEvent * > ( e ) ) {
2012-03-24 14:34:25 +00:00
result = ( me - > modifiers ( ) = = ( Qt : : ControlModifier | Qt : : ShiftModifier ) ) ;
}
}
return ( result ) ;
}
/**
@ return true if there is a selected item and that item has the focus .
*/
2020-09-07 22:03:40 +02:00
bool DiagramView : : selectedItemHasFocus ( )
{
2012-03-24 14:34:25 +00:00
return (
2017-08-03 17:36:08 +00:00
m_diagram - > hasFocus ( ) & &
m_diagram - > focusItem ( ) & &
m_diagram - > focusItem ( ) - > isSelected ( )
2012-03-24 14:34:25 +00:00
) ;
}
2013-09-10 14:44:25 +00:00
/**
2020-08-16 11:19:36 +02:00
@ brief DiagramView : : editSelection
Edit the selected item if he can be edited and if only one item is selected
*/
2020-09-07 22:03:40 +02:00
void DiagramView : : editSelection ( )
{
2017-08-03 17:36:08 +00:00
if ( m_diagram - > isReadOnly ( ) | | m_diagram - > selectedItems ( ) . size ( ) ! = 1 ) return ;
2013-09-10 14:44:25 +00:00
2017-08-03 17:36:08 +00:00
QGraphicsItem * item = m_diagram - > selectedItems ( ) . first ( ) ;
2015-02-20 18:44:44 +00:00
//We use dynamic_cast instead of qgraphicsitem_cast for QetGraphicsItem
//because they haven't got they own type().
//Use qgraphicsitem_cast will have weird behavior for this class.
2018-07-30 15:24:29 +00:00
if ( IndependentTextItem * iti = qgraphicsitem_cast < IndependentTextItem * > ( item ) )
2014-09-25 09:44:41 +00:00
iti - > edit ( ) ;
2018-07-30 15:24:29 +00:00
else if ( QetGraphicsItem * qgi = dynamic_cast < QetGraphicsItem * > ( item ) )
2014-09-25 09:44:41 +00:00
qgi - > editProperty ( ) ;
2018-07-30 15:24:29 +00:00
else if ( Conductor * c = qgraphicsitem_cast < Conductor * > ( item ) )
2015-02-20 18:44:44 +00:00
c - > editProperty ( ) ;
2014-03-07 08:05:25 +00:00
}
2013-08-24 15:18:45 +00:00
/**
2020-08-16 11:19:36 +02:00
@ brief DiagramView : : setEventInterface
Set an event interface to diagram view .
If diagram view already have an event interface , he delete it before .
Diagram view take ownership of event interface and delete it when event interface is finish
*/
2015-09-19 13:27:06 +00:00
void DiagramView : : setEventInterface ( DVEventInterface * event_interface )
{
2014-09-24 09:38:16 +00:00
if ( m_event_interface ) delete m_event_interface ;
2015-03-02 20:14:56 +00:00
m_event_interface = event_interface ;
2015-09-19 13:27:06 +00:00
connect ( m_event_interface , & DVEventInterface : : finish , this , [ = ] ( ) { delete this - > m_event_interface ; this - > m_event_interface = nullptr ; } , Qt : : QueuedConnection ) ;
2008-07-09 21:14:30 +00:00
}
2007-11-02 18:04:13 +00:00
/**
2020-08-16 11:19:36 +02:00
@ brief DiagramView : : contextMenuActions
@ return a list of actions currently available for a context menu .
*/
2018-07-01 18:35:03 +00:00
QList < QAction * > DiagramView : : contextMenuActions ( ) const
{
QList < QAction * > list ;
if ( QETDiagramEditor * qde = diagramEditor ( ) )
{
if ( m_diagram - > selectedItems ( ) . isEmpty ( ) )
{
list < < m_paste_here ;
2018-07-02 13:48:47 +00:00
list < < m_separators . at ( 0 ) ;
2018-07-01 18:35:03 +00:00
list < < qde - > m_edit_diagram_properties ;
list < < qde - > m_row_column_actions_group . actions ( ) ;
}
else
{
list < < qde - > m_cut ;
list < < qde - > m_copy ;
list < < m_multi_paste ;
2018-07-02 13:48:47 +00:00
list < < m_separators . at ( 0 ) ;
2018-07-01 18:35:03 +00:00
list < < qde - > m_conductor_reset ;
2018-07-02 13:48:47 +00:00
list < < m_separators . at ( 1 ) ;
2018-07-01 18:35:03 +00:00
list < < qde - > m_selection_actions_group . actions ( ) ;
2018-07-02 13:48:47 +00:00
list < < m_separators . at ( 2 ) ;
2018-07-01 18:35:03 +00:00
list < < qde - > m_depth_action_group - > actions ( ) ;
2007-11-02 18:04:13 +00:00
}
2020-09-25 22:06:11 +02:00
2018-03-31 11:21:55 +00:00
//Remove from the context menu the actions which are disabled.
2018-07-01 18:35:03 +00:00
const QList < QAction * > actions = list ;
2018-03-31 11:21:55 +00:00
for ( QAction * action : actions )
{
2018-07-01 18:35:03 +00:00
if ( ! action - > isEnabled ( ) ) {
list . removeAll ( action ) ;
}
}
}
2020-09-25 22:06:11 +02:00
2018-07-01 18:35:03 +00:00
return list ;
}
/**
2020-08-16 11:19:36 +02:00
@ brief DiagramView : : contextMenuEvent
@ param e
*/
2018-07-01 18:35:03 +00:00
void DiagramView : : contextMenuEvent ( QContextMenuEvent * e )
{
2023-05-13 18:12:28 +02:00
QGraphicsView : : contextMenuEvent ( e ) ;
if ( e - > isAccepted ( ) )
return ;
2021-12-28 15:25:35 +01:00
if ( auto qgi = m_diagram - > itemAt ( mapToScene ( e - > pos ( ) ) , transform ( ) ) )
2018-07-01 18:35:03 +00:00
{
2021-12-28 15:25:35 +01:00
if ( ! qgi - > isSelected ( ) ) {
2018-07-01 18:35:03 +00:00
m_diagram - > clearSelection ( ) ;
2018-03-31 11:21:55 +00:00
}
2020-09-25 22:06:11 +02:00
2022-12-04 06:24:28 -05:00
// At this step qgi can be deleted for example if qgi is a QetGraphicsHandlerItem.
2021-12-28 15:25:35 +01:00
// When we call clearSelection the parent item of the handler
// is deselected and so delete all handlers, in this case,
// qgi become a dangling pointer.
// we need to call again itemAt.
if ( auto item_ = m_diagram - > itemAt ( mapToScene ( e - > pos ( ) ) , transform ( ) ) ) {
item_ - > setSelected ( true ) ;
}
2018-07-01 18:35:03 +00:00
}
2020-09-25 22:06:11 +02:00
2018-07-01 18:35:03 +00:00
if ( m_diagram - > selectedItems ( ) . isEmpty ( ) )
{
m_paste_here_pos = e - > pos ( ) ;
m_paste_here - > setEnabled ( Diagram : : clipboardMayContainDiagram ( ) ) ;
}
QList < QAction * > list = contextMenuActions ( ) ;
if ( ! list . isEmpty ( ) )
{
2018-07-30 15:24:29 +00:00
QMenu * context_menu = new QMenu ( this ) ;
2018-07-01 18:35:03 +00:00
context_menu - > addActions ( list ) ;
context_menu - > popup ( e - > globalPos ( ) ) ;
e - > accept ( ) ;
2007-11-02 18:04:13 +00:00
}
}
2009-04-13 01:35:01 +00:00
/**
@ return l ' editeur de schemas parent ou 0
*/
2020-09-07 22:03:40 +02:00
QETDiagramEditor * DiagramView : : diagramEditor ( ) const
{
2007-11-02 18:04:13 +00:00
// 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
/**
2020-08-16 11:19:36 +02:00
@ brief DiagramView : : mouseDoubleClickEvent
@ param e
*/
2015-09-19 13:27:06 +00:00
void DiagramView : : mouseDoubleClickEvent ( QMouseEvent * e )
{
if ( m_event_interface & & m_event_interface - > mouseDoubleClickEvent ( e ) ) return ;
2014-09-24 09:38:16 +00:00
2017-08-03 17:36:08 +00:00
BorderTitleBlock & bi = m_diagram - > border_and_titleblock ;
2016-05-13 15:00:22 +00:00
2014-09-02 18:41:25 +00:00
//Get the click pos on the diagram
2007-12-01 12:42:31 +00:00
QPointF click_pos = viewportTransform ( ) . inverted ( ) . map ( e - > pos ( ) ) ;
2016-05-13 15:00:22 +00:00
2015-03-18 18:07:18 +00:00
if ( bi . titleBlockRect ( ) . contains ( click_pos ) | | bi . columnsRect ( ) . contains ( click_pos ) | | bi . rowsRect ( ) . contains ( click_pos ) ) {
2014-09-02 18:41:25 +00:00
e - > accept ( ) ;
2009-04-03 19:30:25 +00:00
editDiagramProperties ( ) ;
2014-09-02 18:41:25 +00:00
return ;
2007-12-01 12:42:31 +00:00
}
2014-09-02 18:41:25 +00:00
QGraphicsView : : mouseDoubleClickEvent ( e ) ;
2007-12-01 12:42:31 +00:00
}