Qt4: Hide buttons not matching typed command
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.
This commit is contained in:
committed by
Pasi Kallinen
parent
25f770509a
commit
c13eed7369
@@ -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
|
||||
|
||||
@@ -21,6 +21,8 @@ public:
|
||||
|
||||
private:
|
||||
QLabel *prompt;
|
||||
QVector<QPushButton *> buttons;
|
||||
void enableButtons();
|
||||
|
||||
private slots:
|
||||
void cancel();
|
||||
|
||||
Reference in New Issue
Block a user