diff --git a/UI/forms/OBSLogViewer.ui b/UI/forms/OBSLogViewer.ui new file mode 100644 index 000000000..67afb7138 --- /dev/null +++ b/UI/forms/OBSLogViewer.ui @@ -0,0 +1,132 @@ + + + OBSLogViewer + + + + 0 + 0 + 805 + 300 + + + + LogViewer + + + + 0 + + + 0 + + + 0 + + + 4 + + + + + true + + + + + + + 10 + + + 0 + + + 10 + + + 0 + + + + + ShowOnStartup + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + OpenFile + + + + + + + Clear + + + + + + + Close + + + + + + + + + + + + + closeButton + clicked() + OBSLogViewer + close() + + + 20 + 20 + + + 20 + 20 + + + + + clearButton + clicked() + textArea + clear() + + + 20 + 20 + + + 20 + 20 + + + + + diff --git a/UI/log-viewer.cpp b/UI/log-viewer.cpp index 18702e3f4..32b60e511 100644 --- a/UI/log-viewer.cpp +++ b/UI/log-viewer.cpp @@ -12,58 +12,27 @@ #include "log-viewer.hpp" #include "qt-wrappers.hpp" -OBSLogViewer::OBSLogViewer(QWidget *parent) : QDialog(parent) +OBSLogViewer::OBSLogViewer(QWidget *parent) + : QDialog(parent), ui(new Ui::OBSLogViewer) { setWindowFlags(windowFlags() & Qt::WindowMaximizeButtonHint & ~Qt::WindowContextHelpButtonHint); setAttribute(Qt::WA_DeleteOnClose); - QVBoxLayout *layout = new QVBoxLayout(); - layout->setContentsMargins(0, 0, 0, 0); + ui->setupUi(this); const QFont fixedFont = QFontDatabase::systemFont(QFontDatabase::FixedFont); - textArea = new QPlainTextEdit(); - textArea->setReadOnly(true); - textArea->setFont(fixedFont); + ui->textArea->setFont(fixedFont); // Fix display of tabs & multiple spaces - textArea->document()->setDefaultStyleSheet( + ui->textArea->document()->setDefaultStyleSheet( "font { white-space: pre; }"); - QHBoxLayout *buttonLayout = new QHBoxLayout(); - QPushButton *clearButton = new QPushButton(QTStr("Clear")); - connect(clearButton, &QPushButton::clicked, this, - &OBSLogViewer::ClearText); - QPushButton *openButton = new QPushButton(QTStr("OpenFile")); - connect(openButton, &QPushButton::clicked, this, - &OBSLogViewer::OpenFile); - QPushButton *closeButton = new QPushButton(QTStr("Close")); - connect(closeButton, &QPushButton::clicked, this, &QDialog::close); - bool showLogViewerOnStartup = config_get_bool( App()->GlobalConfig(), "LogViewer", "ShowLogStartup"); - QCheckBox *showStartup = new QCheckBox(QTStr("ShowOnStartup")); - showStartup->setChecked(showLogViewerOnStartup); - connect(showStartup, SIGNAL(toggled(bool)), this, - SLOT(ToggleShowStartup(bool))); - - buttonLayout->addSpacing(10); - buttonLayout->addWidget(showStartup); - buttonLayout->addStretch(); - buttonLayout->addWidget(openButton); - buttonLayout->addWidget(clearButton); - buttonLayout->addWidget(closeButton); - buttonLayout->addSpacing(10); - buttonLayout->setContentsMargins(0, 0, 0, 4); - - layout->addWidget(textArea); - layout->addLayout(buttonLayout); - setLayout(layout); - - setWindowTitle(QTStr("LogViewer")); - resize(800, 300); + ui->showStartup->setChecked(showLogViewerOnStartup); const char *geom = config_get_string(App()->GlobalConfig(), "LogViewer", "geometry"); @@ -82,7 +51,7 @@ OBSLogViewer::~OBSLogViewer() saveGeometry().toBase64().constData()); } -void OBSLogViewer::ToggleShowStartup(bool checked) +void OBSLogViewer::on_showStartup_clicked(bool checked) { config_set_bool(App()->GlobalConfig(), "LogViewer", "ShowLogStartup", checked); @@ -109,7 +78,7 @@ void OBSLogViewer::InitLog() in.setCodec("UTF-8"); #endif - QTextDocument *doc = textArea->document(); + QTextDocument *doc = ui->textArea->document(); QTextCursor cursor(doc); cursor.movePosition(QTextCursor::End); cursor.beginEditBlock(); @@ -122,7 +91,7 @@ void OBSLogViewer::InitLog() file.close(); } - QScrollBar *scroll = textArea->verticalScrollBar(); + QScrollBar *scroll = ui->textArea->verticalScrollBar(); scroll->setValue(scroll->maximum()); obsLogViewer = this; @@ -144,13 +113,13 @@ void OBSLogViewer::AddLine(int type, const QString &str) break; } - QScrollBar *scroll = textArea->verticalScrollBar(); + QScrollBar *scroll = ui->textArea->verticalScrollBar(); bool bottomScrolled = scroll->value() >= scroll->maximum() - 10; if (bottomScrolled) scroll->setValue(scroll->maximum()); - QTextDocument *doc = textArea->document(); + QTextDocument *doc = ui->textArea->document(); QTextCursor cursor(doc); cursor.movePosition(QTextCursor::End); cursor.beginEditBlock(); @@ -162,12 +131,7 @@ void OBSLogViewer::AddLine(int type, const QString &str) scroll->setValue(scroll->maximum()); } -void OBSLogViewer::ClearText() -{ - textArea->clear(); -} - -void OBSLogViewer::OpenFile() +void OBSLogViewer::on_openButton_clicked() { char logDir[512]; if (GetConfigPath(logDir, sizeof(logDir), "obs-studio/logs") <= 0) diff --git a/UI/log-viewer.hpp b/UI/log-viewer.hpp index e17a88457..d9e329bba 100644 --- a/UI/log-viewer.hpp +++ b/UI/log-viewer.hpp @@ -4,18 +4,19 @@ #include #include "obs-app.hpp" +#include "ui_OBSLogViewer.h" + class OBSLogViewer : public QDialog { Q_OBJECT - QPointer textArea; + std::unique_ptr ui; void InitLog(); private slots: void AddLine(int type, const QString &text); - void ClearText(); - void ToggleShowStartup(bool checked); - void OpenFile(); + void on_openButton_clicked(); + void on_showStartup_clicked(bool checked); public: OBSLogViewer(QWidget *parent = 0);