Fix focus traps

* Fix focus issues with new PasswordWidget
* Fix focus wrapping when DatabaseTabWidget is not showing the tab bar
* Fix focus wrapping in EditWidget views to move between category list and contents. This is not a perfect fix, but Qt has a mind of its own with these complex widgets. This will be fixed in future Ui improvements that move away from the category widget.
This commit is contained in:
Jonathan White 2022-10-01 11:57:47 -04:00
parent 6f64c84c7d
commit affff20b49
10 changed files with 64 additions and 51 deletions

View File

@ -213,6 +213,7 @@ void DatabaseOpenWidget::clearForms()
m_ui->editPassword->setShowPassword(false);
m_ui->keyFileLineEdit->clear();
m_ui->keyFileLineEdit->setShowPassword(false);
m_ui->keyFileLineEdit->setClearButtonEnabled(true);
m_ui->challengeResponseCombo->clear();
m_ui->centralStack->setCurrentIndex(0);
m_db.reset();
@ -442,12 +443,6 @@ void DatabaseOpenWidget::browseKeyFile()
}
}
void DatabaseOpenWidget::clearKeyFileText()
{
m_ui->keyFileLineEdit->clear();
m_ui->keyFileLineEdit->setShowPassword(false);
}
void DatabaseOpenWidget::pollHardwareKey()
{
if (m_pollingHardwareKey) {

View File

@ -70,7 +70,6 @@ protected slots:
private slots:
void browseKeyFile();
void clearKeyFileText();
void pollHardwareKey();
void hardwareKeyResponse(bool found);
void openHardwareKeyHelp();

View File

@ -145,13 +145,13 @@
</widget>
</item>
<item>
<widget class="PasswordWidget" name="editPassword">
<widget class="PasswordWidget" name="editPassword" native="true">
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
<property name="accessibleName">
<string>Password field</string>
</property>
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item>
@ -380,22 +380,19 @@
<number>0</number>
</property>
<item row="0" column="1">
<widget class="PasswordWidget" name="keyFileLineEdit">
<widget class="PasswordWidget" name="keyFileLineEdit" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
<property name="accessibleName">
<string>Key file to unlock the database</string>
</property>
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
<property name="clearButtonEnabled">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
@ -463,6 +460,9 @@
</property>
<item alignment="Qt::AlignRight">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Close|QDialogButtonBox::Ok</set>
</property>
@ -618,7 +618,7 @@
<customwidgets>
<customwidget>
<class>PasswordWidget</class>
<extends>QLineEdit</extends>
<extends>QWidget</extends>
<header>gui/PasswordWidget.h</header>
<container>1</container>
</customwidget>

View File

@ -76,9 +76,11 @@ void DatabaseTabWidget::toggleTabbar()
{
if (count() > 1) {
tabBar()->show();
setFocusPolicy(Qt::StrongFocus);
emit tabVisibilityChanged(true);
} else {
tabBar()->hide();
setFocusPolicy(Qt::NoFocus);
emit tabVisibilityChanged(false);
}
}

View File

@ -1641,7 +1641,7 @@ bool DatabaseWidget::focusNextPrevChild(bool next)
// Find the next visible element in the sequence and set the focus
while (idx >= 0 && idx < sequence.size()) {
widget = sequence[idx];
if (widget && widget->isVisible() && widget->height() > 0 && widget->width() > 0) {
if (widget && widget->isVisible() && widget->isEnabled() && widget->height() > 0 && widget->width() > 0) {
widget->setFocus();
return widget;
}

View File

@ -66,10 +66,16 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="focusPolicy">
<enum>Qt::TabFocus</enum>
</property>
</widget>
</item>
<item>
<widget class="QStackedWidget" name="stackedWidget">
<property name="focusPolicy">
<enum>Qt::TabFocus</enum>
</property>
<property name="currentIndex">
<number>-1</number>
</property>
@ -84,6 +90,9 @@
</property>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="focusPolicy">
<enum>Qt::TabFocus</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
@ -107,6 +116,11 @@
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>categoryList</tabstop>
<tabstop>stackedWidget</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>

View File

@ -87,9 +87,9 @@
</layout>
</item>
<item row="0" column="0">
<widget class="PasswordWidget" name="editNewPassword">
<widget class="PasswordWidget" name="editNewPassword" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Minimum">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -100,6 +100,9 @@
<height>0</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
<property name="accessibleName">
<string>Generated password</string>
</property>
@ -991,7 +994,7 @@ QProgressBar::chunk {
<customwidgets>
<customwidget>
<class>PasswordWidget</class>
<extends>QLineEdit</extends>
<extends>QWidget</extends>
<header>gui/PasswordWidget.h</header>
<container>1</container>
</customwidget>

View File

@ -31,9 +31,9 @@
</widget>
</item>
<item row="0" column="1">
<widget class="PasswordWidget" name="enterPasswordEdit">
<widget class="PasswordWidget" name="enterPasswordEdit" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -44,12 +44,12 @@
<height>0</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
<property name="accessibleName">
<string>Password field</string>
</property>
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item row="1" column="0">
@ -60,9 +60,9 @@
</widget>
</item>
<item row="1" column="1">
<widget class="PasswordWidget" name="repeatPasswordEdit">
<widget class="PasswordWidget" name="repeatPasswordEdit" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -73,12 +73,12 @@
<height>0</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
<property name="accessibleName">
<string>Repeat password field</string>
</property>
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
</layout>
@ -86,7 +86,7 @@
<customwidgets>
<customwidget>
<class>PasswordWidget</class>
<extends>QLineEdit</extends>
<extends>QWidget</extends>
<header>gui/PasswordWidget.h</header>
<container>1</container>
</customwidget>

View File

@ -243,13 +243,13 @@
</widget>
</item>
<item row="2" column="1">
<widget class="PasswordWidget" name="passwordEdit">
<widget class="PasswordWidget" name="passwordEdit" native="true">
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
<property name="accessibleName">
<string>Password field</string>
</property>
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item row="6" column="0">
@ -296,12 +296,6 @@
</widget>
</widget>
<customwidgets>
<customwidget>
<class>PasswordWidget</class>
<extends>QLineEdit</extends>
<header>gui/PasswordWidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>TagsEdit</class>
<extends>QWidget</extends>
@ -314,6 +308,12 @@
<header>gui/URLEdit.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>PasswordWidget</class>
<extends>QWidget</extends>
<header>gui/PasswordWidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>titleEdit</tabstop>

View File

@ -51,9 +51,9 @@
</widget>
</item>
<item row="2" column="1">
<widget class="PasswordWidget" name="passwordEdit">
<widget class="PasswordWidget" name="passwordEdit" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -64,12 +64,12 @@
<height>0</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
<property name="accessibleName">
<string>Password field</string>
</property>
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item row="0" column="0">
@ -191,7 +191,7 @@
<customwidgets>
<customwidget>
<class>PasswordWidget</class>
<extends>QLineEdit</extends>
<extends>QWidget</extends>
<header>gui/PasswordWidget.h</header>
<container>1</container>
</customwidget>