Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set password input field font correctly #8732

Merged
merged 1 commit into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions src/gui/PasswordWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ PasswordWidget::PasswordWidget(QWidget* parent)
// use a monospace font for the password field
QFont passwordFont = Font::fixedFont();
passwordFont.setLetterSpacing(QFont::PercentageSpacing, 110);
setFont(passwordFont);
m_ui->passwordEdit->setFont(passwordFont);

// Prevent conflicts with global Mac shortcuts (force Control on all platforms)
#ifdef Q_OS_MAC
Expand Down Expand Up @@ -143,19 +143,19 @@ void PasswordWidget::setReadOnly(bool state)
m_ui->passwordEdit->setReadOnly(state);
}

void PasswordWidget::setRepeatPartner(PasswordWidget* repeatEdit)
void PasswordWidget::setRepeatPartner(PasswordWidget* repeatPartner)
{
m_repeatPasswordEdit = repeatEdit;
m_repeatPasswordEdit->setParentPasswordEdit(this);
m_repeatPasswordWidget = repeatPartner;
m_repeatPasswordWidget->setParentPasswordEdit(this);

connect(
m_ui->passwordEdit, SIGNAL(textChanged(QString)), m_repeatPasswordEdit, SLOT(autocompletePassword(QString)));
connect(m_ui->passwordEdit, SIGNAL(textChanged(QString)), m_repeatPasswordEdit, SLOT(updateRepeatStatus()));
m_ui->passwordEdit, SIGNAL(textChanged(QString)), m_repeatPasswordWidget, SLOT(autocompletePassword(QString)));
connect(m_ui->passwordEdit, SIGNAL(textChanged(QString)), m_repeatPasswordWidget, SLOT(updateRepeatStatus()));
}

void PasswordWidget::setParentPasswordEdit(PasswordWidget* parent)
{
m_parentPasswordEdit = parent;
m_parentPasswordWidget = parent;
// Hide actions
m_toggleVisibleAction->setVisible(false);
m_passwordGeneratorAction->setVisible(false);
Expand All @@ -176,13 +176,13 @@ void PasswordWidget::setShowPassword(bool show)
m_toggleVisibleAction->setIcon(icons()->onOffIcon("password-show", show));
m_toggleVisibleAction->setChecked(show);

if (m_repeatPasswordEdit) {
m_repeatPasswordEdit->setEchoMode(show ? QLineEdit::Normal : QLineEdit::Password);
if (m_repeatPasswordWidget) {
m_repeatPasswordWidget->setEchoMode(show ? QLineEdit::Normal : QLineEdit::Password);
if (!config()->get(Config::Security_PasswordsRepeatVisible).toBool()) {
m_repeatPasswordEdit->setEnabled(!show);
m_repeatPasswordEdit->setText(text());
m_repeatPasswordWidget->setEnabled(!show);
m_repeatPasswordWidget->setText(text());
} else {
m_repeatPasswordEdit->setEnabled(true);
m_repeatPasswordWidget->setEnabled(true);
}
}
}
Expand All @@ -199,19 +199,19 @@ void PasswordWidget::popupPasswordGenerator()
generator->setPasswordLength(text().length());

connect(generator, SIGNAL(appliedPassword(QString)), SLOT(setText(QString)));
if (m_repeatPasswordEdit) {
connect(generator, SIGNAL(appliedPassword(QString)), m_repeatPasswordEdit, SLOT(setText(QString)));
if (m_repeatPasswordWidget) {
connect(generator, SIGNAL(appliedPassword(QString)), m_repeatPasswordWidget, SLOT(setText(QString)));
}
}

void PasswordWidget::updateRepeatStatus()
{
static const auto stylesheetTemplate = QStringLiteral("QLineEdit { background: %1; }");
if (!m_parentPasswordEdit) {
if (!m_parentPasswordWidget) {
return;
}

const auto otherPassword = m_parentPasswordEdit->text();
const auto otherPassword = m_parentPasswordWidget->text();
const auto password = text();
if (otherPassword != password) {
bool isCorrect = false;
Expand Down Expand Up @@ -251,7 +251,7 @@ bool PasswordWidget::event(QEvent* event)

void PasswordWidget::checkCapslockState()
{
if (m_parentPasswordEdit) {
if (m_parentPasswordWidget) {
return;
}

Expand Down
6 changes: 3 additions & 3 deletions src/gui/PasswordWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class PasswordWidget : public QWidget
explicit PasswordWidget(QWidget* parent = nullptr);
~PasswordWidget() override;
void enablePasswordGenerator();
void setRepeatPartner(PasswordWidget* repeatEdit);
void setRepeatPartner(PasswordWidget* repeatPartner);
void setQualityVisible(bool state);

bool isPasswordVisible() const;
Expand Down Expand Up @@ -76,8 +76,8 @@ private slots:
QPointer<QAction> m_toggleVisibleAction;
QPointer<QAction> m_passwordGeneratorAction;
QPointer<QAction> m_capslockAction;
QPointer<PasswordWidget> m_repeatPasswordEdit;
QPointer<PasswordWidget> m_parentPasswordEdit;
QPointer<PasswordWidget> m_repeatPasswordWidget;
QPointer<PasswordWidget> m_parentPasswordWidget;

bool m_capslockState = false;
};
Expand Down