]> granicus.if.org Git - nethack/commitdiff
Qt status window icon alignment
authorPatR <rankin@nethack.org>
Sat, 17 Oct 2020 18:10:00 +0000 (11:10 -0700)
committerPatR <rankin@nethack.org>
Sat, 17 Oct 2020 18:10:00 +0000 (11:10 -0700)
When the game windows were initialized, the anhk icon for alignment
was centered relative to Lawful/Neutral/Chaotic label but during
the first status update it noticeably shifted left.  Non-blank
hunger or encumbrance states could change from centered to left
justified when they were present and the icon was replaced.  Oddly,
resetting the 'centered' attribute for the widget wasn't sufficient
to fix this.  Running the resize code for that widget did.  Another
case of trial and error to make things work the way they ought.

Also, don't highlight a change in alignment or dungeon location as
"got worse" if the internal numeric value went down instead of up;
always highlight as "got better" for those two fields.  There ought
to be a third choice for just "changed" but that would have been
more complicated.

doc/fixes37.0
win/Qt/qt_icon.cpp
win/Qt/qt_icon.h
win/Qt/qt_stat.cpp

index f9c67c9461c50262e36c6333fc283fa6ebb40693..a9655feb1d31f193c0ba49ed0ce22d714e9ec221 100644 (file)
@@ -1,4 +1,4 @@
-NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.330 $ $NHDT-Date: 1602716771 2020/10/14 23:06:11 $
+NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.332 $ $NHDT-Date: 1602958104 2020/10/17 18:08:24 $
 
 General Fixes and Modified Features
 -----------------------------------
@@ -443,6 +443,9 @@ Qt: for menu search, don't require clicking on the search target popup before
 Qt: rest ("Zz") button on the toolbar only worked when 'rest_on_space' was On
        (core issue, not Qt's fault)
 Qt: rename toolbar button "Get" and action menu choice "Get" to "Pick up"
+Qt: status icons for alignment|hunger|encumbrance which started out centered
+       relative to the label text below them would shift to being left
+       justified when status got updated
 Qt+OSX: 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 27b578420754b6d2cb0d24eba8e252f7305fb9e9..2e027b3f558450a85e31f18d31ccf6af54249627 100644 (file)
@@ -52,15 +52,16 @@ void NetHackQtLabelledIcon::setLabel(const QString& t, bool lower)
     if (!label) {
        label=new QLabel(this);
        label->setFont(font());
-       resizeEvent(0);
     }
     if (label->text() != t) {
        label->setText(t);
-       highlight(lower==low_is_good ? hl_good : hl_bad);
+        ForceResize();
+       highlight((lower == low_is_good) ? hl_good : hl_bad);
     }
 }
 
-void NetHackQtLabelledIcon::setLabel(const QString& t, long v, long cv, const QString& tail)
+void NetHackQtLabelledIcon::setLabel(const QString& t, long v, long cv,
+                                     const QString& tail)
 {
     QString buf;
     if (v==NoNum) {
@@ -72,16 +73,19 @@ void NetHackQtLabelledIcon::setLabel(const QString& t, long v, long cv, const QS
     prev_value=cv;
 }
 
-void NetHackQtLabelledIcon::setLabel(const QString& t, long v, const QString& tail)
+void NetHackQtLabelledIcon::setLabel(const QString& t, long v,
+                                     const QString& tail)
 {
     setLabel(t,v,v,tail);
 }
 
 void NetHackQtLabelledIcon::setIcon(const QPixmap& i)
 {
-    if (icon) icon->setPixmap(i);
-    else { icon=new QLabel(this); icon->setPixmap(i); resizeEvent(0); }
-    icon->resize(i.width(),i.height());
+    if (!icon)
+        icon = new QLabel(this);
+    icon->setPixmap(i);
+    ForceResize();
+    icon->resize(i.width(), i.height());
 }
 
 void NetHackQtLabelledIcon::setFont(const QFont& f)
@@ -171,6 +175,13 @@ void NetHackQtLabelledIcon::unhighlight()
     }
 }
 
+// used when label (most status fields) or pixmap (alignment, hunger,
+// encumbrance) changes value
+void NetHackQtLabelledIcon::ForceResize()
+{
+    this->resizeEvent((QResizeEvent *) NULL);
+}
+
 void NetHackQtLabelledIcon::resizeEvent(QResizeEvent*)
 {
     setAlignments();
index f1974ba4440707350bdc54f20f85431f9e2c14de..eda5c56892aaf6a504c0ccc1a344c71636d25d9d 100644 (file)
@@ -24,6 +24,7 @@ public:
        void highlightWhenChanging();
        void lowIsGood();
        void dissipateHighlight();
+        void ForceResize();
 
        virtual void show();
        virtual QSize sizeHint() const;
index 6d200fe10097971a40f140638c81709e63b63cdd..02fb15772e6e42996eb92856225a65f6a87f7cbd 100644 (file)
@@ -344,7 +344,7 @@ void NetHackQtStatusWindow::resizeEvent(QResizeEvent*)
 /*
  * Set all widget values to a null string.  This is used after all spacings
  * have been calculated so that when the window is popped up we don't get all
- * kinds of funny values being displayed.
+ * kinds of funny values being displayed.  [Actually it isn't used at all.]
  */
 void NetHackQtStatusWindow::nullOut()
 {
@@ -436,6 +436,7 @@ void NetHackQtStatusWindow::updateStats()
     } else {
        hunger.setIcon(u.uhs ? p_hungry : p_satiated);
        hunger.setLabel(hung);
+        hunger.ForceResize();
        hunger.show();
     }
     const char *enc = enc_stat[near_capacity()];
@@ -444,6 +445,7 @@ void NetHackQtStatusWindow::updateStats()
     } else {
        encumber.setIcon(p_encumber[near_capacity() - 1]);
        encumber.setLabel(enc);
+        encumber.ForceResize();
        encumber.show();
     }
     if (Stoned) stoned.show(); else stoned.hide();
@@ -468,6 +470,7 @@ void NetHackQtStatusWindow::updateStats()
     if (Stunned) stunned.show(); else stunned.hide();
     if (Confusion) confused.show(); else confused.hide();
     if (Hallucination) hallu.show(); else hallu.hide();
+    // [pr - Why is blind handled differently from other on/off conditions?]
     if (Blind) {
        blind.setLabel("Blind");
        blind.show();
@@ -490,12 +493,13 @@ void NetHackQtStatusWindow::updateStats()
     name.setLabel(buf2, NetHackQtLabelledIcon::NoNum, u.ulevel);
 
     char buf3[BUFSZ];
-    if (describe_level(buf3)) {
-       dlevel.setLabel(buf3,true);
-    } else {
-       buf.sprintf("%s, level ", g.dungeons[u.uz.dnum].dname);
-       dlevel.setLabel(buf,(long)::depth(&u.uz));
+    if (!describe_level(buf3)) {
+       Sprintf(buf3, "%s, level %d",
+                g.dungeons[u.uz.dnum].dname, ::depth(&u.uz));
     }
+    // false: always highlight as 'change for the better' regardless of
+    // new depth compared to old
+    dlevel.setLabel(buf3, false);
 
     gold.setLabel("Au:", money_cnt(g.invent));
 
@@ -521,13 +525,14 @@ void NetHackQtStatusWindow::updateStats()
     }
     buf.sprintf("/%d", u.uenmax);
     power.setLabel("Pow:", u.uen, buf);
-    ac.setLabel("AC:",(long)u.uac);
+    ac.setLabel("AC:", (long) u.uac);
     //if (::flags.showexp) {
     //    exp.setLabel("Exp:", (long) u.uexp);
     //} else {
-        // 'exp' now only used to pad the line that Xp/Exp is displayed on
+        // 'exp' is now only used to pad the line that Xp/Exp is displayed on
         exp.setLabel("");
     //}
+    text = NULL;
     if (u.ualign.type==A_CHAOTIC) {
        align.setIcon(p_chaotic);
        text = "Chaotic";
@@ -538,7 +543,14 @@ void NetHackQtStatusWindow::updateStats()
        align.setIcon(p_lawful);
        text = "Lawful";
     }
-    align.setLabel(text);
+    if (text) {
+        // false: don't highlight as 'became lower' even if the internal
+        // numeric value is becoming lower (N -> C, L -> N || C)
+        align.setLabel(text, false);
+        // without this, the ankh pixmap shifts from centered to left
+        // justified relative to the label text for some unknown reason...
+        align.ForceResize();
+    }
 
     if (::flags.time)
         time.setLabel("Time:", (long) g.moves);