/*** Olive - Non-Linear Video Editor Copyright (C) 2021 Olive Team This program 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 3 of the License, or (at your option) any later version. This program 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 this program. If not, see . ***/ #ifndef NODEVIEW_H #define NODEVIEW_H #include #include #include "core.h" #include "node/graph.h" #include "node/nodecopypaste.h" #include "nodeviewedge.h" #include "nodeviewcontext.h" #include "nodeviewminimap.h" #include "nodeviewscene.h" #include "widget/handmovableview/handmovableview.h" #include "widget/menu/menu.h" namespace olive { /** * @brief A widget for viewing and editing node graphs * * This widget takes a NodeGraph object and constructs a QGraphicsScene representing its data, viewing and allowing * the user to make modifications to it. */ class NodeView : public HandMovableView, public NodeCopyPasteService { Q_OBJECT public: NodeView(QWidget* parent = nullptr); virtual ~NodeView() override; void SetContexts(const QVector &nodes); void CloseContextsBelongingToProject(Project *project); void ClearGraph(); /** * @brief Delete selected nodes from graph (user-friendly/undoable) */ void DeleteSelected(); void SelectAll(); void DeselectAll(); void Select(const QVector &nodes, bool center_view_on_item); void CopySelected(bool cut); void Paste(); void Duplicate(); void SetColorLabel(int index); void ZoomIn(); void ZoomOut(); const QVector &GetCurrentContexts() const { return contexts_; } public slots: void SetMiniMapEnabled(bool e) { minimap_->setVisible(e); } void ShowAddMenu() { Menu *m = CreateAddMenu(nullptr); m->exec(QCursor::pos()); delete m; } void CenterOnItemsBoundingRect(); signals: void NodesSelected(const QVector& nodes); void NodesDeselected(const QVector& nodes); protected: virtual void keyPressEvent(QKeyEvent *event) override; virtual void mousePressEvent(QMouseEvent *event) override; virtual void mouseMoveEvent(QMouseEvent *event) override; virtual void mouseReleaseEvent(QMouseEvent* event) override; virtual void mouseDoubleClickEvent(QMouseEvent* event) override; virtual void resizeEvent(QResizeEvent *event) override; virtual void ZoomIntoCursorPosition(QWheelEvent *event, double multiplier, const QPointF &cursor_pos) override; virtual bool event(QEvent *event) override; virtual bool eventFilter(QObject *object, QEvent *event) override; virtual void CopyNodesToClipboardInternal(QXmlStreamWriter *writer, const QVector &nodes, void* userdata) override; virtual void PasteNodesFromClipboardInternal(QXmlStreamReader *reader, XMLNodeData &xml_node_data, void* userdata) override; virtual void changeEvent(QEvent *e) override; private: void AttachItemsToCursor(const QVector &items); void DetachItemsFromCursor(); void SetFlowDirection(NodeViewCommon::FlowDirection dir); void MoveAttachedNodesToCursor(const QPoint &p); void ConnectSelectionChangedSignal(); void DisconnectSelectionChangedSignal(); void ZoomFromKeyboard(double multiplier); void ClearCreateEdgeInputIfNecessary(); QPointF GetEstimatedPositionForContext(NodeViewItem *item, Node *context) const; Menu *CreateAddMenu(Menu *parent); void PositionNewEdge(const QPoint &pos); void PasteNodesInternal(const QVector &duplicate_nodes = QVector()); void AddContext(Node *n); void RemoveContext(Node *n); bool IsItemAttachedToCursor(NodeViewItem *item) const; void ExpandItem(NodeViewItem *item); void CollapseItem(NodeViewItem *item); NodeViewMiniMap *minimap_; struct AttachedItem { NodeViewItem* item; QPointF original_pos; }; QList attached_items_; NodeViewEdge* drop_edge_; NodeInput drop_input_; NodeViewEdge* create_edge_; NodeViewItem* create_edge_output_item_; NodeViewItem* create_edge_input_item_; NodeInput create_edge_input_; bool create_edge_already_exists_; bool create_edge_from_output_; QVector create_edge_expanded_items_; NodeViewScene scene_; MultiUndoCommand* paste_command_; QVector selected_nodes_; QVector contexts_; QVector last_set_filter_nodes_; QMap context_offsets_; QMap dragging_items_; double scale_; static const double kMinimumScale; private slots: /** * @brief Receiver for when the scene's selected items change */ void UpdateSelectionCache(); /** * @brief Receiver for when the user right clicks (or otherwise requests a context menu) */ void ShowContextMenu(const QPoint &pos); /** * @brief Receiver for when the user requests a new node from the add menu */ void CreateNodeSlot(QAction* action); /** * @brief Receiver for setting the direction from the context menu */ void ContextMenuSetDirection(QAction* action); /** * @brief Opens the selected node in a Viewer */ void OpenSelectedNodeInViewer(); void UpdateSceneBoundingRect(); void RepositionMiniMap(); void UpdateViewportOnMiniMap(); void MoveToScenePoint(const QPointF &pos); void NodeRemovedFromGraph(); void GroupNodes(); void UngroupNodes(); void ShowNodeProperties(); void LabelSelectedNodes(); }; } #endif // NODEVIEW_H