Qt menu fix

Menus have [ok], [cancel], [all], [none], [invert], and [search]
buttons across their top but the [all], [none], and [invert] choices
didn't redraw the menu after making changes to the pending selections
so it seemed as if they weren't doing anything.  Subsequently picking
[ok] revealed otherwise.

[search] is broken (instead of accepting a search string, the letters
I type are being used to toggle individual entries as I type).  This
doesn't attempt to address that.
This commit is contained in:
PatR
2020-08-28 17:31:33 -07:00
parent 1df2fdca44
commit fae20ad3e2
2 changed files with 33 additions and 9 deletions

View File

@@ -1,4 +1,4 @@
NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.290 $ $NHDT-Date: 1598570054 2020/08/27 23:14:14 $
NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.291 $ $NHDT-Date: 1598661087 2020/08/29 00:31:27 $
General Fixes and Modified Features
-----------------------------------
@@ -390,6 +390,8 @@ Qt: when hero died, gold on tombstone only included gold in inventory, not
Qt: tombstone showed newly constructed date instead of the value set up at
time of death; it only shows year but that could be wrong if player
stared at or ignored prior --More-- for long enough on 31 December
Qt: menu choices All, None, Invert were setting, unsetting, or toggling menu
entry checkboxes internally but didn't redraw the menu to show that
Qt+QSX: fix control key
Qt+OSX: rename menu entry "nethack->Preferences..." for invoking nethack's
'O' command to "Game->Run-time options" and entry "Game->Qt settings"

View File

@@ -215,7 +215,7 @@ int NetHackQtMenuWindow::SelectMenu(int h, MENU_ITEM_P **menu_list)
how=h;
ok->setEnabled(how!=PICK_ONE);ok->setDefault(how!=PICK_ONE);
ok->setEnabled(how!=PICK_ONE); ok->setDefault(how!=PICK_ONE);
cancel->setEnabled(true);
all->setEnabled(how==PICK_ANY);
none->setEnabled(how==PICK_ANY);
@@ -499,7 +499,8 @@ void NetHackQtMenuWindow::keyPressEvent(QKeyEvent* event)
InputCount(key);
else {
for (int i=0; i<itemcount; i++) {
if ((unsigned int) itemlist[i].ch == key || (unsigned int) itemlist[i].gch == key)
if ((unsigned int) itemlist[i].ch == key
|| (unsigned int) itemlist[i].gch == key)
ToggleSelect(i);
}
}
@@ -511,32 +512,45 @@ void NetHackQtMenuWindow::All()
if (how != PICK_ANY)
return;
bool didcheck = false;
for (int i=0; i<itemcount; i++) {
QTableWidgetItem *count = table->item(i, 0);
if (count != NULL) count->setText("");
QCheckBox *cb = dynamic_cast<QCheckBox *>(table->cellWidget(i, 1));
if (cb != NULL) cb->setChecked(true);
if (cb != NULL) {
cb->setChecked(true);
didcheck = true;
}
}
if (didcheck)
table->repaint();
}
void NetHackQtMenuWindow::ChooseNone()
{
if (how != PICK_ANY)
return;
bool diduncheck = false;
for (int i=0; i<itemcount; i++) {
QTableWidgetItem *count = table->item(i, 0);
if (count != NULL) count->setText("");
QCheckBox *cb = dynamic_cast<QCheckBox *>(table->cellWidget(i, 1));
if (cb != NULL) cb->setChecked(false);
if (cb != NULL) {
cb->setChecked(false);
diduncheck = true;
}
}
if (diduncheck)
table->repaint();
}
void NetHackQtMenuWindow::Invert()
{
if (how != PICK_ANY)
return;
boolean didtoggle = false;
for (int i=0; i<itemcount; i++) {
if (!menuitem_invert_test(0, itemlist[i].itemflags,
itemlist[i].selected))
@@ -546,8 +560,13 @@ void NetHackQtMenuWindow::Invert()
if (count != NULL) count->setText("");
QCheckBox *cb = dynamic_cast<QCheckBox *>(table->cellWidget(i, 1));
if (cb != NULL) cb->setChecked(cb->checkState() == Qt::Unchecked);
if (cb != NULL) {
cb->setChecked(cb->checkState() == Qt::Unchecked);
didtoggle = true;
}
}
if (didtoggle)
table->repaint();
}
void NetHackQtMenuWindow::Search()
{
@@ -556,6 +575,7 @@ void NetHackQtMenuWindow::Search()
NetHackQtStringRequestor requestor(this, "Search for:");
char line[256];
line[0] = '\0'; /* for EDIT_GETLIN */
if (requestor.Get(line)) {
for (int i=0; i<itemcount; i++) {
if (itemlist[i].str.contains(line))
@@ -569,8 +589,8 @@ void NetHackQtMenuWindow::ToggleSelect(int i)
QCheckBox *cb = dynamic_cast<QCheckBox *>(table->cellWidget(i, 1));
if (cb == NULL) return;
cb->setChecked((counting && !countstr.isEmpty())
|| cb->checkState() == Qt::Unchecked);
cb->setChecked((counting && !countstr.isEmpty())
|| cb->checkState() == Qt::Unchecked);
QTableWidgetItem *count = table->item(i, 0);
if (count != NULL) count->setText(countstr);
@@ -579,7 +599,9 @@ void NetHackQtMenuWindow::ToggleSelect(int i)
if (how==PICK_ONE) {
accept();
}
} else {
table->repaint();
}
}
}