mirror of
https://github.com/obsproject/obs-studio.git
synced 2024-07-14 15:24:07 +00:00
UI: Allow the use of Esc key to quit settings window
This commit is contained in:
parent
6fcb57daa7
commit
f2f336229d
|
@ -80,6 +80,6 @@ protected:
|
|||
return filter(obj, event);
|
||||
}
|
||||
|
||||
private:
|
||||
public:
|
||||
EventFilterFunc filter;
|
||||
};
|
||||
|
|
|
@ -55,6 +55,33 @@
|
|||
|
||||
using namespace std;
|
||||
|
||||
class SettingsEventFilter : public QObject {
|
||||
QScopedPointer<OBSEventFilter> shortcutFilter;
|
||||
|
||||
public:
|
||||
inline SettingsEventFilter()
|
||||
: shortcutFilter((OBSEventFilter *)CreateShortcutFilter())
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *obj, QEvent *event) override
|
||||
{
|
||||
int key;
|
||||
|
||||
switch (event->type()) {
|
||||
case QEvent::KeyPress:
|
||||
case QEvent::KeyRelease:
|
||||
key = static_cast<QKeyEvent *>(event)->key();
|
||||
if (key == Qt::Key_Escape) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return shortcutFilter->filter(obj, event);
|
||||
}
|
||||
};
|
||||
|
||||
// Used for QVariant in codec comboboxes
|
||||
namespace {
|
||||
static bool StringEquals(QString left, QString right)
|
||||
|
@ -656,7 +683,7 @@ OBSBasicSettings::OBSBasicSettings(QWidget *parent)
|
|||
// Initialize libff library
|
||||
ff_init();
|
||||
|
||||
installEventFilter(CreateShortcutFilter());
|
||||
installEventFilter(new SettingsEventFilter());
|
||||
|
||||
LoadEncoderTypes();
|
||||
LoadColorRanges();
|
||||
|
@ -3611,14 +3638,14 @@ bool OBSBasicSettings::QueryChanges()
|
|||
|
||||
void OBSBasicSettings::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
if (Changed() && !QueryChanges())
|
||||
if (!AskIfCanCloseSettings())
|
||||
event->ignore();
|
||||
}
|
||||
|
||||
if (forceAuthReload) {
|
||||
main->auth->Save();
|
||||
main->auth->Load();
|
||||
forceAuthReload = false;
|
||||
}
|
||||
void OBSBasicSettings::reject()
|
||||
{
|
||||
if (AskIfCanCloseSettings())
|
||||
close();
|
||||
}
|
||||
|
||||
void OBSBasicSettings::on_theme_activated(int idx)
|
||||
|
@ -3872,6 +3899,22 @@ void OBSBasicSettings::RecalcOutputResPixels(const char *resText)
|
|||
}
|
||||
}
|
||||
|
||||
bool OBSBasicSettings::AskIfCanCloseSettings()
|
||||
{
|
||||
bool canCloseSettings = false;
|
||||
|
||||
if (!Changed() || QueryChanges())
|
||||
canCloseSettings = true;
|
||||
|
||||
if (forceAuthReload) {
|
||||
main->auth->Save();
|
||||
main->auth->Load();
|
||||
forceAuthReload = false;
|
||||
}
|
||||
|
||||
return canCloseSettings;
|
||||
}
|
||||
|
||||
void OBSBasicSettings::on_filenameFormatting_textEdited(const QString &text)
|
||||
{
|
||||
#ifdef __APPLE__
|
||||
|
|
|
@ -289,6 +289,8 @@ private:
|
|||
|
||||
void RecalcOutputResPixels(const char *resText);
|
||||
|
||||
bool AskIfCanCloseSettings();
|
||||
|
||||
QIcon generalIcon;
|
||||
QIcon streamIcon;
|
||||
QIcon outputIcon;
|
||||
|
@ -376,6 +378,7 @@ private slots:
|
|||
|
||||
protected:
|
||||
virtual void closeEvent(QCloseEvent *event);
|
||||
void reject() override;
|
||||
|
||||
public:
|
||||
OBSBasicSettings(QWidget *parent);
|
||||
|
|
Loading…
Reference in a new issue