]> granicus.if.org Git - nethack/commitdiff
Qt: yn dialog bit
authorPatR <rankin@nethack.org>
Sat, 31 Oct 2020 22:34:47 +0000 (15:34 -0700)
committerPatR <rankin@nethack.org>
Sat, 31 Oct 2020 22:34:47 +0000 (15:34 -0700)
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 <return> accepts it.

win/Qt/qt_yndlg.cpp
win/Qt/qt_yndlg.h

index 4ea3688b0c1f5f7fe2635e715adf9f3295fec7b2..4c59c073f93f3ce9a983f7f3635d481d329f438c 100644 (file)
@@ -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 <return>, 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 <return> 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);
 
index cdbdc07109a704247627e6b594c81d94e72e22c0..e6c1bcdef47e70396479cc65c82434b48b305403 100644 (file)
@@ -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];