1288 lines
37 KiB
C++
Raw Normal View History

/*
2023-01-01 17:05:57 +01:00
Copyright 2006-2023 The QElectroTech Team
This file is part of QElectroTech.
QElectroTech is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
QElectroTech is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#include "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"
#include "projectview.h"
#include "qetdiagrameditor.h"
2020-12-08 19:57:35 +01:00
#include "qetgraphicsitem/conductor.h"
#include "qetgraphicsitem/conductortextitem.h"
#include "qetgraphicsitem/independenttextitem.h"
#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"
#include "undocommand/addgraphicsobjectcommand.h"
2021-02-07 20:44:17 +01:00
#include "diagram.h"
2020-10-03 15:42:58 +02:00
#include <QDropEvent>
/**
Constructeur
@param diagram Schema a afficher ; si diagram vaut 0, un nouveau Diagram est utilise
@param parent Le QWidget parent de cette vue de schema
*/
DiagramView::DiagramView(Diagram *diagram, QWidget *parent) :
QGraphicsView (parent),
m_diagram (diagram)
{
grabGesture(Qt::PinchGesture);
setAttribute(Qt::WA_DeleteOnClose, true);
setInteractive(true);
QString whatsthis = tr(
Merge Qt5 branch sources folder to trunk -Cette ligne, et les suivantes ci-dessous, seront ignorées-- M sources/aboutqet.cpp M sources/bordertitleblock.cpp M sources/conductorproperties.h M sources/configdialog.cpp M sources/configpages.cpp M sources/configpages.h M sources/createdxf.h M sources/diagram.cpp M sources/diagram.h M sources/diagramcommands.cpp M sources/diagramcommands.h M sources/diagramprintdialog.cpp M sources/diagramprintdialog.h M sources/diagramschooser.cpp M sources/diagramschooser.h M sources/diagramview.cpp M sources/diagramview.h M sources/dvevent/dveventaddimage.cpp M sources/dvevent/dveventaddshape.cpp M sources/editor/arceditor.cpp M sources/editor/arceditor.h M sources/editor/editorcommands.cpp M sources/editor/editorcommands.h M sources/editor/elementitemeditor.h M sources/editor/elementprimitivedecorator.cpp M sources/editor/elementscene.cpp M sources/editor/elementscene.h M sources/editor/elementview.cpp M sources/editor/ellipseeditor.cpp M sources/editor/ellipseeditor.h M sources/editor/esevent/eseventaddtext.cpp M sources/editor/esevent/eseventaddtextfield.cpp M sources/editor/esevent/eseventinterface.cpp M sources/editor/graphicspart/customelementpart.h M sources/editor/graphicspart/parttext.cpp M sources/editor/graphicspart/parttext.h M sources/editor/graphicspart/parttextfield.cpp M sources/editor/graphicspart/parttextfield.h M sources/editor/lineeditor.cpp M sources/editor/lineeditor.h M sources/editor/polygoneditor.cpp M sources/editor/qetelementeditor.cpp M sources/editor/qetelementeditor.h M sources/editor/rectangleeditor.cpp M sources/editor/rectangleeditor.h M sources/editor/styleeditor.cpp M sources/editor/styleeditor.h M sources/editor/terminaleditor.cpp M sources/editor/terminaleditor.h M sources/editor/texteditor.cpp M sources/editor/texteditor.h M sources/editor/textfieldeditor.cpp M sources/editor/textfieldeditor.h M sources/editor/ui/elementpropertieseditorwidget.cpp M sources/elementdefinition.cpp M sources/elementdeleter.cpp M sources/elementdeleter.h M sources/elementdialog.cpp M sources/elementscategorieslist.h M sources/elementscategorieswidget.cpp M sources/elementscategorieswidget.h M sources/elementscategory.cpp M sources/elementscategorydeleter.cpp M sources/elementscategorydeleter.h M sources/elementscategoryeditor.cpp M sources/elementscategoryeditor.h M sources/elementscollection.cpp M sources/elementscollectioncache.cpp M sources/elementspanel.cpp M sources/elementspanel.h M sources/elementspanelwidget.cpp M sources/elementspanelwidget.h M sources/elementtextsmover.h M sources/exportdialog.cpp M sources/exportdialog.h M sources/exportproperties.cpp M sources/exportpropertieswidget.cpp M sources/exportpropertieswidget.h M sources/genericpanel.cpp M sources/integrationmoveelementshandler.cpp M sources/integrationmoveelementshandler.h M sources/interactivemoveelementshandler.cpp M sources/nameslistwidget.cpp M sources/nameslistwidget.h M sources/newelementwizard.cpp M sources/newelementwizard.h M sources/nomenclature.cpp M sources/nomenclature.h M sources/projectconfigpages.cpp M sources/projectview.cpp M sources/projectview.h M sources/qet.cpp M sources/qetapp.cpp M sources/qetapp.h M sources/qetdiagrameditor.cpp M sources/qetdiagrameditor.h M sources/qetgraphicsitem/conductor.cpp M sources/qetgraphicsitem/conductortextitem.cpp M sources/qetgraphicsitem/customelement.cpp M sources/qetgraphicsitem/diagramimageitem.cpp M sources/qetgraphicsitem/diagramtextitem.cpp M sources/qetgraphicsitem/diagramtextitem.h M sources/qetgraphicsitem/element.cpp M sources/qetgraphicsitem/ghostelement.cpp M sources/qetgraphicsitem/qetshapeitem.cpp M sources/qetgraphicsitem/terminal.cpp M sources/qetgraphicsitem/terminal.h M sources/qeticons.cpp M sources/qeticons.h M sources/qetmainwindow.cpp M sources/qetmessagebox.cpp M sources/qetmessagebox.h M sources/qetprintpreviewdialog.cpp M sources/qetprintpreviewdialog.h M sources/qetproject.cpp M sources/qetsingleapplication.cpp M sources/qettabbar.h M sources/qfilenameedit.cpp M sources/qtextorientationspinboxwidget.cpp M sources/qtextorientationspinboxwidget.h M sources/qtextorientationwidget.cpp M sources/qtextorientationwidget.h M sources/richtext/richtexteditor.cpp M sources/richtext/richtexteditor_p.h M sources/richtext/ui_addlinkdialog.h M sources/titleblock/dimensionwidget.h M sources/titleblock/gridlayoutanimation.h M sources/titleblock/helpercell.h M sources/titleblock/integrationmovetemplateshandler.cpp M sources/titleblock/integrationmovetemplateshandler.h M sources/titleblock/qettemplateeditor.cpp M sources/titleblock/qettemplateeditor.h M sources/titleblock/templatecellsset.h M sources/titleblock/templatecellwidget.cpp M sources/titleblock/templatecellwidget.h M sources/titleblock/templatecommands.cpp M sources/titleblock/templatedeleter.cpp M sources/titleblock/templatedeleter.h M sources/titleblock/templatelocationchooser.cpp M sources/titleblock/templatelocationchooser.h M sources/titleblock/templatelocationsaver.cpp M sources/titleblock/templatelocationsaver.h M sources/titleblock/templatelogomanager.cpp M sources/titleblock/templatelogomanager.h M sources/titleblock/templateview.cpp M sources/titleblock/templatevisualcell.h M sources/titleblockcell.cpp M sources/titleblocktemplate.cpp M sources/treecoloranimation.h M sources/ui/conductorpropertieswidget.cpp M sources/ui/diagrampropertiesdialog.cpp M sources/ui/diagramselection.cpp M sources/ui/dialogautonum.cpp M sources/ui/dialogwaiting.cpp M sources/ui/elementpropertieswidget.cpp M sources/ui/elementselectorwidget.cpp M sources/ui/linksingleelementwidget.cpp M sources/ui/masterpropertieswidget.cpp M sources/ui/potentialtextsdialog.cpp M sources/ui/projectpropertiesdialog.cpp M sources/ui/selectautonumw.cpp M sources/ui/titleblockpropertieswidget.cpp M sources/ui/xrefpropertieswidget.cpp M sources/undocommand/changeelementinformationcommand.cpp git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3783 bfdf4180-ca20-0410-9c96-a3a8aa849046
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.",
"\"What's this?\" tip"
);
setWhatsThis(whatsthis);
// active l'antialiasing
setRenderHint(QPainter::Antialiasing, true);
setRenderHint(QPainter::TextAntialiasing, true);
setRenderHint(QPainter::SmoothPixmapTransform, true);
setScene(m_diagram);
m_diagram -> undoStack().setClean();
setWindowIcon(QET::Icons::QETLogo);
setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
setResizeAnchor(QGraphicsView::AnchorUnderMouse);
setAlignment(Qt::AlignLeft | Qt::AlignTop);
setSelectionMode();
adjustSceneRect();
updateWindowTitle();
m_diagram->loadElmtFolioSeq();
m_diagram->loadCndFolioSeq();
m_paste_here = new QAction(QET::Icons::EditPaste, tr("Coller ici", "context menu action"), this);
connect(m_paste_here, SIGNAL(triggered()), this, SLOT(pasteHere()));
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();
});
//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);
}
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()));
connect(diagram, SIGNAL(findElementRequired(ElementsLocation)), this, SIGNAL(findElementRequired(ElementsLocation)));
QShortcut *edit_conductor_color_shortcut = new QShortcut(QKeySequence(Qt::Key_F2), this);
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);
}
}
});
}
/**
Destructeur
*/
2020-09-07 22:03:40 +02:00
DiagramView::~DiagramView()
2020-10-02 18:38:24 +02:00
{}
/**
Accepte ou refuse le drag'n drop en fonction du type de donnees entrant
@param e le QDragEnterEvent correspondant au drag'n drop tente
*/
void DiagramView::dragEnterEvent(QDragEnterEvent *e) {
if (e -> mimeData() -> hasFormat("application/x-qet-element-uri")) {
e -> acceptProposedAction();
} else if (e -> mimeData() -> hasFormat("application/x-qet-titleblock-uri")) {
e -> acceptProposedAction();
} else if (e -> mimeData() -> hasText()) {
e -> acceptProposedAction();
} else {
e -> ignore();
}
}
/**
Accepte ou refuse le drag'n drop en fonction du type de donnees entrant
@param e le QDragMoveEvent correspondant au drag'n drop tente
*/
void DiagramView::dragMoveEvent(QDragMoveEvent *e) {
if (e -> mimeData() -> hasFormat("text/plain")) e -> acceptProposedAction();
else e-> ignore();
}
/**
Handle the drops accepted on diagram (elements and title block templates).
@param e the QDropEvent describing the current drag'n drop
*/
void DiagramView::dropEvent(QDropEvent *e) {
if (e -> mimeData() -> hasFormat("application/x-qet-element-uri")) {
handleElementDrop(e);
} else if (e -> mimeData() -> hasFormat("application/x-qet-titleblock-uri")) {
handleTitleBlockDrop(e);
} else if (e -> mimeData() -> hasText()) {
handleTextDrop(e);
}
}
/**
2020-08-20 21:57:35 +02:00
@brief DiagramView::handleElementDrop
Handle the drop of an element.
2020-08-20 21:57:35 +02:00
@param event the QDropEvent describing the current drag'n drop
*/
void DiagramView::handleElementDrop(QDropEvent *event)
{
//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;
}
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
//Set focus to the view to get event
this->setFocus();
}
/**
2020-08-16 11:19:36 +02:00
@brief DiagramView::handleTitleBlockDrop
Handle the dropEvent that contain data of a titleblock
@param e
*/
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())
{
// fetch the current title block properties
TitleBlockProperties titleblock_properties_before = m_diagram->border_and_titleblock.exportTitleBlock();
// check the provided template is not already applied
QETProject *tbt_parent_project = tbt_loc.parentProject();
if (tbt_parent_project && tbt_parent_project == m_diagram -> project())
{
// 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))
{
IntegrationMoveTitleBlockTemplatesHandler *handler = new IntegrationMoveTitleBlockTemplatesHandler(this);
//QString error_message;
integrated_template_name = m_diagram->project()->integrateTitleBlockTemplate(tbt_loc, 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;
m_diagram->undoStack().push(new ChangeTitleBlockCommand(m_diagram, titleblock_properties_before, titleblock_properties_after));
adjustSceneRect();
}
}
/**
2020-08-16 11:19:36 +02:00
@brief DiagramView::handleTextDrop
*handle the drop of text
2020-08-16 11:19:36 +02:00
@param e the QDropEvent describing the current drag'n drop
*/
void DiagramView::handleTextDrop(QDropEvent *e) {
if (m_diagram -> isReadOnly() || (e -> mimeData() -> hasText() == false) ) return;
IndependentTextItem *iti = new IndependentTextItem (e -> mimeData() -> text());
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
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
m_diagram->undoStack().push(new AddGraphicsObjectCommand(
iti, m_diagram, e->position()));
2020-10-03 15:42:58 +02:00
#endif
}
/**
Set the Diagram in visualisation mode
*/
2020-09-07 22:03:40 +02:00
void DiagramView::setVisualisationMode()
{
setDragMode(ScrollHandDrag);
applyReadOnly();
setInteractive(false);
emit(modeChanged());
}
/**
Set the Diagram in Selection mode
*/
2020-09-07 22:03:40 +02:00
void DiagramView::setSelectionMode()
{
setDragMode(RubberBandDrag);
setInteractive(true);
applyReadOnly();
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
*/
void DiagramView::zoom(const qreal zoom_factor)
{
if (zoom_factor >= 1){
scale(zoom_factor, zoom_factor);
}
else
{
QSettings settings;
if (settings.value("diagrameditor/zoom-out-beyond-of-folio", false).toBool() ||
(horizontalScrollBar()->maximum() || verticalScrollBar()->maximum()) )
if (zoom_factor >= 0){
scale(zoom_factor, zoom_factor);
}
}
m_diagram->adjustSceneRect();
adjustGridToZoom();
adjustSceneRect();
}
/**
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()
{
adjustSceneRect();
fitInView(m_diagram->sceneRect(), Qt::KeepAspectRatio);
adjustGridToZoom();
}
/**
Adjust zoom to fit all elements in the view, regardless of diagram borders.
*/
2020-09-07 22:03:40 +02:00
void DiagramView::zoomContent()
{
fitInView(m_diagram -> itemsBoundingRect(), Qt::KeepAspectRatio);
adjustGridToZoom();
}
/**
Reinitialise le zoom
*/
2020-09-07 22:03:40 +02:00
void DiagramView::zoomReset()
{
resetTransform();
adjustGridToZoom();
}
/**
Copie les elements selectionnes du schema dans le presse-papier puis les supprime
*/
2020-09-07 22:03:40 +02:00
void DiagramView::cut()
{
copy();
DiagramContent cut_content(m_diagram);
m_diagram -> clearSelection();
m_diagram -> undoStack().push(new CutDiagramCommand(m_diagram, cut_content));
}
/**
Copie les elements selectionnes du schema dans le presse-papier
*/
2020-09-07 22:03:40 +02:00
void DiagramView::copy()
{
QClipboard *presse_papier = QApplication::clipboard();
QString contenu_presse_papier = m_diagram -> toXml(false).toString(4);
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
*/
void DiagramView::paste(const QPointF &pos, QClipboard::Mode clipboard_mode) {
if (!isInteractive() || m_diagram -> isReadOnly()) return;
QString texte_presse_papier = QApplication::clipboard() -> text(clipboard_mode);
if ((texte_presse_papier).isEmpty()) return;
QDomDocument document_xml;
if (!document_xml.setContent(texte_presse_papier)) return;
DiagramContent content_pasted;
m_diagram->fromXml(document_xml, pos, false, &content_pasted);
//If something was really added to diagram, we create an undo object.
if (content_pasted.count())
{
m_diagram -> clearSelection();
m_diagram -> undoStack().push(new PasteDiagramCommand(m_diagram, content_pasted));
adjustSceneRect();
}
}
/**
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()
{
paste(mapToScene(m_paste_here_pos));
}
/**
Manage the events press click :
* click to add an independent text field
*/
void DiagramView::mousePressEvent(QMouseEvent *e)
{
e->ignore();
if (m_fresh_focus_in)
{
switchToVisualisationModeIfNeeded(e);
m_fresh_focus_in = false;
}
if (m_event_interface && m_event_interface->mousePressEvent(e)) return;
//Start drag view when hold the middle button
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 1) // ### Qt 6: remove
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
{
m_drag_last_pos = e->pos();
viewport()->setCursor(Qt::ClosedHandCursor);
e->accept();
return;
}
//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);
}
if (e->isAccepted()) {
return;
}
if (e->button() == Qt::LeftButton &&
e->modifiers() == Qt::CTRL)
{
m_free_rubberbanding = true;
m_free_rubberband = QPolygon();
e->accept();
return;
}
if (!e->isAccepted()) {
QGraphicsView::mousePressEvent(e);
}
}
/**
2020-08-16 11:19:36 +02:00
@brief DiagramView::mouseMoveEvent
Manage the event move mouse
*/
void DiagramView::mouseMoveEvent(QMouseEvent *e)
{
setToolTip(tr("X: %1 Y: %2").arg(e->pos().x()).arg(e->pos().y()));
if (m_event_interface && m_event_interface->mouseMoveEvent(e)) return;
// 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)
#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)
#endif
{
QScrollBar *h = horizontalScrollBar();
QScrollBar *v = verticalScrollBar();
QPointF pos = m_drag_last_pos - e -> pos();
m_drag_last_pos = e -> pos();
h -> setValue(h -> value() + pos.x());
v -> setValue(v -> value() + pos.y());
adjustSceneRect();
}
else if (m_free_rubberbanding)
{
//Update old free rubberband
if (viewportUpdateMode() != QGraphicsView::NoViewportUpdate && !m_free_rubberband.isEmpty())
{
if (viewportUpdateMode() != QGraphicsView::FullViewportUpdate) {
viewport()->update(m_free_rubberband.boundingRect().toRect().adjusted(-10,-10,10,10));
}
else {
update();
}
}
//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);
if (viewportUpdateMode() != QGraphicsView::NoViewportUpdate)
{
if (viewportUpdateMode() != QGraphicsView::FullViewportUpdate) {
viewport()->update(mapFromScene(m_free_rubberband.boundingRect().adjusted(-10,-10,10,10)));
}
else {
update();
}
}
//Set the new selection area
QPainterPath selection_area;
selection_area.addPolygon(m_free_rubberband);
m_diagram->setSelectionArea(selection_area);
}
else QGraphicsView::mouseMoveEvent(e);
}
/**
2020-08-16 11:19:36 +02:00
@brief DiagramView::mouseReleaseEvent
Manage event release click mouse
*/
void DiagramView::mouseReleaseEvent(QMouseEvent *e)
{
if (m_event_interface && m_event_interface->mouseReleaseEvent(e)) return;
// Stop drag view
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 1) // ### Qt 6: remove
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
{
viewport()->setCursor(Qt::ArrowCursor);
}
else if (m_free_rubberbanding && !e->buttons())
{
if (viewportUpdateMode() != QGraphicsView::NoViewportUpdate)
{
if (viewportUpdateMode() != QGraphicsView::FullViewportUpdate)
{
QRectF r(mapFromScene(m_free_rubberband).boundingRect());
r.adjust(-10, -10, 10, 10);
viewport()->update(r.toRect());
}
else
{
update();
}
}
if (m_free_rubberband.count() > 3)
{
//Popup a menu with an action to create conductors between
//all selected terminals.
QAction *act = new QAction(tr("Connecter les bornes sélectionnées"), this);
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
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
}
m_free_rubberbanding = false;
m_free_rubberband = QPolygon();
emit freeRubberBandChanged(m_free_rubberband);
e->accept();
}
else
QGraphicsView::mouseReleaseEvent(e);
}
/**
2020-08-16 11:19:36 +02:00
@brief DiagramView::gestures
@return
*/
bool DiagramView::gestures() const
{
QSettings settings;
return(settings.value("diagramview/gestures", false).toBool());
}
/**
2020-08-20 21:57:35 +02:00
@brief DiagramView::wheelEvent
Manage wheel event of mouse
2020-08-20 21:57:35 +02:00
@param event QWheelEvent
*/
void DiagramView::wheelEvent(QWheelEvent *event)
{
if (m_event_interface && m_event_interface->wheelEvent(event)) return;
//Zoom and scrolling
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);
}
else
QGraphicsView::wheelEvent(event);
}
/**
2020-08-16 11:19:36 +02:00
@brief DiagramView::gestureEvent
Use the pinch of the trackpad for zoom
@param event
@return
*/
bool DiagramView::gestureEvent(QGestureEvent *event)
{
if (QGesture *gesture = event->gesture(Qt::PinchGesture))
{
QPinchGesture *pinch = static_cast<QPinchGesture *>(gesture);
if (pinch->changeFlags() & QPinchGesture::ScaleFactorChanged)
{
qreal value = gesture->property("scaleFactor").toReal();
value > 1 ? zoom(1.02) : zoom(0.98);
}
}
return true;
}
/**
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) {
m_fresh_focus_in = true;
}
}
/**
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
*/
void DiagramView::keyPressEvent(QKeyEvent *e)
{
if (m_event_interface && m_event_interface->keyPressEvent(e))
return;
ProjectView *current_project = this->diagramEditor()->currentProjectView();
DiagramContent dc(m_diagram);
switch(e -> key())
{
case Qt::Key_PageUp:
current_project->changeTabUp();
return;
case Qt::Key_PageDown:
current_project->changeTabDown();
return;
case Qt::Key_Home:
if (dc.selectedTexts().isEmpty()) {
if (
qgraphicsitem_cast<IndependentTextItem *>(m_diagram->focusItem()) ||
qgraphicsitem_cast<ConductorTextItem *>(m_diagram->focusItem()) ||
qgraphicsitem_cast<DiagramTextItem *>(m_diagram->focusItem())
)
break;
current_project->changeFirstTab();
return;
}
else break;
case Qt::Key_End:
if (dc.selectedTexts().isEmpty()) {
if (
qgraphicsitem_cast<IndependentTextItem *>(m_diagram->focusItem()) ||
qgraphicsitem_cast<ConductorTextItem *>(m_diagram->focusItem()) ||
qgraphicsitem_cast<DiagramTextItem *>(m_diagram->focusItem())
)
break;
current_project->changeLastTab();
return;
}
else break;
case Qt::Key_ZoomOut:
zoom(0.85);
return;
case Qt::Key_ZoomIn:
zoom(1.15);
return;
case Qt::Key_Minus: {
if (e->modifiers() & Qt::ControlModifier)
zoom(0.85);
}
break;
case Qt::Key_Plus: {
if (e->modifiers() & Qt::ControlModifier)
zoom(1.15);
}
break;
case Qt::Key_Up: {
if(!dc.items(DiagramContent::All).isEmpty() && !dc.hasTextEditing())
scrollOnMovement(e);
}
break;
case Qt::Key_Down: {
if(!dc.items(DiagramContent::All).isEmpty() && !dc.hasTextEditing())
scrollOnMovement(e);
}
break;
case Qt::Key_Left: {
if(!dc.items(DiagramContent::All).isEmpty() && !dc.hasTextEditing())
scrollOnMovement(e);
}
break;
case Qt::Key_Right: {
if(!dc.items(DiagramContent::All).isEmpty() && !dc.hasTextEditing())
scrollOnMovement(e);
}
break;
}
switchToVisualisationModeIfNeeded(e);
QGraphicsView::keyPressEvent(e);
}
/**
Handles "key release" events. Reimplemented here to switch to selection
mode if needed.
*/
void DiagramView::keyReleaseEvent(QKeyEvent *e) {
if (m_event_interface && m_event_interface->KeyReleaseEvent(e)) return;
switchToSelectionModeIfNeeded(e);
QGraphicsView::keyReleaseEvent(e);
}
/**
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
*/
void DiagramView::scrollOnMovement(QKeyEvent *e)
{
const QList<QGraphicsItem *> selected_elmts = DiagramContent(m_diagram).items(DiagramContent::All);
QRectF viewed_scene = viewedSceneRect();
for (QGraphicsItem *qgi : selected_elmts)
{
if (qgraphicsitem_cast<Conductor *>(qgi))
continue;
if(qgi->parentItem() && qgi->parentItem()->isSelected())
continue;
qreal x = qgi->pos().x();
qreal y = qgi->pos().y();
qreal bottom = viewed_scene.bottom();
qreal top = viewed_scene.top();
qreal left = viewed_scene.left();
qreal right = viewed_scene.right();
qreal elmt_top = y + qgi->boundingRect().top();
qreal elmt_bottom = y + qgi->boundingRect().bottom();
qreal elmt_right = x + qgi->boundingRect().right();
qreal elmt_left = x + qgi->boundingRect().left();
bool elmt_right_of_left_margin = elmt_left>=left;
bool elmt_left_of_right_margin = elmt_right<=right;
bool elmt_below_top_margin = elmt_top>=top;
bool elmt_above_bottom_margin = elmt_bottom<=bottom;
if (!(elmt_right_of_left_margin && elmt_left_of_right_margin) ||
!(elmt_below_top_margin && elmt_above_bottom_margin ) )
{
QScrollBar *h = horizontalScrollBar();
QScrollBar *v = verticalScrollBar();
int h_increment=0;
int v_increment=0;
if (e->key()==Qt::Key_Up && elmt_above_bottom_margin) {
v_increment = 2*qgi->boundingRect().top();
if (v_increment == 0) v_increment = -2*qgi->boundingRect().height();
}
else if(e->key()==Qt::Key_Down && elmt_below_top_margin) {
v_increment = 2*qgi->boundingRect().bottom();
if (v_increment == 0) v_increment = -2*qgi->boundingRect().height();
}
else if (e->key()==Qt::Key_Left && elmt_left_of_right_margin) {
h_increment = 2*qgi->boundingRect().left();
if (h_increment == 0) h_increment = -2*qgi->boundingRect().width();
}
else if (e->key()==Qt::Key_Right && elmt_right_of_left_margin) {
h_increment = 2*qgi->boundingRect().right();
if (h_increment == 0) h_increment = -2*qgi->boundingRect().width();
}
if (((elmt_right >= m_diagram->sceneRect().right() - qgi->boundingRect().right()) ||
(elmt_bottom >= m_diagram->sceneRect().bottom() - qgi->boundingRect().bottom())) &&
(e->key()==Qt::Key_Right || e->key()==Qt::Key_Down)){
m_diagram->adjustSceneRect();
}
h -> setValue(h -> value() + h_increment);
v -> setValue(v -> value() + v_increment);
}
}
}
/**
@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()
*/
2020-09-07 22:03:40 +02:00
QString DiagramView::title() const
{
QString view_title;
QString diagram_title(m_diagram -> title());
if (diagram_title.isEmpty()) {
view_title = tr("Sans titre", "what to display for untitled diagrams");
} else {
view_title = diagram_title;
}
return(view_title);
}
/**
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()
{
DiagramPropertiesDialog::diagramPropertiesDialog(m_diagram, diagramEditor());
}
/**
2020-08-16 11:19:36 +02:00
@brief DiagramView::adjustSceneRect
Calcul and set the area of the scene visualized by this view
*/
void DiagramView::adjustSceneRect()
{
QRectF scene_rect = m_diagram->sceneRect();
scene_rect.adjust(-Diagram::margin, -Diagram::margin, Diagram::margin, Diagram::margin);
QSettings settings;
if (settings.value("diagrameditor/zoom-out-beyond-of-folio", false).toBool())
{
//When zoom out beyond of folio is active,
//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);
}
setSceneRect(scene_rect);
}
/**
Met a jour le titre du widget
*/
2020-09-07 22:03:40 +02:00
void DiagramView::updateWindowTitle()
{
emit(titleChanged(this, title()));
}
/**
Enables or disables the drawing grid according to the amount of pixels display
*/
2020-09-07 22:03:40 +02:00
void DiagramView::adjustGridToZoom()
{
QRectF viewed_scene = viewedSceneRect();
if (diagramEditor()->drawGrid())
m_diagram->setDisplayGrid(viewed_scene.width() < 2000 || viewed_scene.height() < 2000);
else
m_diagram->setDisplayGrid(false);
}
/**
@return le rectangle du schema (classe Diagram) visualise par ce DiagramView
*/
2020-09-07 22:03:40 +02: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));
}
/**
@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
{
// 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
QETProject *tbt_parent_project = tbt_loc.parentProject();
if (!tbt_parent_project) return(true);
return(tbt_parent_project != m_diagram -> project());
}
/**
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()
{
if (!m_diagram) return;
bool is_writable = !m_diagram -> isReadOnly();
setInteractive(is_writable);
setAcceptDrops(is_writable);
}
/**
Reinitialise le profil des conducteurs selectionnes
*/
2020-09-07 22:03:40 +02:00
void DiagramView::resetConductors()
{
if (m_diagram -> isReadOnly()) return;
// recupere les conducteurs selectionnes
QSet<Conductor *> selected_conductors = m_diagram -> selectedConductors();
// repere les conducteurs modifies (= profil non nul)
QHash<Conductor *, ConductorProfilesGroup> conductors_and_profiles;
foreach(Conductor *conductor, selected_conductors) {
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);
}
}
if (conductors_and_profiles.isEmpty()) return;
m_diagram -> undoStack().push(new ResetConductorCommand(conductors_and_profiles));
}
/**
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
*/
bool DiagramView::event(QEvent *e) {
if (Q_UNLIKELY(m_first_activation)) {
if (e -> type() == QEvent::Show) {
zoomFit();
m_first_activation = false;
}
}
// 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));
// fait en sorte que les raccourcis clavier arrivent prioritairement sur la
// vue plutot que de remonter vers les QMenu / QAction
if (
e -> type() == QEvent::ShortcutOverride &&
selectedItemHasFocus()
) {
e -> accept();
return(true);
}
return(QGraphicsView::event(e));
}
/**
2020-08-16 11:19:36 +02:00
@brief DiagramView::paintEvent
Reimplemented from QGraphicsView
@param event
*/
void DiagramView::paintEvent(QPaintEvent *event)
{
QGraphicsView::paintEvent(event);
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));
}
}
/**
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) {
if (!selectedItemHasFocus() && !isCtrlShifting(e)) {
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) {
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.
*/
2020-09-07 22:03:40 +02:00
bool DiagramView::selectedItemHasFocus()
{
return(
m_diagram -> hasFocus() &&
m_diagram -> focusItem() &&
m_diagram -> focusItem() -> isSelected()
);
}
/**
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()
{
if (m_diagram -> isReadOnly() || m_diagram -> selectedItems().size() != 1 ) return;
QGraphicsItem *item = m_diagram->selectedItems().first();
//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.
if (IndependentTextItem *iti = qgraphicsitem_cast<IndependentTextItem *>(item))
iti -> edit();
else if (QetGraphicsItem *qgi = dynamic_cast<QetGraphicsItem *> (item))
qgi -> editProperty();
else if (Conductor *c = qgraphicsitem_cast<Conductor *>(item))
c -> editProperty();
}
/**
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
*/
void DiagramView::setEventInterface(DVEventInterface *event_interface)
{
if (m_event_interface) delete m_event_interface;
Merge Qt5 branch sources folder to trunk -Cette ligne, et les suivantes ci-dessous, seront ignorées-- M sources/aboutqet.cpp M sources/bordertitleblock.cpp M sources/conductorproperties.h M sources/configdialog.cpp M sources/configpages.cpp M sources/configpages.h M sources/createdxf.h M sources/diagram.cpp M sources/diagram.h M sources/diagramcommands.cpp M sources/diagramcommands.h M sources/diagramprintdialog.cpp M sources/diagramprintdialog.h M sources/diagramschooser.cpp M sources/diagramschooser.h M sources/diagramview.cpp M sources/diagramview.h M sources/dvevent/dveventaddimage.cpp M sources/dvevent/dveventaddshape.cpp M sources/editor/arceditor.cpp M sources/editor/arceditor.h M sources/editor/editorcommands.cpp M sources/editor/editorcommands.h M sources/editor/elementitemeditor.h M sources/editor/elementprimitivedecorator.cpp M sources/editor/elementscene.cpp M sources/editor/elementscene.h M sources/editor/elementview.cpp M sources/editor/ellipseeditor.cpp M sources/editor/ellipseeditor.h M sources/editor/esevent/eseventaddtext.cpp M sources/editor/esevent/eseventaddtextfield.cpp M sources/editor/esevent/eseventinterface.cpp M sources/editor/graphicspart/customelementpart.h M sources/editor/graphicspart/parttext.cpp M sources/editor/graphicspart/parttext.h M sources/editor/graphicspart/parttextfield.cpp M sources/editor/graphicspart/parttextfield.h M sources/editor/lineeditor.cpp M sources/editor/lineeditor.h M sources/editor/polygoneditor.cpp M sources/editor/qetelementeditor.cpp M sources/editor/qetelementeditor.h M sources/editor/rectangleeditor.cpp M sources/editor/rectangleeditor.h M sources/editor/styleeditor.cpp M sources/editor/styleeditor.h M sources/editor/terminaleditor.cpp M sources/editor/terminaleditor.h M sources/editor/texteditor.cpp M sources/editor/texteditor.h M sources/editor/textfieldeditor.cpp M sources/editor/textfieldeditor.h M sources/editor/ui/elementpropertieseditorwidget.cpp M sources/elementdefinition.cpp M sources/elementdeleter.cpp M sources/elementdeleter.h M sources/elementdialog.cpp M sources/elementscategorieslist.h M sources/elementscategorieswidget.cpp M sources/elementscategorieswidget.h M sources/elementscategory.cpp M sources/elementscategorydeleter.cpp M sources/elementscategorydeleter.h M sources/elementscategoryeditor.cpp M sources/elementscategoryeditor.h M sources/elementscollection.cpp M sources/elementscollectioncache.cpp M sources/elementspanel.cpp M sources/elementspanel.h M sources/elementspanelwidget.cpp M sources/elementspanelwidget.h M sources/elementtextsmover.h M sources/exportdialog.cpp M sources/exportdialog.h M sources/exportproperties.cpp M sources/exportpropertieswidget.cpp M sources/exportpropertieswidget.h M sources/genericpanel.cpp M sources/integrationmoveelementshandler.cpp M sources/integrationmoveelementshandler.h M sources/interactivemoveelementshandler.cpp M sources/nameslistwidget.cpp M sources/nameslistwidget.h M sources/newelementwizard.cpp M sources/newelementwizard.h M sources/nomenclature.cpp M sources/nomenclature.h M sources/projectconfigpages.cpp M sources/projectview.cpp M sources/projectview.h M sources/qet.cpp M sources/qetapp.cpp M sources/qetapp.h M sources/qetdiagrameditor.cpp M sources/qetdiagrameditor.h M sources/qetgraphicsitem/conductor.cpp M sources/qetgraphicsitem/conductortextitem.cpp M sources/qetgraphicsitem/customelement.cpp M sources/qetgraphicsitem/diagramimageitem.cpp M sources/qetgraphicsitem/diagramtextitem.cpp M sources/qetgraphicsitem/diagramtextitem.h M sources/qetgraphicsitem/element.cpp M sources/qetgraphicsitem/ghostelement.cpp M sources/qetgraphicsitem/qetshapeitem.cpp M sources/qetgraphicsitem/terminal.cpp M sources/qetgraphicsitem/terminal.h M sources/qeticons.cpp M sources/qeticons.h M sources/qetmainwindow.cpp M sources/qetmessagebox.cpp M sources/qetmessagebox.h M sources/qetprintpreviewdialog.cpp M sources/qetprintpreviewdialog.h M sources/qetproject.cpp M sources/qetsingleapplication.cpp M sources/qettabbar.h M sources/qfilenameedit.cpp M sources/qtextorientationspinboxwidget.cpp M sources/qtextorientationspinboxwidget.h M sources/qtextorientationwidget.cpp M sources/qtextorientationwidget.h M sources/richtext/richtexteditor.cpp M sources/richtext/richtexteditor_p.h M sources/richtext/ui_addlinkdialog.h M sources/titleblock/dimensionwidget.h M sources/titleblock/gridlayoutanimation.h M sources/titleblock/helpercell.h M sources/titleblock/integrationmovetemplateshandler.cpp M sources/titleblock/integrationmovetemplateshandler.h M sources/titleblock/qettemplateeditor.cpp M sources/titleblock/qettemplateeditor.h M sources/titleblock/templatecellsset.h M sources/titleblock/templatecellwidget.cpp M sources/titleblock/templatecellwidget.h M sources/titleblock/templatecommands.cpp M sources/titleblock/templatedeleter.cpp M sources/titleblock/templatedeleter.h M sources/titleblock/templatelocationchooser.cpp M sources/titleblock/templatelocationchooser.h M sources/titleblock/templatelocationsaver.cpp M sources/titleblock/templatelocationsaver.h M sources/titleblock/templatelogomanager.cpp M sources/titleblock/templatelogomanager.h M sources/titleblock/templateview.cpp M sources/titleblock/templatevisualcell.h M sources/titleblockcell.cpp M sources/titleblocktemplate.cpp M sources/treecoloranimation.h M sources/ui/conductorpropertieswidget.cpp M sources/ui/diagrampropertiesdialog.cpp M sources/ui/diagramselection.cpp M sources/ui/dialogautonum.cpp M sources/ui/dialogwaiting.cpp M sources/ui/elementpropertieswidget.cpp M sources/ui/elementselectorwidget.cpp M sources/ui/linksingleelementwidget.cpp M sources/ui/masterpropertieswidget.cpp M sources/ui/potentialtextsdialog.cpp M sources/ui/projectpropertiesdialog.cpp M sources/ui/selectautonumw.cpp M sources/ui/titleblockpropertieswidget.cpp M sources/ui/xrefpropertieswidget.cpp M sources/undocommand/changeelementinformationcommand.cpp git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3783 bfdf4180-ca20-0410-9c96-a3a8aa849046
2015-03-02 20:14:56 +00:00
m_event_interface = event_interface;
connect(m_event_interface, &DVEventInterface::finish, this, [=](){delete this->m_event_interface; this->m_event_interface = nullptr;}, Qt::QueuedConnection);
}
/**
2020-08-16 11:19:36 +02:00
@brief DiagramView::contextMenuActions
@return a list of actions currently available for a context menu.
*/
QList<QAction *> DiagramView::contextMenuActions() const
{
QList<QAction *> list;
if (QETDiagramEditor *qde = diagramEditor())
{
if (m_diagram->selectedItems().isEmpty())
{
list << m_paste_here;
list << m_separators.at(0);
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;
list << m_separators.at(0);
list << qde->m_conductor_reset;
list << m_separators.at(1);
list << qde->m_selection_actions_group.actions();
list << m_separators.at(2);
list << qde->m_depth_action_group->actions();
}
//Remove from the context menu the actions which are disabled.
const QList<QAction *> actions = list;
for(QAction *action : actions)
{
if (!action->isEnabled()) {
list.removeAll(action);
}
}
}
return list;
}
/**
2020-08-16 11:19:36 +02:00
@brief DiagramView::contextMenuEvent
@param e
*/
void DiagramView::contextMenuEvent(QContextMenuEvent *e)
{
if (auto qgi = m_diagram->itemAt(mapToScene(e->pos()), transform()))
{
if (!qgi->isSelected()) {
m_diagram->clearSelection();
}
// At this step qgi can be deleted for example if qgi is a QetGraphicsHandlerItem.
// 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);
}
}
if (m_diagram->selectedItems().isEmpty())
{
m_paste_here_pos = e->pos();
m_paste_here->setEnabled(Diagram::clipboardMayContainDiagram());
}
QList <QAction *> list = contextMenuActions();
if(!list.isEmpty())
{
QMenu *context_menu = new QMenu(this);
context_menu->addActions(list);
context_menu->popup(e->globalPos());
e->accept();
}
}
/**
@return l'editeur de schemas parent ou 0
*/
2020-09-07 22:03:40 +02: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));
}
/**
2020-08-16 11:19:36 +02:00
@brief DiagramView::mouseDoubleClickEvent
@param e
*/
void DiagramView::mouseDoubleClickEvent(QMouseEvent *e)
{
if (m_event_interface && m_event_interface -> mouseDoubleClickEvent(e)) return;
BorderTitleBlock &bi = m_diagram -> border_and_titleblock;
//Get the click pos on the diagram
QPointF click_pos = viewportTransform().inverted().map(e -> pos());
if (bi.titleBlockRect().contains(click_pos) || bi.columnsRect().contains(click_pos) || bi.rowsRect().contains(click_pos)) {
e->accept();
editDiagramProperties();
return;
}
QGraphicsView::mouseDoubleClickEvent(e);
}