Qt4: put and get message history
authorPasi Kallinen <paxed@alt.org>
Tue, 10 Oct 2017 19:55:30 +0000 (22:55 +0300)
committerPasi Kallinen <paxed@alt.org>
Tue, 10 Oct 2017 19:55:30 +0000 (22:55 +0300)
win/Qt4/qt4bind.cpp
win/Qt4/qt4bind.h
win/Qt4/qt4main.cpp
win/Qt4/qt4main.h
win/Qt4/qt4msg.cpp
win/Qt4/qt4msg.h

index ab4726a5f9fbf5e978641ae4065b866521711d11..75c5f821b84f0d7fae082f9149f1c4ff343f04f6 100644 (file)
@@ -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
index 99a2c0d11cc514f4a1bd7751c575b5374bef902a..ad396b78cf8a0d20cefcb333eb36c269cf548519 100644 (file)
@@ -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();
 
index f9a74e5064b167d268e5c6c2f02d34a41a5c4ea9..4fd8d14da5d9c510ee3338a5c8b0389a2d4a8d58 100644 (file)
@@ -866,6 +866,11 @@ void NetHackQtMainWindow::AddMessageWindow(NetHackQtMessageWindow* window)
     ShowIfReady();
 }
 
+NetHackQtMessageWindow * NetHackQtMainWindow::GetMessageWindow()
+{
+    return message;
+}
+
 void NetHackQtMainWindow::AddMapWindow(NetHackQtMapWindow2* window)
 {
 
index 33f5b2635fded926077912c4af239208f45c2cf6..a3ec15ac2b90613073fe1705ae0f9278446da8c2 100644 (file)
@@ -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);
index e1194795d6fc19006a747e3b87b7034730a15aa9..7c3ccd1dfd96002faed5e3f4e9371fe12a58b0da 100644 (file)
@@ -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
index 5c391cc4fb5ced8081eca3f7115e5543d3ee8507..238ace4780f455a55e262a76e949ee3132563b62 100644 (file)
@@ -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: