attach_controls.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. #include "ui/chat/attach/attach_controls.h"
  8. #include "styles/style_chat_helpers.h"
  9. namespace Ui {
  10. AttachControls::AttachControls()
  11. : _rect(st::sendBoxAlbumGroupRadius, st::roundedBg) {
  12. }
  13. void AttachControls::paint(QPainter &p, int x, int y) {
  14. const auto groupWidth = width();
  15. const auto groupHeight = height();
  16. const auto full = (_type == Type::Full);
  17. QRect groupRect(x, y, groupWidth, groupHeight);
  18. _rect.paint(p, groupRect);
  19. if (full) {
  20. const auto groupHalfWidth = groupWidth / 2;
  21. const auto groupHalfHeight = groupHeight / 2;
  22. const auto editRect = _vertical
  23. ? QRect(x, y, groupWidth, groupHalfHeight)
  24. : QRect(x, y, groupHalfWidth, groupHeight);
  25. st::sendBoxAlbumGroupButtonMediaEdit.paintInCenter(p, editRect);
  26. const auto deleteRect = _vertical
  27. ? QRect(x, y + groupHalfHeight, groupWidth, groupHalfHeight)
  28. : QRect(x + groupHalfWidth, y, groupHalfWidth, groupHeight);
  29. st::sendBoxAlbumGroupButtonMediaDelete.paintInCenter(p, deleteRect);
  30. } else if (_type == Type::EditOnly) {
  31. st::sendBoxAlbumButtonMediaEdit.paintInCenter(p, groupRect);
  32. }
  33. }
  34. int AttachControls::width() const {
  35. return (_type == Type::Full)
  36. ? (_vertical
  37. ? st::sendBoxAlbumGroupSizeVertical.width()
  38. : st::sendBoxAlbumGroupSize.width())
  39. : (_type == Type::EditOnly)
  40. ? st::sendBoxAlbumSmallGroupSize.width()
  41. : 0;
  42. }
  43. int AttachControls::height() const {
  44. return (_type == Type::Full)
  45. ? (_vertical
  46. ? st::sendBoxAlbumGroupSizeVertical.height()
  47. : st::sendBoxAlbumGroupSize.height())
  48. : (_type == Type::EditOnly)
  49. ? st::sendBoxAlbumSmallGroupSize.height()
  50. : 0;
  51. }
  52. AttachControls::Type AttachControls::type() const {
  53. return _type;
  54. }
  55. bool AttachControls::vertical() const {
  56. return _vertical;
  57. }
  58. void AttachControls::setType(Type type) {
  59. if (_type != type) {
  60. _type = type;
  61. }
  62. }
  63. void AttachControls::setVertical(bool vertical) {
  64. _vertical = vertical;
  65. }
  66. AttachControlsWidget::AttachControlsWidget(
  67. not_null<RpWidget*> parent,
  68. AttachControls::Type type)
  69. : RpWidget(parent)
  70. , _edit(base::make_unique_q<AbstractButton>(this))
  71. , _delete(base::make_unique_q<AbstractButton>(this)) {
  72. _controls.setType(type);
  73. const auto w = _controls.width();
  74. resize(w, _controls.height());
  75. if (type == AttachControls::Type::Full) {
  76. _edit->resize(w / 2, _controls.height());
  77. _delete->resize(w / 2, _controls.height());
  78. _edit->moveToLeft(0, 0, w);
  79. _delete->moveToRight(0, 0, w);
  80. } else if (type == AttachControls::Type::EditOnly) {
  81. _edit->resize(w, _controls.height());
  82. _edit->moveToLeft(0, 0, w);
  83. }
  84. paintRequest(
  85. ) | rpl::start_with_next([=] {
  86. auto p = QPainter(this);
  87. _controls.paint(p, 0, 0);
  88. }, lifetime());
  89. }
  90. rpl::producer<> AttachControlsWidget::editRequests() const {
  91. return _edit->clicks() | rpl::to_empty;
  92. }
  93. rpl::producer<> AttachControlsWidget::deleteRequests() const {
  94. return _delete->clicks() | rpl::to_empty;
  95. }
  96. } // namespace Ui