qt_map.cpp source formatting

Clean up the Qt code a bit.  The only intended change is to use
a different check for being polymorphed.
This commit is contained in:
PatR
2020-09-08 13:26:13 -07:00
parent 0b67fd60df
commit d3181e20ba
+63 -35
View File
@@ -153,11 +153,12 @@ void NetHackQtMapViewport::paintEvent(QPaintEvent* event)
); );
} }
#ifdef TEXTCOLOR #ifdef TEXTCOLOR
if (((special & MG_PET) != 0) && ::iflags.hilite_pet) { if ((special & MG_PET) != 0 && ::iflags.hilite_pet) {
painter.drawPixmap(QPoint(i*qt_settings->glyphs().width(), painter.drawPixmap(QPoint(i*qt_settings->glyphs().width(),
j*qt_settings->glyphs().height()), j*qt_settings->glyphs().height()),
pet_annotation); pet_annotation);
} else if (((special & MG_OBJPILE) != 0) && ::iflags.hilite_pile) { } else if ((special & MG_OBJPILE) != 0
&& ::iflags.hilite_pile) {
painter.drawPixmap(QPoint(i*qt_settings->glyphs().width(), painter.drawPixmap(QPoint(i*qt_settings->glyphs().width(),
j*qt_settings->glyphs().height()), j*qt_settings->glyphs().height()),
pile_annotation); pile_annotation);
@@ -177,11 +178,12 @@ void NetHackQtMapViewport::paintEvent(QPaintEvent* event)
mapglyph(g, &ch, &color, &special, i, j, 0); mapglyph(g, &ch, &color, &special, i, j, 0);
qt_settings->glyphs().drawCell(painter, g, i, j); qt_settings->glyphs().drawCell(painter, g, i, j);
#ifdef TEXTCOLOR #ifdef TEXTCOLOR
if (((special & MG_PET) != 0) && ::iflags.hilite_pet) { if ((special & MG_PET) != 0 && ::iflags.hilite_pet) {
painter.drawPixmap(QPoint(i*qt_settings->glyphs().width(), painter.drawPixmap(QPoint(i*qt_settings->glyphs().width(),
j*qt_settings->glyphs().height()), j*qt_settings->glyphs().height()),
pet_annotation); pet_annotation);
} else if (((special & MG_OBJPILE) != 0) && ::iflags.hilite_pile) { } else if ((special & MG_OBJPILE) != 0
&& ::iflags.hilite_pile) {
painter.drawPixmap(QPoint(i*qt_settings->glyphs().width(), painter.drawPixmap(QPoint(i*qt_settings->glyphs().width(),
j*qt_settings->glyphs().height()), j*qt_settings->glyphs().height()),
pile_annotation); pile_annotation);
@@ -201,32 +203,42 @@ void NetHackQtMapViewport::paintEvent(QPaintEvent* event)
} else } else
{ {
int hp100; int hp100;
if (u.mtimedone) { if (Upolyd) {
hp100=u.mhmax ? u.mh*100/u.mhmax : 100; hp100=u.mhmax ? u.mh*100/u.mhmax : 100;
} else { } else {
hp100=u.uhpmax ? u.uhp*100/u.uhpmax : 100; hp100=u.uhpmax ? u.uhp*100/u.uhpmax : 100;
} }
if (hp100 > 75) painter.setPen(Qt::white); if (hp100 > 75)
else if (hp100 > 50) painter.setPen(Qt::yellow); painter.setPen(Qt::white);
else if (hp100 > 25) painter.setPen(QColor(0xff,0xbf,0x00)); // orange else if (hp100 > 50)
else if (hp100 > 10) painter.setPen(Qt::red); painter.setPen(Qt::yellow);
else painter.setPen(Qt::magenta); else if (hp100 > 25)
painter.setPen(QColor(0xff, 0xbf, 0x00)); // orange
else if (hp100 > 10)
painter.setPen(Qt::red);
else
painter.setPen(Qt::magenta);
} }
painter.drawRect( painter.drawRect(cursor.x() * qt_settings->glyphs().width(),
cursor.x()*qt_settings->glyphs().width(),cursor.y()*qt_settings->glyphs().height(), cursor.y() * qt_settings->glyphs().height(),
qt_settings->glyphs().width()-1,qt_settings->glyphs().height()-1); qt_settings->glyphs().width() - 1,
qt_settings->glyphs().height() - 1);
} }
#if 0 #if 0
if (area.intersects(messages_rect)) { if (area.intersects(messages_rect)) {
painter.setPen(Qt::black); painter.setPen(Qt::black);
painter.drawText(viewport.contentsX()+1,viewport.contentsY()+1, painter.drawText(viewport.contentsX() + 1, viewport.contentsY() + 1,
viewport.width(),0, Qt::TextWordWrap|Qt::AlignTop|Qt::AlignLeft|Qt::TextDontClip, messages); viewport.width(), 0,
(Qt::TextWordWrap | Qt::AlignTop
| Qt::AlignLeft | Qt::TextDontClip), messages);
painter.setPen(Qt::white); painter.setPen(Qt::white);
painter.drawText(viewport.contentsX(),viewport.contentsY(), painter.drawText(viewport.contentsX(), viewport.contentsY(),
viewport.width(),0, Qt::TextWordWrap|Qt::AlignTop|Qt::AlignLeft|Qt::TextDontClip, messages); viewport.width(), 0,
(Qt::TextWordWrap | Qt::AlignTop
| Qt::AlignLeft | Qt::TextDontClip), messages);
} }
#endif #endif
@@ -696,7 +708,11 @@ void NetHackQtMapWindow::putMessage(int attr, const QString& text)
messages += "\n"; messages += "\n";
messages += QString(text).replace(QChar(0x200B), ""); messages += QString(text).replace(QChar(0x200B), "");
QFontMetrics fm = fontMetrics(); QFontMetrics fm = fontMetrics();
messages_rect = fm.boundingRect(viewport.contentsX(),viewport.contentsY(),viewport.width(),0, Qt::TextWordWrap|Qt::AlignTop|Qt::AlignLeft|Qt::TextDontClip, messages); messages_rect = fm.boundingRect(viewport.contentsX(), viewport.contentsY(),
viewport.width(), 0,
(Qt::TextWordWrap | Qt::AlignTop
| Qt::AlignLeft | Qt::TextDontClip),
messages);
update(messages_rect); update(messages_rect);
} }
@@ -849,11 +865,12 @@ void NetHackQtMapWindow::paintEvent(QPaintEvent* event)
QString(QChar(ch)).left(1) QString(QChar(ch)).left(1)
); );
#ifdef TEXTCOLOR #ifdef TEXTCOLOR
if (((special & MG_PET) != 0) && ::iflags.hilite_pet) { if ((special & MG_PET) != 0 && ::iflags.hilite_pet) {
painter.drawPixmap(QPoint(i*qt_settings->glyphs().width(), painter.drawPixmap(QPoint(i*qt_settings->glyphs().width(),
j*qt_settings->glyphs().height()), j*qt_settings->glyphs().height()),
pet_annotation); pet_annotation);
} else if (((special & MG_OBJPILE) != 0) && ::iflags.hilite_pile) { } else if ((special & MG_OBJPILE) != 0
&& ::iflags.hilite_pile) {
painter.drawPixmap(QPoint(i*qt_settings->glyphs().width(), painter.drawPixmap(QPoint(i*qt_settings->glyphs().width(),
j*qt_settings->glyphs().height()), j*qt_settings->glyphs().height()),
pile_annotation); pile_annotation);
@@ -873,11 +890,12 @@ void NetHackQtMapWindow::paintEvent(QPaintEvent* event)
mapglyph(g, &ch, &color, &special, i, j, 0); mapglyph(g, &ch, &color, &special, i, j, 0);
qt_settings->glyphs().drawCell(painter, g, i, j); qt_settings->glyphs().drawCell(painter, g, i, j);
#ifdef TEXTCOLOR #ifdef TEXTCOLOR
if (((special & MG_PET) != 0) && ::iflags.hilite_pet) { if ((special & MG_PET) != 0 && ::iflags.hilite_pet) {
painter.drawPixmap(QPoint(i*qt_settings->glyphs().width(), painter.drawPixmap(QPoint(i*qt_settings->glyphs().width(),
j*qt_settings->glyphs().height()), j*qt_settings->glyphs().height()),
pet_annotation); pet_annotation);
} else if (((special & MG_OBJPILE) != 0) && ::iflags.hilite_pile) { } else if ((special & MG_OBJPILE) != 0
&& ::iflags.hilite_pile) {
painter.drawPixmap(QPoint(i*qt_settings->glyphs().width(), painter.drawPixmap(QPoint(i*qt_settings->glyphs().width(),
j*qt_settings->glyphs().height()), j*qt_settings->glyphs().height()),
pile_annotation); pile_annotation);
@@ -897,31 +915,41 @@ void NetHackQtMapWindow::paintEvent(QPaintEvent* event)
} else } else
{ {
int hp100; int hp100;
if (u.mtimedone) { if (Upolyd) {
hp100=u.mhmax ? u.mh*100/u.mhmax : 100; hp100=u.mhmax ? u.mh*100/u.mhmax : 100;
} else { } else {
hp100=u.uhpmax ? u.uhp*100/u.uhpmax : 100; hp100=u.uhpmax ? u.uhp*100/u.uhpmax : 100;
} }
if (hp100 > 75) painter.setPen(Qt::white); if (hp100 > 75)
else if (hp100 > 50) painter.setPen(Qt::yellow); painter.setPen(Qt::white);
else if (hp100 > 25) painter.setPen(QColor(0xff,0xbf,0x00)); // orange else if (hp100 > 50)
else if (hp100 > 10) painter.setPen(Qt::red); painter.setPen(Qt::yellow);
else painter.setPen(Qt::magenta); else if (hp100 > 25)
painter.setPen(QColor(0xff, 0xbf, 0x00)); // orange
else if (hp100 > 10)
painter.setPen(Qt::red);
else
painter.setPen(Qt::magenta);
} }
painter.drawRect( painter.drawRect(cursor.x() * qt_settings->glyphs().width(),
cursor.x()*qt_settings->glyphs().width(),cursor.y()*qt_settings->glyphs().height(), cursor.y() * qt_settings->glyphs().height(),
qt_settings->glyphs().width()-1,qt_settings->glyphs().height()-1); qt_settings->glyphs().width() - 1,
qt_settings->glyphs().height() - 1);
} }
if (area.intersects(messages_rect)) { if (area.intersects(messages_rect)) {
painter.setPen(Qt::black); painter.setPen(Qt::black);
painter.drawText(viewport.contentsX()+1,viewport.contentsY()+1, painter.drawText(viewport.contentsX() + 1, viewport.contentsY() + 1,
viewport.width(),0, Qt::TextWordWrap|Qt::AlignTop|Qt::AlignLeft|Qt::TextDontClip, messages); viewport.width(), 0,
(Qt::TextWordWrap | Qt::AlignTop
| Qt::AlignLeft | Qt::TextDontClip), messages);
painter.setPen(Qt::white); painter.setPen(Qt::white);
painter.drawText(viewport.contentsX(),viewport.contentsY(), painter.drawText(viewport.contentsX(), viewport.contentsY(),
viewport.width(),0, Qt::TextWordWrap|Qt::AlignTop|Qt::AlignLeft|Qt::TextDontClip, messages); viewport.width(), 0,
(Qt::TextWordWrap | Qt::AlignTop
| Qt::AlignLeft | Qt::TextDontClip), messages);
} }
painter.end(); painter.end();