From fa7394723c2191be36aac25e3e89d3ad046425a4 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 7 Feb 2022 11:51:48 +0100 Subject: [PATCH] [users] Don't mess up cursor position when typing hostname If the hostname changes while the field has focus, that means that the user is typing in the field, and we shouldn't mess with the cursor position. FIXES #1884 --- src/modules/users/UsersPage.cpp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/modules/users/UsersPage.cpp b/src/modules/users/UsersPage.cpp index 04554454c..6ac6c5bf6 100644 --- a/src/modules/users/UsersPage.cpp +++ b/src/modules/users/UsersPage.cpp @@ -107,7 +107,15 @@ UsersPage::UsersPage( Config* config, QWidget* parent ) ui->textBoxHostName->setText( config->hostName() ); connect( ui->textBoxHostName, &QLineEdit::textEdited, config, &Config::setHostName ); - connect( config, &Config::hostNameChanged, ui->textBoxHostName, &QLineEdit::setText ); + connect( config, + &Config::hostNameChanged, + [ this ]( const QString& name ) + { + if ( !ui->textBoxHostName->hasFocus() ) + { + ui->textBoxHostName->setText( name ); + } + } ); connect( config, &Config::hostNameStatusChanged, this, &UsersPage::reportHostNameStatus ); ui->textBoxLoginName->setText( config->loginName() ); @@ -116,9 +124,10 @@ UsersPage::UsersPage( Config* config, QWidget* parent ) connect( config, &Config::loginNameStatusChanged, this, &UsersPage::reportLoginNameStatus ); ui->checkBoxDoAutoLogin->setChecked( m_config->doAutoLogin() ); - connect( ui->checkBoxDoAutoLogin, &QCheckBox::stateChanged, this, [this]( int checked ) { - m_config->setAutoLogin( checked != Qt::Unchecked ); - } ); + connect( ui->checkBoxDoAutoLogin, + &QCheckBox::stateChanged, + this, + [ this ]( int checked ) { m_config->setAutoLogin( checked != Qt::Unchecked ); } ); connect( config, &Config::autoLoginChanged, ui->checkBoxDoAutoLogin, &QCheckBox::setChecked ); ui->checkBoxReusePassword->setVisible( m_config->writeRootPassword() ); @@ -133,9 +142,10 @@ UsersPage::UsersPage( Config* config, QWidget* parent ) ui->checkBoxRequireStrongPassword->setChecked( m_config->requireStrongPasswords() ); if ( m_config->permitWeakPasswords() ) { - connect( ui->checkBoxRequireStrongPassword, &QCheckBox::stateChanged, this, [this]( int checked ) { - m_config->setRequireStrongPasswords( checked != Qt::Unchecked ); - } ); + connect( ui->checkBoxRequireStrongPassword, + &QCheckBox::stateChanged, + this, + [ this ]( int checked ) { m_config->setRequireStrongPasswords( checked != Qt::Unchecked ); } ); connect( config, &Config::requireStrongPasswordsChanged, ui->checkBoxRequireStrongPassword, &QCheckBox::setChecked ); }