forward_options_box.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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/forward_options_box.h"
  8. #include "ui/widgets/checkbox.h"
  9. #include "ui/widgets/labels.h"
  10. #include "lang/lang_keys.h"
  11. #include "styles/style_layers.h"
  12. #include "styles/style_boxes.h"
  13. namespace Ui {
  14. void FillForwardOptions(
  15. Fn<not_null<AbstractCheckView*>(
  16. rpl::producer<QString> &&,
  17. bool)> createView,
  18. ForwardOptions options,
  19. Fn<void(ForwardOptions)> optionsChanged,
  20. rpl::lifetime &lifetime) {
  21. Expects(optionsChanged != nullptr);
  22. const auto names = createView(
  23. (options.sendersCount == 1
  24. ? tr::lng_forward_show_sender
  25. : tr::lng_forward_show_senders)(),
  26. !options.dropNames);
  27. const auto captions = options.captionsCount
  28. ? createView(
  29. (options.captionsCount == 1
  30. ? tr::lng_forward_show_caption
  31. : tr::lng_forward_show_captions)(),
  32. !options.dropCaptions).get()
  33. : nullptr;
  34. const auto notify = [=] {
  35. optionsChanged({
  36. .sendersCount = options.sendersCount,
  37. .captionsCount = options.captionsCount,
  38. .dropNames = !names->checked(),
  39. .dropCaptions = (captions && !captions->checked()),
  40. });
  41. };
  42. names->checkedChanges(
  43. ) | rpl::start_with_next([=](bool showNames) {
  44. if (showNames && captions && !captions->checked()) {
  45. captions->setChecked(true, anim::type::normal);
  46. } else {
  47. notify();
  48. }
  49. }, lifetime);
  50. if (captions) {
  51. captions->checkedChanges(
  52. ) | rpl::start_with_next([=](bool showCaptions) {
  53. if (!showCaptions && names->checked()) {
  54. names->setChecked(false, anim::type::normal);
  55. } else {
  56. notify();
  57. }
  58. }, lifetime);
  59. }
  60. }
  61. } // namespace Ui