2021-03-26 19:23:12 +04: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 "base/object_ptr.h"
|
|
|
|
#include "base/unique_qptr.h"
|
|
|
|
|
|
|
|
namespace Ui {
|
|
|
|
class RpWidget;
|
|
|
|
class InputField;
|
|
|
|
class MaskedInputField;
|
2021-03-26 21:09:09 +04:00
|
|
|
class BoxContent;
|
2021-03-26 19:23:12 +04:00
|
|
|
} // namespace Ui
|
|
|
|
|
|
|
|
namespace Payments::Ui {
|
|
|
|
|
|
|
|
using namespace ::Ui;
|
|
|
|
|
|
|
|
enum class FieldType {
|
|
|
|
Text,
|
|
|
|
CardNumber,
|
|
|
|
CardExpireDate,
|
|
|
|
CardCVC,
|
|
|
|
Country,
|
|
|
|
Phone,
|
|
|
|
Email,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct FieldConfig {
|
|
|
|
FieldType type = FieldType::Text;
|
|
|
|
rpl::producer<QString> placeholder;
|
|
|
|
QString value;
|
2021-03-26 21:09:09 +04:00
|
|
|
Fn<void(object_ptr<BoxContent>)> showBox;
|
|
|
|
QString defaultCountry;
|
2021-03-26 19:23:12 +04:00
|
|
|
int maxLength = 0;
|
|
|
|
bool required = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Field final {
|
|
|
|
public:
|
|
|
|
Field(QWidget *parent, FieldConfig &&config);
|
|
|
|
|
|
|
|
[[nodiscard]] RpWidget *widget() const;
|
|
|
|
[[nodiscard]] object_ptr<RpWidget> ownedWidget() const;
|
|
|
|
|
|
|
|
[[nodiscard]] QString value() const;
|
|
|
|
|
|
|
|
void setFocus();
|
|
|
|
void setFocusFast();
|
|
|
|
void showError();
|
|
|
|
|
|
|
|
private:
|
2021-03-26 21:09:09 +04:00
|
|
|
void setupMaskedGeometry();
|
|
|
|
void setupCountry();
|
|
|
|
|
|
|
|
const FieldConfig _config;
|
2021-03-26 19:23:12 +04:00
|
|
|
const base::unique_qptr<RpWidget> _wrap;
|
|
|
|
InputField *_input = nullptr;
|
|
|
|
MaskedInputField *_masked = nullptr;
|
2021-03-26 21:09:09 +04:00
|
|
|
QString _countryIso2;
|
2021-03-26 19:23:12 +04:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Payments::Ui
|