QElectroTech  0.70
diagramview.h
Go to the documentation of this file.
1 /*
2  Copyright 2006-2019 The QElectroTech Team
3  This file is part of QElectroTech.
4 
5  QElectroTech is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 2 of the License, or
8  (at your option) any later version.
9 
10  QElectroTech is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #ifndef DIAGRAMVIEW_H
19 #define DIAGRAMVIEW_H
20 
21 #include <QGraphicsView>
22 #include <QClipboard>
23 #include "elementslocation.h"
24 #include "templatelocation.h"
25 
26 class Conductor;
27 class Diagram;
28 class QETDiagramEditor;
29 class DVEventInterface;
30 class QInputEvent;
31 class QGestureEvent;
32 
37 class DiagramView : public QGraphicsView
38 {
39  Q_OBJECT
40 
41  // constructors, destructor
42  public:
43  DiagramView(Diagram *diagram, QWidget * = nullptr);
44  ~DiagramView() override;
45 
46  private:
47  DiagramView(const DiagramView &);
48 
49  // attributes
50 
51  Diagram *m_diagram = nullptr;
53  QAction *m_paste_here = nullptr;
54  QAction *m_multi_paste = nullptr;
56  QPointF m_drag_last_pos;
59  QList<QAction *> m_separators;
60  QPolygonF m_free_rubberband;
61  bool m_free_rubberbanding = false;
62 
63 
64  public:
65  QString title() const;
66  void editDiagramProperties();
67  Diagram *diagram() { return(m_diagram); }
69  void editSelection();
70  void setEventInterface (DVEventInterface *event_interface);
71  QList<QAction *> contextMenuActions() const;
72 
73  protected:
74  void mouseDoubleClickEvent(QMouseEvent *) override;
75  void contextMenuEvent(QContextMenuEvent *) override;
76  void wheelEvent(QWheelEvent *) override;
77  void focusInEvent(QFocusEvent *) override;
78  void keyPressEvent(QKeyEvent *) override;
79  void keyReleaseEvent(QKeyEvent *) override;
80  bool event(QEvent *) override;
81  void paintEvent(QPaintEvent *event) override;
82  void mousePressEvent(QMouseEvent *) override;
83  void mouseMoveEvent(QMouseEvent *) override;
84  void mouseReleaseEvent(QMouseEvent *) override;
85  void dragEnterEvent(QDragEnterEvent *) override;
86  void dragMoveEvent(QDragMoveEvent *) override;
87  void dropEvent(QDropEvent *) override;
88 
89  virtual bool switchToVisualisationModeIfNeeded(QInputEvent *e);
90  virtual bool switchToSelectionModeIfNeeded(QInputEvent *e);
91  virtual bool isCtrlShifting(QInputEvent *);
92  virtual bool selectedItemHasFocus();
93 
94  private:
95  void handleElementDrop(QDropEvent *);
96  void handleTitleBlockDrop(QDropEvent *);
97  void handleTextDrop(QDropEvent *);
98  void scrollOnMovement(QKeyEvent *);
99  bool gestureEvent(QGestureEvent *event);
100  QRectF viewedSceneRect() const;
102  bool gestures() const;
103 
104  signals:
106  void selectionChanged();
108  void modeChanged();
110  void titleChanged(DiagramView *, const QString &);
116  void showDiagram (Diagram *);
119  void freeRubberBandChanged(QPolygonF polygon);
120 
121  public slots:
122  void selectNothing();
123  void selectAll();
124  void selectInvert();
125  void setVisualisationMode();
126  void setSelectionMode();
127  void zoom(const qreal zoom_factor);
128  void zoomFit();
129  void zoomContent();
130  void zoomReset();
131  void cut();
132  void copy();
133  void paste(const QPointF & = QPointF(), QClipboard::Mode = QClipboard::Clipboard);
134  void pasteHere();
135  void adjustSceneRect();
136  void updateWindowTitle();
139  void resetConductors();
140 
141  private slots:
142  void adjustGridToZoom();
143  void applyReadOnly();
144 };
145 #endif
void editConductorColor(Conductor *)
void dragEnterEvent(QDragEnterEvent *) override
void focusInEvent(QFocusEvent *) override
QAction * m_paste_here
Definition: diagramview.h:53
void handleElementDrop(QDropEvent *)
void setEventInterface(DVEventInterface *event_interface)
DiagramView::setEventInterface Set an event interface to diagram view. If diagram view already have a...
void zoomFit()
QString title() const
void zoom(const qreal zoom_factor)
DiagramView::zoom Zomm the view. A zoom_factor > 1 zoom in. A zoom_factor < 1 zoom out...
QETDiagramEditor * diagramEditor() const
void scrollOnMovement(QKeyEvent *)
virtual bool switchToVisualisationModeIfNeeded(QInputEvent *e)
void mousePressEvent(QMouseEvent *) override
Diagram * diagram()
Definition: diagramview.h:67
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.
void applyReadOnly()
void selectionChanged()
Signal emitted after the selection changed.
void contextMenuEvent(QContextMenuEvent *) override
DiagramView::contextMenuEvent.
void handleTextDrop(QDropEvent *)
DiagramView::handleTextDrop handle the drop of text.
DiagramView(Diagram *diagram, QWidget *=nullptr)
Definition: diagramview.cpp:54
void zoomContent()
QPointF m_drag_last_pos
Definition: diagramview.h:56
void paintEvent(QPaintEvent *event) override
DiagramView::paintEvent Reimplemented from QGraphicsView.
QPoint m_paste_here_pos
Definition: diagramview.h:55
void zoomReset()
void editSelection()
DiagramView::editSelection Edit the selected item if he can be edited and if only one item is selecte...
void selectInvert()
void adjustSceneRect()
DiagramView::adjustSceneRect Calcul and set the area of the scene visualized by this view...
void keyPressEvent(QKeyEvent *) override
DiagramView::keyPressEvent Handles "key press" events. Reimplemented here to switch to visualisation ...
void adjustGridToZoom()
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 setSelectionMode()
void titleChanged(DiagramView *, const QString &)
Signal emitted after the diagram title changed.
QAction * m_multi_paste
Definition: diagramview.h:54
void editSelectedConductorColor()
DiagramView::editSelectedConductorColor Edit the color of the selected conductor; does nothing if mul...
bool gestureEvent(QGestureEvent *event)
DiagramView::gestureEvent Use the pinch of the trackpad for zoom.
void updateWindowTitle()
void wheelEvent(QWheelEvent *) override
~DiagramView() override
void handleTitleBlockDrop(QDropEvent *)
DiagramView::handleTitleBlockDrop Handle the dropEvent that contain data of a titleblock.
bool m_first_activation
Definition: diagramview.h:58
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
Definition: diagramview.h:59
QList< QAction * > contextMenuActions() const
DiagramView::contextMenuActions.
virtual bool isCtrlShifting(QInputEvent *)
bool mustIntegrateTitleBlockTemplate(const TitleBlockTemplateLocation &) const
void pasteHere()
virtual bool switchToSelectionModeIfNeeded(QInputEvent *e)
bool gestures() const
DiagramView::gestures.
void selectAll()
void freeRubberBandChanged(QPolygonF polygon)
QRectF viewedSceneRect() const
void setVisualisationMode()
void resetConductors()
void editElementRequired(const ElementsLocation &)
Signal emitted when users wish to edit an element from the diagram.
DVEventInterface * m_event_interface
Definition: diagramview.h:52
bool m_free_rubberbanding
Definition: diagramview.h:61
bool m_fresh_focus_in
Definition: diagramview.h:57
void mouseReleaseEvent(QMouseEvent *) override
DiagramView::mouseReleaseEvent Manage event release click mouse.
void dragMoveEvent(QDragMoveEvent *) override
void editDiagramProperties()
DiagramView::editDiagramProperties Edit the properties of the viewed digram.
virtual bool selectedItemHasFocus()
QPolygonF m_free_rubberband
Definition: diagramview.h:60
Diagram * m_diagram
Definition: diagramview.h:51
void paste(const QPointF &=QPointF(), QClipboard::Mode=QClipboard::Clipboard)
DiagramView::paste Import the element stored in the clipboard to the diagram.
void selectNothing()