2018-12-20 16:02:44 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "boxes/abstract_box.h"
|
2019-08-20 13:21:10 +00:00
|
|
|
#include "api/api_common.h"
|
|
|
|
#include "data/data_poll.h"
|
2020-01-24 14:45:05 +00:00
|
|
|
#include "base/flags.h"
|
2018-12-20 16:02:44 +00:00
|
|
|
|
2019-08-02 10:40:35 +00:00
|
|
|
struct PollData;
|
|
|
|
|
2018-12-20 16:02:44 +00:00
|
|
|
namespace Ui {
|
|
|
|
class VerticalLayout;
|
|
|
|
} // namespace Ui
|
|
|
|
|
2020-06-10 18:08:17 +00:00
|
|
|
namespace Window {
|
|
|
|
class SessionController;
|
|
|
|
} // namespace Window
|
2018-12-20 16:02:44 +00:00
|
|
|
|
2019-09-18 11:19:05 +00:00
|
|
|
class CreatePollBox : public Ui::BoxContent {
|
2018-12-20 16:02:44 +00:00
|
|
|
public:
|
2019-08-20 13:21:10 +00:00
|
|
|
struct Result {
|
|
|
|
PollData poll;
|
|
|
|
Api::SendOptions options;
|
|
|
|
};
|
2018-12-20 16:02:44 +00:00
|
|
|
|
2019-08-20 13:21:10 +00:00
|
|
|
CreatePollBox(
|
|
|
|
QWidget*,
|
2020-06-10 18:08:17 +00:00
|
|
|
not_null<Window::SessionController*> controller,
|
2020-01-15 13:30:29 +00:00
|
|
|
PollData::Flags chosen,
|
|
|
|
PollData::Flags disabled,
|
2019-08-20 13:21:10 +00:00
|
|
|
Api::SendType sendType);
|
|
|
|
|
2020-04-06 11:54:05 +00:00
|
|
|
[[nodiscard]] rpl::producer<Result> submitRequests() const;
|
2018-12-20 16:02:44 +00:00
|
|
|
void submitFailed(const QString &error);
|
|
|
|
|
|
|
|
void setInnerFocus() override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void prepare() override;
|
|
|
|
|
|
|
|
private:
|
2020-01-24 14:45:05 +00:00
|
|
|
enum class Error {
|
|
|
|
Question = 0x01,
|
|
|
|
Options = 0x02,
|
|
|
|
Correct = 0x04,
|
|
|
|
Other = 0x08,
|
2020-04-13 08:17:55 +00:00
|
|
|
Solution = 0x10,
|
2020-01-24 14:45:05 +00:00
|
|
|
};
|
|
|
|
friend constexpr inline bool is_flag_type(Error) { return true; }
|
|
|
|
using Errors = base::flags<Error>;
|
|
|
|
|
2020-04-06 11:54:05 +00:00
|
|
|
[[nodiscard]] object_ptr<Ui::RpWidget> setupContent();
|
|
|
|
[[nodiscard]] not_null<Ui::InputField*> setupQuestion(
|
2018-12-20 16:02:44 +00:00
|
|
|
not_null<Ui::VerticalLayout*> container);
|
2020-04-06 11:54:05 +00:00
|
|
|
[[nodiscard]] not_null<Ui::InputField*> setupSolution(
|
|
|
|
not_null<Ui::VerticalLayout*> container,
|
|
|
|
rpl::producer<bool> shown);
|
2018-12-20 16:02:44 +00:00
|
|
|
|
2020-06-10 18:08:17 +00:00
|
|
|
const not_null<Window::SessionController*> _controller;
|
2020-01-15 13:30:29 +00:00
|
|
|
const PollData::Flags _chosen = PollData::Flags();
|
|
|
|
const PollData::Flags _disabled = PollData::Flags();
|
2019-08-20 13:21:10 +00:00
|
|
|
const Api::SendType _sendType = Api::SendType();
|
2018-12-20 16:02:44 +00:00
|
|
|
Fn<void()> _setInnerFocus;
|
|
|
|
Fn<rpl::producer<bool>()> _dataIsValidValue;
|
2019-08-20 13:21:10 +00:00
|
|
|
rpl::event_stream<Result> _submitRequests;
|
2018-12-20 16:02:44 +00:00
|
|
|
|
|
|
|
};
|