]> granicus.if.org Git - nethack/commitdiff
Qt: add tool tips for status window icons
authorPatR <rankin@nethack.org>
Sun, 6 Feb 2022 02:43:44 +0000 (18:43 -0800)
committerPatR <rankin@nethack.org>
Sun, 6 Feb 2022 02:43:44 +0000 (18:43 -0800)
Show a tip if the mouse hovers over any of the various icons displayed
in the status window (for one each of the six characteristics, another
for alignment, and one for each status condition).  They all already
have text labels below but many of those are abbreviated; the tips can
be more verbose since they don't compete with each for for screen space.

Also fixes "weak" not being centered under the hunger icon.  It /was/
centered but invisible trailing spaces made the visible text be shifted
to the left.

doc/fixes3-7-0.txt
win/Qt/qt_icon.cpp
win/Qt/qt_icon.h
win/Qt/qt_stat.cpp

index 2d603c87ae4de92d32efa702ae099f4e4cc6cf13..6f7890927ef2969ee8c662d2acc24ab73f36cde8 100644 (file)
@@ -1419,6 +1419,7 @@ Qt: [later] augment extended command selection dialog's Filter to add a
 Qt: add '#' as "Extended-commands" to the 'game' dropdown menu
 Qt: add tool tips to the extended command selector's buttons to show command
        descriptions
+Qt: add tool tips to the icons shown in the status window
 tiles: male and female variations in monsters.txt; tested only with tile2bmp
        conversion utility so far; also supported by tilemap utility to
        generate tile.c
index fea5747421fb85b3d5d95cfa891ae5f385fb801d..2c07ccbced30b288a297daff14ffa49887e7a9f9 100644 (file)
@@ -118,11 +118,15 @@ void NetHackQtLabelledIcon::setLabel(const QString& t, long v,
     setLabel(t,v,v,tail);
 }
 
-void NetHackQtLabelledIcon::setIcon(const QPixmap& i)
+void NetHackQtLabelledIcon::setIcon(
+    const QPixmap& i,
+    const QString& tooltip)
 {
     if (!icon)
         icon = new QLabel(this);
     icon->setPixmap(i);
+    if (!tooltip.isNull() && !tooltip.isEmpty())
+        icon->setToolTip(" " + tooltip + " ");
     ForceResize();
     icon->resize(i.width(), i.height());
 }
index 4542368968d890b425967c484f073686cefa437e..dddcda7ff1542654694a6ef6c66785aa0a687a6c 100644 (file)
@@ -25,7 +25,7 @@ public:
         void setLabel(const QString &, long, const QString &tail=""); // number
         void setLabel(const QString &, long show_value,
                       long comparative_value, const QString &tail="");
-        void setIcon(const QPixmap &);
+        void setIcon(const QPixmap &, const QString &tooltip=NULL);
         virtual void setFont(const QFont &);
         //QString labelText() { return QString(this->label->text()); }
 
index 5fce613c6b5544cae91e86e3f49c770c311ff7a8..f5b03fd0f7f6fb3a478518dfe3acd4159098feea 100644 (file)
@@ -72,7 +72,6 @@
 //    the rest of status.  That takes up more space, which is ok, but it
 //    also increases the vertical margin in between them by more than is
 //    necessary.  Should squeeze some of that excess blank space out.
-//  Add tool tips for the status condition icons, maybe the other icons.
 //
 
 extern "C" {
@@ -156,6 +155,9 @@ NetHackQtStatusWindow::NetHackQtStatusWindow() :
         int w = NetHackQtBind::mainWidget()->width();
         setMaximumWidth(w / 2);
     }
+    // for tool tips; they mostly work without this but sometimes changes
+    // to hunger or encumbrance seemed to cause tip display to stop
+    setMouseTracking(true);
 
     p_str = QPixmap(str_xpm);
     p_str = QPixmap(str_xpm);
@@ -193,31 +195,31 @@ NetHackQtStatusWindow::NetHackQtStatusWindow() :
     p_fly = QPixmap(fly_xpm);
     p_ride = QPixmap(ride_xpm);
 
-    str.setIcon(p_str);
-    dex.setIcon(p_dex);
-    con.setIcon(p_con);
-    intel.setIcon(p_int);
-    wis.setIcon(p_wis);
-    cha.setIcon(p_cha);
+    str.setIcon(p_str, "strength");
+    dex.setIcon(p_dex, "dexterity");
+    con.setIcon(p_con, "constitution");
+    intel.setIcon(p_int, "intelligence");
+    wis.setIcon(p_wis, "wisdom");
+    cha.setIcon(p_cha, "charisma");
 
     align.setIcon(p_neutral);
     blank2.setIcon(p_blank2); // used for spacing when Conditions row is empty
     hunger.setIcon(p_hungry);
     encumber.setIcon(p_encumber[0]);
 
-    stoned.setIcon(p_stoned);
-    slimed.setIcon(p_slimed);
-    strngld.setIcon(p_strngld);
-    sick_fp.setIcon(p_sick_fp);
-    sick_il.setIcon(p_sick_il);
-    stunned.setIcon(p_stunned);
-    confused.setIcon(p_confused);
-    hallu.setIcon(p_hallu);
-    blind.setIcon(p_blind);
-    deaf.setIcon(p_deaf);
-    lev.setIcon(p_lev);
-    fly.setIcon(p_fly);
-    ride.setIcon(p_ride);
+    stoned.setIcon(p_stoned, "turning to stone");
+    slimed.setIcon(p_slimed, "turning into slime");
+    strngld.setIcon(p_strngld, "being strangled");
+    sick_fp.setIcon(p_sick_fp, "severe food poisoning");
+    sick_il.setIcon(p_sick_il, "terminal illness");
+    stunned.setIcon(p_stunned, "stunned");
+    confused.setIcon(p_confused, "confused");
+    hallu.setIcon(p_hallu, "hallucinating");
+    blind.setIcon(p_blind, "cannot see");
+    deaf.setIcon(p_deaf, "cannot hear");
+    lev.setIcon(p_lev, "levitating");
+    fly.setIcon(p_fly, "flying");
+    ride.setIcon(p_ride, "riding");
 
     // separator lines
     hline1.setFrameStyle(QFrame::HLine | QFrame::Sunken);
@@ -625,7 +627,8 @@ void NetHackQtStatusWindow::HitpointBar()
             geoH.setRight(std::min(lox + pxl_health - 1, hix));
             hpbar_health.setGeometry(geoH);
             w = geoH.right() - geoH.left() + 1; // might yield 0 (ie, if dead)
-            styleH = QString::asprintf(styleformat, barcolors[colorindx][0], w, w);
+            styleH = QString::asprintf(styleformat, barcolors[colorindx][0],
+                                       w, w);
             hpbar_health.setStyleSheet(styleH);
             // when healing, having the old injury-side shown while the new
             // health-side expands pushes the injury farther right and it's
@@ -638,7 +641,8 @@ void NetHackQtStatusWindow::HitpointBar()
             geoI.setRight(hix);
             hpbar_injury.setGeometry(geoI);
             w = geoI.right() - geoI.left() + 1;
-            styleI = QString::asprintf(styleformat, barcolors[colorindx][1], w, w);
+            styleI = QString::asprintf(styleformat, barcolors[colorindx][1],
+                                       w, w);
             hpbar_injury.setStyleSheet(styleI);
             if (geoI.left() != oldleft)
                 hpbar_injury.move(geoI.left(), geoI.top());
@@ -656,7 +660,8 @@ void NetHackQtStatusWindow::HitpointBar()
             geoH.setRight(hix);
             hpbar_health.setGeometry(geoH);
             w = geoH.right() - geoH.left() + 1;
-            styleH = QString::asprintf(styleformat, barcolors[colorindx][0], w, w);
+            styleH = QString::asprintf(styleformat, barcolors[colorindx][0],
+                                       w, w);
             hpbar_health.setStyleSheet(styleH);
             hpbar_health.show();
 
@@ -727,6 +732,7 @@ void NetHackQtStatusWindow::updateStats()
 
     long qt_uhs = 0L;
     const char *hung = hu_stat[u.uhs];
+    QString qhung = QString(hung).trimmed();
     if (hung[0]==' ') {
         if (!hunger.isHidden()) {
             hunger.setLabel("", NetHackQtLabelledIcon::NoNum, qt_uhs);
@@ -745,8 +751,8 @@ void NetHackQtStatusWindow::updateStats()
         case FAINTING:   qt_uhs = 4L; break;
         default:         qt_uhs = 5L; break; // fainted, starved
         }
-       hunger.setIcon(u.uhs ? p_hungry : p_satiated);
-        hunger.setLabel(hung, NetHackQtLabelledIcon::NoNum, qt_uhs);
+        hunger.setIcon(u.uhs ? p_hungry : p_satiated, qhung.toLower());
+        hunger.setLabel(qhung, NetHackQtLabelledIcon::NoNum, qt_uhs);
         hunger.ForceResize();
        ++k, hunger.show();
     }
@@ -758,7 +764,7 @@ void NetHackQtStatusWindow::updateStats()
             encumber.hide();
         }
     } else {
-        encumber.setIcon(p_encumber[encindx - 1]);
+        encumber.setIcon(p_encumber[encindx - 1], QString(enc).toLower());
         encumber.setLabel(enc, NetHackQtLabelledIcon::NoNum, encindx);
         encumber.ForceResize();
        ++k, encumber.show();
@@ -838,9 +844,11 @@ void NetHackQtStatusWindow::updateStats()
         for (int i = ::flags.showexp ? 0 : 3; i < 4; ++i) {
             // passes 0,1,2 are with Exp, 3 is without Exp and always fits
             if (i < 3) {
-                buf = QString::asprintf("%s%ld/%ld", lvllbl[i], (long) u.ulevel, u.uexp);
+                buf = QString::asprintf("%s%ld/%ld", lvllbl[i],
+                                        (long) u.ulevel, u.uexp);
             } else {
-                buf = QString::asprintf("%s%ld", lvllbl[i - 3], (long) u.ulevel);
+                buf = QString::asprintf("%s%ld", lvllbl[i - 3],
+                                        (long) u.ulevel);
             }
             // +2: allow a couple of pixels at either end to be clipped off
             if (fm.size(0, buf).width() <= (2 + level.label->width() + 2))
@@ -870,20 +878,24 @@ void NetHackQtStatusWindow::updateStats()
     goldamt = std::min(goldamt, 99999999L); // ditto
     gold.setLabel("Gold:", goldamt);
 
-    const char *text = NULL;
+    const char *text;
+    QString qtext;
+    QPixmap *pxmp;
     if (u.ualign.type == A_LAWFUL) {
-        align.setIcon(p_lawful);
+        pxmp = &p_lawful;
         text = "Lawful";
     } else if (u.ualign.type == A_NEUTRAL) {
-        align.setIcon(p_neutral);
+        pxmp = &p_neutral;
         text = "Neutral";
     } else {
-        // Unaligned should never happen but handle it sanely if it does
-        align.setIcon(p_chaotic);
+        pxmp = &p_chaotic;
+        // Unaligned should never happen
         text = (u.ualign.type == A_CHAOTIC) ? "Chaotic"
                : (u.ualign.type == A_NONE) ? "unaligned"
                  : "other?";
     }
+    qtext = QString::asprintf("%sly aligned", text);
+    align.setIcon(*pxmp, qtext.toLower());
     align.setLabel(QString(text));
     // without this, the ankh pixmap shifts from centered to left
     // justified relative to the label text for some unknown reason...