log.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /* docks/log.h - global log
  2. * Copyright (C) 2018 caryoscelus
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #ifndef STUDIO_DOCKS_LOG_H_CFC4FC28_FAB2_56B1_86EA_B7766369B6DA
  18. #define STUDIO_DOCKS_LOG_H_CFC4FC28_FAB2_56B1_86EA_B7766369B6DA
  19. #include <fstream>
  20. #include <core/std/memory.h>
  21. #include <generic/dock_registry.h>
  22. #include "close_destroy_dock.h"
  23. namespace Ui {
  24. class LogDock;
  25. }
  26. namespace rainynite::studio {
  27. /**
  28. * Global log
  29. */
  30. class LogDock : public DockWidget {
  31. public:
  32. explicit LogDock(QWidget* parent = nullptr);
  33. ~LogDock();
  34. class RedirectStream;
  35. private:
  36. unique_ptr<Ui::LogDock> ui;
  37. unique_ptr<RedirectStream> buff;
  38. observer_ptr<std::streambuf> old_cout;
  39. observer_ptr<std::streambuf> old_cerr;
  40. unique_ptr<QTimer> timer;
  41. };
  42. REGISTER_DOCK("Log", LogDock, Qt::BottomDockWidgetArea);
  43. } // namespace rainynite::studio
  44. #endif