From: PatR Date: Sat, 31 Oct 2020 22:34:47 +0000 (-0700) Subject: Qt: yn dialog bit X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5b0ac4ceacce83a94a9c03a1fe8e14550fce5d39;p=nethack Qt: yn dialog bit Take care of a Qt TODO: when using 'popup_dialog' and entering a count during a yn#aq question, change the default answer button from 'n' to 'y' since ending the count with accepts it. --- diff --git a/win/Qt/qt_yndlg.cpp b/win/Qt/qt_yndlg.cpp index 4ea3688b0..4c59c073f 100644 --- a/win/Qt/qt_yndlg.cpp +++ b/win/Qt/qt_yndlg.cpp @@ -37,7 +37,8 @@ NetHackQtYnDialog::NetHackQtYnDialog(QWidget *parent, const QString &q, question(q), choices(ch), def(df), keypress('\033'), allow_count(false), - le((QLineEdit *) NULL) + le((QLineEdit *) NULL), + y_btn((QPushButton *) NULL) { setWindowTitle("NetHack: Question"); @@ -182,6 +183,7 @@ char NetHackQtYnDialog::Exec() QPushButton *button; for (int i = 0; i < nchoices; ++i) { + bool making_y = false; if (ch[i] == '\033') break; // ESC and anything after are hidden if (ch[i] == '#' && allow_count) @@ -193,6 +195,7 @@ char NetHackQtYnDialog::Exec() switch (ch[i].cell()) { case 'y': button_name = "Yes"; + making_y = true; break; case 'n': button_name = "No"; @@ -260,6 +263,8 @@ char NetHackQtYnDialog::Exec() } } button=new QPushButton(button_name); + if (making_y && allow_count) + y_btn = button; // to change default in keyPressEvent() if (!enable.isNull()) { if (!enable.contains(ch[i])) button->setEnabled(false); @@ -394,17 +399,9 @@ void NetHackQtYnDialog::keyPressEvent(QKeyEvent* event) le->setAttribute(Qt::WA_KeyboardFocusChange, true); // this is definitely useful... le->setFocus(Qt::ActiveWindowFocusReason); - // - // TODO: 'No' is highlighted as default for result if player - // types , but once count entry starts that should - // be changed because this LineEdit dialog has now become - // the defacto default. We can't just turn off the default - // setting for the 'No' button because only works - // if there is a default explicitly set. Unfortunately the - // LineEdit widget isn't a viable candidate for that because - // it isn't a button. [Maybe just highlight 'Yes' instead?] - // - + // change default button from 'n' to 'y' + if (y_btn) + y_btn->setDefault(true); } else if (where != -1) { this->done(where + 1000); diff --git a/win/Qt/qt_yndlg.h b/win/Qt/qt_yndlg.h index cdbdc0710..e6c1bcdef 100644 --- a/win/Qt/qt_yndlg.h +++ b/win/Qt/qt_yndlg.h @@ -18,6 +18,7 @@ private: char keypress; bool allow_count; QLineEdit *le; + QPushButton *y_btn; // abritrary size; might need to be more sophisicated someday char alt_answer[26 + 1], alt_result[26 + 1];