Qt click-to-command

Consolidate some recently added duplicated code.
This commit is contained in:
PatR
2020-10-07 04:19:55 -07:00
parent da8558e262
commit eb4288e608
4 changed files with 19 additions and 23 deletions

View File

@@ -167,17 +167,12 @@ QSize NetHackQtInvUsageWindow::sizeHint(void) const
}
}
// ENHANCED_PAPERDOLL - clicking on the PaperDoll runs #seeall
// ENHANCED_PAPERDOLL - clicking on the PaperDoll runs #seeall ('*')
void NetHackQtInvUsageWindow::mousePressEvent(QMouseEvent *event UNUSED)
{
#ifdef ENHANCED_PAPERDOLL
char cmdbuf[32];
Strcpy(cmdbuf, "#");
(void) cmdname_from_func(doprinuse, &cmdbuf[1], FALSE);
// queue up #seeall as if user had typed it; we don't execute doprinuse()
// directly because the program might not be ready for the next command
QWidget *main = NetHackQtBind::mainWidget();
(static_cast <NetHackQtMainWindow *> (main))->DollClickToKeys(cmdbuf);
(static_cast <NetHackQtMainWindow *> (main))->FuncAsCommand(doprinuse);
#endif
}

View File

@@ -982,19 +982,26 @@ void NetHackQtMainWindow::doGuidebook(bool)
}
#endif
void NetHackQtMainWindow::doKeys(const char *cmds)
{
keysink.Put(cmds);
qApp->exit();
}
void NetHackQtMainWindow::doKeys(const QString& k)
{
/* [this should probably be using toLocal8Bit();
toAscii() is not offered as an alternative...] */
keysink.Put(k.toLatin1().constData());
qApp->exit();
doKeys(k.toLatin1().constData());
}
// ENHANCED_PAPERDOLL - player clicked on PaperDoll window
void NetHackQtMainWindow::DollClickToKeys(const char *cmds)
// queue up the command name for a function, as if user had typed it
void NetHackQtMainWindow::FuncAsCommand(int NDECL((*func)))
{
keysink.Put(cmds);
qApp->exit();
char cmdbuf[32];
Strcpy(cmdbuf, "#");
(void) cmdname_from_func(func, &cmdbuf[1], FALSE);
doKeys(cmdbuf);
}
void NetHackQtMainWindow::AddMessageWindow(NetHackQtMessageWindow* window)

View File

@@ -49,9 +49,9 @@ public:
void fadeHighlighting(bool before_key);
// these are unconditional in case qt_main.h comes before qt_set.h
void FuncAsCommand(int NDECL((*func)));
// this is unconditional in case qt_main.h comes before qt_set.h
void resizePaperDoll(bool); // ENHANCED_PAPERDOLL
void DollClickToKeys(const char *); // ENHANCED_PAPERDOLL
public slots:
void doMenuItem(QAction *);
@@ -59,6 +59,7 @@ public slots:
void doAbout(bool);
void doQuit(bool);
//RLC void doGuidebook(bool);
void doKeys(const char *);
void doKeys(const QString&);
protected:

View File

@@ -606,15 +606,8 @@ void NetHackQtStatusWindow::checkTurnEvents()
// clicking on status window runs #attributes (^X)
void NetHackQtStatusWindow::mousePressEvent(QMouseEvent *event UNUSED)
{
// same code as NetHackQtInvUsageWindow::mousePressEvent except for func
char cmdbuf[32];
Strcpy(cmdbuf, "#");
(void) cmdname_from_func(doattributes, &cmdbuf[1], FALSE);
// queue up #attribues as if user had typed it; we don't execute
// doattributes() directly because the program might not be ready
// for a command right now
QWidget *main = NetHackQtBind::mainWidget();
(static_cast <NetHackQtMainWindow *> (main))->DollClickToKeys(cmdbuf);
(static_cast <NetHackQtMainWindow *> (main))->FuncAsCommand(doattributes);
}
} // namespace nethack_qt_