mirror of
https://github.com/obsproject/obs-studio.git
synced 2024-09-19 20:32:15 +02:00
UI: Create Log Viewer window XML file, migrate code
This commit is contained in:
parent
dbb063eae6
commit
c426622690
132
UI/forms/OBSLogViewer.ui
Normal file
132
UI/forms/OBSLogViewer.ui
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>OBSLogViewer</class>
|
||||||
|
<widget class="QDialog" name="OBSLogViewer">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>805</width>
|
||||||
|
<height>300</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>LogViewer</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>4</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<widget class="QPlainTextEdit" name="textArea">
|
||||||
|
<property name="readOnly">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="buttonLayout">
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>10</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>10</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="showStartup">
|
||||||
|
<property name="text">
|
||||||
|
<string>ShowOnStartup</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="openButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>OpenFile</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="clearButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Clear</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="closeButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Close</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources>
|
||||||
|
<include location="obs.qrc"/>
|
||||||
|
</resources>
|
||||||
|
<connections>
|
||||||
|
<connection>
|
||||||
|
<sender>closeButton</sender>
|
||||||
|
<signal>clicked()</signal>
|
||||||
|
<receiver>OBSLogViewer</receiver>
|
||||||
|
<slot>close()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>20</x>
|
||||||
|
<y>20</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>20</x>
|
||||||
|
<y>20</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>clearButton</sender>
|
||||||
|
<signal>clicked()</signal>
|
||||||
|
<receiver>textArea</receiver>
|
||||||
|
<slot>clear()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>20</x>
|
||||||
|
<y>20</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>20</x>
|
||||||
|
<y>20</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
</connections>
|
||||||
|
</ui>
|
@ -12,58 +12,27 @@
|
|||||||
#include "log-viewer.hpp"
|
#include "log-viewer.hpp"
|
||||||
#include "qt-wrappers.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 &
|
setWindowFlags(windowFlags() & Qt::WindowMaximizeButtonHint &
|
||||||
~Qt::WindowContextHelpButtonHint);
|
~Qt::WindowContextHelpButtonHint);
|
||||||
setAttribute(Qt::WA_DeleteOnClose);
|
setAttribute(Qt::WA_DeleteOnClose);
|
||||||
|
|
||||||
QVBoxLayout *layout = new QVBoxLayout();
|
ui->setupUi(this);
|
||||||
layout->setContentsMargins(0, 0, 0, 0);
|
|
||||||
|
|
||||||
const QFont fixedFont =
|
const QFont fixedFont =
|
||||||
QFontDatabase::systemFont(QFontDatabase::FixedFont);
|
QFontDatabase::systemFont(QFontDatabase::FixedFont);
|
||||||
|
|
||||||
textArea = new QPlainTextEdit();
|
ui->textArea->setFont(fixedFont);
|
||||||
textArea->setReadOnly(true);
|
|
||||||
textArea->setFont(fixedFont);
|
|
||||||
// Fix display of tabs & multiple spaces
|
// Fix display of tabs & multiple spaces
|
||||||
textArea->document()->setDefaultStyleSheet(
|
ui->textArea->document()->setDefaultStyleSheet(
|
||||||
"font { white-space: pre; }");
|
"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(
|
bool showLogViewerOnStartup = config_get_bool(
|
||||||
App()->GlobalConfig(), "LogViewer", "ShowLogStartup");
|
App()->GlobalConfig(), "LogViewer", "ShowLogStartup");
|
||||||
|
|
||||||
QCheckBox *showStartup = new QCheckBox(QTStr("ShowOnStartup"));
|
ui->showStartup->setChecked(showLogViewerOnStartup);
|
||||||
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);
|
|
||||||
|
|
||||||
const char *geom = config_get_string(App()->GlobalConfig(), "LogViewer",
|
const char *geom = config_get_string(App()->GlobalConfig(), "LogViewer",
|
||||||
"geometry");
|
"geometry");
|
||||||
@ -82,7 +51,7 @@ OBSLogViewer::~OBSLogViewer()
|
|||||||
saveGeometry().toBase64().constData());
|
saveGeometry().toBase64().constData());
|
||||||
}
|
}
|
||||||
|
|
||||||
void OBSLogViewer::ToggleShowStartup(bool checked)
|
void OBSLogViewer::on_showStartup_clicked(bool checked)
|
||||||
{
|
{
|
||||||
config_set_bool(App()->GlobalConfig(), "LogViewer", "ShowLogStartup",
|
config_set_bool(App()->GlobalConfig(), "LogViewer", "ShowLogStartup",
|
||||||
checked);
|
checked);
|
||||||
@ -109,7 +78,7 @@ void OBSLogViewer::InitLog()
|
|||||||
in.setCodec("UTF-8");
|
in.setCodec("UTF-8");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
QTextDocument *doc = textArea->document();
|
QTextDocument *doc = ui->textArea->document();
|
||||||
QTextCursor cursor(doc);
|
QTextCursor cursor(doc);
|
||||||
cursor.movePosition(QTextCursor::End);
|
cursor.movePosition(QTextCursor::End);
|
||||||
cursor.beginEditBlock();
|
cursor.beginEditBlock();
|
||||||
@ -122,7 +91,7 @@ void OBSLogViewer::InitLog()
|
|||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
QScrollBar *scroll = textArea->verticalScrollBar();
|
QScrollBar *scroll = ui->textArea->verticalScrollBar();
|
||||||
scroll->setValue(scroll->maximum());
|
scroll->setValue(scroll->maximum());
|
||||||
|
|
||||||
obsLogViewer = this;
|
obsLogViewer = this;
|
||||||
@ -144,13 +113,13 @@ void OBSLogViewer::AddLine(int type, const QString &str)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
QScrollBar *scroll = textArea->verticalScrollBar();
|
QScrollBar *scroll = ui->textArea->verticalScrollBar();
|
||||||
bool bottomScrolled = scroll->value() >= scroll->maximum() - 10;
|
bool bottomScrolled = scroll->value() >= scroll->maximum() - 10;
|
||||||
|
|
||||||
if (bottomScrolled)
|
if (bottomScrolled)
|
||||||
scroll->setValue(scroll->maximum());
|
scroll->setValue(scroll->maximum());
|
||||||
|
|
||||||
QTextDocument *doc = textArea->document();
|
QTextDocument *doc = ui->textArea->document();
|
||||||
QTextCursor cursor(doc);
|
QTextCursor cursor(doc);
|
||||||
cursor.movePosition(QTextCursor::End);
|
cursor.movePosition(QTextCursor::End);
|
||||||
cursor.beginEditBlock();
|
cursor.beginEditBlock();
|
||||||
@ -162,12 +131,7 @@ void OBSLogViewer::AddLine(int type, const QString &str)
|
|||||||
scroll->setValue(scroll->maximum());
|
scroll->setValue(scroll->maximum());
|
||||||
}
|
}
|
||||||
|
|
||||||
void OBSLogViewer::ClearText()
|
void OBSLogViewer::on_openButton_clicked()
|
||||||
{
|
|
||||||
textArea->clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
void OBSLogViewer::OpenFile()
|
|
||||||
{
|
{
|
||||||
char logDir[512];
|
char logDir[512];
|
||||||
if (GetConfigPath(logDir, sizeof(logDir), "obs-studio/logs") <= 0)
|
if (GetConfigPath(logDir, sizeof(logDir), "obs-studio/logs") <= 0)
|
||||||
|
@ -4,18 +4,19 @@
|
|||||||
#include <QPlainTextEdit>
|
#include <QPlainTextEdit>
|
||||||
#include "obs-app.hpp"
|
#include "obs-app.hpp"
|
||||||
|
|
||||||
|
#include "ui_OBSLogViewer.h"
|
||||||
|
|
||||||
class OBSLogViewer : public QDialog {
|
class OBSLogViewer : public QDialog {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
QPointer<QPlainTextEdit> textArea;
|
std::unique_ptr<Ui::OBSLogViewer> ui;
|
||||||
|
|
||||||
void InitLog();
|
void InitLog();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void AddLine(int type, const QString &text);
|
void AddLine(int type, const QString &text);
|
||||||
void ClearText();
|
void on_openButton_clicked();
|
||||||
void ToggleShowStartup(bool checked);
|
void on_showStartup_clicked(bool checked);
|
||||||
void OpenFile();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
OBSLogViewer(QWidget *parent = 0);
|
OBSLogViewer(QWidget *parent = 0);
|
||||||
|
Loading…
Reference in New Issue
Block a user