round_rect.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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/rect_part.h"
  9. #include "ui/style/style_core.h"
  10. enum class ImageRoundRadius;
  11. class QPainter;
  12. namespace Ui {
  13. [[nodiscard]] QPainterPath ComplexRoundedRectPath(
  14. const QRect &rect,
  15. int topLeftRadius,
  16. int topRightRadius,
  17. int bottomLeftRadius,
  18. int bottomRightRadius);
  19. void DrawRoundedRect(
  20. QPainter &p,
  21. const QRect &rect,
  22. const QBrush &brush,
  23. const std::array<QImage, 4> &corners,
  24. RectParts parts = RectPart::Full);
  25. class RoundRect final {
  26. public:
  27. RoundRect(ImageRoundRadius radius, const style::color &color);
  28. RoundRect(int radius, const style::color &color);
  29. [[nodiscard]] const style::color &color() const;
  30. void setColor(const style::color &color);
  31. void paint(
  32. QPainter &p,
  33. const QRect &rect,
  34. RectParts parts = RectPart::Full) const;
  35. void paintSomeRounded(
  36. QPainter &p,
  37. const QRect &rect,
  38. RectParts corners) const;
  39. private:
  40. style::color _color;
  41. std::array<QImage, 4> _corners;
  42. Fn<void()> _refresh;
  43. rpl::lifetime _lifetime;
  44. };
  45. } // namespace Ui