mirror of
https://github.com/Palakis/obs-websocket.git
synced 2024-08-30 18:12:16 +00:00
Preliminary work on the Preview request types
This commit is contained in:
parent
69061869a7
commit
07c868edcd
80
Utils.cpp
80
Utils.cpp
@ -20,6 +20,9 @@ with this program. If not, see <https://www.gnu.org/licenses/>
|
|||||||
#include <obs-frontend-api.h>
|
#include <obs-frontend-api.h>
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <QSpinBox>
|
#include <QSpinBox>
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QListWidget>
|
||||||
|
#include <QLayout>
|
||||||
#include "obs-websocket.h"
|
#include "obs-websocket.h"
|
||||||
|
|
||||||
obs_data_array_t* string_list_to_array(char** strings, char* key)
|
obs_data_array_t* string_list_to_array(char** strings, char* key)
|
||||||
@ -238,6 +241,83 @@ void Utils::SetTransitionDuration(int ms)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QPushButton* Utils::GetPreviewModeButtonControl()
|
||||||
|
{
|
||||||
|
QMainWindow* main = (QMainWindow*)obs_frontend_get_main_window();
|
||||||
|
return main->findChild<QPushButton*>("modeSwitch");
|
||||||
|
}
|
||||||
|
|
||||||
|
QLayout* Utils::GetPreviewLayout()
|
||||||
|
{
|
||||||
|
QMainWindow* main = (QMainWindow*)obs_frontend_get_main_window();
|
||||||
|
return main->findChild<QLayout*>("previewLayout");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Utils::IsPreviewModeActive()
|
||||||
|
{
|
||||||
|
QMainWindow* main = (QMainWindow*)obs_frontend_get_main_window();
|
||||||
|
|
||||||
|
// Clue 1 : "Studio Mode" button is toggled on
|
||||||
|
bool buttonToggledOn = GetPreviewModeButtonControl()->isChecked();
|
||||||
|
|
||||||
|
// Clue 2 : Preview layout has more than one item
|
||||||
|
int previewChildCount = GetPreviewLayout()->children().count();
|
||||||
|
|
||||||
|
return buttonToggledOn || (previewChildCount >= 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Utils::EnablePreviewMode()
|
||||||
|
{
|
||||||
|
GetPreviewModeButtonControl()->setChecked(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Utils::DisablePreviewMode()
|
||||||
|
{
|
||||||
|
GetPreviewModeButtonControl()->setChecked(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Utils::TogglePreviewMode()
|
||||||
|
{
|
||||||
|
GetPreviewModeButtonControl()->toggle();
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* Utils::GetPreviewSceneName()
|
||||||
|
{
|
||||||
|
if (IsPreviewModeActive())
|
||||||
|
{
|
||||||
|
QMainWindow* main = (QMainWindow*)obs_frontend_get_main_window();
|
||||||
|
QListWidget* sceneList = main->findChild<QListWidget*>("scenes");
|
||||||
|
|
||||||
|
QString name = sceneList->selectedItems().first()->text();
|
||||||
|
return name.toUtf8().constData();
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Utils::TransitionToProgram()
|
||||||
|
{
|
||||||
|
if (!IsPreviewModeActive())
|
||||||
|
return;
|
||||||
|
|
||||||
|
// WARNING : if the layout created in OBS' CreateProgramOptions() changes
|
||||||
|
// then this won't work as expected
|
||||||
|
|
||||||
|
// The program options widget is the second item in the left-to-right layout
|
||||||
|
QWidget* programOptions = GetPreviewLayout()->itemAt(1)->widget();
|
||||||
|
|
||||||
|
// The "Transition" button lies in the mainButtonLayout
|
||||||
|
// which is the first itemin the program options' layout
|
||||||
|
QLayout* mainButtonLayout = programOptions->layout()->itemAt(0)->layout();
|
||||||
|
QWidget* transitionBtnWidget = mainButtonLayout->itemAt(0)->widget();
|
||||||
|
|
||||||
|
// Try to cast that widget into a button
|
||||||
|
QPushButton* transitionBtn = qobject_cast<QPushButton*>(transitionBtnWidget);
|
||||||
|
|
||||||
|
// Perform a click on that button
|
||||||
|
transitionBtn->click();
|
||||||
|
}
|
||||||
|
|
||||||
const char* Utils::OBSVersionString() {
|
const char* Utils::OBSVersionString() {
|
||||||
uint32_t version = obs_get_version();
|
uint32_t version = obs_get_version();
|
||||||
|
|
||||||
|
13
Utils.h
13
Utils.h
@ -20,6 +20,8 @@ with this program. If not, see <https://www.gnu.org/licenses/>
|
|||||||
#define UTILS_H
|
#define UTILS_H
|
||||||
|
|
||||||
#include <QSpinBox>
|
#include <QSpinBox>
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QLayout>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <obs-module.h>
|
#include <obs-module.h>
|
||||||
|
|
||||||
@ -42,6 +44,17 @@ class Utils
|
|||||||
static int GetTransitionDuration();
|
static int GetTransitionDuration();
|
||||||
static void SetTransitionDuration(int ms);
|
static void SetTransitionDuration(int ms);
|
||||||
|
|
||||||
|
static QPushButton* GetPreviewModeButtonControl();
|
||||||
|
static QLayout* GetPreviewLayout();
|
||||||
|
|
||||||
|
static bool IsPreviewModeActive();
|
||||||
|
static void EnablePreviewMode();
|
||||||
|
static void DisablePreviewMode();
|
||||||
|
static void TogglePreviewMode();
|
||||||
|
|
||||||
|
static const char* GetPreviewSceneName();
|
||||||
|
static void TransitionToProgram();
|
||||||
|
|
||||||
static const char* OBSVersionString();
|
static const char* OBSVersionString();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user