1 // Copyright (c) Warwick Allison, 1999.
2 // Qt4 conversion copyright (c) Ray Chason, 2012-2014.
3 // NetHack may be freely redistributed. See license for details.
5 // qt4msg.cpp -- a message window
20 #include <QtGui/QtGui>
21 #if QT_VERSION >= 0x050000
22 #include <QtWidgets/QtWidgets>
30 namespace nethack_qt4 {
32 NetHackQtMessageWindow::NetHackQtMessageWindow() :
33 list(new QListWidget())
35 list->setFocusPolicy(Qt::NoFocus);
36 ::iflags.window_inited = 1;
39 connect(qt_settings,SIGNAL(fontChanged()),this,SLOT(updateFont()));
43 NetHackQtMessageWindow::~NetHackQtMessageWindow()
45 ::iflags.window_inited = 0;
49 QWidget* NetHackQtMessageWindow::Widget() { return list; }
51 void NetHackQtMessageWindow::setMap(NetHackQtMapWindow2* m)
57 void NetHackQtMessageWindow::updateFont()
59 list->setFont(qt_settings->normalFont());
61 map->setFont(qt_settings->normalFont());
64 void NetHackQtMessageWindow::Scroll(int dx, int dy)
66 //RLC Is this necessary?
67 //RLC list->Scroll(dx,dy);
70 void NetHackQtMessageWindow::Clear()
76 void NetHackQtMessageWindow::ClearMessages()
82 void NetHackQtMessageWindow::Display(bool block)
90 const char * NetHackQtMessageWindow::GetStr(bool init)
95 QListWidgetItem *item = list->item(currgetmsg++);
97 QString str = item->text();
98 //raw_printf("getstr[%i]='%s'", currgetmsg, str.toLatin1().constData());
99 return str.toLatin1().constData();
104 void NetHackQtMessageWindow::PutStr(int attr, const QString& text)
107 play_sound_for_message(text.toLatin1().constData());
112 // If the line is output from the "/" command, map the first character
115 if (text.mid(1, 3) == " ") {
116 text2 = QChar(cp437(text.at(0).unicode())) + text.mid(1);
121 QListWidgetItem *item = new QListWidgetItem(text2);
123 QFont font = item->font();
124 font.setUnderline(attr == ATR_ULINE);
125 font.setWeight((attr == ATR_BOLD) ? QFont::Bold : QFont::Normal);
128 QColor fg = item->foreground().color();
129 QColor bg = item->background().color();
132 fg.setAlpha(fg.alpha() / 2);
134 if (attr == ATR_INVERSE)
137 swap = fg; fg = bg; bg = swap;
139 item->setForeground(fg);
140 item->setBackground(bg);
143 // ATR_BLINK not supported
144 if (list->count() >= ::iflags.msg_history)
145 delete list->item(0);
146 list->addItem(text2);
148 // Force scrollbar to bottom
149 list->setCurrentRow(list->count()-1);
152 map->putMessage(attr, text2);
155 } // namespace nethack_qt4