diff --git a/.gitignore b/.gitignore index c938048..eee2496 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,6 @@ /CMakeLists.txt.user* # Clangd -/compile_commands.json /.cache # Gdb diff --git a/compile_commands.json b/compile_commands.json new file mode 120000 index 0000000..affbd32 --- /dev/null +++ b/compile_commands.json @@ -0,0 +1 @@ +./build/compile_commands.json \ No newline at end of file diff --git a/core/src/logger.cpp b/core/src/logger.cpp index be4fa30..8af1379 100644 --- a/core/src/logger.cpp +++ b/core/src/logger.cpp @@ -4,8 +4,10 @@ #include #include #include +#include static std::ofstream logStream; +static std::vector logListeners; std::string Logger::currentLogDir = "NULL"; void Logger::init() { @@ -38,7 +40,15 @@ void Logger::log(std::string message, Logger::LogLevel logLevel) { logStream << formattedLogLine << std::endl; printf("%s\n", formattedLogLine.c_str()); + for (Logger::LogListener listener : logListeners) { + listener(logLevel, message); + } + if (logLevel == Logger::LogLevel::FATAL_ERROR) { displayErrorMessage(message); } } + +void Logger::addLogListener(Logger::LogListener listener) { + logListeners.push_back(listener); +} \ No newline at end of file diff --git a/core/src/logger.h b/core/src/logger.h index 4638971..8f9792b 100644 --- a/core/src/logger.h +++ b/core/src/logger.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include namespace Logger { @@ -12,10 +13,13 @@ namespace Logger { FATAL_ERROR, }; + typedef std::function LogListener; + extern std::string currentLogDir; void init(); void finish(); + void addLogListener(LogListener); void log(std::string message, LogLevel logLevel); inline void info(std::string message) { log(message, LogLevel::INFO); } diff --git a/editor/mainglwidget.cpp b/editor/mainglwidget.cpp index 546690c..c605d3f 100644 --- a/editor/mainglwidget.cpp +++ b/editor/mainglwidget.cpp @@ -16,6 +16,7 @@ #include "datatypes/cframe.h" #include "editorcommon.h" +#include "logger.h" #include "mainwindow.h" #include "objects/handles.h" #include "physics/util.h" @@ -280,6 +281,13 @@ void MainGLWidget::keyPressEvent(QKeyEvent* evt) { })); syncPartPhysics(lastPart); } + + if (evt->key() == Qt::Key_U) + Logger::info("info message"); + if (evt->key() == Qt::Key_I) + Logger::warning("warning message"); + if (evt->key() == Qt::Key_O) + Logger::error("error message"); } void MainGLWidget::keyReleaseEvent(QKeyEvent* evt) { diff --git a/editor/mainwindow.cpp b/editor/mainwindow.cpp index 06a6774..a930574 100644 --- a/editor/mainwindow.cpp +++ b/editor/mainwindow.cpp @@ -10,14 +10,17 @@ #include #include #include +#include #include #include #include +#include #include #include #include "common.h" #include "editorcommon.h" +#include "logger.h" #include "objects/base/instance.h" #include "objects/datamodel.h" #include "objects/handles.h" @@ -41,6 +44,19 @@ MainWindow::MainWindow(QWidget *parent) timer.start(33, this); setMouseTracking(true); + setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea); + setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea); + + // Logger + + Logger::addLogListener(std::bind(&MainWindow::handleLog, this, std::placeholders::_1, std::placeholders::_2)); + + QFont font(""); + font.setStyleHint(QFont::Monospace); + ui->outputTextView->setFont(font); + + // Explorer View + ui->explorerView->buildContextMenu(); connect(ui->actionToolSelect, &QAction::triggered, this, [&]() { selectedTool = SelectedTool::SELECT; updateToolbars(); }); @@ -234,6 +250,17 @@ MainWindow::MainWindow(QWidget *parent) syncPartPhysics(ui->mainWidget->lastPart); } +void MainWindow::handleLog(Logger::LogLevel logLevel, std::string message) { + if (logLevel == Logger::LogLevel::DEBUG) return; + + if (logLevel == Logger::LogLevel::INFO) + ui->outputTextView->appendHtml(QString("

%1

").arg(QString::fromStdString(message))); + if (logLevel == Logger::LogLevel::WARNING) + ui->outputTextView->appendHtml(QString("

%1

").arg(QString::fromStdString(message))); + if (logLevel == Logger::LogLevel::ERROR || logLevel == Logger::LogLevel::FATAL_ERROR) + ui->outputTextView->appendHtml(QString("

%1

").arg(QString::fromStdString(message))); +} + static std::chrono::time_point lastTime = std::chrono::steady_clock::now(); void MainWindow::timerEvent(QTimerEvent* evt) { if (evt->timerId() != timer.timerId()) { diff --git a/editor/mainwindow.h b/editor/mainwindow.h index 7117432..03bc13d 100644 --- a/editor/mainwindow.h +++ b/editor/mainwindow.h @@ -1,6 +1,7 @@ #ifndef MAINWINDOW_H #define MAINWINDOW_H +#include "logger.h" #include "panes/explorerview.h" #include "qbasictimer.h" #include "qcoreevent.h" @@ -45,6 +46,7 @@ private: void updateToolbars(); void timerEvent(QTimerEvent*) override; + void handleLog(Logger::LogLevel, std::string); std::optional openFileDialog(QString filter, QString defaultExtension, QFileDialog::AcceptMode acceptMode, QString title = ""); }; diff --git a/editor/mainwindow.ui b/editor/mainwindow.ui index f333260..7e8240d 100644 --- a/editor/mainwindow.ui +++ b/editor/mainwindow.ui @@ -7,7 +7,7 @@ 0 0 1027 - 600 + 750 @@ -48,11 +48,19 @@ File + + + Edit + + + + + @@ -127,6 +135,21 @@ + + + Output + + + 8 + + + + + + + + +