59 lines
1.3 KiB
C++
59 lines
1.3 KiB
C++
#ifndef DIALOGCONTROLPASSWORD_H
|
|
#define DIALOGCONTROLPASSWORD_H
|
|
|
|
#include <QDialog>
|
|
#include <QShowEvent>
|
|
#include <QString>
|
|
#include <QVector>
|
|
|
|
#include <functional>
|
|
|
|
class QLabel;
|
|
class QKeyEvent;
|
|
|
|
namespace Ui {
|
|
class DialogControlPassword;
|
|
}
|
|
|
|
class DialogControlPassword : public QDialog
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
static const int kPasswordLength = 6;
|
|
|
|
explicit DialogControlPassword(QWidget* parent = nullptr);
|
|
~DialogControlPassword() override;
|
|
|
|
void SetTitle(const QString& title);
|
|
QString Password() const;
|
|
void SetError(const QString& text);
|
|
void SetPasswordChecker(const std::function<bool(const QString&)>& checker);
|
|
|
|
protected:
|
|
void showEvent(QShowEvent* event) override;
|
|
void keyPressEvent(QKeyEvent* event) override;
|
|
|
|
private slots:
|
|
void on_btnOK_clicked();
|
|
void on_btnCancel_clicked();
|
|
|
|
private:
|
|
void ApplyUiFont();
|
|
void BuildDigitBoxes();
|
|
void BuildKeypad();
|
|
void AppendDigit(QChar digit);
|
|
void RemoveLastDigit();
|
|
void ClearPassword();
|
|
void RefreshDigits();
|
|
void UpdateOkEnabled();
|
|
void TryAccept();
|
|
|
|
Ui::DialogControlPassword* ui = nullptr;
|
|
std::function<bool(const QString&)> m_passwordChecker;
|
|
QString m_password;
|
|
QVector<QLabel*> m_digitLabels;
|
|
};
|
|
|
|
#endif // DIALOGCONTROLPASSWORD_H
|