Add WindowSelectionWidget

Refreshes list of windows when widget becomes visible to support widget
caching
This commit is contained in:
WarmUpTill 2025-05-21 13:05:31 +02:00 committed by WarmUpTill
parent c43439ee64
commit c281c6db83
7 changed files with 50 additions and 15 deletions

View File

@ -181,7 +181,9 @@ target_sources(
utils/websocket-helpers.cpp
utils/websocket-helpers.hpp
utils/websocket-tab.cpp
utils/websocket-tab.hpp)
utils/websocket-tab.hpp
utils/window-selection.cpp
utils/window-selection.hpp)
if(OS_WINDOWS)
target_sources(${PROJECT_NAME} PRIVATE utils/windows/windows.cpp)

View File

@ -163,16 +163,12 @@ MacroActionWindowEdit::MacroActionWindowEdit(
QWidget *parent, std::shared_ptr<MacroActionWindow> entryData)
: QWidget(parent),
_actions(new QComboBox()),
_windows(new QComboBox()),
_windows(new WindowSelectionWidget(this)),
_regex(new RegexConfigWidget(this)),
_infoLayout(new QHBoxLayout())
{
populateActionSelection(_actions);
_windows->setEditable(true);
_windows->setMaxVisibleItems(20);
PopulateWindowSelection(_windows);
auto focusLimitation = new QLabel(obs_module_text(
"AdvSceneSwitcher.action.window.type.setFocusWindow.limitation"));
_infoLayout->addWidget(focusLimitation);

View File

@ -2,6 +2,7 @@
#include "macro-action-edit.hpp"
#include "regex-config.hpp"
#include "variable-string.hpp"
#include "window-selection.hpp"
namespace advss {
@ -62,7 +63,7 @@ private:
void SetWidgetVisibility();
QComboBox *_actions;
QComboBox *_windows;
WindowSelectionWidget *_windows;
RegexConfigWidget *_regex;
QHBoxLayout *_infoLayout;

View File

@ -2,7 +2,6 @@
#include "layout-helpers.hpp"
#include "plugin-state-helpers.hpp"
#include "platform-funcs.hpp"
#include "selection-helpers.hpp"
#include <regex>
@ -193,7 +192,7 @@ void MacroConditionWindow::SetupTempVars()
MacroConditionWindowEdit::MacroConditionWindowEdit(
QWidget *parent, std::shared_ptr<MacroConditionWindow> entryData)
: QWidget(parent),
_windowSelection(new QComboBox()),
_windowSelection(new WindowSelectionWidget(this)),
_windowRegex(new RegexConfigWidget(this)),
_checkTitle(new QCheckBox()),
_fullscreen(new QCheckBox()),
@ -206,9 +205,6 @@ MacroConditionWindowEdit::MacroConditionWindowEdit(
_focusWindow(new QLabel()),
_currentFocusLayout(new QHBoxLayout())
{
_windowSelection->setEditable(true);
_windowSelection->setMaxVisibleItems(20);
_checkText->setToolTip(obs_module_text(
"AdvSceneSwitcher.condition.window.entry.text.note"));
_text->setToolTip(obs_module_text(
@ -240,8 +236,6 @@ MacroConditionWindowEdit::MacroConditionWindowEdit(
QWidget::connect(&_timer, SIGNAL(timeout()), this,
SLOT(UpdateFocusWindow()));
PopulateWindowSelection(_windowSelection);
const std::unordered_map<std::string, QWidget *> widgetPlaceholders = {
{"{{windows}}", _windowSelection},
{"{{windowRegex}}", _windowRegex},

View File

@ -2,6 +2,7 @@
#include "macro-condition-edit.hpp"
#include "variable-text-edit.hpp"
#include "regex-config.hpp"
#include "window-selection.hpp"
#include <QComboBox>
#include <QCheckBox>
@ -77,7 +78,7 @@ signals:
void HeaderInfoChanged(const QString &);
protected:
QComboBox *_windowSelection;
WindowSelectionWidget *_windowSelection;
RegexConfigWidget *_windowRegex;
QCheckBox *_checkTitle;
QCheckBox *_fullscreen;

View File

@ -0,0 +1,25 @@
#include "window-selection.hpp"
#include "selection-helpers.hpp"
namespace advss {
WindowSelectionWidget::WindowSelectionWidget(QWidget *parent)
: FilterComboBox(parent)
{
setEditable(true);
SetAllowUnmatchedSelection(true);
setMaxVisibleItems(20);
PopulateWindowSelection(this);
}
void WindowSelectionWidget::showEvent(QShowEvent *event)
{
FilterComboBox::showEvent(event);
const QSignalBlocker b(this);
const auto text = currentText();
clear();
PopulateWindowSelection(this);
setCurrentText(text);
}
} // namespace advss

View File

@ -0,0 +1,16 @@
#pragma once
#include "filter-combo-box.hpp"
namespace advss {
class WindowSelectionWidget : public FilterComboBox {
Q_OBJECT
public:
WindowSelectionWidget(QWidget *parent);
protected:
void showEvent(QShowEvent *event) override;
};
} // namespace advss