]> granicus.if.org Git - nethack/commitdiff
Qt message [un]highlighting
authorPatR <rankin@nethack.org>
Mon, 31 Aug 2020 05:50:02 +0000 (22:50 -0700)
committerPatR <rankin@nethack.org>
Mon, 31 Aug 2020 05:50:02 +0000 (22:50 -0700)
The Qt interface highlights the last message issued (using a
mechanism for selection, as if for copy+paste or similar operation)
but it was staying highlighted until another message was eventually
given.  Having an old message seem to stick around is annoying and
is particularly bad when the message is a prompt.  If the player's
answer doesn't cause a message to be shown then it seems as if the
prompt is still pending.

This removes the highlighting (by bulk unselecting) once the player
gives another input keystroke or mouse click.

It would be much better if the selecting/highlighting was for all
messages issued since last time highlighting was cleared.  Figuring
out how to do that correctly is more effort than I want to expend.

doc/fixes37.0
win/Qt/qt_bind.cpp
win/Qt/qt_main.cpp
win/Qt/qt_main.h
win/Qt/qt_map.cpp
win/Qt/qt_msg.cpp
win/Qt/qt_msg.h

index a5579a86c224c331d89fa883cf0cc897c6bb349c..d0d6e975f8bb1c77a9218d798c9c592424c4b443 100644 (file)
@@ -1,4 +1,4 @@
-NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.292 $ $NHDT-Date: 1598831076 2020/08/30 23:44:36 $
+NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.293 $ $NHDT-Date: 1598852985 2020/08/31 05:49:45 $
 
 General Fixes and Modified Features
 -----------------------------------
@@ -393,6 +393,7 @@ Qt: tombstone showed newly constructed date instead of the value set up at
 Qt: menu choices All, None, Invert were setting, unsetting, or toggling menu
        entry checkboxes internally but didn't redraw the menu to show that
 Qt: fix the F1/F2/Tab macro keys to not require that number_pad be On
+Qt: unhighlight highlighted message (last one issued) after player has seen it
 Qt+QSX: fix control key
 Qt+OSX: rename menu entry "nethack->Preferences..." for invoking nethack's
        'O' command to "Game->Run-time options" and entry "Game->Qt settings"
index 7e849b77be5538158f642240f257256bc7209382..e6492aaea9f1ceaa6d1afaf6532cdd2d3a3e3016 100644 (file)
@@ -471,7 +471,7 @@ void NetHackQtBind::qt_raw_print_bold(const char *str)
 int NetHackQtBind::qt_nhgetch()
 {
     if (main)
-       main->fadeHighlighting();
+       main->fadeHighlighting(true);
 
     // Process events until a key arrives.
     //
@@ -479,19 +479,28 @@ int NetHackQtBind::qt_nhgetch()
        qApp->exec();
     }
 
+    // after getting a key rather than before
+    if (main)
+        main->fadeHighlighting(false);
+
     return keybuffer.GetAscii();
 }
 
 int NetHackQtBind::qt_nh_poskey(int *x, int *y, int *mod)
 {
     if (main)
-       main->fadeHighlighting();
+       main->fadeHighlighting(true);
 
     // Process events until a key or map-click arrives.
     //
     while (keybuffer.Empty() && clickbuffer.Empty()) {
        qApp->exec();
     }
+
+    // after getting a key or click rather than before
+    if (main)
+        main->fadeHighlighting(false);
+
     if (!keybuffer.Empty()) {
        return keybuffer.GetAscii();
     } else {
index ca32f1e4a71bf36568d84a4d045ae81fbfe079be..e57a1a8e1784684762f122abaa7a9617a4d7e905 100644 (file)
@@ -751,7 +751,7 @@ NetHackQtMainWindow::NetHackQtMainWindow(NetHackQtKeyBuffer& ks) :
        the application menu instead of the help menu; we'll add it to
        the latter now and have two ways to access it; without the
        leading underscore (or some other spelling variation such as
-       "'bout"), this one would get interceptd too and then evidently
+       "'bout"), this one would get intercepted too and then evidently
        be discarded as a duplicate */
     help->addSeparator();
     help->addAction("_About_Qt_NetHack_", this, SLOT(doAbout(bool)));
@@ -1042,10 +1042,16 @@ void NetHackQtMainWindow::updateInventory()
     }
 }
 
-void NetHackQtMainWindow::fadeHighlighting()
+void NetHackQtMainWindow::fadeHighlighting(bool before_key)
 {
-    if (status) {
-       status->fadeHighlighting();
+    if (before_key) {
+        // status highlighting fades at start of turn
+        if (status)
+            status->fadeHighlighting();
+    } else {
+        // message highlighting fades after user has given input
+        if (message && message->hilit_mesgs())
+            message->unhighlight_mesgs();
     }
 }
 
index f043c619f3bacf3c307fb2c3ee05d9b48aff2856..fbec9fb63129a8e6ed4cf551fe2302197d47e5ee 100644 (file)
@@ -47,7 +47,7 @@ public:
        void RemoveWindow(NetHackQtWindow* window);
        void updateInventory();
 
-       void fadeHighlighting();
+       void fadeHighlighting(bool before_key);
 
         // this is unconditional in case qt_main.h comes before qt_set.h
         void resizePaperDoll(bool); // ENHANCED_PAPERDOLL
index eb497da865cd937479c03f9f8e346dbb071af64c..2e507e6914d0f3c08753ea90d95882774682e27e 100644 (file)
@@ -582,12 +582,16 @@ void NetHackQtMapWindow2::clearMessages()
 
 void NetHackQtMapWindow2::putMessage(int attr UNUSED, const QString& text)
 {
-    if ( !messages.isEmpty() )
+    if (!messages.isEmpty())
        messages += "\n";
     messages += QString(text).replace(QChar(0x200B), "");
-    QFontMetrics fm = fontMetrics();
 #if 0
-    messages_rect = fm.boundingRect(viewport.contentsX(),viewport.contentsY(),viewport.width(),0, Qt::TextWordWrap|Qt::AlignTop|Qt::AlignLeft|Qt::TextDontClip, messages);
+    QFontMetrics fm = fontMetrics();
+    messages_rect = fm.boundingRect(viewport.contentsX(), viewport.contentsY(),
+                                    viewport.width(), 0,
+                                    (Qt::TextWordWrap | Qt::AlignTop
+                                     | Qt::AlignLeft | Qt::TextDontClip),
+                                    messages);
     update(messages_rect);
 #endif
 }
index aee2ea135cd9f3b9b5cd4ccef7732456345848af..dcb643efb692d10a3c879cff294504dc2f74ef88 100644 (file)
@@ -74,6 +74,9 @@ void NetHackQtMessageWindow::ClearMessages()
 
 void NetHackQtMessageWindow::Display(bool block UNUSED)
 {
+    //
+    // FIXME: support for 'block' is necessary for MSGTYPE=stop
+    //
     if (changed) {
        list->repaint();
        changed=false;
@@ -88,8 +91,9 @@ const char * NetHackQtMessageWindow::GetStr(bool init)
     QListWidgetItem *item = list->item(currgetmsg++);
     if (item) {
         QString str = item->text();
-        //raw_printf("getstr[%i]='%s'", currgetmsg, str.toLatin1().constData());
-        return str.toLatin1().constData();
+        const char *result = str.toLatin1().constData();
+        //raw_printf("getstr[%d]='%s'", currgetmsg, result);
+        return result;
     }
     return NULL;
 }
@@ -114,31 +118,52 @@ void NetHackQtMessageWindow::PutStr(int attr, const QString& text)
     font.setWeight((attr == ATR_BOLD) ? QFont::Bold : QFont::Normal);
     item->setFont(font);
 
-    QColor fg = item->foreground().color();
-    QColor bg = item->background().color();
-    if (attr == ATR_DIM)
-    {
-       fg.setAlpha(fg.alpha() / 2);
+    if (attr == ATR_DIM || attr == ATR_INVERSE) {
+        QColor fg = item->foreground().color();
+        QColor bg = item->background().color();
+        if (attr == ATR_DIM) {
+            fg.setAlpha(fg.alpha() / 2);
+            new_fgbg = true;
+        }
+        if (attr == ATR_INVERSE) {
+            QColor swap;
+            swap = fg; fg = bg; bg = swap;
+        }
+        item->setForeground(fg);
+        item->setBackground(bg);
     }
-    if (attr == ATR_INVERSE)
-    {
-       QColor swap;
-       swap = fg; fg = bg; bg = swap;
-    }
-    item->setForeground(fg);
-    item->setBackground(bg);
+    // ATR_BLINK not supported
 #endif
 
-    // ATR_BLINK not supported
     if (list->count() >= (int) ::iflags.msg_history)
        delete list->item(0);
     list->addItem(text2);
 
     // Force scrollbar to bottom
-    list->setCurrentRow(list->count()-1);
+    list->setCurrentRow(list->count() - 1);
 
-    if ( map )
+    if (map)
        map->putMessage(attr, text2);
 }
 
+// are there any highlighted messages?
+bool NetHackQtMessageWindow::hilit_mesgs()
+{
+    // PutStr() uses setCurrentRow() to select the last message line;
+    // being selected causes that line to be highlighted.
+    //
+    // We could/should keep track of whether anything is currently
+    // highlighted instead of just assuming that last message still is.
+    if (list && list->count())
+        return true;
+    return false;
+}
+
+// unhighlight any highlighted messages
+void NetHackQtMessageWindow::unhighlight_mesgs()
+{
+    if (list)
+        list->clearSelection();
+}
+
 } // namespace nethack_qt_
index 08c029b9b8805ac2466f5fe9f6f3b77f21083f2e..1aa2b94c8a056db745c73b47acbb5560fad16840 100644 (file)
@@ -30,6 +30,9 @@ public:
 
        void setMap(NetHackQtMapWindow2*);
 
+        bool hilit_mesgs();
+        void unhighlight_mesgs();
+
 private:
        QListWidget* list;
        bool changed;