Qt status window icon alignment

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.
This commit is contained in:
PatR
2020-10-17 11:10:00 -07:00
parent fc6b491303
commit 9a6bc0fd8f
4 changed files with 44 additions and 17 deletions

View 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();