CmQtEditorWindow.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #pragma once
  2. #include "CmEditorPrerequisites.h"
  3. #include <QtWidgets/QWidget>
  4. #include <QtCore/QPoint>
  5. namespace CamelotEditor
  6. {
  7. // TODO - Low priority. When resizing from left/top, the window resize noticeably lags behind
  8. // TODO - Low priority. When resizing from left/top, if a minimum size is reached, the window will just move as if it's being dragged
  9. // 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
  10. class QtEditorWindow : public QWidget
  11. {
  12. Q_OBJECT
  13. enum ResizeMode
  14. {
  15. RM_NONE = 0x00,
  16. RM_LEFT = 0x01,
  17. RM_RIGHT = 0x02,
  18. RM_TOP = 0x04,
  19. RM_BOTTOM = 0x08
  20. };
  21. public:
  22. QtEditorWindow(QWidget* parent, const QString& title);
  23. virtual ~QtEditorWindow() { }
  24. void undock();
  25. void dock();
  26. bool isDocked() { return mIsDocked; }
  27. protected:
  28. QWidget* mContent;
  29. QSizePolicy sizePolicy() const;
  30. private:
  31. ResizeMode mResizeMode;
  32. bool mMoveMode;
  33. QPoint mDragOffset;
  34. QWidget* mTitleBar;
  35. QLabel* mLblTitle;
  36. QPushButton* mBtnClose;
  37. QWidget* mCentralWidget;
  38. bool mIsDocked;
  39. void setupUi(QString title);
  40. void setupSignals();
  41. void retranslateUi(QString title);
  42. void mousePressEvent(QMouseEvent* event);
  43. void mouseReleaseEvent(QMouseEvent* event);
  44. void mouseMoveEvent(QMouseEvent* event);
  45. ResizeMode getResizeMode(QPoint mousePos);
  46. bool isOverResizeArea(QPoint mousePos);
  47. /**
  48. * @brief Query if 'mousePos' is over the area that can be used for dragging the window around.
  49. *
  50. * @param mousePos The mouse position, in global coordinates.
  51. */
  52. bool isOverDragArea(QPoint mousePos);
  53. static const int RESIZE_BORDER_SIZE = 2;
  54. static const int TITLE_BAR_HEIGHT = 20;
  55. /************************************************************************/
  56. /* SLOTS */
  57. /************************************************************************/
  58. private Q_SLOTS:
  59. void closeWindow();
  60. };
  61. }