windowscreen.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. #ifndef WINDOWSCREEN_H
  9. #define WINDOWSCREEN_H
  10. #if !defined(Q_MOC_RUN)
  11. #include <QObject>
  12. #include <QString>
  13. #include <QWindow>
  14. #endif
  15. /** The WindowScreenInfo struct stores the x, y, width, height and
  16. * other window state info.
  17. */
  18. struct WindowScreenInfo
  19. {
  20. int m_positionX = 0;
  21. int m_positionY = 0;
  22. int m_width = 0;
  23. int m_height = 0;
  24. QWindow::Visibility m_windowState = QWindow::Windowed;
  25. };
  26. /** The WindowScreen class is responsible for storing information about the
  27. * application window.
  28. */
  29. class WindowScreen
  30. : public QObject
  31. {
  32. Q_OBJECT
  33. Q_PROPERTY(int positionX READ positionX WRITE setPositionX NOTIFY positionXChanged)
  34. Q_PROPERTY(int positionY READ positionY WRITE setPositionY NOTIFY positionYChanged)
  35. Q_PROPERTY(int width READ width WRITE setWidth NOTIFY widthChanged)
  36. Q_PROPERTY(int height READ height WRITE setHeight NOTIFY heightChanged)
  37. Q_PROPERTY(QWindow::Visibility windowState READ windowState WRITE setWindowState NOTIFY windowStateChanged)
  38. Q_PROPERTY(QString windowName READ windowName WRITE setWindowName)
  39. public:
  40. /// standard Qt constructor
  41. explicit WindowScreen(QObject* parent = 0);
  42. virtual ~WindowScreen();
  43. ///Loads settings
  44. Q_INVOKABLE void loadSettings(int width, int heigth, int minimumWidth, int minimumHeight);
  45. ///save settings
  46. Q_INVOKABLE void saveSettings();
  47. int positionX() const;
  48. void setPositionX(int positionX);
  49. int positionY() const;
  50. void setPositionY(int positionY);
  51. int width() const;
  52. void setWidth(int width);
  53. int height() const;
  54. void setHeight(int height);
  55. bool isMaximize() const;
  56. void setIsMaximize(bool isMaximize);
  57. QString windowName() const;
  58. void setWindowName(QString windowName);
  59. QWindow::Visibility windowState() const;
  60. void setWindowState(QWindow::Visibility state);
  61. Q_SIGNALS:
  62. void positionXChanged();
  63. void positionYChanged();
  64. void widthChanged();
  65. void heightChanged();
  66. void windowStateChanged();
  67. private:
  68. ///Check to see whether settings are valid or not
  69. bool CheckSettings(int minimumWidth, int minimumHeight);
  70. ///Centers the window in primary screen
  71. void CenterWindowInPrimaryScreen(int minimumWidth, int minimumHeight);
  72. WindowScreenInfo m_windowCurrentInfo;
  73. WindowScreenInfo m_windowPreviousInfo;
  74. QString m_windowName = QString();
  75. };
  76. #endif // WINDOWSCREEN_H