UI: Allow the use of Esc key to quit settings window

This commit is contained in:
Bennik2000 2020-05-12 00:08:08 +02:00 committed by jp9000
parent 6fcb57daa7
commit f2f336229d
3 changed files with 54 additions and 8 deletions

View file

@ -80,6 +80,6 @@ protected:
return filter(obj, event);
}
private:
public:
EventFilterFunc filter;
};

View file

@ -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__

View file

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