layer_manager.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. #include <QtCore/QMargins>
  11. namespace style {
  12. struct Box;
  13. } // namespace style
  14. namespace Ui {
  15. class BoxContent;
  16. class RpWidget;
  17. class Show;
  18. class LayerManager final : public base::has_weak_ptr {
  19. public:
  20. explicit LayerManager(not_null<RpWidget*> widget);
  21. void setStyleOverrides(
  22. const style::Box *boxSt,
  23. const style::Box *layerSt);
  24. void setHideByBackgroundClick(bool hide);
  25. void showBox(
  26. object_ptr<BoxContent> box,
  27. LayerOptions options = LayerOption::KeepOther,
  28. anim::type animated = anim::type::normal);
  29. void showLayer(
  30. std::unique_ptr<LayerWidget> layer,
  31. LayerOptions options = LayerOption::KeepOther,
  32. anim::type animated = anim::type::normal);
  33. void hideAll(anim::type animated = anim::type::normal);
  34. void raise();
  35. bool setFocus();
  36. [[nodiscard]] rpl::producer<bool> layerShownValue() const {
  37. return _layerShown.value();
  38. }
  39. [[nodiscard]] not_null<Ui::RpWidget*> toastParent() const {
  40. return _widget;
  41. }
  42. [[nodiscard]] const LayerWidget *topShownLayer() const;
  43. [[nodiscard]] std::shared_ptr<Show> uiShow();
  44. private:
  45. class ManagerShow;
  46. void ensureLayerCreated();
  47. void destroyLayer();
  48. const not_null<RpWidget*> _widget;
  49. base::unique_qptr<LayerStackWidget> _layer;
  50. std::shared_ptr<ManagerShow> _cachedShow;
  51. rpl::variable<bool> _layerShown;
  52. const style::Box *_boxSt = nullptr;
  53. const style::Box *_layerSt = nullptr;
  54. bool _hideByBackgroundClick = false;
  55. };
  56. } // namespace Ui