Qt message [un]highlighting
The Qt interface highlights the last message issued (using a mechanism for selection, as if for copy+paste or similar operation) but it was staying highlighted until another message was eventually given. Having an old message seem to stick around is annoying and is particularly bad when the message is a prompt. If the player's answer doesn't cause a message to be shown then it seems as if the prompt is still pending. This removes the highlighting (by bulk unselecting) once the player gives another input keystroke or mouse click. It would be much better if the selecting/highlighting was for all messages issued since last time highlighting was cleared. Figuring out how to do that correctly is more effort than I want to expend.
This commit is contained in:
+11
-2
@@ -471,7 +471,7 @@ void NetHackQtBind::qt_raw_print_bold(const char *str)
|
||||
int NetHackQtBind::qt_nhgetch()
|
||||
{
|
||||
if (main)
|
||||
main->fadeHighlighting();
|
||||
main->fadeHighlighting(true);
|
||||
|
||||
// Process events until a key arrives.
|
||||
//
|
||||
@@ -479,19 +479,28 @@ int NetHackQtBind::qt_nhgetch()
|
||||
qApp->exec();
|
||||
}
|
||||
|
||||
// after getting a key rather than before
|
||||
if (main)
|
||||
main->fadeHighlighting(false);
|
||||
|
||||
return keybuffer.GetAscii();
|
||||
}
|
||||
|
||||
int NetHackQtBind::qt_nh_poskey(int *x, int *y, int *mod)
|
||||
{
|
||||
if (main)
|
||||
main->fadeHighlighting();
|
||||
main->fadeHighlighting(true);
|
||||
|
||||
// Process events until a key or map-click arrives.
|
||||
//
|
||||
while (keybuffer.Empty() && clickbuffer.Empty()) {
|
||||
qApp->exec();
|
||||
}
|
||||
|
||||
// after getting a key or click rather than before
|
||||
if (main)
|
||||
main->fadeHighlighting(false);
|
||||
|
||||
if (!keybuffer.Empty()) {
|
||||
return keybuffer.GetAscii();
|
||||
} else {
|
||||
|
||||
+10
-4
@@ -751,7 +751,7 @@ NetHackQtMainWindow::NetHackQtMainWindow(NetHackQtKeyBuffer& ks) :
|
||||
the application menu instead of the help menu; we'll add it to
|
||||
the latter now and have two ways to access it; without the
|
||||
leading underscore (or some other spelling variation such as
|
||||
"'bout"), this one would get interceptd too and then evidently
|
||||
"'bout"), this one would get intercepted too and then evidently
|
||||
be discarded as a duplicate */
|
||||
help->addSeparator();
|
||||
help->addAction("_About_Qt_NetHack_", this, SLOT(doAbout(bool)));
|
||||
@@ -1042,10 +1042,16 @@ void NetHackQtMainWindow::updateInventory()
|
||||
}
|
||||
}
|
||||
|
||||
void NetHackQtMainWindow::fadeHighlighting()
|
||||
void NetHackQtMainWindow::fadeHighlighting(bool before_key)
|
||||
{
|
||||
if (status) {
|
||||
status->fadeHighlighting();
|
||||
if (before_key) {
|
||||
// status highlighting fades at start of turn
|
||||
if (status)
|
||||
status->fadeHighlighting();
|
||||
} else {
|
||||
// message highlighting fades after user has given input
|
||||
if (message && message->hilit_mesgs())
|
||||
message->unhighlight_mesgs();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -47,7 +47,7 @@ public:
|
||||
void RemoveWindow(NetHackQtWindow* window);
|
||||
void updateInventory();
|
||||
|
||||
void fadeHighlighting();
|
||||
void fadeHighlighting(bool before_key);
|
||||
|
||||
// this is unconditional in case qt_main.h comes before qt_set.h
|
||||
void resizePaperDoll(bool); // ENHANCED_PAPERDOLL
|
||||
|
||||
+7
-3
@@ -582,12 +582,16 @@ void NetHackQtMapWindow2::clearMessages()
|
||||
|
||||
void NetHackQtMapWindow2::putMessage(int attr UNUSED, const QString& text)
|
||||
{
|
||||
if ( !messages.isEmpty() )
|
||||
if (!messages.isEmpty())
|
||||
messages += "\n";
|
||||
messages += QString(text).replace(QChar(0x200B), "");
|
||||
QFontMetrics fm = fontMetrics();
|
||||
#if 0
|
||||
messages_rect = fm.boundingRect(viewport.contentsX(),viewport.contentsY(),viewport.width(),0, Qt::TextWordWrap|Qt::AlignTop|Qt::AlignLeft|Qt::TextDontClip, messages);
|
||||
QFontMetrics fm = fontMetrics();
|
||||
messages_rect = fm.boundingRect(viewport.contentsX(), viewport.contentsY(),
|
||||
viewport.width(), 0,
|
||||
(Qt::TextWordWrap | Qt::AlignTop
|
||||
| Qt::AlignLeft | Qt::TextDontClip),
|
||||
messages);
|
||||
update(messages_rect);
|
||||
#endif
|
||||
}
|
||||
|
||||
+42
-17
@@ -74,6 +74,9 @@ void NetHackQtMessageWindow::ClearMessages()
|
||||
|
||||
void NetHackQtMessageWindow::Display(bool block UNUSED)
|
||||
{
|
||||
//
|
||||
// FIXME: support for 'block' is necessary for MSGTYPE=stop
|
||||
//
|
||||
if (changed) {
|
||||
list->repaint();
|
||||
changed=false;
|
||||
@@ -88,8 +91,9 @@ const char * NetHackQtMessageWindow::GetStr(bool init)
|
||||
QListWidgetItem *item = list->item(currgetmsg++);
|
||||
if (item) {
|
||||
QString str = item->text();
|
||||
//raw_printf("getstr[%i]='%s'", currgetmsg, str.toLatin1().constData());
|
||||
return str.toLatin1().constData();
|
||||
const char *result = str.toLatin1().constData();
|
||||
//raw_printf("getstr[%d]='%s'", currgetmsg, result);
|
||||
return result;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@@ -114,31 +118,52 @@ void NetHackQtMessageWindow::PutStr(int attr, const QString& text)
|
||||
font.setWeight((attr == ATR_BOLD) ? QFont::Bold : QFont::Normal);
|
||||
item->setFont(font);
|
||||
|
||||
QColor fg = item->foreground().color();
|
||||
QColor bg = item->background().color();
|
||||
if (attr == ATR_DIM)
|
||||
{
|
||||
fg.setAlpha(fg.alpha() / 2);
|
||||
if (attr == ATR_DIM || attr == ATR_INVERSE) {
|
||||
QColor fg = item->foreground().color();
|
||||
QColor bg = item->background().color();
|
||||
if (attr == ATR_DIM) {
|
||||
fg.setAlpha(fg.alpha() / 2);
|
||||
new_fgbg = true;
|
||||
}
|
||||
if (attr == ATR_INVERSE) {
|
||||
QColor swap;
|
||||
swap = fg; fg = bg; bg = swap;
|
||||
}
|
||||
item->setForeground(fg);
|
||||
item->setBackground(bg);
|
||||
}
|
||||
if (attr == ATR_INVERSE)
|
||||
{
|
||||
QColor swap;
|
||||
swap = fg; fg = bg; bg = swap;
|
||||
}
|
||||
item->setForeground(fg);
|
||||
item->setBackground(bg);
|
||||
// ATR_BLINK not supported
|
||||
#endif
|
||||
|
||||
// ATR_BLINK not supported
|
||||
if (list->count() >= (int) ::iflags.msg_history)
|
||||
delete list->item(0);
|
||||
list->addItem(text2);
|
||||
|
||||
// Force scrollbar to bottom
|
||||
list->setCurrentRow(list->count()-1);
|
||||
list->setCurrentRow(list->count() - 1);
|
||||
|
||||
if ( map )
|
||||
if (map)
|
||||
map->putMessage(attr, text2);
|
||||
}
|
||||
|
||||
// are there any highlighted messages?
|
||||
bool NetHackQtMessageWindow::hilit_mesgs()
|
||||
{
|
||||
// PutStr() uses setCurrentRow() to select the last message line;
|
||||
// being selected causes that line to be highlighted.
|
||||
//
|
||||
// We could/should keep track of whether anything is currently
|
||||
// highlighted instead of just assuming that last message still is.
|
||||
if (list && list->count())
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
// unhighlight any highlighted messages
|
||||
void NetHackQtMessageWindow::unhighlight_mesgs()
|
||||
{
|
||||
if (list)
|
||||
list->clearSelection();
|
||||
}
|
||||
|
||||
} // namespace nethack_qt_
|
||||
|
||||
@@ -30,6 +30,9 @@ public:
|
||||
|
||||
void setMap(NetHackQtMapWindow2*);
|
||||
|
||||
bool hilit_mesgs();
|
||||
void unhighlight_mesgs();
|
||||
|
||||
private:
|
||||
QListWidget* list;
|
||||
bool changed;
|
||||
|
||||
Reference in New Issue
Block a user