history_view_object.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. namespace HistoryView {
  9. class Object {
  10. public:
  11. Object() = default;
  12. Object(const Object &other) = delete;
  13. Object &operator=(const Object &other) = delete;
  14. void initDimensions() {
  15. setOptimalSize(countOptimalSize());
  16. }
  17. int resizeGetHeight(int newWidth) {
  18. setCurrentSize(countCurrentSize(newWidth));
  19. return _height;
  20. }
  21. [[nodiscard]] QSize optimalSize() const {
  22. return { _maxWidth, _minHeight };
  23. }
  24. [[nodiscard]] QSize currentSize() const {
  25. return { _width, _height };
  26. }
  27. [[nodiscard]] int maxWidth() const {
  28. return _maxWidth;
  29. }
  30. [[nodiscard]] int minHeight() const {
  31. return _minHeight;
  32. }
  33. [[nodiscard]] int width() const {
  34. return _width;
  35. }
  36. [[nodiscard]] int height() const {
  37. return _height;
  38. }
  39. virtual ~Object() = default;
  40. protected:
  41. void setOptimalSize(QSize size) {
  42. _maxWidth = size.width();
  43. _minHeight = size.height();
  44. }
  45. void setCurrentSize(QSize size) {
  46. _width = size.width();
  47. _height = size.height();
  48. }
  49. private:
  50. virtual QSize countOptimalSize() = 0;
  51. virtual QSize countCurrentSize(int newWidth) = 0;
  52. int _maxWidth = 0;
  53. int _minHeight = 0;
  54. int _width = 0;
  55. int _height = 0;
  56. };
  57. } // namespace HistoryView