diff -r 7ef03c2b46ab -r 1fa0e1de9f0a src/main.cpp --- a/src/main.cpp Mon Jun 20 17:27:30 2022 +0300 +++ b/src/main.cpp Mon Jun 20 18:40:22 2022 +0300 @@ -15,6 +15,7 @@ #include "widgets/colorselectdialog.h" #include "settings.h" #include "ui/circletooloptionswidget.h" +#include "messagelog.h" static const QDir LOCALE_DIR {":/locale"}; @@ -342,6 +343,7 @@ return result; } +#include int main(int argc, char *argv[]) { doQtRegistrations(); @@ -355,6 +357,7 @@ QStringList recentlyOpenedFiles; ColorTable colorTable; gl::RenderPreferences renderPreferences; + MessageLog messageLog; ui.setupUi(&mainWindow); const uiutilities::KeySequenceMap defaultKeyboardShortcuts = uiutilities::makeKeySequenceMap(uiutilities::collectActions(&mainWindow)); @@ -413,22 +416,6 @@ saveSettings(); updateRecentlyOpenedDocumentsMenu(); }; - const auto logMessage = [&ui](const Message& message){ - QString messagetext = message.time.toString(QObject::tr("[hh:mm:ss]")); - switch(message.type) { - case Message::Info: - messagetext += QObject::tr(" [INFO] "); - break; - case Message::Warning: - messagetext += QObject::tr(" [WARN] "); - break; - case Message::Error: - messagetext += QObject::tr(" [ERR!] "); - break; - } - messagetext += message.text; - ui.messageLog->append(messagetext); - }; const auto openModelForEditing = [&](const ModelId modelId){ Model* model = documents.getModelById(modelId); if (model != nullptr) { @@ -641,8 +628,18 @@ } } }); + ui.messageLog->setModel(&messageLog); QObject::connect(ui.actionAboutQt, &QAction::triggered, &app, &QApplication::aboutQt); - QObject::connect(&documents, &DocumentManager::message, logMessage); + QObject::connect(&documents, &DocumentManager::message, &messageLog, &MessageLog::addMessage); + QObject::connect(&messageLog, &MessageLog::rowsAboutToBeInserted, [&]{ + const auto bar = ui.messageLog->verticalScrollBar(); + ui.messageLog->setProperty("shouldAutoScroll", bar->value() == bar->maximum()); + }); + QObject::connect(&messageLog, &MessageLog::rowsInserted, [&]{ + if (ui.messageLog->property("shouldAutoScroll").toBool()) { + ui.messageLog->scrollToBottom(); + } + }); mainWindow.setWindowTitle(title()); mainWindow.restoreGeometry(setting()); restoreSettings();