rp_window.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // This file is part of Desktop App Toolkit,
  2. // a set of libraries for developing nice desktop applications.
  3. //
  4. // For license and copyright information please follow this link:
  5. // https://github.com/desktop-app/legal/blob/master/LEGAL
  6. //
  7. #pragma once
  8. #include "ui/rp_widget.h"
  9. #include "base/flags.h"
  10. namespace style {
  11. struct WindowTitle;
  12. struct TextStyle;
  13. } // namespace style
  14. namespace Ui {
  15. namespace Platform {
  16. class BasicWindowHelper;
  17. struct HitTestRequest;
  18. enum class HitTestResult;
  19. } // namespace Platform
  20. enum class WindowTitleHitTestFlag {
  21. None = 0x00,
  22. Move = 0x01,
  23. Menu = 0x02,
  24. Maximize = 0x04,
  25. FullScreen = 0x08,
  26. };
  27. inline constexpr bool is_flag_type(WindowTitleHitTestFlag) {
  28. return true;
  29. }
  30. using WindowTitleHitTestFlags = base::flags<WindowTitleHitTestFlag>;
  31. class RpWindow : public RpWidget {
  32. public:
  33. explicit RpWindow(QWidget *parent = nullptr);
  34. ~RpWindow();
  35. [[nodiscard]] not_null<RpWidget*> body();
  36. [[nodiscard]] not_null<const RpWidget*> body() const;
  37. [[nodiscard]] QMargins frameMargins() const;
  38. // In Windows 11 the window rounding shadow takes about
  39. // round(1px * system_scale) from the window geometry on each side.
  40. //
  41. // Top shift is made by the TitleWidget height, but the rest of the
  42. // side shifts are left for the RpWindow client to consider.
  43. [[nodiscard]] int additionalContentPadding() const;
  44. [[nodiscard]] rpl::producer<int> additionalContentPaddingValue() const;
  45. [[nodiscard]] auto hitTestRequests() const
  46. -> rpl::producer<not_null<Platform::HitTestRequest*>>;
  47. [[nodiscard]] auto systemButtonOver() const
  48. -> rpl::producer<Platform::HitTestResult>;
  49. [[nodiscard]] auto systemButtonDown() const
  50. -> rpl::producer<Platform::HitTestResult>;
  51. void overrideSystemButtonOver(Platform::HitTestResult button);
  52. void overrideSystemButtonDown(Platform::HitTestResult button);
  53. void setTitle(const QString &title);
  54. void setTitleStyle(const style::WindowTitle &st);
  55. void setNativeFrame(bool enabled);
  56. void setMinimumSize(QSize size);
  57. void setFixedSize(QSize size);
  58. void setStaysOnTop(bool enabled);
  59. void setGeometry(QRect rect);
  60. void showFullScreen();
  61. void showNormal();
  62. void close();
  63. [[nodiscard]] int manualRoundingRadius() const;
  64. void setBodyTitleArea(Fn<WindowTitleHitTestFlags(QPoint)> testMethod);
  65. // Check if MouseButtonRelease was from the pressed state being
  66. // cancelled by startSystemMove / startSystemResize call.
  67. [[nodiscard]] bool mousePressCancelled() const;
  68. [[nodiscard]] const style::TextStyle &titleTextStyle() const;
  69. private:
  70. const std::unique_ptr<Platform::BasicWindowHelper> _helper;
  71. };
  72. } // namespace Ui