Add button to open settings window to dock

Also apply current OBS theme to status dock by using "OBSDock" wrapper
class
This commit is contained in:
WarmUpTill 2022-12-28 22:11:34 +01:00 committed by WarmUpTill
parent 5444d6fd9e
commit 378bf4dfd6
4 changed files with 61 additions and 27 deletions

View File

@ -699,6 +699,21 @@ void LoadPlugins()
}
}
void OpenSettingsWindow()
{
if (switcher->settingsWindowOpened) {
AdvSceneSwitcher::window->show();
AdvSceneSwitcher::window->raise();
AdvSceneSwitcher::window->activateWindow();
} else {
AdvSceneSwitcher::window =
new AdvSceneSwitcher(static_cast<QMainWindow *>(
obs_frontend_get_main_window()));
AdvSceneSwitcher::window->setAttribute(Qt::WA_DeleteOnClose);
AdvSceneSwitcher::window->show();
}
}
extern "C" void InitSceneSwitcher(obs_module_t *m, translateFunc t)
{
blog(LOG_INFO, "version: %s", g_GIT_TAG);
@ -712,25 +727,10 @@ extern "C" void InitSceneSwitcher(obs_module_t *m, translateFunc t)
LoadPlugins();
SetupDock();
auto cb = []() {
if (switcher->settingsWindowOpened) {
AdvSceneSwitcher::window->show();
AdvSceneSwitcher::window->raise();
AdvSceneSwitcher::window->activateWindow();
} else {
AdvSceneSwitcher::window =
new AdvSceneSwitcher(static_cast<QMainWindow *>(
obs_frontend_get_main_window()));
AdvSceneSwitcher::window->setAttribute(
Qt::WA_DeleteOnClose);
AdvSceneSwitcher::window->show();
}
};
obs_frontend_add_save_callback(SaveSceneSwitcher, nullptr);
obs_frontend_add_event_callback(OBSEvent, switcher);
QAction *action = (QAction *)obs_frontend_add_tools_menu_qaction(
obs_module_text("AdvSceneSwitcher.pluginName"));
action->connect(action, &QAction::triggered, cb);
action->connect(action, &QAction::triggered, OpenSettingsWindow);
}

View File

@ -314,10 +314,11 @@ private:
int currentActionIdx = -1;
};
void OpenSettingsWindow();
/******************************************************************************
* Sceneswitch helper
******************************************************************************/
void setNextTransition(const sceneSwitchInfo &ssi, obs_source_t *currentSource,
transitionData &td);
void overwriteTransitionOverride(const sceneSwitchInfo &ssi,

View File

@ -98,21 +98,46 @@ void StatusControl::SetStopped()
_setToStopped = true;
}
StatusDock::StatusDock(QWidget *parent)
: QDockWidget(obs_module_text("AdvSceneSwitcher.windowTitle"), parent)
#include <QToolBar>
StatusDock::StatusDock(QWidget *parent) : OBSDock(parent)
{
setFloating(true);
setWindowTitle(obs_module_text("AdvSceneSwitcher.windowTitle"));
setFeatures(DockWidgetClosable | DockWidgetMovable |
DockWidgetFloatable);
// Setting a fixed object name is crucial for OBS to be able to restore
// the docks position, if the dock is not floating
setObjectName("Adv-ss-dock");
// Not sure why an extra QWidget wrapper is necessary...
// without it the dock widget seems to be partially transparent.
QWidget *tmp = new QWidget;
QHBoxLayout *layout = new QHBoxLayout;
QAction *action = new QAction;
action->setProperty("themeID", QVariant(QString::fromUtf8("cogsIcon")));
action->connect(action, &QAction::triggered, OpenSettingsWindow);
QIcon icon;
icon.addFile(
QString::fromUtf8(":/settings/images/settings/advanced.svg"),
QSize(), QIcon::Normal, QIcon::Off);
action->setIcon(icon);
auto toolLayout = new QBoxLayout(QBoxLayout::TopToBottom, this);
toolLayout->setContentsMargins(0, 0, 0, 0);
auto toolbar = new QToolBar;
toolbar->setIconSize({16, 16});
toolbar->setFloatable(false);
toolbar->addAction(action);
toolLayout->addWidget(toolbar);
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(new StatusControl(this));
tmp->setLayout(layout);
setWidget(tmp);
layout->setContentsMargins(0, 0, 0, 0);
layout->addLayout(toolLayout);
// QFrame wrapper is necessary to avoid dock being partially
// transparent
QFrame *wrapper = new QFrame;
wrapper->setFrameShape(QFrame::StyledPanel);
wrapper->setFrameShadow(QFrame::Sunken);
wrapper->setLayout(layout);
setWidget(wrapper);
}
void SetupDock()

View File

@ -31,7 +31,15 @@ private:
bool _setToStopped = true;
};
class StatusDock : public QDockWidget {
// Only used to enable applying "OBSDock" stylesheet
class OBSDock : public QDockWidget {
Q_OBJECT
public:
inline OBSDock(QWidget *parent = nullptr) : QDockWidget(parent) {}
};
class StatusDock : public OBSDock {
Q_OBJECT
public: