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 <return> accepts it.
This commit is contained in:
+9
-12
@@ -37,7 +37,8 @@ NetHackQtYnDialog::NetHackQtYnDialog(QWidget *parent, const QString &q,
|
|||||||
question(q), choices(ch), def(df),
|
question(q), choices(ch), def(df),
|
||||||
keypress('\033'),
|
keypress('\033'),
|
||||||
allow_count(false),
|
allow_count(false),
|
||||||
le((QLineEdit *) NULL)
|
le((QLineEdit *) NULL),
|
||||||
|
y_btn((QPushButton *) NULL)
|
||||||
{
|
{
|
||||||
setWindowTitle("NetHack: Question");
|
setWindowTitle("NetHack: Question");
|
||||||
|
|
||||||
@@ -182,6 +183,7 @@ char NetHackQtYnDialog::Exec()
|
|||||||
|
|
||||||
QPushButton *button;
|
QPushButton *button;
|
||||||
for (int i = 0; i < nchoices; ++i) {
|
for (int i = 0; i < nchoices; ++i) {
|
||||||
|
bool making_y = false;
|
||||||
if (ch[i] == '\033')
|
if (ch[i] == '\033')
|
||||||
break; // ESC and anything after are hidden
|
break; // ESC and anything after are hidden
|
||||||
if (ch[i] == '#' && allow_count)
|
if (ch[i] == '#' && allow_count)
|
||||||
@@ -193,6 +195,7 @@ char NetHackQtYnDialog::Exec()
|
|||||||
switch (ch[i].cell()) {
|
switch (ch[i].cell()) {
|
||||||
case 'y':
|
case 'y':
|
||||||
button_name = "Yes";
|
button_name = "Yes";
|
||||||
|
making_y = true;
|
||||||
break;
|
break;
|
||||||
case 'n':
|
case 'n':
|
||||||
button_name = "No";
|
button_name = "No";
|
||||||
@@ -260,6 +263,8 @@ char NetHackQtYnDialog::Exec()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
button=new QPushButton(button_name);
|
button=new QPushButton(button_name);
|
||||||
|
if (making_y && allow_count)
|
||||||
|
y_btn = button; // to change default in keyPressEvent()
|
||||||
if (!enable.isNull()) {
|
if (!enable.isNull()) {
|
||||||
if (!enable.contains(ch[i]))
|
if (!enable.contains(ch[i]))
|
||||||
button->setEnabled(false);
|
button->setEnabled(false);
|
||||||
@@ -394,17 +399,9 @@ void NetHackQtYnDialog::keyPressEvent(QKeyEvent* event)
|
|||||||
le->setAttribute(Qt::WA_KeyboardFocusChange, true);
|
le->setAttribute(Qt::WA_KeyboardFocusChange, true);
|
||||||
// this is definitely useful...
|
// this is definitely useful...
|
||||||
le->setFocus(Qt::ActiveWindowFocusReason);
|
le->setFocus(Qt::ActiveWindowFocusReason);
|
||||||
//
|
// change default button from 'n' to 'y'
|
||||||
// TODO: 'No' is highlighted as default for result if player
|
if (y_btn)
|
||||||
// types <return>, but once count entry starts that should
|
y_btn->setDefault(true);
|
||||||
// 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?]
|
|
||||||
//
|
|
||||||
|
|
||||||
} else if (where != -1) {
|
} else if (where != -1) {
|
||||||
this->done(where + 1000);
|
this->done(where + 1000);
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ private:
|
|||||||
char keypress;
|
char keypress;
|
||||||
bool allow_count;
|
bool allow_count;
|
||||||
QLineEdit *le;
|
QLineEdit *le;
|
||||||
|
QPushButton *y_btn;
|
||||||
|
|
||||||
// abritrary size; might need to be more sophisicated someday
|
// abritrary size; might need to be more sophisicated someday
|
||||||
char alt_answer[26 + 1], alt_result[26 + 1];
|
char alt_answer[26 + 1], alt_result[26 + 1];
|
||||||
|
|||||||
Reference in New Issue
Block a user