Qt: delay first log frame update

This fixes the log not scrolling automatically when we first open RPCS3 with a low log level.
This commit is contained in:
Megamouse 2022-10-10 22:52:28 +02:00
parent 021783dcc1
commit 0f626c8d30
2 changed files with 15 additions and 8 deletions

View File

@ -155,11 +155,10 @@ log_frame::log_frame(std::shared_ptr<gui_settings> _gui_settings, QWidget* paren
m_tty_file.open(fs::get_cache_dir() + "TTY.log", fs::read + fs::create);
CreateAndConnectActions();
LoadSettings();
// Check for updates every ~10 ms
QTimer *timer = new QTimer(this);
connect(timer, &QTimer::timeout, this, &log_frame::UpdateUI);
timer->start(10);
m_timer = new QTimer(this);
connect(m_timer, &QTimer::timeout, this, &log_frame::UpdateUI);
}
void log_frame::SetLogLevel(logs::level lev) const
@ -394,8 +393,6 @@ void log_frame::CreateAndConnectActions()
m_tty_input->clear();
});
LoadSettings();
}
void log_frame::LoadSettings()
@ -420,6 +417,14 @@ void log_frame::LoadSettings()
{
m_tty->document()->setMaximumBlockCount(m_gui_settings->GetValue(gui::l_limit_tty).toInt());
}
// Note: There's an issue where the scrollbar value won't be set to max if we start the log frame too early,
// so let's delay the timer until we load the settings from the main window for the first time.
if (m_timer && !m_timer->isActive())
{
// Check for updates every ~10 ms
m_timer->start(10);
}
}
void log_frame::RepaintTextColors()
@ -610,7 +615,7 @@ void log_frame::UpdateUI()
// save old log state
QScrollBar* sb = m_log->verticalScrollBar();
const bool isMax = sb->value() == sb->maximum();
const bool is_max = sb->value() == sb->maximum();
const int sb_pos = sb->value();
QTextCursor text_cursor = m_log->textCursor();
@ -668,7 +673,7 @@ void log_frame::UpdateUI()
m_log->setTextCursor(text_cursor);
// set scrollbar to max means auto-scroll
sb->setValue(isMax ? sb->maximum() : sb_pos);
sb->setValue(is_max ? sb->maximum() : sb_pos);
m_log_text.clear();
};

View File

@ -46,6 +46,8 @@ private:
std::unique_ptr<find_dialog> m_find_dialog;
QTimer* m_timer = nullptr;
QList<QColor> m_color;
QColor m_color_stack;
QPlainTextEdit* m_log = nullptr;