KonvergoWindow.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #ifndef KONVERGOWINDOW_H
  2. #define KONVERGOWINDOW_H
  3. #include <QQuickWindow>
  4. #include <QEvent>
  5. // This controls how big the web view will zoom using semantic zoom
  6. // over a specific number of pixels and we run out of space for on screen
  7. // tiles in chromium. This only happens on OSX since on other platforms
  8. // we can use the GPU to transfer tiles directly but we set the limit on all platforms
  9. // to keep it consistent.
  10. //
  11. // See more discussion in: https://github.com/plexinc/plex-media-player/issues/10
  12. // The number of pixels here are REAL pixels, the code in webview.qml will compensate
  13. // for a higher DevicePixelRatio
  14. //
  15. #define WEBUI_MAX_HEIGHT 1440.0
  16. #define WEBUI_SIZE QSize(1280, 720)
  17. #define WINDOWW_MIN_SIZE QSize(426, 240)
  18. ///////////////////////////////////////////////////////////////////////////////////////////////////
  19. class KonvergoWindow : public QQuickWindow
  20. {
  21. Q_OBJECT
  22. Q_PROPERTY(bool fullScreen READ isFullScreen WRITE setFullScreen NOTIFY fullScreenSwitched)
  23. Q_PROPERTY(bool showDebugLayer MEMBER m_debugLayer NOTIFY debugLayerChanged)
  24. Q_PROPERTY(QString debugInfo MEMBER m_debugInfo NOTIFY debugInfoChanged)
  25. Q_PROPERTY(QString videoInfo MEMBER m_videoInfo NOTIFY debugInfoChanged)
  26. Q_PROPERTY(qreal webScale READ webScale NOTIFY webScaleChanged)
  27. Q_PROPERTY(qreal webHeightMax READ webHeightMax NOTIFY webScaleChanged)
  28. Q_PROPERTY(QSize webUISize READ webUISize NOTIFY webScaleChanged)
  29. Q_PROPERTY(qreal windowScale READ windowScale NOTIFY webScaleChanged)
  30. Q_PROPERTY(QSize windowMinSize READ windowMinSize NOTIFY webScaleChanged)
  31. Q_PROPERTY(bool alwaysOnTop READ isAlwaysOnTop WRITE setAlwaysOnTop)
  32. public:
  33. static void RegisterClass();
  34. explicit KonvergoWindow(QWindow* parent = nullptr);
  35. ~KonvergoWindow() override;
  36. bool isFullScreen()
  37. {
  38. return ((flags() & Qt::FramelessWindowHint) || (visibility() == QWindow::FullScreen));
  39. }
  40. void setFullScreen(bool enable);
  41. bool isAlwaysOnTop()
  42. {
  43. Qt::WindowFlags forceOnTopFlags = Qt::WindowStaysOnTopHint;
  44. #ifdef Q_OS_LINUX
  45. forceOnTopFlags = forceOnTopFlags | Qt::X11BypassWindowManagerHint;
  46. #endif
  47. return (flags() & forceOnTopFlags);
  48. }
  49. void setAlwaysOnTop(bool enable);
  50. Q_SLOT void otherAppFocus()
  51. {
  52. setWindowState((Qt::WindowState)((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive));
  53. raise();
  54. }
  55. Q_SLOT void toggleDebug();
  56. Q_SLOT void toggleFullscreen()
  57. {
  58. setFullScreen(!isFullScreen());
  59. }
  60. Q_SLOT void toggleAlwaysOnTop()
  61. {
  62. setAlwaysOnTop(!isAlwaysOnTop());
  63. }
  64. Q_SLOT void reloadWeb()
  65. {
  66. emit reloadWebClient();
  67. }
  68. qreal windowScale() { return CalculateScale(size()); }
  69. qreal webScale() { return CalculateWebScale(size(), devicePixelRatio()); }
  70. qreal webHeightMax() { return WEBUI_MAX_HEIGHT; }
  71. QSize webUISize() { return WEBUI_SIZE; }
  72. QSize windowMinSize() { return WINDOWW_MIN_SIZE; }
  73. static qreal CalculateScale(const QSize& size);
  74. static qreal CalculateWebScale(const QSize& size, qreal devicePixelRatio);
  75. Q_SIGNALS:
  76. void fullScreenSwitched();
  77. void webScaleChanged();
  78. void enableVideoWindowSignal();
  79. void debugLayerChanged();
  80. void debugInfoChanged();
  81. void reloadWebClient();
  82. protected:
  83. void focusOutEvent(QFocusEvent* ev) override;
  84. void resizeEvent(QResizeEvent* event) override;
  85. private slots:
  86. void closingWindow();
  87. void enableVideoWindow();
  88. void onVisibilityChanged(QWindow::Visibility visibility);
  89. void updateMainSectionSettings(const QVariantMap& values);
  90. void updateFullscreenState(bool saveGeo = true);
  91. void updateAlwaysOnTopState();
  92. void onScreenCountChanged(int newCount);
  93. void updateDebugInfo();
  94. void playerWindowVisible(bool visible);
  95. private:
  96. void notifyScale(const QSize& size);
  97. void saveGeometry();
  98. QRect loadGeometry();
  99. QRect loadGeometryRect();
  100. bool fitsInScreens(const QRect& rc);
  101. QScreen* loadLastScreen();
  102. bool m_debugLayer;
  103. qreal m_lastScale;
  104. QTimer* m_infoTimer;
  105. QString m_debugInfo, m_systemDebugInfo, m_videoInfo;
  106. };
  107. #endif // KONVERGOWINDOW_H