Skip to content

Commit

Permalink
Merge pull request #556 from emsec/feature/move_multi_nodes
Browse files Browse the repository at this point in the history
Feature/move multi nodes
  • Loading branch information
joern274 authored Feb 1, 2024
2 parents 31a7e7f + f71c050 commit 21c660c
Show file tree
Hide file tree
Showing 12 changed files with 393 additions and 162 deletions.
84 changes: 84 additions & 0 deletions plugins/gui/include/gui/graph_widget/drag_controller.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// MIT License
//
// Copyright (c) 2019 Ruhr University Bochum, Chair for Embedded Security. All Rights reserved.
// Copyright (c) 2019 Marc Fyrbiak, Sebastian Wallat, Max Hoffmann ("ORIGINAL AUTHORS"). All rights reserved.
// Copyright (c) 2021 Max Planck Institute for Security and Privacy. All Rights reserved.
// Copyright (c) 2021 Jörn Langheinrich, Julian Speith, Nils Albartus, René Walendy, Simon Klix ("ORIGINAL AUTHORS"). All Rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#pragma once
#include <QObject>
#include <QSet>
#include <QPoint>
#include <QHash>
#include "gui/gui_def.h"
#include "gui/graph_widget/items/utility_items/node_drag_shadow.h"

namespace hal {

class GraphWidget;
class GraphicsNode;
class NodeBox;
class NodeDragShadow;
class GraphicsScene;

class DragController : public QObject
{
Q_OBJECT
GraphWidget* mGraphWidget;
bool mDropAllowed;
bool mWantSwap;
QPoint mMousedownPosition;
NodeBox* mDragNodeBox;
QPoint mCurrentGridpos;
QSet<NodeBox*> mAdditionalBoxes;
QHash<const NodeBox*,NodeDragShadow*> mShadows;
GraphicsScene* mShadowScene;

void setSwapIntent(bool wantSwap);
void addShadow(const NodeBox* nb);
public:
DragController(GraphWidget* gw, QObject* parent = nullptr);

void clear();

void set(GraphicsNode* drgItem, const QPoint& eventPos);

/**
* Starts the dragging of a gate or module to show its shadow meanwhile.
*
* @param wantSwap - True if keyboard swap modifier has been pressed, false otherwise
*/
void enterDrag(bool wantSwap);

/**
* Moves the shadow that appears while dragging a gate or module.
*
* @param eventPos - The mouse position in scene coordinates while dragging
* @param wantSwap - True if keyboard swap modifier has been pressed, false otherwise
* @param gridPos - The new grid position of the primary node
*/
void move(const QPoint& eventPos, bool wantSwap, const QPoint& gridPos);
bool hasDragged(const QPoint& eventPos);
bool isDropAllowed() const;
GridPlacement* finalGridPlacement() const;
NodeDragShadow::DragCue dragCue() const;
};
}
11 changes: 4 additions & 7 deletions plugins/gui/include/gui/graph_widget/graph_graphics_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ namespace hal
{
class GraphicsItem;
class GraphWidget;
class DragController;

namespace graph_widget_constants
{
Expand Down Expand Up @@ -202,6 +203,8 @@ namespace hal
void addSuccessorToView(int maxLevel, bool succ);
void addCommonSuccessorToView(int maxLevel, bool succ);

void dragPan(float dpx, float dpy);

GraphWidget* mGraphWidget;

QSet<u32> getSelectableGates();
Expand Down Expand Up @@ -233,13 +236,7 @@ namespace hal
bool mGridClustersEnabled;
GraphicsScene::GridType mGridType;

QPoint mDragMousedownPosition;
QPoint mDragStartGridpos;
GraphicsGate* mDragItem;
QPoint mDragCurrentGridpos;
bool mDragCurrentModifier;
bool mDropAllowed;

DragController* mDragController;
Qt::KeyboardModifier mDragModifier;

QPoint mMovePosition;
Expand Down
24 changes: 0 additions & 24 deletions plugins/gui/include/gui/graph_widget/graphics_scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,28 +119,6 @@ namespace hal
*/
~GraphicsScene();

/**
* Starts the dragging of a gate or module to show its shadow meanwhile.
*
* @param posF - The position of the shadow
* @param sizeF - The size of the shadow (i.e. the size of the dragged gate)
* @param cue - The cue of the current position
*/
void startDragShadow(const QPointF& posF, const QSizeF& sizeF, const NodeDragShadow::DragCue cue);

/**
* Moves the shadow that appears while dragging a gate or module.
*
* @param posF - The new position of the shadow
* @param cue - The cue of the current position
*/
void moveDragShadow(const QPointF& posF, const NodeDragShadow::DragCue cue);

/**
* Removes the shadow that appears while dragging a gate or module (at the end of the drag action).
*/
void stopDragShadow();

/**
* Gets the position of the drag shadow.
*
Expand Down Expand Up @@ -321,8 +299,6 @@ namespace hal

void drawBackground(QPainter* painter, const QRectF& rect) override;

NodeDragShadow* mDragShadowGate;

QVector<GraphicsModule*> mModuleItems;
QVector<GraphicsGate*> mGateItems;
QVector<GraphicsNet*> mNetItems;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#pragma once

#include <QGraphicsObject>
#include <QRectF>
#include <QList>

namespace hal
{
Expand All @@ -50,14 +52,17 @@ namespace hal
void start(const QPointF& posF, const QSizeF& sizeF);
void stop();

/*
qreal width() const;
qreal height() const;
QSizeF size() const;
void setWidth(const qreal width);
void setHeight(const qreal height);
*/

void setVisualCue(const DragCue cue);
QList<QPoint> multiMoveGridPositions() const;

static void setLod(const qreal lod);
static void loadSettings();
Expand All @@ -75,8 +80,6 @@ namespace hal
static QColor sColorTranslucent[];

DragCue mCue;

qreal mWidth;
qreal mHeight;
QRectF mRect;
};
} // namespace hal
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,15 @@ namespace hal

const QMap<Node, QPoint> nodeToPositionMap() const;
const QMap<QPoint, Node> positionToNodeMap() const;

/**
* Creates a new GridPlacement instance (node to position hash) and returns the pointer
* The caller has the ownership and responsibility to delete that instance
*/
GridPlacement* gridPlacementFactory() const;

NetLayoutPoint positonForNode(const Node& nd) const;
Node nodeAtPosition(const QPoint& p) const;

QPoint gridPointByItem(GraphicsNode* item) const;

Expand Down
2 changes: 1 addition & 1 deletion plugins/gui/include/gui/user_action/action_move_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ namespace hal
* @param from - The initial position of the node to move
* @param to - The destination of the node
*/
ActionMoveNode(u32 ctxID, const QPoint& from, const QPoint& to, bool swap = false);
// ActionMoveNode(u32 ctxID, const QPoint& from, const QPoint& to, bool swap = false);

/**
* Action constructor.
Expand Down
Loading

0 comments on commit 21c660c

Please sign in to comment.