KonvergoWindow.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. public:
  32. static void RegisterClass();
  33. KonvergoWindow(QWindow* parent = nullptr);
  34. ~KonvergoWindow();
  35. bool isFullScreen()
  36. {
  37. return ((flags() & Qt::FramelessWindowHint) || (visibility() == QWindow::FullScreen));
  38. }
  39. void setFullScreen(bool enable);
  40. Q_SLOT void otherAppFocus()
  41. {
  42. setWindowState((Qt::WindowState)((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive));
  43. raise();
  44. }
  45. Q_SLOT void toggleDebug();
  46. Q_SLOT void toggleFullscreen()
  47. {
  48. setFullScreen(!isFullScreen());
  49. }
  50. Q_SLOT void reloadWeb()
  51. {
  52. emit reloadWebClient();
  53. }
  54. qreal windowScale() { return CalculateScale(size()); }
  55. qreal webScale() { return CalculateWebScale(size(), devicePixelRatio()); }
  56. qreal webHeightMax() { return WEBUI_MAX_HEIGHT; }
  57. QSize webUISize() { return WEBUI_SIZE; }
  58. QSize windowMinSize() { return WINDOWW_MIN_SIZE; }
  59. static qreal CalculateScale(const QSize& size);
  60. static qreal CalculateWebScale(const QSize& size, qint32 devicePixelRatio);
  61. Q_SIGNALS:
  62. void fullScreenSwitched();
  63. void webScaleChanged();
  64. void enableVideoWindowSignal();
  65. void debugLayerChanged();
  66. void debugInfoChanged();
  67. void reloadWebClient();
  68. protected:
  69. virtual void focusOutEvent(QFocusEvent* ev) override;
  70. virtual void resizeEvent(QResizeEvent* event) override;
  71. private slots:
  72. void closingWindow();
  73. void enableVideoWindow();
  74. void onVisibilityChanged(QWindow::Visibility visibility);
  75. void updateMainSectionSettings(const QVariantMap& values);
  76. void updateFullscreenState(bool saveGeo = true);
  77. void onScreenCountChanged(int newCount);
  78. void updateDebugInfo();
  79. void playerWindowVisible(bool visible);
  80. void playerPlaybackStarting();
  81. private:
  82. void notifyScale(const QSize& size);
  83. void saveGeometry();
  84. void loadGeometry();
  85. QRect loadGeometryRect();
  86. bool fitsInScreens(const QRect& rc);
  87. QScreen* loadLastScreen();
  88. bool m_debugLayer;
  89. qreal m_lastScale;
  90. QTimer* m_infoTimer;
  91. QString m_debugInfo, m_systemDebugInfo, m_videoInfo;
  92. };
  93. #endif // KONVERGOWINDOW_H