]> granicus.if.org Git - nethack/commitdiff
Qt message window: horizontal scrolling
authorPatR <rankin@nethack.org>
Mon, 30 Nov 2020 00:58:56 +0000 (16:58 -0800)
committerPatR <rankin@nethack.org>
Mon, 30 Nov 2020 00:58:56 +0000 (16:58 -0800)
Multiple stints of flailing about without a clue finally led to
a breakthrough.  When writing a new message to the multi-line
message window, force the view back to showing the starts of
lines if player has scrolled it to the side and left it that way.
Put another way, if it has been scrolled to the right, scroll it
as far as possible back to the left.

doc/fixes37.0
win/Qt/qt_msg.cpp
win/Qt/qt_msg.h

index c5e5d77bea41b0bac2cb6411c3ed0ec6e349835d..392ff76e21fb839c3202bf1081c7ea204153bc00 100644 (file)
@@ -1,4 +1,4 @@
-NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.366 $ $NHDT-Date: 1606504240 2020/11/27 19:10:40 $
+NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.367 $ $NHDT-Date: 1606697932 2020/11/30 00:58:52 $
 
 General Fixes and Modified Features
 -----------------------------------
@@ -500,6 +500,8 @@ Qt: don't clobber an existing save file after choosing "new game" in the
        saved game selection widget
 Qt: don't get stuck in a loop after choosing "play" while the character name
        field is empty in the character selection widget
+Qt: when a new message is issued, pan the message window to its left edge if
+       player panned it horizontally then didn't manually scroll it back
 Qt: {maybe just Qt+OSX:} when viewing a text window ('V' to look at 'history'
        for instance), clicking on [Search], entering a search target in the
        resulting popup and clicking on [Okay] or typing <return>, the text
index c9c3537b886ac5eaa21bc1783db98a4f1190564c..66fd93daee6aab7da241c7108b883adc6be9cfe6 100644 (file)
@@ -23,9 +23,12 @@ extern "C" {
 namespace nethack_qt_ {
 
 NetHackQtMessageWindow::NetHackQtMessageWindow() :
-    list(new QListWidget())
+    list(new QListWidget()),
+    scrollarea(new QScrollArea())
 {
     list->setFocusPolicy(Qt::NoFocus);
+    scrollarea->setFocusPolicy(Qt::NoFocus);
+    scrollarea->takeWidget();
     ::iflags.window_inited = 1;
     map = 0;
     currgetmsg = 0;
@@ -39,7 +42,9 @@ NetHackQtMessageWindow::~NetHackQtMessageWindow()
     delete list;
 }
 
-QWidget* NetHackQtMessageWindow::Widget() { return list; }
+QWidget* NetHackQtMessageWindow::Widget() {
+    return list;
+}
 
 void NetHackQtMessageWindow::setMap(NetHackQtMapWindow2* m)
 {
@@ -152,6 +157,8 @@ void NetHackQtMessageWindow::PutStr(int attr, const QString& text)
             item->setBackground(bg);
         }
     }
+#else
+    nhUse(attr);
 #endif
 
     if (list->count() >= (int) ::iflags.msg_history)
@@ -163,6 +170,13 @@ void NetHackQtMessageWindow::PutStr(int attr, const QString& text)
     // selects most recent message, which causes it to be highlighted
     list->setCurrentRow(list->count() - 1);
 
+    // if message window has been scrolled right, force back to left edge
+    QScrollBar *sb = list->horizontalScrollBar();
+    if (sb && sb->value() > 0) {
+        sb->setValue(0);
+        this->viewport()->update();
+    }
+
     if (map)
        map->putMessage(attr, text2);
 }
index ca84acaf57f84ffe84bc3c21d125b941e8be6d61..b3274bc13569973d4beb8dc26fb74eb9459f44ed 100644 (file)
@@ -13,7 +13,7 @@ namespace nethack_qt_ {
 
 class NetHackQtMapWindow2;
 
-class NetHackQtMessageWindow : QObject, public NetHackQtWindow {
+class NetHackQtMessageWindow : QScrollArea, public NetHackQtWindow {
        Q_OBJECT
 public:
        NetHackQtMessageWindow();
@@ -37,8 +37,9 @@ public:
         void AddToStr(const char *answerbuf);
 
 private:
-       QListWidget* list;
-       bool changed;
+        QListWidget *list;
+        QScrollArea *scrollarea;
+        bool changed;
         int currgetmsg;
        NetHackQtMapWindow2* map;