/
qgsfocuskeeper.cpp
42 lines (37 loc) · 1.52 KB
/
qgsfocuskeeper.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/***************************************************************************
qgsfocuskeeper.cpp
-----------------
Date : May 2020
Copyright : (C) 2020 Even Rouault
Email : even dot rouault at spatialys dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgsfocuskeeper.h"
#include <QApplication>
#include <QEvent>
#include <QWidget>
QgsFocusKeeper::QgsFocusKeeper(): mWidgetToKeepFocused( QApplication::focusWidget() )
{
if ( mWidgetToKeepFocused )
mWidgetToKeepFocused->installEventFilter( this );
}
QgsFocusKeeper::~QgsFocusKeeper()
{
if ( mWidgetToKeepFocused )
mWidgetToKeepFocused->removeEventFilter( this );
}
bool QgsFocusKeeper::eventFilter( QObject *obj, QEvent *event )
{
if ( obj == mWidgetToKeepFocused && event &&
( event->type() == QEvent::FocusOut || event->type() == QEvent::FocusAboutToChange ) )
{
return true;
}
return QObject::eventFilter( obj, event );
}