Qt menu overhaul

handle preselected item in pick-one menu; picking it returns that
  item rather than toggling it off and returning nothing, picking
  something else only returns the other thing (was returning first
  of the chosen item or the preselected item, foiling core's attempt
  to deal with both and giving wrong result whenever the preselected
  one came first--like pick-an-attribute for menu colors);

when handling typed input, check selector letters before menu
  command keys so that special "letters" '-' (fingers, hands, self)
  and ':' (look inside container) that are specified by a few menus
  can be chosen by keyboard;

menus were using default line heights which are excessively tall,
  effectively making them be double spaced and using more screen
  space than should have been needed; reduce height to 60% of what
  it was, still a bit taller than regular spacing; look at ^X--which
  is rendered via menu--before and after to see the difference;

start with count column empty instead of 6 spaces; grow it as counts
  get entered; reset to empty if [all], [none], or [invert] is used;
  treat intermediate counts as long rather than int; right justify
  formatted count values;

simplify creating menu return data (pick-one doesn't need separate
  handling);

for pick-one menus,
  enable [ok] button if there is one preselected item,
  enable [all] button if there is only one item (may never happen),
  enable [none] if there is a preselected item (menu remains active
    if [none] is used to clear the preselection);
  enable [invert] if there is one item (may never happen; should
    allow two items if one of them is preselected--definitely does
    happen--but that wouldn't work as intended without code changes);

honor pending count if an item is selected by clicking its checkbox
  (already done for typing its letter or for clicking another part
  of item's menu line);

accept <delete>/<rubout> in addition to <backspace> when backing out
  a digit as a count is being typed;

accept ^[ as well as ESC key for cancelling count or entire menu;

honor 'menucolors'=false to ignore any defined menu color patterns.
This commit is contained in:
PatR
2020-09-16 15:51:33 -07:00
parent 81771ccda3
commit 5401d18c4b
2 changed files with 543 additions and 295 deletions
+26 -14
View File
@@ -10,6 +10,9 @@
#include "qt_win.h"
#include "qt_rip.h"
// some menu fields aren't wide enough even though sized for measured text
#define MENU_WIDTH_SLOP 10 /* this should not be necessary */
namespace nethack_qt_ {
class NetHackQtTextListBox : public QListWidget {
@@ -54,8 +57,9 @@ public:
virtual QWidget* Widget();
virtual void StartMenu();
virtual void AddMenu(int glyph, const ANY_P* identifier, char ch, char gch, int attr,
const QString& str, unsigned itemflags);
virtual void AddMenu(int glyph, const ANY_P *identifier,
char ch, char gch, int attr,
const QString& str, unsigned itemflags);
virtual void EndMenu(const QString& prompt);
virtual int SelectMenu(int how, MENU_ITEM_P **menu_list);
@@ -65,9 +69,9 @@ public slots:
void Invert();
void Search();
void ToggleSelect(int);
void cellToggleSelect(int, int);
void DoSelection(bool);
void ToggleSelect(int row, bool alyready_checked);
void TableCellClicked(int row, int col);
void CheckboxClicked(bool on_off);
protected:
virtual void keyPressEvent(QKeyEvent*);
@@ -81,10 +85,11 @@ private:
ANY_P identifier;
int attr;
QString str;
int count;
long count;
char ch;
char gch;
bool selected;
bool selected; // True if checkbox is set
bool preselected; // True if caller told us to set checkbox
unsigned itemflags;
unsigned color;
@@ -108,19 +113,25 @@ private:
// Count replaces prompt while it is being input
QString promptstr;
QString countstr;
bool counting;
long biggestcount; // determines width of field #0
int countdigits; // number of digits to format biggestcount
bool counting; // in midst of entering a count
bool searching; // in midst of entering a search string
void InputCount(char key);
void ClearCount(void);
int how;
bool has_glyphs;
int how; // pick-none, pick-one, pick-any
bool has_glyphs; // at least one item specified a glyph
bool isSelected(int row);
int count(int row);
long count(int row);
void AddRow(int row, const MenuItem& mi);
void WidenColumn(int column, int width);
void PadMenuColumns(bool split_descr);
void UpdateCountColumn(long newcount);
void ClearSearch();
};
class NetHackQtTextWindow : public QDialog, public NetHackQtWindow {
@@ -172,8 +183,9 @@ public:
// Menu
virtual void StartMenu();
virtual void AddMenu(int glyph, const ANY_P* identifier, char ch, char gch, int attr,
const QString& str, unsigned itemflags);
virtual void AddMenu(int glyph, const ANY_P *identifier,
char ch, char gch, int attr,
const QString& str, unsigned itemflags);
virtual void EndMenu(const QString& prompt);
virtual int SelectMenu(int how, MENU_ITEM_P **menu_list);