Clean up the chat dialog code a bit, set the keyboard focus on the chat message field
ClosedPublic

Authored by yurchor on Dec 14 2019, 9:49 AM.

Details

Summary

Remove unnecessary repetition of code and focusing of "Configure..." button by default that leads to unexpected opening of the chat configuration dialog or closing the chat dialog when you press Enter in the message field.

Test Plan

Open the "Game -> Network Chat..." dialog, add some message and press Enter. Chat does not work as before (I cannot figure up why) but at least it does not open the configuration dialog and does not close either.

Diff Detail

Repository
R395 KFourInLine
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
yurchor created this revision.Dec 14 2019, 9:49 AM
Restricted Application added a subscriber: kde-games-devel. · View Herald TranscriptDec 14 2019, 9:49 AM
yurchor requested review of this revision.Dec 14 2019, 9:49 AM
aacid added a subscriber: aacid.Dec 17 2019, 10:53 PM

Doesn't this mean then that you can't trigger those buttons with the keyboard alone?

Doesn't this mean then that you can't trigger those buttons with the keyboard alone?

No. Ctrl+Enter works as expected (closes the chat dialog by triggering "OK"). The patch just prevents stealing focus from the message input field.

But i mean by focus tabbing, focus tabbing is important for accessibility stuff too like screen readers for blnd people

yurchor updated this revision to Diff 72324.Dec 29 2019, 10:41 AM

Adding one more false button restores the desired behavior. I'm lost. Need some advice.

aacid added a comment.Jan 2 2020, 11:53 PM

Does something like this fix the problem?

diff --git a/src/chatdlg.cpp b/src/chatdlg.cpp
index 0b7ec1d..35a9ffe 100644
--- a/src/chatdlg.cpp
+++ b/src/chatdlg.cpp
@@ -50,11 +50,10 @@ ChatDlg::ChatDlg(KGame *game,QWidget *parent)
   QVBoxLayout *mainLayout = new QVBoxLayout;
   setLayout(mainLayout);
   QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
-  okButton->setDefault(true);
   okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
   connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
   connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
-  okButton->setDefault(true);
+  okButton->setAutoDefault(false);
   setModal(false);
   setMinimumSize(QSize(200,200));
   
@@ -68,6 +67,7 @@ ChatDlg::ChatDlg(KGame *game,QWidget *parent)
   mGridLayout->addWidget(b,0,0);
   
   QPushButton *mButton     = new QPushButton(i18n("Configure..."),frame);
+  mButton->setAutoDefault(false);
   mGridLayout->addWidget(mButton,1,1);
   
   mainLayout->addWidget(frame);
yurchor updated this revision to Diff 72665.Jan 3 2020, 7:06 AM

Use setAutoDefault(false) that really solves the problem. Thanks.

aacid accepted this revision.Jan 3 2020, 9:45 PM
This revision is now accepted and ready to land.Jan 3 2020, 9:45 PM
This revision was automatically updated to reflect the committed changes.