2024-02-08 12:20:33 +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
|
|
|
|
*/
|
2023-11-27 17:08:59 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "ui/rp_widget.h"
|
|
|
|
|
|
|
|
namespace Ui {
|
|
|
|
|
|
|
|
class CodeDigit;
|
2023-11-28 03:57:55 +00:00
|
|
|
class PopupMenu;
|
2023-11-27 17:08:59 +00:00
|
|
|
|
|
|
|
class CodeInput final : public Ui::RpWidget {
|
|
|
|
public:
|
|
|
|
CodeInput(QWidget *parent);
|
|
|
|
|
|
|
|
void setDigitsCountMax(int digitsCount);
|
|
|
|
|
|
|
|
void setCode(QString code);
|
|
|
|
|
|
|
|
void requestCode();
|
|
|
|
[[nodiscard]] rpl::producer<QString> codeCollected() const;
|
|
|
|
|
|
|
|
void clear();
|
|
|
|
void showError();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void focusInEvent(QFocusEvent *e) override;
|
|
|
|
void focusOutEvent(QFocusEvent *e) override;
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
void keyPressEvent(QKeyEvent *e) override;
|
2023-11-28 03:57:55 +00:00
|
|
|
void contextMenuEvent(QContextMenuEvent *e) override;
|
2023-11-27 17:08:59 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
[[nodiscard]] QString collectDigits() const;
|
|
|
|
|
2023-11-28 03:57:55 +00:00
|
|
|
void insertCodeAndSubmit(const QString &code);
|
2023-11-27 17:08:59 +00:00
|
|
|
void unfocusAll(int except);
|
|
|
|
void findEmptyAndPerform(const Fn<void(int)> &callback);
|
|
|
|
|
|
|
|
int _digitsCountMax = 0;
|
|
|
|
std::vector<not_null<CodeDigit*>> _digits;
|
|
|
|
int _currentIndex = 0;
|
|
|
|
|
2023-11-28 03:57:55 +00:00
|
|
|
base::unique_qptr<Ui::PopupMenu> _menu;
|
|
|
|
|
2023-11-27 17:08:59 +00:00
|
|
|
rpl::event_stream<QString> _codeCollected;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Ui
|