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());
|
pb->setMinimumSize(butw,pb->sizeHint().height());
|
||||||
group->addButton(pb, i+1);
|
group->addButton(pb, i+1);
|
||||||
gl->addWidget(pb,i/ncols,i%ncols);
|
gl->addWidget(pb,i/ncols,i%ncols);
|
||||||
|
buttons.append(pb);
|
||||||
}
|
}
|
||||||
group->addButton(can, 0);
|
group->addButton(can, 0);
|
||||||
connect(group,SIGNAL(buttonPressed(int)),this,SLOT(done(int)));
|
connect(group,SIGNAL(buttonPressed(int)),this,SLOT(done(int)));
|
||||||
@@ -92,6 +93,7 @@ void NetHackQtExtCmdRequestor::keyPressEvent(QKeyEvent *event)
|
|||||||
QString promptstr = prompt->text();
|
QString promptstr = prompt->text();
|
||||||
if (promptstr != "#")
|
if (promptstr != "#")
|
||||||
prompt->setText(promptstr.left(promptstr.size()-1));
|
prompt->setText(promptstr.left(promptstr.size()-1));
|
||||||
|
enableButtons();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -111,6 +113,7 @@ void NetHackQtExtCmdRequestor::keyPressEvent(QKeyEvent *event)
|
|||||||
done(match+1);
|
done(match+1);
|
||||||
else if (matches >= 2)
|
else if (matches >= 2)
|
||||||
prompt->setText(promptstr);
|
prompt->setText(promptstr);
|
||||||
|
enableButtons();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,4 +134,15 @@ int NetHackQtExtCmdRequestor::get()
|
|||||||
return result()-1;
|
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
|
} // namespace nethack_qt4
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QLabel *prompt;
|
QLabel *prompt;
|
||||||
|
QVector<QPushButton *> buttons;
|
||||||
|
void enableButtons();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void cancel();
|
void cancel();
|
||||||
|
|||||||
Reference in New Issue
Block a user