소스 검색

UI: Create Log Viewer window XML file, migrate code

Matt Gajownik 3 년 전
부모
커밋
c426622690
3개의 변경된 파일149개의 추가작업 그리고 52개의 파일을 삭제
  1. 132 0
      UI/forms/OBSLogViewer.ui
  2. 12 48
      UI/log-viewer.cpp
  3. 5 4
      UI/log-viewer.hpp

+ 132 - 0
UI/forms/OBSLogViewer.ui

@@ -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 - 48
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)

+ 5 - 4
UI/log-viewer.hpp

@@ -4,18 +4,19 @@
 #include <QPlainTextEdit>
 #include "obs-app.hpp"
 
+#include "ui_OBSLogViewer.h"
+
 class OBSLogViewer : public QDialog {
 	Q_OBJECT
 
-	QPointer<QPlainTextEdit> textArea;
+	std::unique_ptr<Ui::OBSLogViewer> 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);