create_poll_box.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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/layers/box_content.h"
  9. #include "api/api_common.h"
  10. #include "data/data_poll.h"
  11. #include "base/flags.h"
  12. struct PollData;
  13. namespace ChatHelpers {
  14. class TabbedPanel;
  15. } // namespace ChatHelpers
  16. namespace Ui {
  17. class VerticalLayout;
  18. } // namespace Ui
  19. namespace Window {
  20. class SessionController;
  21. } // namespace Window
  22. namespace SendMenu {
  23. struct Details;
  24. } // namespace SendMenu
  25. class CreatePollBox : public Ui::BoxContent {
  26. public:
  27. struct Result {
  28. PollData poll;
  29. Api::SendOptions options;
  30. };
  31. CreatePollBox(
  32. QWidget*,
  33. not_null<Window::SessionController*> controller,
  34. PollData::Flags chosen,
  35. PollData::Flags disabled,
  36. rpl::producer<int> starsRequired,
  37. Api::SendType sendType,
  38. SendMenu::Details sendMenuDetails);
  39. [[nodiscard]] rpl::producer<Result> submitRequests() const;
  40. void submitFailed(const QString &error);
  41. void setInnerFocus() override;
  42. protected:
  43. void prepare() override;
  44. private:
  45. enum class Error {
  46. Question = 0x01,
  47. Options = 0x02,
  48. Correct = 0x04,
  49. Other = 0x08,
  50. Solution = 0x10,
  51. };
  52. friend constexpr inline bool is_flag_type(Error) { return true; }
  53. using Errors = base::flags<Error>;
  54. [[nodiscard]] object_ptr<Ui::RpWidget> setupContent();
  55. [[nodiscard]] not_null<Ui::InputField*> setupQuestion(
  56. not_null<Ui::VerticalLayout*> container);
  57. [[nodiscard]] not_null<Ui::InputField*> setupSolution(
  58. not_null<Ui::VerticalLayout*> container,
  59. rpl::producer<bool> shown);
  60. const not_null<Window::SessionController*> _controller;
  61. const PollData::Flags _chosen = PollData::Flags();
  62. const PollData::Flags _disabled = PollData::Flags();
  63. const Api::SendType _sendType = Api::SendType();
  64. const Fn<SendMenu::Details()> _sendMenuDetails;
  65. rpl::variable<int> _starsRequired;
  66. base::unique_qptr<ChatHelpers::TabbedPanel> _emojiPanel;
  67. Fn<void()> _setInnerFocus;
  68. Fn<rpl::producer<bool>()> _dataIsValidValue;
  69. rpl::event_stream<Result> _submitRequests;
  70. };