logwindow.h (1486B)
1 // SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin <stenzek@gmail.com> 2 // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) 3 4 #pragma once 5 6 #include "common/log.h" 7 8 #include <QtWidgets/QMainWindow> 9 #include <QtWidgets/QPlainTextEdit> 10 #include <span> 11 12 class LogWindow : public QMainWindow 13 { 14 Q_OBJECT 15 16 public: 17 LogWindow(bool attach_to_main); 18 ~LogWindow(); 19 20 static void updateSettings(); 21 static void destroy(); 22 23 ALWAYS_INLINE bool isAttachedToMainWindow() const { return m_attached_to_main_window; } 24 void reattachToMainWindow(); 25 26 void updateWindowTitle(); 27 28 private: 29 void createUi(); 30 void updateLogLevelUi(); 31 void setLogLevel(LOGLEVEL level); 32 void populateFilters(QMenu* filter_menu); 33 void setChannelFiltered(size_t index, bool state); 34 35 static void logCallback(void* pUserParam, const char* channelName, const char* functionName, LOGLEVEL level, 36 std::string_view message); 37 38 protected: 39 void closeEvent(QCloseEvent* event); 40 41 private Q_SLOTS: 42 void onClearTriggered(); 43 void onSaveTriggered(); 44 void appendMessage(const QLatin1StringView& channel, quint32 level, const QString& message); 45 46 private: 47 static constexpr int DEFAULT_WIDTH = 750; 48 static constexpr int DEFAULT_HEIGHT = 400; 49 50 void saveSize(); 51 void restoreSize(); 52 53 QPlainTextEdit* m_text; 54 QMenu* m_level_menu; 55 std::span<const char*> m_filter_names; 56 57 bool m_attached_to_main_window = true; 58 bool m_destroying = false; 59 }; 60 61 extern LogWindow* g_log_window;