mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
refactor(capslockindicator): encapsulate event handling
Use an event filter on QCoreApplication instead of requiring the caller to manually call updateIndicator() when the caps lock state changed.
This commit is contained in:
parent
f9190734d7
commit
5fc67284cd
|
@ -2,6 +2,7 @@
|
|||
#ifdef QTOX_PLATFORM_EXT
|
||||
#include "src/platform/capslock.h"
|
||||
#endif
|
||||
#include <QCoreApplication>
|
||||
|
||||
CapsLockIndicator::CapsLockIndicator(QLineEdit *parent) :
|
||||
QAction(parent),
|
||||
|
@ -9,6 +10,8 @@ CapsLockIndicator::CapsLockIndicator(QLineEdit *parent) :
|
|||
{
|
||||
setIcon(QIcon(":img/caps_lock.svg"));
|
||||
setToolTip(tr("CAPS-LOCK ENABLED"));
|
||||
|
||||
QCoreApplication::instance()->installEventFilter(this);
|
||||
}
|
||||
|
||||
void CapsLockIndicator::updateIndicator()
|
||||
|
@ -24,3 +27,21 @@ void CapsLockIndicator::updateIndicator()
|
|||
else
|
||||
parent->removeAction(this);
|
||||
}
|
||||
|
||||
bool CapsLockIndicator::eventFilter(QObject *obj, QEvent *event)
|
||||
{
|
||||
switch (event->type())
|
||||
{
|
||||
case QEvent::Show:
|
||||
if (obj == this)
|
||||
updateIndicator();
|
||||
break;
|
||||
case QEvent::KeyRelease:
|
||||
updateIndicator();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return QAction::eventFilter(obj, event);
|
||||
}
|
||||
|
|
|
@ -8,6 +8,11 @@ class CapsLockIndicator : QAction
|
|||
{
|
||||
public:
|
||||
CapsLockIndicator(QLineEdit *widget);
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *obj, QEvent *event);
|
||||
|
||||
private:
|
||||
void updateIndicator();
|
||||
|
||||
private:
|
||||
|
|
|
@ -120,11 +120,6 @@ bool LoginScreen::event(QEvent* event)
|
|||
emit windowStateChanged(windowState());
|
||||
break;
|
||||
#endif
|
||||
case QEvent::Show:
|
||||
case QEvent::KeyRelease:
|
||||
capsIndicator->updateIndicator();
|
||||
confimCapsIndicator->updateIndicator();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user