CmQtEditorWindow.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #pragma once
  2. #include "CmEditorPrerequisites.h"
  3. #include "CmQtEditorWidget.h"
  4. #include "CmEditorPrefs.h"
  5. #include <QtWidgets/QWidget>
  6. #include <QtCore/QPoint>
  7. #include <boost/signal.hpp>
  8. namespace CamelotEditor
  9. {
  10. // TODO - Low priority. When resizing from left/top, the window resize noticeably lags behind
  11. // TODO - Low priority. When resizing or moving, the top/right sides seem to redraw a frame too late and borders appear invisible for a split second
  12. class QtEditorWindow : public QWidget
  13. {
  14. Q_OBJECT
  15. enum ResizeMode
  16. {
  17. RM_NONE = 0x00,
  18. RM_LEFT = 0x01,
  19. RM_RIGHT = 0x02,
  20. RM_TOP = 0x04,
  21. RM_BOTTOM = 0x08
  22. };
  23. public:
  24. QtEditorWindow(QWidget* parent, INT32 id);
  25. virtual ~QtEditorWindow() { }
  26. void undock();
  27. void dock();
  28. bool isDocked() const { return mIsDocked; }
  29. UINT32 getId() const { return mId; }
  30. WindowLayoutDesc getLayoutDesc() const;
  31. void restoreFromLayoutDesc(const WindowLayoutDesc& desc);
  32. void addWidget(QtEditorWidget* widget);
  33. void insertWidget(UINT32 idx, QtEditorWidget* widget);
  34. void removeWidget(UINT32 idx);
  35. UINT32 getNumWidgets() const { return (UINT32)mEditorWidgets.size(); }
  36. QtEditorWidget* getWidget(UINT32 idx) const;
  37. void setActiveWidget(UINT32 idx);
  38. QWidget* getContentWidget() const;
  39. QWidget* getTabWidget() const;
  40. std::vector<QPolygon> getTabBarDropLocations() const;
  41. INT32 getActiveTabBarDropLocation(const QPoint& mousePos) const;
  42. void closeWindow();
  43. boost::signal<void(QtEditorWindow*)> onClosed;
  44. protected:
  45. QSizePolicy sizePolicy() const;
  46. private:
  47. INT32 mId;
  48. ResizeMode mResizeMode;
  49. bool mMoveMode;
  50. QPoint mDragOffset;
  51. QWidget* mTitleBar;
  52. QtDynamicTabBar* mTabBar;
  53. QPushButton* mBtnClose;
  54. QPushButton* mBtnUndock;
  55. QWidget* mCentralWidget;
  56. QStackedWidget* mStackedWidget;
  57. QTimer* mTimer;
  58. bool mIsDocked;
  59. Vector<QtEditorWidget*>::type mEditorWidgets;
  60. UINT32 mActiveWidgetIdx;
  61. void setupUi();
  62. void setupSignals();
  63. void retranslateUi();
  64. void setObjectNames();
  65. void enterEvent(QEvent *e);
  66. void leaveEvent(QEvent *e);
  67. void mousePressEvent(QMouseEvent* event);
  68. void mouseReleaseEvent(QMouseEvent* event);
  69. void mouseMoveEvent(QMouseEvent* event);
  70. ResizeMode getResizeMode(QPoint mousePos);
  71. bool isOverResizeArea(QPoint mousePos);
  72. void resizeCentered(const QSize& size);
  73. /**
  74. * @brief Query if 'mousePos' is over the area that can be used for dragging the window around.
  75. *
  76. * @param mousePos The mouse position, in global coordinates.
  77. */
  78. bool isOverDragArea(QPoint mousePos);
  79. static const int RESIZE_BORDER_SIZE = 2;
  80. static const int TITLE_BAR_HEIGHT = 20;
  81. /************************************************************************/
  82. /* SLOTS */
  83. /************************************************************************/
  84. private Q_SLOTS:
  85. void timerUpdate();
  86. void closeWidget();
  87. void undockWidget();
  88. };
  89. }