GraphTabBar.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #if !defined(Q_MOC_RUN)
  10. #include <AzQtComponents/Components/Widgets/TabWidget.h>
  11. #include <QMetaType>
  12. #include <AzCore/Component/EntityId.h>
  13. #include <AzCore/Asset/AssetCommon.h>
  14. #include <ScriptCanvas/Core/Core.h>
  15. #include <ScriptCanvas/Bus/RequestBus.h>
  16. #endif
  17. class QGraphicsView;
  18. class QVBoxLayout;
  19. namespace ScriptCanvasEditor
  20. {
  21. using SourceHandle = SourceHandle;
  22. namespace Widget
  23. {
  24. class CanvasWidget;
  25. struct GraphTabMetadata
  26. {
  27. SourceHandle m_assetId;
  28. QWidget* m_hostWidget = nullptr;
  29. CanvasWidget* m_canvasWidget = nullptr;
  30. Tracker::ScriptCanvasFileState m_fileState = Tracker::ScriptCanvasFileState::INVALID;
  31. };
  32. class GraphTabBar
  33. : public AzQtComponents::TabBar
  34. {
  35. Q_OBJECT
  36. public:
  37. GraphTabBar(QWidget* parent = nullptr);
  38. ~GraphTabBar() override = default;
  39. AZStd::optional<GraphTabMetadata> GetTabData(int index) const;
  40. AZStd::optional<GraphTabMetadata> GetTabData(SourceHandle assetId) const;
  41. void SetTabData(const GraphTabMetadata& data, int index);
  42. void SetTabData(const GraphTabMetadata& data, SourceHandle assetId);
  43. void AddGraphTab(SourceHandle assetId, Tracker::ScriptCanvasFileState fileState);
  44. void CloseTab(int index);
  45. void CloseAllTabs();
  46. int InsertGraphTab(int tabIndex, SourceHandle assetId, Tracker::ScriptCanvasFileState fileState);
  47. bool SelectTab(SourceHandle assetId);
  48. int FindTab(SourceHandle assetId) const;
  49. int FindTab(ScriptCanvasEditor::GraphPtrConst graph) const;
  50. int FindSaveOverMatch(SourceHandle assetId) const;
  51. SourceHandle FindTabByPath(AZStd::string_view path) const;
  52. SourceHandle FindAssetId(int tabIndex);
  53. ScriptCanvas::ScriptCanvasId FindScriptCanvasIdFromGraphCanvasId(const GraphCanvas::GraphId& graphCanvasGraphId) const;
  54. void ClearTabView(int tabIndex);
  55. CanvasWidget* ModOrCreateTabView(int tabIndex);
  56. CanvasWidget* ModTabView(int tabIndex);
  57. void OnContextMenu(const QPoint& point);
  58. void mouseReleaseEvent(QMouseEvent* event) override;
  59. // Updates the tab at the supplied index with the GraphTabMetadata
  60. // The host widget field of the tabMetadata is not used and will not overwrite the tab data
  61. void SetTabText(int tabIndex, const QString& path, Tracker::ScriptCanvasFileState fileState = Tracker::ScriptCanvasFileState::INVALID);
  62. void UpdateFileState(const SourceHandle& assetId, Tracker::ScriptCanvasFileState fileState);
  63. Q_SIGNALS:
  64. void TabInserted(int index);
  65. void TabRemoved(int index);
  66. // Emits a signal to close the tab which is distinct from pressing the close button the actual tab bar.
  67. // This allows handling of the close tab button being pressed different than the actual closing of the tab.
  68. // Pressing the close tab button will prompt the user to save file in tab if it is modified
  69. void TabCloseNoButton(int index);
  70. void SaveTab(int index);
  71. void CloseAllTabsSignal();
  72. void CloseAllTabsButSignal(int index);
  73. void CopyPathToClipboard(int index);
  74. void OnActiveFileStateChanged();
  75. protected:
  76. void tabInserted(int index) override;
  77. void tabRemoved(int index) override;
  78. private:
  79. // Called when the selected tab changes
  80. void currentChangedTab(int index);
  81. int m_signalSaveOnChangeTo = -1;
  82. };
  83. }
  84. }
  85. Q_DECLARE_METATYPE(ScriptCanvasEditor::Widget::GraphTabMetadata);