-
Notifications
You must be signed in to change notification settings - Fork 939
Adds zoom fit selected and zoom fit all functionalities. #509
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 10 commits
2edfb0b
988ce45
1c84750
3007c23
129d414
e0b0c4a
e002f5b
985b638
3f55e35
50c6bec
1c09ecf
50ce760
f2c120f
965eb15
545c018
c34e6e3
97d48d5
89ac7f2
37c3bf8
b23ecc3
0a35f76
a9be092
5530b72
03e311a
a87ceb2
ae3715b
eedc666
1298605
47d948f
21b55ac
4f1b23c
87e219b
dea439b
cc81264
83426c7
422cdd5
9fdc3e8
f2473e7
bc1b6cb
2b3ac01
891b702
8d6c26b
e828567
02b3969
5d1d07b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
|
|
||
| #include "BasicGraphicsScene.hpp" | ||
| #include "ConnectionGraphicsObject.hpp" | ||
| #include "DataFlowGraphModel.hpp" | ||
| #include "NodeGraphicsObject.hpp" | ||
| #include "StyleCollection.hpp" | ||
| #include "UndoCommands.hpp" | ||
|
|
@@ -23,7 +24,9 @@ | |
| #include <cmath> | ||
|
|
||
| using QtNodes::BasicGraphicsScene; | ||
| using QtNodes::DataFlowGraphModel; | ||
| using QtNodes::GraphicsView; | ||
| using QtNodes::NodeGraphicsObject; | ||
|
|
||
| GraphicsView::GraphicsView(QWidget *parent) | ||
| : QGraphicsView(parent) | ||
|
|
@@ -75,8 +78,7 @@ QAction *GraphicsView::deleteSelectionAction() const | |
| void GraphicsView::setScene(BasicGraphicsScene *scene) | ||
| { | ||
| QGraphicsView::setScene(scene); | ||
| if (!scene) | ||
| { | ||
| if (!scene) { | ||
| // Clear actions. | ||
| delete _clearSelectionAction; | ||
| delete _deleteSelectionAction; | ||
|
|
@@ -162,6 +164,13 @@ void GraphicsView::setScene(BasicGraphicsScene *scene) | |
| auto redoAction = scene->undoStack().createRedoAction(this, tr("&Redo")); | ||
| redoAction->setShortcuts(QKeySequence::Redo); | ||
| addAction(redoAction); | ||
|
|
||
| /// Connections to context menu funcionality | ||
| connect(scene, &BasicGraphicsScene::zoomFitAllClicked, this, &GraphicsView::zoomFitAll); | ||
| connect(scene, | ||
| &BasicGraphicsScene::zoomFitSelectedClicked, | ||
| this, | ||
| &GraphicsView::zoomFitSelected); | ||
| } | ||
|
|
||
| void GraphicsView::centerScene() | ||
|
|
@@ -181,16 +190,23 @@ void GraphicsView::centerScene() | |
|
|
||
| void GraphicsView::contextMenuEvent(QContextMenuEvent *event) | ||
| { | ||
| if (itemAt(event->pos())) { | ||
| QGraphicsView::contextMenuEvent(event); | ||
| return; | ||
| } | ||
| QGraphicsView::contextMenuEvent(event); | ||
| QMenu *menu = nullptr; | ||
|
|
||
| if (!nodeScene()) return; | ||
| bool isZoomFitMenu = false; | ||
|
|
||
| auto const scenePos = mapToScene(event->pos()); | ||
| auto *dfModel = &nodeScene()->graphModel(); | ||
| auto n = qgraphicsitem_cast<NodeGraphicsObject *>(itemAt(event->pos())); | ||
|
|
||
| QMenu *menu = nodeScene()->createSceneMenu(scenePos); | ||
| if (dfModel && n) { | ||
| isZoomFitMenu = dfModel->nodeZoomFitMenu(n->nodeId()); | ||
| } | ||
|
|
||
| if (itemAt(event->pos()) && isZoomFitMenu) { | ||
| menu = nodeScene()->createZoomMenu(mapToScene(event->pos())); | ||
| } else if (!itemAt(event->pos())) { | ||
| menu = nodeScene()->createSceneMenu(mapToScene(event->pos())); | ||
| } | ||
|
||
|
|
||
| if (menu) { | ||
| menu->exec(event->globalPos()); | ||
|
|
@@ -291,14 +307,16 @@ void GraphicsView::setupScale(double scale) | |
|
|
||
| void GraphicsView::onDeleteSelectedObjects() | ||
| { | ||
| if (!nodeScene()) return; | ||
| if (!nodeScene()) | ||
| return; | ||
|
|
||
| nodeScene()->undoStack().push(new DeleteCommand(nodeScene())); | ||
| } | ||
|
|
||
| void GraphicsView::onDuplicateSelectedObjects() | ||
| { | ||
| if (!nodeScene()) return; | ||
| if (!nodeScene()) | ||
| return; | ||
|
|
||
| QPointF const pastePosition = scenePastePosition(); | ||
|
|
||
|
|
@@ -308,14 +326,16 @@ void GraphicsView::onDuplicateSelectedObjects() | |
|
|
||
| void GraphicsView::onCopySelectedObjects() | ||
| { | ||
| if (!nodeScene()) return; | ||
| if (!nodeScene()) | ||
| return; | ||
|
|
||
| nodeScene()->undoStack().push(new CopyCommand(nodeScene())); | ||
| } | ||
|
|
||
| void GraphicsView::onPasteObjects() | ||
| { | ||
| if (!nodeScene()) return; | ||
| if (!nodeScene()) | ||
| return; | ||
|
|
||
| QPointF const pastePosition = scenePastePosition(); | ||
| nodeScene()->undoStack().push(new PasteCommand(nodeScene(), pastePosition)); | ||
|
|
@@ -360,7 +380,8 @@ void GraphicsView::mouseMoveEvent(QMouseEvent *event) | |
| { | ||
| QGraphicsView::mouseMoveEvent(event); | ||
|
|
||
| if (!scene()) return; | ||
| if (!scene()) | ||
| return; | ||
|
|
||
| if (scene()->mouseGrabberItem() == nullptr && event->buttons() == Qt::LeftButton) { | ||
| // Make sure shift is not being pressed | ||
|
|
@@ -434,3 +455,22 @@ QPointF GraphicsView::scenePastePosition() | |
|
|
||
| return mapToScene(origin); | ||
| } | ||
|
|
||
| void GraphicsView::zoomFitAll() | ||
| { | ||
| fitInView(scene()->itemsBoundingRect(), Qt::KeepAspectRatio); | ||
Llcoolsouder marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| void GraphicsView::zoomFitSelected() | ||
| { | ||
| if (scene()->selectedItems().count() > 0) { | ||
| QRectF unitedBoundingRect{}; | ||
|
|
||
| for (QGraphicsItem *item : scene()->selectedItems()) { | ||
| unitedBoundingRect = unitedBoundingRect.united( | ||
| item->mapRectToScene(item->boundingRect())); | ||
| } | ||
|
|
||
| fitInView(unitedBoundingRect, Qt::KeepAspectRatio); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.