File indexing completed on 2024-05-12 04:41:11
0001 /* AtCore KDE Libary for 3D Printers 0002 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0003 SPDX-FileCopyrightText: 2018, 2020 Chris Rizzitello <rizzitello@kde.org> 0004 */ 0005 0006 #pragma once 0007 0008 #include <QWidget> 0009 0010 #include "atcorewidgets_export.h" 0011 0012 class QPlainTextEdit; 0013 class QTemporaryFile; 0014 0015 /** 0016 * @brief The LogWidget will display the log for the connected atcore. Create with a pointer to a new QTemporaryFile. 0017 */ 0018 class ATCOREWIDGETS_EXPORT LogWidget : public QWidget 0019 { 0020 Q_OBJECT 0021 public: 0022 explicit LogWidget(QTemporaryFile *tempFile, QWidget *parent = nullptr); 0023 explicit LogWidget(QWidget *parent = nullptr); 0024 0025 /** 0026 * @brief Add a message to the log. Should always also be connected to AtCore::atcoreMessage; 0027 * @param msg: Message 0028 */ 0029 void appendLog(const QString &msg); 0030 0031 /** 0032 * @brief Connect to AtCore::receivedMessage 0033 * @param bmsg: Message 0034 */ 0035 void appendRLog(const QByteArray &bmsg); 0036 0037 /** 0038 * @brief Connect to AtCore::pushedCommand 0039 * @param bmsg: Message 0040 */ 0041 void appendSLog(const QByteArray &bmsg); 0042 0043 /** 0044 * @brief test if last line of log is string 0045 * @param string: line to test for 0046 * @return true if last line starts with 0047 */ 0048 bool endsWith(const QString &string); 0049 0050 private: 0051 void initialize(); 0052 0053 /** 0054 * @brief Return string with actual time 0055 * @return QString 0056 */ 0057 QString getTime(); 0058 0059 /** 0060 * @brief save Log pressed. 0061 */ 0062 void savePressed(); 0063 0064 /** 0065 * @brief Append text in temporary file 0066 * @param text 0067 */ 0068 void writeTempFile(const QString &text); 0069 0070 /** 0071 * @brief flush unwritten strings to temp file 0072 */ 0073 void flushTemp(); 0074 QStringList unsyncedStrings; 0075 QTemporaryFile *logFile = nullptr; 0076 QPlainTextEdit *textLog = nullptr; 0077 };