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 faa4c07095
commit 3e3990934a
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->editPassword->setShowPassword(false);
m_ui->keyFileLineEdit->clear(); m_ui->keyFileLineEdit->clear();
m_ui->keyFileLineEdit->setShowPassword(false); m_ui->keyFileLineEdit->setShowPassword(false);
m_ui->keyFileLineEdit->setClearButtonEnabled(true);
m_ui->challengeResponseCombo->clear(); m_ui->challengeResponseCombo->clear();
m_ui->centralStack->setCurrentIndex(0); m_ui->centralStack->setCurrentIndex(0);
m_db.reset(); 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() void DatabaseOpenWidget::pollHardwareKey()
{ {
if (m_pollingHardwareKey) { if (m_pollingHardwareKey) {

View File

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

View File

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

View File

@ -76,9 +76,11 @@ void DatabaseTabWidget::toggleTabbar()
{ {
if (count() > 1) { if (count() > 1) {
tabBar()->show(); tabBar()->show();
setFocusPolicy(Qt::StrongFocus);
emit tabVisibilityChanged(true); emit tabVisibilityChanged(true);
} else { } else {
tabBar()->hide(); tabBar()->hide();
setFocusPolicy(Qt::NoFocus);
emit tabVisibilityChanged(false); 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 // Find the next visible element in the sequence and set the focus
while (idx >= 0 && idx < sequence.size()) { while (idx >= 0 && idx < sequence.size()) {
widget = sequence[idx]; 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(); widget->setFocus();
return widget; return widget;
} }

View File

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

View File

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

View File

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

View File

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

View File

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