show.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 "base/weak_ptr.h"
  9. #include "ui/layers/layer_widget.h"
  10. struct TextWithEntities;
  11. namespace anim {
  12. enum class type : uchar;
  13. } // namespace anim
  14. namespace Ui::Toast {
  15. struct Config;
  16. class Instance;
  17. } // namespace Ui::Toast
  18. namespace Ui {
  19. class BoxContent;
  20. class LayerWidget;
  21. inline constexpr auto kZOrderBasic = 0;
  22. class Show {
  23. public:
  24. virtual ~Show() = 0;
  25. virtual void showOrHideBoxOrLayer(
  26. std::variant<
  27. v::null_t,
  28. object_ptr<BoxContent>,
  29. std::unique_ptr<LayerWidget>> &&layer,
  30. LayerOptions options,
  31. anim::type animated) const = 0;
  32. [[nodiscard]] virtual not_null<QWidget*> toastParent() const = 0;
  33. [[nodiscard]] virtual bool valid() const = 0;
  34. virtual operator bool() const = 0;
  35. void showBox(
  36. object_ptr<BoxContent> content,
  37. LayerOptions options = LayerOption::KeepOther,
  38. anim::type animated = anim::type()) const;
  39. void showLayer(
  40. std::unique_ptr<LayerWidget> layer,
  41. LayerOptions options = LayerOption::KeepOther,
  42. anim::type animated = anim::type()) const;
  43. void hideLayer(anim::type animated = anim::type()) const;
  44. base::weak_ptr<Toast::Instance> showToast(Toast::Config &&config) const;
  45. base::weak_ptr<Toast::Instance> showToast(
  46. TextWithEntities &&text,
  47. crl::time duration = 0) const;
  48. base::weak_ptr<Toast::Instance> showToast(
  49. const QString &text,
  50. crl::time duration = 0) const;
  51. template <
  52. typename BoxType,
  53. typename = std::enable_if_t<std::is_base_of_v<BoxContent, BoxType>>>
  54. QPointer<BoxType> show(
  55. object_ptr<BoxType> content,
  56. LayerOptions options = LayerOption::KeepOther,
  57. anim::type animated = anim::type()) const {
  58. auto result = QPointer<BoxType>(content.data());
  59. showBox(std::move(content), options, animated);
  60. return result;
  61. }
  62. private:
  63. mutable base::weak_ptr<Toast::Instance> _lastToast;
  64. };
  65. inline Show::~Show() = default;
  66. } // namespace Ui