pgLab/pglab/PasswordPromptDialog.h
eelke 24751f81dd Improved PasswordPromptDialog
- can now also set caption
- can set initial state of save option
- improved size and spacing
2018-11-11 12:30:53 +01:00

54 lines
1.2 KiB
C++

#ifndef PASSWORDPROMPTDIALOG_H
#define PASSWORDPROMPTDIALOG_H
#include <QDialog>
#include <optional>
class QCheckBox;
class QDialogButtonBox;
class QLabel;
class QLineEdit;
class PasswordPromptDialog : public QDialog
{
Q_OBJECT
public:
enum Flag {
ConfirmPassword = 1,
SaveOption = 2
};
Q_DECLARE_FLAGS(Flags, Flag)
//Q_FLAG(Flags)
explicit PasswordPromptDialog(Flags flags, QWidget *parent = nullptr);
PasswordPromptDialog& setCaption(const std::optional<QString> &caption);
PasswordPromptDialog& setDescription(const QString &description);
/// Checks the save checkbox when save is true, this call is ignored when the checkbox does not exist
PasswordPromptDialog& setSaveChecked(bool save);
QString password() const;
bool saveChecked() const;
private:
static const char* translateContext;
Flags m_Flags;
QLabel *m_descriptionLabel = nullptr;
QLabel *m_passwordLabel[2] = { nullptr, nullptr };
QLineEdit *m_passwordInput[2] = { nullptr, nullptr };
QCheckBox *m_saveCheck = nullptr;
QDialogButtonBox *m_DialogButtons = nullptr;
std::optional<QString> m_customCaption;
void retranslateUi();
void updateOkEnabled();
void UpdateCaption();
private slots:
void passwordChanged(const QString &text);
};
#endif // PASSWORDPROMPTDIALOG_H