window_top_bar_wrap.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #pragma once
  8. #include "ui/wrap/slide_wrap.h"
  9. namespace Window {
  10. template <typename Inner>
  11. class TopBarWrapWidget : public Ui::SlideWrap<Inner> {
  12. using Parent = Ui::SlideWrap<Inner>;
  13. public:
  14. TopBarWrapWidget(
  15. QWidget *parent,
  16. object_ptr<Inner> inner,
  17. rpl::producer<bool> oneColumnValue)
  18. : Parent(parent, std::move(inner)) {
  19. this->sizeValue(
  20. ) | rpl::start_with_next([=](const QSize &size) {
  21. updateShadowGeometry(size);
  22. }, this->lifetime());
  23. std::move(
  24. oneColumnValue
  25. ) | rpl::start_with_next([=](bool oneColumn) {
  26. _isOneColumn = oneColumn;
  27. }, this->lifetime());
  28. }
  29. void updateAdaptiveLayout() {
  30. updateShadowGeometry(this->size());
  31. }
  32. void showShadow() {
  33. this->entity()->showShadow();
  34. }
  35. void hideShadow() {
  36. this->entity()->hideShadow();
  37. }
  38. int contentHeight() const {
  39. return qMax(this->height() - st::lineWidth, 0);
  40. }
  41. private:
  42. void updateShadowGeometry(const QSize &size) {
  43. const auto skip = _isOneColumn ? 0 : st::lineWidth;
  44. this->entity()->setShadowGeometryToLeft(
  45. skip,
  46. size.height() - st::lineWidth,
  47. size.width() - skip,
  48. st::lineWidth);
  49. }
  50. bool _isOneColumn = false;
  51. };
  52. } // namespace Window