Qt: split menu window color and attr setting

This commit is contained in:
Pasi Kallinen
2024-02-18 13:27:47 +02:00
parent 2952bdab63
commit a0c28e97da
2 changed files with 52 additions and 46 deletions

View File

@@ -541,6 +541,56 @@ static const char *color_name(const QColor q)
}
#endif
void NetHackQtMenuWindow::SetTwiAttr(QTableWidgetItem *twi, int color, int attr)
{
if (color != NO_COLOR) {
twi->setForeground(colors[color].q);
}
if (attr != ATR_NONE) {
QFont itemfont(table->font());
switch (attr) {
case ATR_BOLD:
itemfont.setWeight(QFont::Bold);
twi->setFont(itemfont);
break;
case ATR_ITALIC:
itemfont.setItalic(true);
twi->setFont(itemfont);
break;
case ATR_DIM:
twi->setFlags(Qt::NoItemFlags);
break;
case ATR_ULINE:
itemfont.setUnderline(true);
twi->setFont(itemfont);
break;
case ATR_INVERSE: {
QBrush fg = twi->foreground();
QBrush bg = twi->background();
if (fg.color() == bg.color()) {
// default foreground and background come up the same for
// some unknown reason
//[pr: both are set to 'Qt::color1' which has same RGB
// value as 'Qt::black'; X11 on OSX behaves similarly]
if (fg.color() == Qt::color1) {
fg = Qt::black;
bg = Qt::white;
} else {
fg = (bg.color() == Qt::white) ? Qt::black : Qt::white;
}
}
twi->setForeground(bg);
twi->setBackground(fg);
break;
}
case ATR_BLINK:
// not supported
break;
} /* switch */
} /* if attr != ATR_NONE */
}
void NetHackQtMenuWindow::AddRow(int row, const MenuItem& mi)
{
QFontMetrics fm(table->font());
@@ -612,52 +662,7 @@ void NetHackQtMenuWindow::AddRow(int row, const MenuItem& mi)
table->item(row, 4)->setFlags(Qt::ItemIsEnabled);
WidenColumn(4, fm.QFM_WIDTH(text));
if ((int) mi.color != NO_COLOR) {
twi->setForeground(colors[mi.color].q);
}
if (mi.attr != ATR_NONE) {
QFont itemfont(table->font());
switch (mi.attr) {
case ATR_BOLD:
itemfont.setWeight(QFont::Bold);
twi->setFont(itemfont);
break;
case ATR_ITALIC:
itemfont.setItalic(true);
twi->setFont(itemfont);
break;
case ATR_DIM:
twi->setFlags(Qt::NoItemFlags);
break;
case ATR_ULINE:
itemfont.setUnderline(true);
twi->setFont(itemfont);
break;
case ATR_INVERSE: {
QBrush fg = twi->foreground();
QBrush bg = twi->background();
if (fg.color() == bg.color()) {
// default foreground and background come up the same for
// some unknown reason
//[pr: both are set to 'Qt::color1' which has same RGB
// value as 'Qt::black'; X11 on OSX behaves similarly]
if (fg.color() == Qt::color1) {
fg = Qt::black;
bg = Qt::white;
} else {
fg = (bg.color() == Qt::white) ? Qt::black : Qt::white;
}
}
twi->setForeground(bg);
twi->setBackground(fg);
break;
}
case ATR_BLINK:
// not supported
break;
} /* switch */
} /* if mi.attr != ATR_NONE */
SetTwiAttr(twi, mi.color, mi.attr);
}
void NetHackQtMenuWindow::WidenColumn(int column, int width)

View File

@@ -128,6 +128,7 @@ private:
bool isSelected(int row);
long count(int row);
void SetTwiAttr(QTableWidgetItem *twi, int color, int attr);
void AddRow(int row, const MenuItem& mi);
void WidenColumn(int column, int width);
void PadMenuColumns(bool split_descr);