mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-15 21:57:10 +02:00
Added ability to paste login code from clipboard to new code input.
This commit is contained in:
parent
ac8117a6d8
commit
9f0b4bc799
2 changed files with 36 additions and 0 deletions
|
@ -6,14 +6,18 @@
|
|||
//
|
||||
#include "intro/intro_code_input.h"
|
||||
|
||||
#include "lang/lang_keys.h"
|
||||
#include "ui/abstract_button.h"
|
||||
#include "ui/effects/shake_animation.h"
|
||||
#include "ui/rect.h"
|
||||
#include "ui/text/text_entity.h"
|
||||
#include "ui/widgets/popup_menu.h"
|
||||
#include "styles/style_intro.h"
|
||||
#include "styles/style_layers.h" // boxRadius
|
||||
|
||||
#include <QtCore/QRegularExpression>
|
||||
#include <QtGui/QClipboard>
|
||||
#include <QtGui/QGuiApplication>
|
||||
|
||||
namespace Ui {
|
||||
namespace {
|
||||
|
@ -268,6 +272,8 @@ void CodeInput::keyPressEvent(QKeyEvent *e) {
|
|||
unfocusAll(_currentIndex);
|
||||
} else if (key == Qt::Key_Enter || key == Qt::Key_Return) {
|
||||
requestCode();
|
||||
} else if (e == QKeySequence::Paste) {
|
||||
insertCodeAndSubmit(QGuiApplication::clipboard()->text());
|
||||
} else if (key >= Qt::Key_A && key <= Qt::Key_Z) {
|
||||
_digits[_currentIndex]->shake();
|
||||
} else if (key == Qt::Key_Home || key == Qt::Key_PageUp) {
|
||||
|
@ -277,6 +283,31 @@ void CodeInput::keyPressEvent(QKeyEvent *e) {
|
|||
}
|
||||
}
|
||||
|
||||
void CodeInput::contextMenuEvent(QContextMenuEvent *e) {
|
||||
if (_menu) {
|
||||
return;
|
||||
}
|
||||
_menu = base::make_unique_q<Ui::PopupMenu>(this, st::defaultPopupMenu);
|
||||
_menu->addAction(tr::lng_mac_menu_paste(tr::now), [=] {
|
||||
insertCodeAndSubmit(QGuiApplication::clipboard()->text());
|
||||
})->setEnabled(!QGuiApplication::clipboard()->text().isEmpty());
|
||||
_menu->popup(QCursor::pos());
|
||||
}
|
||||
|
||||
void CodeInput::insertCodeAndSubmit(const QString &code) {
|
||||
if (code.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
setCode(code);
|
||||
_currentIndex = _digits.size() - 1;
|
||||
findEmptyAndPerform([&](int i) { _currentIndex = i; });
|
||||
unfocusAll(_currentIndex);
|
||||
if ((_currentIndex == _digits.size() - 1)
|
||||
&& _digits[_currentIndex]->digit() != kDigitNone) {
|
||||
requestCode();
|
||||
}
|
||||
}
|
||||
|
||||
QString CodeInput::collectDigits() const {
|
||||
auto result = QString();
|
||||
for (const auto &digit : _digits) {
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
namespace Ui {
|
||||
|
||||
class CodeDigit;
|
||||
class PopupMenu;
|
||||
|
||||
class CodeInput final : public Ui::RpWidget {
|
||||
public:
|
||||
|
@ -31,10 +32,12 @@ protected:
|
|||
void focusOutEvent(QFocusEvent *e) override;
|
||||
void paintEvent(QPaintEvent *e) override;
|
||||
void keyPressEvent(QKeyEvent *e) override;
|
||||
void contextMenuEvent(QContextMenuEvent *e) override;
|
||||
|
||||
private:
|
||||
[[nodiscard]] QString collectDigits() const;
|
||||
|
||||
void insertCodeAndSubmit(const QString &code);
|
||||
void unfocusAll(int except);
|
||||
void findEmptyAndPerform(const Fn<void(int)> &callback);
|
||||
|
||||
|
@ -42,6 +45,8 @@ private:
|
|||
std::vector<not_null<CodeDigit*>> _digits;
|
||||
int _currentIndex = 0;
|
||||
|
||||
base::unique_qptr<Ui::PopupMenu> _menu;
|
||||
|
||||
rpl::event_stream<QString> _codeCollected;
|
||||
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue