From: Pasi Kallinen Date: Tue, 10 Oct 2017 19:55:30 +0000 (+0300) Subject: Qt4: put and get message history X-Git-Tag: NetHack-3.6.1_RC01~282 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2fcf1ad1396b3b866820aae9b155a9e5e29dc11c;p=nethack Qt4: put and get message history --- diff --git a/win/Qt4/qt4bind.cpp b/win/Qt4/qt4bind.cpp index ab4726a5f..75c5f821b 100644 --- a/win/Qt4/qt4bind.cpp +++ b/win/Qt4/qt4bind.cpp @@ -605,6 +605,30 @@ void NetHackQtBind::qt_outrip(winid wid, int how, time_t when) window->UseRIP(how, when); } +char * NetHackQtBind::qt_getmsghistory(BOOLEAN_P init) +{ + NetHackQtMessageWindow* window = main->GetMessageWindow(); + if (window) + return (char *)window->GetStr(init); + return NULL; +} + +void NetHackQtBind::qt_putmsghistory(const char *msg, BOOLEAN_P is_restoring) +{ + NetHackQtMessageWindow* window = main->GetMessageWindow(); + //raw_printf("msg='%s'", msg); + if (window && msg) + window->PutStr(ATR_NONE, QString::fromLatin1(msg)); +} + +void NetHackQtBind::qt_putmsghistory(const std::string& msg, BOOLEAN_P is_restoring) +{ + NetHackQtMessageWindow* window = main->GetMessageWindow(); + if (window) + window->PutStr(ATR_NONE, QString::fromLatin1(msg.c_str(), msg.size())); +} + + bool NetHackQtBind::notify(QObject *receiver, QEvent *event) { // Ignore Alt-key navigation to menubar, it's annoying when you @@ -728,7 +752,8 @@ struct window_procs Qt_procs = { #endif genl_preference_update, - genl_getmsghistory, genl_putmsghistory, + nethack_qt4::NetHackQtBind::qt_getmsghistory, + nethack_qt4::NetHackQtBind::qt_putmsghistory, genl_status_init, genl_status_finish, genl_status_enablefield, #ifdef STATUS_HILITES diff --git a/win/Qt4/qt4bind.h b/win/Qt4/qt4bind.h index 99a2c0d11..ad396b78c 100644 --- a/win/Qt4/qt4bind.h +++ b/win/Qt4/qt4bind.h @@ -78,6 +78,10 @@ public: static void qt_start_screen(); static void qt_end_screen(); + static char *qt_getmsghistory(BOOLEAN_P init); + static void qt_putmsghistory(const char *msg, BOOLEAN_P is_restoring); + static void qt_putmsghistory(const std::string& msg, BOOLEAN_P is_restoring); + static void qt_outrip(winid wid, int how, time_t when); static int qt_kbhit(); diff --git a/win/Qt4/qt4main.cpp b/win/Qt4/qt4main.cpp index f9a74e506..4fd8d14da 100644 --- a/win/Qt4/qt4main.cpp +++ b/win/Qt4/qt4main.cpp @@ -866,6 +866,11 @@ void NetHackQtMainWindow::AddMessageWindow(NetHackQtMessageWindow* window) ShowIfReady(); } +NetHackQtMessageWindow * NetHackQtMainWindow::GetMessageWindow() +{ + return message; +} + void NetHackQtMainWindow::AddMapWindow(NetHackQtMapWindow2* window) { diff --git a/win/Qt4/qt4main.h b/win/Qt4/qt4main.h index 33f5b2635..a3ec15ac2 100644 --- a/win/Qt4/qt4main.h +++ b/win/Qt4/qt4main.h @@ -41,6 +41,7 @@ public: NetHackQtMainWindow(NetHackQtKeyBuffer&); void AddMessageWindow(NetHackQtMessageWindow* window); + NetHackQtMessageWindow * GetMessageWindow(); void AddMapWindow(NetHackQtMapWindow2* window); void AddStatusWindow(NetHackQtStatusWindow* window); void RemoveWindow(NetHackQtWindow* window); diff --git a/win/Qt4/qt4msg.cpp b/win/Qt4/qt4msg.cpp index e1194795d..7c3ccd1df 100644 --- a/win/Qt4/qt4msg.cpp +++ b/win/Qt4/qt4msg.cpp @@ -35,6 +35,7 @@ NetHackQtMessageWindow::NetHackQtMessageWindow() : list->setFocusPolicy(Qt::NoFocus); ::iflags.window_inited = 1; map = 0; + currgetmsg = 0; connect(qt_settings,SIGNAL(fontChanged()),this,SLOT(updateFont())); updateFont(); } @@ -80,6 +81,20 @@ void NetHackQtMessageWindow::Display(bool block) } } +const char * NetHackQtMessageWindow::GetStr(bool init) +{ + if (init) + currgetmsg = 0; + + QListWidgetItem *item = list->item(++currgetmsg); + if (item) { + QString str = item->text(); + //raw_printf("getstr[%i]='%s'", currgetmsg, str.toLatin1().constData()); + return str.toLatin1().constData(); + } + return NULL; +} + void NetHackQtMessageWindow::PutStr(int attr, const QString& text) { #ifdef USER_SOUNDS diff --git a/win/Qt4/qt4msg.h b/win/Qt4/qt4msg.h index 5c391cc4f..238ace478 100644 --- a/win/Qt4/qt4msg.h +++ b/win/Qt4/qt4msg.h @@ -22,6 +22,7 @@ public: virtual QWidget* Widget(); virtual void Clear(); virtual void Display(bool block); + virtual const char *GetStr(bool init); virtual void PutStr(int attr, const QString& text); void Scroll(int dx, int dy); @@ -31,6 +32,7 @@ public: private: QListWidget* list; bool changed; + int currgetmsg; NetHackQtMapWindow2* map; private slots: