//
// 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
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;
}
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.
//
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() :
}
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();
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();
}
void NetHackQtMenuWindow::InputCount(char key)
{
- if (key == '\b' || key == '\177') {
+ if (key == '\b' || key == '\177' || how == PICK_NONE) {
if (counting) {
if (countstr.isEmpty())
ClearCount();
}
} 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)
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();
{
// 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++) {