box_layer_widget.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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/unique_qptr.h"
  9. #include "base/flags.h"
  10. #include "ui/layers/layer_widget.h"
  11. #include "ui/layers/box_content.h"
  12. #include "ui/round_rect.h"
  13. #include "ui/rp_widget.h"
  14. class Painter;
  15. struct TextWithEntities;
  16. namespace anim {
  17. enum class type : uchar;
  18. } // namespace anim
  19. namespace style {
  20. struct Box;
  21. } // namespace style
  22. namespace Ui {
  23. class AbstractButton;
  24. class FlatLabel;
  25. class BoxLayerWidget : public LayerWidget, public BoxContentDelegate {
  26. public:
  27. BoxLayerWidget(
  28. not_null<LayerStackWidget*> layer,
  29. object_ptr<BoxContent> content);
  30. ~BoxLayerWidget();
  31. void parentResized() override;
  32. void setLayerType(bool layerType) override;
  33. void setStyle(const style::Box &st) override;
  34. const style::Box &style() override;
  35. void setTitle(rpl::producer<TextWithEntities> title) override;
  36. void setAdditionalTitle(rpl::producer<QString> additional) override;
  37. void showBox(
  38. object_ptr<BoxContent> box,
  39. LayerOptions options,
  40. anim::type animated) override;
  41. void showFinished() override {
  42. _content->showFinished();
  43. }
  44. void setCustomCornersFilling(RectParts corners) override;
  45. void clearButtons() override;
  46. void addButton(object_ptr<AbstractButton> button) override;
  47. void addLeftButton(object_ptr<AbstractButton> button) override;
  48. void addTopButton(object_ptr<AbstractButton> button) override;
  49. void showLoading(bool show) override;
  50. void updateButtonsPositions() override;
  51. ShowFactory showFactory() override;
  52. QPointer<QWidget> outerContainer() override;
  53. void setDimensions(
  54. int newWidth,
  55. int maxHeight,
  56. bool forceCenterPosition = false) override;
  57. void setNoContentMargin(bool noContentMargin) override {
  58. if (_noContentMargin != noContentMargin) {
  59. _noContentMargin = noContentMargin;
  60. updateSize();
  61. }
  62. }
  63. bool isBoxShown() const override {
  64. return !isHidden();
  65. }
  66. void closeBox() override {
  67. closeLayer();
  68. }
  69. void hideLayer() override;
  70. void triggerButton(int index) override;
  71. void setCloseByOutsideClick(bool close) override;
  72. bool closeByOutsideClick() const override;
  73. protected:
  74. void keyPressEvent(QKeyEvent *e) override;
  75. void resizeEvent(QResizeEvent *e) override;
  76. void paintEvent(QPaintEvent *e) override;
  77. void doSetInnerFocus() override {
  78. _content->setInnerFocus();
  79. }
  80. void closeHook() override {
  81. _content->notifyBoxClosing();
  82. }
  83. private:
  84. struct LoadingProgress;
  85. void paintAdditionalTitle(Painter &p);
  86. void updateTitlePosition();
  87. [[nodiscard]] const style::Box &st() const;
  88. [[nodiscard]] bool hasTitle() const;
  89. [[nodiscard]] int titleHeight() const;
  90. [[nodiscard]] int buttonsHeight() const;
  91. [[nodiscard]] int buttonsTop() const;
  92. [[nodiscard]] int contentTop() const;
  93. [[nodiscard]] int countFullHeight() const;
  94. [[nodiscard]] int countRealHeight() const;
  95. [[nodiscard]] QRect loadingRect() const;
  96. void updateSize();
  97. const style::Box *_st = nullptr;
  98. not_null<LayerStackWidget*> _layer;
  99. bool _layerType = false;
  100. int _fullHeight = 0;
  101. bool _noContentMargin = false;
  102. int _maxContentHeight = 0;
  103. object_ptr<BoxContent> _content;
  104. RoundRect _roundRect;
  105. object_ptr<FlatLabel> _title = { nullptr };
  106. Fn<TextWithEntities()> _titleFactory;
  107. rpl::variable<QString> _additionalTitle;
  108. RectParts _customCornersFilling;
  109. int _titleLeft = 0;
  110. int _titleTop = 0;
  111. bool _closeByOutsideClick = true;
  112. std::vector<object_ptr<AbstractButton>> _buttons;
  113. object_ptr<AbstractButton> _leftButton = { nullptr };
  114. base::unique_qptr<AbstractButton> _topButton = { nullptr };
  115. std::unique_ptr<LoadingProgress> _loadingProgress;
  116. };
  117. } // namespace Ui