]> granicus.if.org Git - nethack/commitdiff
Qt menu fix
authorPatR <rankin@nethack.org>
Sat, 29 Aug 2020 00:31:33 +0000 (17:31 -0700)
committerPatR <rankin@nethack.org>
Sat, 29 Aug 2020 00:31:33 +0000 (17:31 -0700)
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.

doc/fixes37.0
win/Qt/qt_menu.cpp

index d4c1b262854590b78ff150fc66610bd2da6d4118..6336374f444a569f56640789e52b89bcd262a1d2 100644 (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"
index 817449ee7f3727bcc3fd0ffda3c22f3054935b68..a90cb7d9bf5f91c91dbbaee35aae6d4bd68a2bd8 100644 (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();
+        }
     }
 }