]> granicus.if.org Git - nethack/commitdiff
Qt4: Hide buttons not matching typed command
authorRay Chason <ray.chason@protonmail.com>
Mon, 28 May 2018 03:32:49 +0000 (23:32 -0400)
committerPasi Kallinen <paxed@alt.org>
Mon, 10 Sep 2018 18:13:32 +0000 (21:13 +0300)
There are way too many buttons on the extended command window.
Let the user type a letter or two, and hide the buttons that don't
match.

win/Qt4/qt4xcmd.cpp
win/Qt4/qt4xcmd.h

index 3e8703e494b9c3316f2c9aa193ff6e3a5c2b79c8..7c078f640589598411426c571f22d56a84f0b238 100644 (file)
@@ -66,6 +66,7 @@ NetHackQtExtCmdRequestor::NetHackQtExtCmdRequestor(QWidget *parent) :
        pb->setMinimumSize(butw,pb->sizeHint().height());
        group->addButton(pb, i+1);
        gl->addWidget(pb,i/ncols,i%ncols);
+        buttons.append(pb);
     }
     group->addButton(can, 0);
     connect(group,SIGNAL(buttonPressed(int)),this,SLOT(done(int)));
@@ -92,6 +93,7 @@ void NetHackQtExtCmdRequestor::keyPressEvent(QKeyEvent *event)
        QString promptstr = prompt->text();
        if (promptstr != "#")
            prompt->setText(promptstr.left(promptstr.size()-1));
+        enableButtons();
     }
     else
     {
@@ -111,6 +113,7 @@ void NetHackQtExtCmdRequestor::keyPressEvent(QKeyEvent *event)
            done(match+1);
        else if (matches >= 2)
            prompt->setText(promptstr);
+        enableButtons();
     }
 }
 
@@ -131,4 +134,15 @@ int NetHackQtExtCmdRequestor::get()
     return result()-1;
 }
 
+// Enable only buttons that match the current prompt string
+void NetHackQtExtCmdRequestor::enableButtons()
+{
+    QString typedstr = prompt->text().mid(1); // skip the '#'
+    std::size_t len = typedstr.size();
+
+    for (auto b = buttons.begin(); b != buttons.end(); ++b) {
+        (*b)->setVisible((*b)->text().left(len) == typedstr);
+    }
+}
+
 } // namespace nethack_qt4
index 29ba23f0db87558ef31080048e42e8b595f1b5e9..338ef33709393d0606d241d7bb90915deea04970 100644 (file)
@@ -21,6 +21,8 @@ public:
 
 private:
     QLabel *prompt;
+    QVector<QPushButton *> buttons;
+    void enableButtons();
 
 private slots:
     void cancel();