DialogStack.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 "MysticQtConfig.h"
  11. #include <QtWidgets/QWidget>
  12. #include <QtWidgets/QScrollArea>
  13. #include <AzCore/std/containers/vector.h>
  14. #endif
  15. // forward declarations
  16. QT_FORWARD_DECLARE_CLASS(QPushButton)
  17. QT_FORWARD_DECLARE_CLASS(QFrame)
  18. QT_FORWARD_DECLARE_CLASS(QLayout)
  19. QT_FORWARD_DECLARE_CLASS(QMouseEvent)
  20. QT_FORWARD_DECLARE_CLASS(QResizeEvent)
  21. QT_FORWARD_DECLARE_CLASS(QSplitter)
  22. namespace AzQtComponents
  23. {
  24. class CardHeader;
  25. }
  26. namespace MysticQt
  27. {
  28. class DialogStackSplitter;
  29. class MYSTICQT_API DialogStack
  30. : public QScrollArea
  31. {
  32. Q_OBJECT // AUTOMOC
  33. public:
  34. DialogStack(QWidget* parent = nullptr);
  35. ~DialogStack();
  36. void Add(QWidget* widget, const QString& headerTitle, bool closed = false, bool maximizeSize = false, bool closable = true, bool stretchWhenMaximize = true);
  37. void Add(QLayout* layout, const QString& headerTitle, bool closed = false, bool maximizeSize = false, bool closable = true, bool stretchWhenMaximize = true);
  38. bool Remove(QWidget* widget);
  39. void ReplaceWidget(QWidget* oldWidget, QWidget* newWidget);
  40. void Clear();
  41. protected:
  42. void mouseMoveEvent(QMouseEvent* event) override;
  43. void mousePressEvent(QMouseEvent* event) override;
  44. void mouseDoubleClickEvent(QMouseEvent* event) override;
  45. void mouseReleaseEvent(QMouseEvent* event) override;
  46. void resizeEvent(QResizeEvent* event) override;
  47. protected slots:
  48. void OnExpandedChanged(bool expanded);
  49. private:
  50. struct Dialog
  51. {
  52. AzQtComponents::CardHeader* m_header = nullptr;
  53. QWidget* m_frame = nullptr;
  54. QWidget* m_widget = nullptr;
  55. QWidget* m_dialogWidget = nullptr;
  56. DialogStackSplitter* m_splitter = nullptr;
  57. bool m_closable = true;
  58. bool m_maximizeSize = false;
  59. bool m_stretchWhenMaximize = false;
  60. int m_minimumHeightBeforeClose = 0;
  61. int m_maximumHeightBeforeClose = 0;
  62. QLayout* m_layout = nullptr;
  63. QLayout* m_dialogLayout = nullptr;
  64. };
  65. private:
  66. size_t FindDialog(AzQtComponents::CardHeader* header);
  67. void Open(AzQtComponents::CardHeader* header);
  68. void Close(AzQtComponents::CardHeader* button);
  69. void UpdateScrollBars();
  70. private:
  71. DialogStackSplitter* m_rootSplitter;
  72. AZStd::vector<Dialog> m_dialogs;
  73. int32 m_prevMouseX;
  74. int32 m_prevMouseY;
  75. };
  76. } // namespace MysticQt