edit_caption_box.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 "history/view/controls/history_view_compose_media_edit_manager.h"
  9. #include "ui/layers/box_content.h"
  10. #include "ui/chat/attach/attach_prepare.h"
  11. namespace ChatHelpers {
  12. class TabbedPanel;
  13. class FieldAutocomplete;
  14. } // namespace ChatHelpers
  15. namespace Window {
  16. class SessionController;
  17. } // namespace Window
  18. namespace Data {
  19. class PhotoMedia;
  20. } // namespace Data
  21. namespace Ui {
  22. class AbstractSinglePreview;
  23. class InputField;
  24. class EmojiButton;
  25. class VerticalLayout;
  26. enum class AlbumType;
  27. } // namespace Ui
  28. class EditCaptionBox final : public Ui::BoxContent {
  29. public:
  30. EditCaptionBox(
  31. QWidget*,
  32. not_null<Window::SessionController*> controller,
  33. not_null<HistoryItem*> item,
  34. TextWithTags &&text,
  35. bool spoilered,
  36. bool invertCaption,
  37. Ui::PreparedList &&list,
  38. Fn<void()> saved);
  39. ~EditCaptionBox();
  40. static void StartMediaReplace(
  41. not_null<Window::SessionController*> controller,
  42. FullMsgId itemId,
  43. TextWithTags text,
  44. bool spoilered,
  45. bool invertCaption,
  46. Fn<void()> saved);
  47. static void StartMediaReplace(
  48. not_null<Window::SessionController*> controller,
  49. FullMsgId itemId,
  50. Ui::PreparedList &&list,
  51. TextWithTags text,
  52. bool spoilered,
  53. bool invertCaption,
  54. Fn<void()> saved);
  55. static void StartPhotoEdit(
  56. not_null<Window::SessionController*> controller,
  57. std::shared_ptr<Data::PhotoMedia> media,
  58. FullMsgId itemId,
  59. TextWithTags text,
  60. bool spoilered,
  61. bool invertCaption,
  62. Fn<void()> saved);
  63. void showFinished() override;
  64. protected:
  65. void prepare() override;
  66. void setInnerFocus() override;
  67. void paintEvent(QPaintEvent *e) override;
  68. void resizeEvent(QResizeEvent *e) override;
  69. void keyPressEvent(QKeyEvent *e) override;
  70. private:
  71. void rebuildPreview();
  72. void setupEditEventHandler();
  73. void setupPhotoEditorEventHandler();
  74. void setupField();
  75. void setupFieldAutocomplete();
  76. void setupControls();
  77. void setInitialText();
  78. void updateBoxSize();
  79. void captionResized();
  80. void setupEmojiPanel();
  81. void updateEmojiPanelGeometry();
  82. void emojiFilterForGeometry(not_null<QEvent*> event);
  83. void setupDragArea();
  84. bool validateLength(const QString &text) const;
  85. void applyChanges();
  86. void save();
  87. void closeAfterSave();
  88. bool fileFromClipboard(not_null<const QMimeData*> data);
  89. [[nodiscard]] int errorTopSkip() const;
  90. [[nodiscard]] bool hasSpoiler() const;
  91. bool setPreparedList(Ui::PreparedList &&list);
  92. const not_null<Window::SessionController*> _controller;
  93. const not_null<HistoryItem*> _historyItem;
  94. const bool _isAllowedEditMedia;
  95. const Ui::AlbumType _albumType;
  96. const base::unique_qptr<Ui::VerticalLayout> _controls;
  97. const base::unique_qptr<Ui::ScrollArea> _scroll;
  98. const base::unique_qptr<Ui::InputField> _field;
  99. const base::unique_qptr<Ui::EmojiButton> _emojiToggle;
  100. std::unique_ptr<ChatHelpers::FieldAutocomplete> _autocomplete;
  101. base::unique_qptr<Ui::AbstractSinglePreview> _content;
  102. base::unique_qptr<ChatHelpers::TabbedPanel> _emojiPanel;
  103. base::unique_qptr<QObject> _emojiFilter;
  104. const TextWithTags _initialText;
  105. Ui::PreparedList _initialList;
  106. Fn<void()> _saved;
  107. std::shared_ptr<Data::PhotoMedia> _photoMedia;
  108. Ui::PreparedList _preparedList;
  109. HistoryView::MediaEditManager _mediaEditManager;
  110. mtpRequestId _saveRequestId = 0;
  111. base::Timer _checkChangedTimer;
  112. bool _isPhoto = false;
  113. bool _asFile = false;
  114. QString _error;
  115. rpl::variable<int> _footerHeight = 0;
  116. rpl::event_stream<> _editMediaClicks;
  117. rpl::event_stream<> _photoEditorOpens;
  118. rpl::event_stream<> _previewRebuilds;
  119. rpl::event_stream<int> _contentHeight;
  120. };