Qt menus, mostly item counts
Don't allow the user to construct a count value when operating on a pick-none menu where counts aren't meaningful. Unfortunately that can still be done on pick-one or pick-any menus which don't happen to have any entries where a count is applicable. Allow a count to be optionally started with '#'. Note that if there is an entry using '#' for the selector letter (probably inventory that has something in the overflow slot), typing '#' will select the entry instead of initiating a count. Flail about a bit trying to get menu size correct--failed on this front.
This commit is contained in:
@@ -6,6 +6,8 @@
|
||||
|
||||
//
|
||||
// TODO:
|
||||
// inventory menus reuse the same menu window over and over (in the core);
|
||||
// it isn't resizing properly to reflect each new instance's content;
|
||||
// implement next_page, prev_page, first_page, and last_page to work
|
||||
// like they do for X11: scroll menu window as if it were paginated;
|
||||
// entering a count that uses more digits than the previous biggest count
|
||||
@@ -65,11 +67,14 @@ int NetHackQtMenuListBox::TotalWidth() const
|
||||
|
||||
int NetHackQtMenuListBox::TotalHeight() const
|
||||
{
|
||||
int height = 0;
|
||||
int row, height = 0;
|
||||
|
||||
for (int row = 0; row < rowCount(); ++row) {
|
||||
for (row = 0; row < rowCount(); ++row) {
|
||||
height += rowHeight(row);
|
||||
}
|
||||
// include extra height so that there will be a blank gap after the
|
||||
// last entry to show that there is nothing to scroll forward too
|
||||
height += (row > 0) ? (rowHeight(row - 1) / 2) : 7;
|
||||
return height;
|
||||
}
|
||||
|
||||
@@ -80,9 +85,41 @@ QSize NetHackQtMenuListBox::sizeHint() const
|
||||
return QSize(TotalWidth()+hsize, TotalHeight()+hsize);
|
||||
}
|
||||
|
||||
//
|
||||
// FIXME:
|
||||
// Inventory displays reuse the same menu window and so far this
|
||||
// is not updating the size as intended. The size of the first
|
||||
// instance persists.
|
||||
//
|
||||
|
||||
// resize current menu window and the table (rows of entries) inside it
|
||||
void NetHackQtMenuWindow::MenuResize()
|
||||
{
|
||||
// when this was just 'adjustSize()', our sizeHints() was not
|
||||
// being called so explicitly indicate the table widget
|
||||
table->adjustSize();
|
||||
this->adjustSize();
|
||||
|
||||
// Temporary? workaround for scrolling becoming wedged if using
|
||||
// all/none/invert removes all counts so we narrow a non-empty
|
||||
// count column to empty. [That can take away the horizontal
|
||||
// scroll bar but should not be affecting the vertical one, yet
|
||||
// is (Qt 5.11.3).] Typing any digit restored normal scrolling
|
||||
// and the only significant thing about that is that it updates
|
||||
// the prompt line which is outside the table of menu items where
|
||||
// scrolling takes place. Oddly, both prompt changes are needed
|
||||
// (possibly the unnecessary space in the first is being optimized
|
||||
// away but the second call to remove it isn't aware of that, or
|
||||
// perhaps the 'fix' only happens when the line gets shorter).
|
||||
prompt.setText(promptstr + " ");
|
||||
prompt.setText(promptstr);
|
||||
// [Later: becoming wedged doesn't just occur after shrinking the
|
||||
// count column and seems to be triggered by table->adjustSize().]
|
||||
}
|
||||
|
||||
// Table view columns (0..4):
|
||||
//
|
||||
// [pick-count] [check-box] [glyph] [accel] [string]
|
||||
// [pick-count] [check-box] [object-glyph] [selector-letter] [description]
|
||||
//
|
||||
// pick-count is normally empty and gets wider as needed.
|
||||
//
|
||||
@@ -155,11 +192,22 @@ NetHackQtMenuWindow::~NetHackQtMenuWindow()
|
||||
|
||||
QWidget* NetHackQtMenuWindow::Widget() { return this; }
|
||||
|
||||
//
|
||||
// Note: inventory menus reuse the same menu window over and over
|
||||
// so StartMenu(), AddMenu(), EndMenu(), and SelectMenu()
|
||||
// can't rely on the MenuWindow constructor for initialization.
|
||||
//
|
||||
|
||||
void NetHackQtMenuWindow::StartMenu()
|
||||
{
|
||||
table->setRowCount((itemcount=0));
|
||||
next_accel=0;
|
||||
has_glyphs=false;
|
||||
itemcount = 0;
|
||||
table->setRowCount(itemcount);
|
||||
next_accel = 0;
|
||||
has_glyphs = false;
|
||||
biggestcount = 0L;
|
||||
countdigits = 0;
|
||||
ClearCount(); // reset 'counting' flag and digit string 'countstr'
|
||||
ClearSearch(); // reset 'searching' flag
|
||||
}
|
||||
|
||||
NetHackQtMenuWindow::MenuItem::MenuItem() :
|
||||
@@ -258,10 +306,11 @@ int NetHackQtMenuWindow::SelectMenu(int h, MENU_ITEM_P **menu_list)
|
||||
}
|
||||
PadMenuColumns(::iflags.menu_tab_sep ? true : false);
|
||||
|
||||
MenuResize();
|
||||
|
||||
//old FIXME: size for compact mode
|
||||
//resize(this->width(), parent()->height()*7/8);
|
||||
move(0, 0);
|
||||
adjustSize();
|
||||
centerOnMain(this);
|
||||
|
||||
exec();
|
||||
@@ -396,23 +445,7 @@ void NetHackQtMenuWindow::UpdateCountColumn(long newcount)
|
||||
|
||||
PadMenuColumns(false);
|
||||
|
||||
// Temporary? workaround for scrolling becoming wedged if using
|
||||
// all/none/invert removes all counts so we narrow a non-empty
|
||||
// count column to empty. [That can take away the horizontal
|
||||
// scroll bar but should not be affecting the vertical one, yet
|
||||
// is (Qt 5.11.3).] Typing any digit restored normal scrolling
|
||||
// and the only significant thing about that is that it updates
|
||||
// the prompt line which is outside the table of menu items where
|
||||
// scrolling takes place. Oddly, both prompt changes are needed
|
||||
// (possibly the unnecessary space in the first is being optimized
|
||||
// away but the second call to remove it isn't aware of that).
|
||||
prompt.setText(promptstr + " ");
|
||||
prompt.setText(promptstr);
|
||||
|
||||
// when this was just 'adjustSize()', our sizeHints() was not
|
||||
// being called so explicitly indicate the table widget
|
||||
table->adjustSize();
|
||||
this->adjustSize();
|
||||
MenuResize();
|
||||
table->repaint();
|
||||
}
|
||||
|
||||
@@ -599,7 +632,7 @@ void NetHackQtMenuWindow::WidenColumn(int column, int width)
|
||||
|
||||
void NetHackQtMenuWindow::InputCount(char key)
|
||||
{
|
||||
if (key == '\b' || key == '\177') {
|
||||
if (key == '\b' || key == '\177' || how == PICK_NONE) {
|
||||
if (counting) {
|
||||
if (countstr.isEmpty())
|
||||
ClearCount();
|
||||
@@ -608,6 +641,15 @@ void NetHackQtMenuWindow::InputCount(char key)
|
||||
}
|
||||
} else {
|
||||
counting = true;
|
||||
// starting a count (enforced by caller) with '#' is optional;
|
||||
// if used, show visible '0'
|
||||
if (key == '#')
|
||||
key = '0';
|
||||
// if we have non-zero digit and are currently showing visible '0',
|
||||
// replace instead of append; doesn't attempt to handle multiple
|
||||
// leading zeroes--they won't affect the outcome, just look odd
|
||||
else if (key > '0' && countstr == "0")
|
||||
countstr = "";
|
||||
countstr += QChar(key);
|
||||
}
|
||||
if (counting)
|
||||
@@ -655,7 +697,9 @@ void NetHackQtMenuWindow::keyPressEvent(QKeyEvent *key_event)
|
||||
reject();
|
||||
} else if (key == '\r' || key == '\n' || key == ' ') {
|
||||
accept();
|
||||
} else if (('0' <= key && key <= '9') || key == '\b' || key == '\177') {
|
||||
} else if (('0' <= key && key <= '9')
|
||||
|| (key == '#' && !counting)
|
||||
|| key == '\b' || key == '\177') {
|
||||
InputCount(key);
|
||||
} else if (key == MENU_SELECT_ALL || key == MENU_SELECT_PAGE) {
|
||||
All();
|
||||
@@ -925,12 +969,12 @@ void NetHackQtTextWindow::UseRIP(int how, time_t when)
|
||||
{
|
||||
// Code from X11 windowport
|
||||
#define STONE_LINE_LEN 16 /* # chars that fit on one line */
|
||||
#define NAME_LINE 0 /* line # for player name */
|
||||
#define GOLD_LINE 1 /* line # for amount of gold */
|
||||
#define NAME_LINE 0 /* line # for player name */
|
||||
#define GOLD_LINE 1 /* line # for amount of gold */
|
||||
#define DEATH_LINE 2 /* line # for death description */
|
||||
#define YEAR_LINE 6 /* line # for year */
|
||||
#define YEAR_LINE 6 /* line # for year */
|
||||
|
||||
static char** rip_line=0;
|
||||
static char **rip_line = 0;
|
||||
if (!rip_line) {
|
||||
rip_line=new char*[YEAR_LINE+1];
|
||||
for (int i=0; i<YEAR_LINE+1; i++) {
|
||||
|
||||
Reference in New Issue
Block a user