DisplayComponent.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #ifndef DISPLAYCOMPONENT_H
  2. #define DISPLAYCOMPONENT_H
  3. #include "DisplayManager.h"
  4. #include "ComponentManager.h"
  5. #include <QScreen>
  6. #include <QTimer>
  7. class DisplayComponent : public ComponentBase
  8. {
  9. Q_OBJECT
  10. DEFINE_SINGLETON(DisplayComponent);
  11. public:
  12. ~DisplayComponent() override;
  13. const char* componentName() override { return "display"; }
  14. bool componentExport() override { return true; }
  15. bool componentInitialize() override;
  16. void componentPostInitialize() override;
  17. inline DisplayManager* getDisplayManager() { return m_displayManager; }
  18. int getApplicationDisplay(bool silent = false);
  19. void setApplicationWindow(QWindow* window) { m_applicationWindow = window; }
  20. // Switch to the best video mode for the given video framerate. Return true only if the actual
  21. // mode was switched. If a good match was found, but the current video mode didn't have to be
  22. // changed, return false. Return false on failure too.
  23. bool switchToBestVideoMode(float frameRate);
  24. // Switch to best overall video mode. This will also switch the resolution.
  25. bool switchToBestOverallVideoMode(int display);
  26. // The syntax is as follows: the command string consists of multiple arguments separated
  27. // by spaces. Each argument can be one of the following:
  28. // <N>hz (e.g.: "24hz"): change the refresh rate
  29. // <W>x<H> (e.g.: "1280x720"): change the resolution
  30. // i: change to interlaced
  31. // p: change to progressive ("not interlaced")
  32. // Example: "123x456 p 45hz"
  33. Q_INVOKABLE void switchCommand(QString command);
  34. double currentRefreshRate();
  35. QString debugInformation();
  36. private:
  37. explicit DisplayComponent(QObject *parent = nullptr);
  38. QString displayName(int display);
  39. QString modePretty(int display, int mode);
  40. DisplayManager *m_displayManager;
  41. int m_lastVideoMode;
  42. int m_lastDisplay;
  43. QTimer m_initTimer;
  44. QWindow* m_applicationWindow;
  45. public Q_SLOTS:
  46. void monitorChange();
  47. bool initializeDisplayManager();
  48. bool restorePreviousVideoMode();
  49. Q_SIGNALS:
  50. void refreshRateChanged();
  51. };
  52. #endif // DISPLAYCOMPONENT_H