34 #include <QGraphicsObject> 35 #include <QGraphicsPixmapItem> 36 #include <QGraphicsSceneMouseEvent> 55 QGraphicsView (parent),
58 grabGesture(Qt::PinchGesture);
59 setAttribute(Qt::WA_DeleteOnClose,
true);
62 QString whatsthis =
tr(
63 "Ceci est la zone dans laquelle vous concevez vos schémas en y ajoutant" 64 " des éléments et en posant des conducteurs entre leurs bornes. Il est" 65 " également possible d'ajouter des textes indépendants.",
66 "\"What's this?\" tip" 68 setWhatsThis(whatsthis);
71 setRenderHint(QPainter::Antialiasing,
true);
72 setRenderHint(QPainter::TextAntialiasing,
true);
73 setRenderHint(QPainter::SmoothPixmapTransform,
true);
78 setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
79 setResizeAnchor(QGraphicsView::AnchorUnderMouse);
80 setAlignment(Qt::AlignLeft | Qt::AlignTop);
97 for(
int i=0 ; i<3 ; ++i)
106 connect(&(
m_diagram -> border_and_titleblock), SIGNAL(diagramTitleChanged(
const QString &)),
this, SLOT(
updateWindowTitle()));
110 QShortcut *edit_conductor_color_shortcut =
new QShortcut(QKeySequence(Qt::Key_F2),
this);
146 if (e -> mimeData() -> hasFormat(
"application/x-qet-element-uri")) {
147 e -> acceptProposedAction();
148 }
else if (e -> mimeData() -> hasFormat(
"application/x-qet-titleblock-uri")) {
149 e -> acceptProposedAction();
150 }
else if (e -> mimeData() -> hasText()) {
151 e -> acceptProposedAction();
162 if (e -> mimeData() -> hasFormat(
"text/plain")) e -> acceptProposedAction();
172 if (e -> mimeData() -> hasFormat(
"application/x-qet-element-uri")) {
174 }
else if (e -> mimeData() -> hasFormat(
"application/x-qet-titleblock-uri")) {
176 }
else if (e -> mimeData() -> hasText()) {
190 if ( !(location.isElement() && location.exist()) )
192 qDebug() <<
"DiagramView::handleElementDrop, location can't be use : " << location;
219 if (tbt_parent_project && tbt_parent_project ==
m_diagram -> project())
227 QString integrated_template_name = tbt_loc.
name();
234 if (integrated_template_name.isEmpty())
239 if (titleblock_properties_before.
template_name == integrated_template_name)
243 titleblock_properties_after.
template_name = integrated_template_name;
256 if (
m_diagram -> isReadOnly() || (e -> mimeData() -> hasText() ==
false) )
return;
260 if (e -> mimeData() -> hasHtml()) {
261 iti -> setHtml (e -> mimeData() -> text());
271 setDragMode(ScrollHandDrag);
273 setInteractive(
false);
281 setDragMode(RubberBandDrag);
282 setInteractive(
true);
296 if (zoom_factor >= 1){
297 scale(zoom_factor, zoom_factor);
302 if (settings.value(
"diagrameditor/zoom-out-beyond-of-folio",
false).toBool() ||
303 (horizontalScrollBar()->maximum() || verticalScrollBar()->maximum()) )
304 if (zoom_factor >= 0){
305 scale(zoom_factor, zoom_factor);
320 fitInView(
m_diagram->sceneRect(), Qt::KeepAspectRatio);
328 fitInView(
m_diagram -> itemsBoundingRect(), Qt::KeepAspectRatio);
354 QClipboard *presse_papier = QApplication::clipboard();
355 QString contenu_presse_papier =
m_diagram -> toXml(
false).toString(4);
356 if (presse_papier -> supportsSelection()) presse_papier -> setText(contenu_presse_papier, QClipboard::Selection);
357 presse_papier -> setText(contenu_presse_papier);
367 if (!isInteractive() ||
m_diagram -> isReadOnly())
return;
369 QString texte_presse_papier = QApplication::clipboard() -> text(clipboard_mode);
370 if ((texte_presse_papier).isEmpty())
return;
372 QDomDocument document_xml;
373 if (!document_xml.setContent(texte_presse_papier))
return;
379 if (content_pasted.
count())
411 if (e->button() == Qt::MidButton)
414 viewport()->setCursor(Qt::ClosedHandCursor);
422 if (e->button() == Qt::LeftButton &&
423 e->modifiers() == Qt::CTRL)
425 QGraphicsView::DragMode dm = dragMode();
426 setDragMode(QGraphicsView::NoDrag);
427 QGraphicsView::mousePressEvent(e);
430 QGraphicsView::mousePressEvent(e);
433 if (e->isAccepted()) {
437 if (e->button() == Qt::LeftButton &&
438 e->modifiers() == Qt::CTRL)
446 if (!e->isAccepted()) {
447 QGraphicsView::mousePressEvent(e);
460 if (e->buttons() == Qt::MidButton)
462 QScrollBar *h = horizontalScrollBar();
463 QScrollBar *v = verticalScrollBar();
466 h -> setValue(h -> value() + pos.x());
467 v -> setValue(v -> value() + pos.y());
473 if (viewportUpdateMode() != QGraphicsView::NoViewportUpdate && !
m_free_rubberband.isEmpty())
475 if (viewportUpdateMode() != QGraphicsView::FullViewportUpdate) {
476 viewport()->update(
m_free_rubberband.boundingRect().toRect().adjusted(-10,-10,10,10));
493 if (viewportUpdateMode() != QGraphicsView::NoViewportUpdate)
495 if (viewportUpdateMode() != QGraphicsView::FullViewportUpdate) {
496 viewport()->update(mapFromScene(
m_free_rubberband.boundingRect().adjusted(-10,-10,10,10)));
504 QPainterPath selection_area;
506 m_diagram->setSelectionArea(selection_area);
509 else QGraphicsView::mouseMoveEvent(e);
521 if (e -> button() == Qt::MidButton)
523 viewport()->setCursor(Qt::ArrowCursor);
527 if (viewportUpdateMode() != QGraphicsView::NoViewportUpdate)
529 if (viewportUpdateMode() != QGraphicsView::FullViewportUpdate)
532 r.adjust(-10, -10, 10, 10);
533 viewport()->update(r.toRect());
545 QAction *act =
new QAction(
tr(
"Connecter les bornes sélectionnées"),
this);
547 connect(act, &QAction::triggered, [
this, polygon_]()
552 QMenu *menu =
new QMenu(
this);
553 menu->addAction(act);
554 menu->popup(e->globalPos());
563 QGraphicsView::mouseReleaseEvent(e);
573 return(settings.value(
"diagramview/gestures",
false).toBool());
585 QPoint angle =
event->angleDelta();
589 if (
event->modifiers() == Qt::ControlModifier)
591 qreal value = angle.y();
592 zoom(1 + value/1000);
596 horizontalScrollBar()->setValue(horizontalScrollBar()->value() - angle.x());
597 verticalScrollBar()->setValue(verticalScrollBar()->value() - angle.y());
600 else if (
event->modifiers() == Qt::NoModifier)
602 qreal value = angle.y();
603 zoom(1 + value/1000);
606 QGraphicsView::wheelEvent(
event);
617 if (QGesture *gesture =
event->gesture(Qt::PinchGesture))
619 QPinchGesture *pinch =
static_cast<QPinchGesture *
>(gesture);
620 if (pinch->changeFlags() & QPinchGesture::ScaleFactorChanged)
622 qreal value = gesture->property(
"scaleFactor").toReal();
623 value > 1 ?
zoom(1.02) :
zoom(0.98);
637 if (e -> reason() == Qt::MouseFocusReason) {
660 case Qt::Key_PageDown:
666 qgraphicsitem_cast<IndependentTextItem *>(
m_diagram->focusItem()) ||
667 qgraphicsitem_cast<ConductorTextItem *>(
m_diagram->focusItem()) ||
668 qgraphicsitem_cast<DiagramTextItem *>(
m_diagram->focusItem())
678 qgraphicsitem_cast<IndependentTextItem *>(
m_diagram->focusItem()) ||
679 qgraphicsitem_cast<ConductorTextItem *>(
m_diagram->focusItem()) ||
680 qgraphicsitem_cast<DiagramTextItem *>(
m_diagram->focusItem())
687 case Qt::Key_ZoomOut:
693 case Qt::Key_Minus: {
694 if (e->modifiers() & Qt::ControlModifier)
699 if (e->modifiers() & Qt::ControlModifier)
718 case Qt::Key_Right: {
726 QGraphicsView::keyPressEvent(e);
737 QGraphicsView::keyReleaseEvent(e);
749 for (QGraphicsItem *qgi : selected_elmts)
751 if (qgraphicsitem_cast<Conductor *>(qgi))
753 if(qgi->parentItem() && qgi->parentItem()->isSelected())
756 qreal x = qgi->pos().x();
757 qreal y = qgi->pos().y();
758 qreal bottom = viewed_scene.bottom();
759 qreal top = viewed_scene.top();
760 qreal left = viewed_scene.left();
761 qreal right = viewed_scene.right();
762 qreal elmt_top = y + qgi->boundingRect().top();
763 qreal elmt_bottom = y + qgi->boundingRect().bottom();
764 qreal elmt_right = x + qgi->boundingRect().right();
765 qreal elmt_left = x + qgi->boundingRect().left();
767 bool elmt_right_of_left_margin = elmt_left>=left;
768 bool elmt_left_of_right_margin = elmt_right<=right;
769 bool elmt_below_top_margin = elmt_top>=top;
770 bool elmt_above_bottom_margin = elmt_bottom<=bottom;
772 if (!(elmt_right_of_left_margin && elmt_left_of_right_margin) ||
773 !(elmt_below_top_margin && elmt_above_bottom_margin ) )
775 QScrollBar *h = horizontalScrollBar();
776 QScrollBar *v = verticalScrollBar();
779 if (e->key()==Qt::Key_Up && elmt_above_bottom_margin) {
780 v_increment = 2*qgi->boundingRect().top();
781 if (v_increment == 0) v_increment = -2*qgi->boundingRect().height();
783 else if(e->key()==Qt::Key_Down && elmt_below_top_margin) {
784 v_increment = 2*qgi->boundingRect().bottom();
785 if (v_increment == 0) v_increment = -2*qgi->boundingRect().height();
787 else if (e->key()==Qt::Key_Left && elmt_left_of_right_margin) {
788 h_increment = 2*qgi->boundingRect().left();
789 if (h_increment == 0) h_increment = -2*qgi->boundingRect().width();
791 else if (e->key()==Qt::Key_Right && elmt_right_of_left_margin) {
792 h_increment = 2*qgi->boundingRect().right();
793 if (h_increment == 0) h_increment = -2*qgi->boundingRect().width();
795 if (((elmt_right >=
m_diagram->sceneRect().right() - qgi->boundingRect().right()) ||
796 (elmt_bottom >=
m_diagram->sceneRect().bottom() - qgi->boundingRect().bottom())) &&
797 (e->key()==Qt::Key_Right || e->key()==Qt::Key_Down)){
800 h -> setValue(h -> value() + h_increment);
801 v -> setValue(v -> value() + v_increment);
816 if (diagram_title.isEmpty()) {
817 view_title =
tr(
"Sans titre",
"what to display for untitled diagrams");
819 view_title = diagram_title;
838 QRectF scene_rect =
m_diagram->sceneRect();
842 if (settings.value(
"diagrameditor/zoom-out-beyond-of-folio",
false).toBool())
846 QRectF vpbr = mapToScene(viewport()->rect()).boundingRect();
847 vpbr.adjust(0, 0, vpbr.width()/3, vpbr.height()/3);
848 scene_rect = scene_rect.united(vpbr);
850 setSceneRect(scene_rect);
876 QSize viewport_size = viewport() -> size();
879 QTransform view_to_scene = viewportTransform().inverted();
882 QPointF scene_left_top = view_to_scene.map(QPointF(0.0, 0.0));
883 QPointF scene_right_bottom = view_to_scene.map(QPointF(viewport_size.width(), viewport_size.height()));
886 return(QRectF(scene_left_top, scene_right_bottom));
898 if (!tbt_parent_project)
return(
true);
900 return(tbt_parent_project !=
m_diagram -> project());
910 bool is_writable = !
m_diagram -> isReadOnly();
911 setInteractive(is_writable);
912 setAcceptDrops(is_writable);
926 if (selected_conductors.count() == 1) {
937 if (
m_diagram -> isReadOnly() || !edited_conductor)
return;
943 QColorDialog *color_dialog =
new QColorDialog(
this);
944 color_dialog -> setWindowTitle(
tr(
"Choisir la nouvelle couleur de ce conducteur"));
946 color_dialog -> setWindowFlags(Qt::Sheet);
948 color_dialog -> setCurrentColor(initial_properties.
color);
951 if (color_dialog -> exec() == QDialog::Accepted)
953 QColor new_color = color_dialog -> selectedColor();
954 if (new_color != initial_properties.
color)
957 QVariant old_value, new_value;
958 old_value.setValue(initial_properties);
959 initial_properties.
color = new_color;
960 new_value.setValue(initial_properties);
963 undo->setText(
tr(
"Modifier les propriétés d'un conducteur",
"undo caption"));
964 diagram() -> undoStack().push(undo);
975 QSet<Conductor *> selected_conductors =
m_diagram -> selectedConductors();
978 QHash<Conductor *, ConductorProfilesGroup> conductors_and_profiles;
979 foreach(
Conductor *conductor, selected_conductors) {
982 !profile[Qt::TopLeftCorner].isNull() ||\
983 !profile[Qt::TopRightCorner].isNull() ||\
984 !profile[Qt::BottomLeftCorner].isNull() ||\
985 !profile[Qt::BottomRightCorner].isNull()
987 conductors_and_profiles.insert(conductor, profile);
991 if (conductors_and_profiles.isEmpty())
return;
1010 if (e -> type() == QEvent::Show) {
1019 if (e->type() == QEvent::Gesture)
1025 e -> type() == QEvent::ShortcutOverride &&
1031 return(QGraphicsView::event(e));
1041 QGraphicsView::paintEvent(
event);
1045 QPainter painter(viewport());
1046 painter.setRenderHint(QPainter::Antialiasing);
1047 QPen pen(Qt::darkGreen);
1049 painter.setPen(pen);
1050 QColor color(Qt::darkGreen);
1052 QBrush brush(color);
1053 painter.setBrush(brush);
1065 if (dragMode() != QGraphicsView::ScrollHandDrag) {
1090 bool result =
false;
1093 if (e -> type() == QEvent::KeyPress || e -> type() == QEvent::KeyRelease) {
1094 if (QKeyEvent *ke = static_cast<QKeyEvent *>(e)) {
1095 result = (ke -> modifiers() == (Qt::ControlModifier | Qt::ShiftModifier));
1097 }
else if (e -> type() >= QEvent::MouseButtonPress && e -> type() <= QEvent::MouseMove) {
1098 if (QMouseEvent *me = static_cast<QMouseEvent *>(e)) {
1099 result = (me -> modifiers() == (Qt::ControlModifier | Qt::ShiftModifier));
1112 m_diagram -> focusItem() -> isSelected()
1123 QGraphicsItem *item =
m_diagram->selectedItems().first();
1130 else if (
QetGraphicsItem *qgi = dynamic_cast<QetGraphicsItem *> (item))
1131 qgi -> editProperty();
1132 else if (
Conductor *c = qgraphicsitem_cast<Conductor *>(item))
1133 c -> editProperty();
1156 QList<QAction *> list;
1163 list << qde->m_edit_diagram_properties;
1164 list << qde->m_row_column_actions_group.actions();
1169 list << qde->m_copy;
1172 list << qde->m_conductor_reset;
1174 list << qde->m_selection_actions_group.actions();
1176 list << qde->m_depth_action_group->actions();
1180 const QList<QAction *> actions = list;
1181 for(QAction *action : actions)
1183 if (!action->isEnabled()) {
1184 list.removeAll(action);
1198 QGraphicsView::contextMenuEvent(e);
1202 if (QGraphicsItem *qgi =
m_diagram->itemAt(mapToScene(e->pos()), transform()))
1204 if (!qgi -> isSelected()) {
1208 qgi->setSelected(
true);
1220 QMenu *context_menu =
new QMenu(
this);
1221 context_menu->addActions(list);
1222 context_menu->popup(e->globalPos());
1233 while (w -> parentWidget() && !w -> isWindow()) {
1234 w = w -> parentWidget();
1237 return(qobject_cast<QETDiagramEditor *>(w));
1251 QPointF click_pos = viewportTransform().inverted().map(e -> pos());
1258 QGraphicsView::mouseDoubleClickEvent(e);
void editConductorColor(Conductor *)
void changeFirstTab()
change current diagramview to first tab
The QPropertyUndoCommand class This undo command manage QProperty of a QObject. This undo command can...
void dragEnterEvent(QDragEnterEvent *) override
void focusInEvent(QFocusEvent *) override
void handleElementDrop(QDropEvent *)
QRectF columnsRect() const
BorderTitleBlock::columnsRect.
void setEventInterface(DVEventInterface *event_interface)
DiagramView::setEventInterface Set an event interface to diagram view. If diagram view already have a...
void setDisplayGrid(bool)
void changeTabDown()
change current diagramview to next folio
void zoom(const qreal zoom_factor)
DiagramView::zoom Zomm the view. A zoom_factor > 1 zoom in. A zoom_factor < 1 zoom out...
QList< DiagramTextItem * > selectedTexts() const
DiagramContent::selectedTexts.
QETDiagramEditor * diagramEditor() const
virtual bool keyPressEvent(QKeyEvent *event)
DVEventInterface::keyPressEvent By default, press escape key abort the curent action. isFinish return true, and emit finish.
void adjustSceneRect()
Diagram::adjustSceneRect Recalcul and adjust the size of the scene.
void scrollOnMovement(QKeyEvent *)
virtual bool switchToVisualisationModeIfNeeded(QInputEvent *e)
static const qreal margin
margin around the diagram
void mousePressEvent(QMouseEvent *) override
void findElementRequired(const ElementsLocation &)
Signal emitted when users wish to locate an element from the diagram within elements collection...
void modeChanged()
Signal emitted after the selection mode changed.
static void create(Diagram *d, const QPolygonF &polygon)
ConductorCreator::create Create an electrical potential between the terminals of the diagram d...
TitleBlockProperties exportTitleBlock()
void selectionChanged()
Signal emitted after the selection changed.
QRectF rowsRect() const
BorderTitleBlock::rowsRect.
void contextMenuEvent(QContextMenuEvent *) override
DiagramView::contextMenuEvent.
virtual bool KeyReleaseEvent(QKeyEvent *event)
The AddItemCommand class This command add an item in a diagram The item to add is template...
void changeTabUp()
change current diagramview to previous tab
void handleTextDrop(QDropEvent *)
DiagramView::handleTextDrop handle the drop of text.
DiagramView(Diagram *diagram, QWidget *=nullptr)
void paintEvent(QPaintEvent *event) override
DiagramView::paintEvent Reimplemented from QGraphicsView.
The ChangeTitleBlockCommand class This command changes the title block properties for a particular di...
QList< QGraphicsItem * > items(int=All) const
DiagramContent::items.
void editSelection()
DiagramView::editSelection Edit the selected item if he can be edited and if only one item is selecte...
virtual bool mouseReleaseEvent(QMouseEvent *event)
void finish()
finish emited when the interface finish is work
void adjustSceneRect()
DiagramView::adjustSceneRect Calcul and set the area of the scene visualized by this view...
QHash< Qt::Corner, ConductorProfile > ConductorProfilesGroup
void keyPressEvent(QKeyEvent *) override
DiagramView::keyPressEvent Handles "key press" events. Reimplemented here to switch to visualisation ...
void mouseDoubleClickEvent(QMouseEvent *) override
DiagramView::mouseDoubleClickEvent.
void keyReleaseEvent(QKeyEvent *) override
The DVEventInterface class This class is the main interface for manage event of a Diagram View...
void titleChanged(DiagramView *, const QString &)
Signal emitted after the diagram title changed.
QRectF titleBlockRect() const
BorderTitleBlock::titleBlockRect.
void editSelectedConductorColor()
DiagramView::editSelectedConductorColor Edit the color of the selected conductor; does nothing if mul...
virtual bool mouseMoveEvent(QMouseEvent *event)
bool gestureEvent(QGestureEvent *event)
DiagramView::gestureEvent Use the pinch of the trackpad for zoom.
void changeLastTab()
change current diagramview to last tab
ProjectView * currentProjectView() const
void wheelEvent(QWheelEvent *) override
static void diagramPropertiesDialog(Diagram *diagram, QWidget *parent=nullptr)
DiagramPropertiesDialog::diagramPropertiesDialog Static method to get a DiagramPropertiesDialog.
void handleTitleBlockDrop(QDropEvent *)
DiagramView::handleTitleBlockDrop Handle the dropEvent that contain data of a titleblock.
void setEventInterface(DiagramEventInterface *event_interface)
Diagram::setEventInterface Set event_interface has current interface. Diagram become the ownership of...
void fromString(const QString &)
void mouseMoveEvent(QMouseEvent *) override
DiagramView::mouseMoveEvent Manage the event move mouse.
void dropEvent(QDropEvent *) override
bool event(QEvent *) override
DiagramView::event Manage the event on this diagram view. -At first activation (QEvent::WindowActivat...
void showDiagram(Diagram *)
Signal emmitted when diagram must be show.
QList< QAction * > m_separators
QString integrateTitleBlockTemplate(const TitleBlockTemplateLocation &, MoveTitleBlockTemplatesHandler *handler)
QList< QAction * > contextMenuActions() const
DiagramView::contextMenuActions.
virtual bool isCtrlShifting(QInputEvent *)
virtual bool wheelEvent(QWheelEvent *event)
bool mustIntegrateTitleBlockTemplate(const TitleBlockTemplateLocation &) const
virtual bool switchToSelectionModeIfNeeded(QInputEvent *e)
bool gestures() const
DiagramView::gestures.
bool fromXml(QDomDocument &, QPointF=QPointF(), bool=true, DiagramContent *=nullptr)
void freeRubberBandChanged(QPolygonF polygon)
QRectF viewedSceneRect() const
The DiagramEventAddElement class This diagram event add a new element, for each left click button at ...
void setVisualisationMode()
QETProject * parentProject() const
virtual bool mousePressEvent(QMouseEvent *event)
bool hasTextEditing()
DiagramContent::hasTextEditing.
static bool clipboardMayContainDiagram()
void editElementRequired(const ElementsLocation &)
Signal emitted when users wish to edit an element from the diagram.
DVEventInterface * m_event_interface
void loadCndFolioSeq()
Diagram::loadCndFolioSeq This class loads all conductor folio sequential variables related to the cur...
bool m_free_rubberbanding
void loadElmtFolioSeq()
Diagram::loadElmtFolioSeq This class loads all folio sequential variables related to the current auto...
BorderTitleBlock border_and_titleblock
Diagram dimensions and title block.
QETProject * project() const
void mouseReleaseEvent(QMouseEvent *) override
DiagramView::mouseReleaseEvent Manage event release click mouse.
QList< Conductor * > conductors(int=AnyConductor) const
DiagramContent::conductors.
void dragMoveEvent(QDragMoveEvent *) override
void editDiagramProperties()
DiagramView::editDiagramProperties Edit the properties of the viewed digram.
virtual bool selectedItemHasFocus()
int count(int=All) const
DiagramContent::count.
QString template_name
Name of the template used to render the title block - an empty string means "the default template pro...
QPolygonF m_free_rubberband
void paste(const QPointF &=QPointF(), QClipboard::Mode=QClipboard::Clipboard)
DiagramView::paste Import the element stored in the clipboard to the diagram.