Improved PasswordPromptDialog
- can now also set caption - can set initial state of save option - improved size and spacing
This commit is contained in:
parent
634345b38f
commit
24751f81dd
3 changed files with 59 additions and 19 deletions
|
|
@ -9,18 +9,24 @@
|
|||
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(PasswordPromptDialog::Flags)
|
||||
|
||||
const char* PasswordPromptDialog::translateContext = "PasswordPromptDialog";
|
||||
|
||||
PasswordPromptDialog::PasswordPromptDialog(Flags flags, QWidget *parent)
|
||||
: QDialog(parent)
|
||||
, m_Flags(flags)
|
||||
{
|
||||
m_connectionLabel = new QLabel(this);
|
||||
m_descriptionLabel = new QLabel(this);
|
||||
m_DialogButtons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
|
||||
|
||||
const size_t inputFieldCount = flags.testFlag(ConfirmPassword) ? 2 : 1;
|
||||
|
||||
setMinimumWidth(400);
|
||||
auto mainLayout = new QGridLayout;
|
||||
mainLayout->setHorizontalSpacing(12);
|
||||
mainLayout->setVerticalSpacing(18);
|
||||
|
||||
int row = 0;
|
||||
mainLayout->addWidget(m_connectionLabel, row, 0, 1, 2);
|
||||
mainLayout->addWidget(m_descriptionLabel, row, 0, 1, 2);
|
||||
++row;
|
||||
for (size_t idx = 0; idx < inputFieldCount; ++idx) {
|
||||
auto lbl = new QLabel(this);
|
||||
|
|
@ -51,18 +57,43 @@ PasswordPromptDialog::PasswordPromptDialog(Flags flags, QWidget *parent)
|
|||
connect(m_passwordInput[1], &QLineEdit::textChanged, this, &PasswordPromptDialog::passwordChanged);
|
||||
}
|
||||
|
||||
PasswordPromptDialog& PasswordPromptDialog::setDescription(const QString &description)
|
||||
{
|
||||
m_descriptionLabel->setText(QString("%1").arg(description));
|
||||
return *this;
|
||||
}
|
||||
|
||||
PasswordPromptDialog& PasswordPromptDialog::setCaption(const std::optional<QString> &caption)
|
||||
{
|
||||
m_customCaption = caption;
|
||||
UpdateCaption();
|
||||
return *this;
|
||||
}
|
||||
|
||||
PasswordPromptDialog& PasswordPromptDialog::setSaveChecked(bool save)
|
||||
{
|
||||
if (m_saveCheck)
|
||||
m_saveCheck->setCheckState(save ? Qt::CheckState::Checked : Qt::CheckState::Unchecked);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void PasswordPromptDialog::UpdateCaption()
|
||||
{
|
||||
QString cap = m_customCaption.value_or(QApplication::translate(translateContext, "Password dialog", nullptr));
|
||||
setWindowTitle(cap);
|
||||
}
|
||||
|
||||
void PasswordPromptDialog::retranslateUi()
|
||||
{
|
||||
const char * context = "PasswordPromptDialog";
|
||||
setWindowTitle(QApplication::translate(context, "Connection password", nullptr));
|
||||
m_passwordLabel[0]->setText(QApplication::translate(context, "Password", nullptr));
|
||||
m_passwordInput[0]->setPlaceholderText(QApplication::translate(context, "Enter password", nullptr));
|
||||
UpdateCaption();
|
||||
m_passwordLabel[0]->setText(QApplication::translate(translateContext, "Password", nullptr));
|
||||
m_passwordInput[0]->setPlaceholderText(QApplication::translate(translateContext, "Enter password", nullptr));
|
||||
if (m_passwordLabel[1])
|
||||
m_passwordLabel[1]->setText(QApplication::translate(context, "Confirm password", nullptr));
|
||||
m_passwordLabel[1]->setText(QApplication::translate(translateContext, "Confirm password", nullptr));
|
||||
if (m_passwordInput[1])
|
||||
m_passwordInput[1]->setPlaceholderText(QApplication::translate(context, "Reenter same password for confirmation", nullptr));
|
||||
m_passwordInput[1]->setPlaceholderText(QApplication::translate(translateContext, "Reenter same password for confirmation", nullptr));
|
||||
if (m_saveCheck)
|
||||
m_saveCheck->setText(QApplication::translate(context, "Save password", nullptr));
|
||||
m_saveCheck->setText(QApplication::translate(translateContext, "Save password", nullptr));
|
||||
}
|
||||
|
||||
void PasswordPromptDialog::updateOkEnabled()
|
||||
|
|
@ -80,12 +111,6 @@ void PasswordPromptDialog::passwordChanged(const QString &)
|
|||
updateOkEnabled();
|
||||
}
|
||||
|
||||
void PasswordPromptDialog::setDescription(const QString &description)
|
||||
{
|
||||
m_connectionLabel->setText(QString("%1").arg(description));
|
||||
|
||||
}
|
||||
|
||||
QString PasswordPromptDialog::password() const
|
||||
{
|
||||
return m_passwordInput[0]->text();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue