Qt message window: horizontal scrolling

Multiple stints of flailing about without a clue finally led to
a breakthrough.  When writing a new message to the multi-line
message window, force the view back to showing the starts of
lines if player has scrolled it to the side and left it that way.
Put another way, if it has been scrolled to the right, scroll it
as far as possible back to the left.
This commit is contained in:
PatR
2020-11-29 16:58:56 -08:00
parent 74565c890d
commit 69dd0485fb
3 changed files with 23 additions and 6 deletions

View File

@@ -23,9 +23,12 @@ extern "C" {
namespace nethack_qt_ {
NetHackQtMessageWindow::NetHackQtMessageWindow() :
list(new QListWidget())
list(new QListWidget()),
scrollarea(new QScrollArea())
{
list->setFocusPolicy(Qt::NoFocus);
scrollarea->setFocusPolicy(Qt::NoFocus);
scrollarea->takeWidget();
::iflags.window_inited = 1;
map = 0;
currgetmsg = 0;
@@ -39,7 +42,9 @@ NetHackQtMessageWindow::~NetHackQtMessageWindow()
delete list;
}
QWidget* NetHackQtMessageWindow::Widget() { return list; }
QWidget* NetHackQtMessageWindow::Widget() {
return list;
}
void NetHackQtMessageWindow::setMap(NetHackQtMapWindow2* m)
{
@@ -152,6 +157,8 @@ void NetHackQtMessageWindow::PutStr(int attr, const QString& text)
item->setBackground(bg);
}
}
#else
nhUse(attr);
#endif
if (list->count() >= (int) ::iflags.msg_history)
@@ -163,6 +170,13 @@ void NetHackQtMessageWindow::PutStr(int attr, const QString& text)
// selects most recent message, which causes it to be highlighted
list->setCurrentRow(list->count() - 1);
// if message window has been scrolled right, force back to left edge
QScrollBar *sb = list->horizontalScrollBar();
if (sb && sb->value() > 0) {
sb->setValue(0);
this->viewport()->update();
}
if (map)
map->putMessage(attr, text2);
}