mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
refactor(capslockindicator): expose as a QAction to simplify API
This commit is contained in:
parent
2fe41071be
commit
6a40ca0b55
|
@ -4,9 +4,8 @@
|
|||
#endif
|
||||
#include <QCoreApplication>
|
||||
|
||||
CapsLockIndicator::CapsLockIndicator(QLineEdit *parent) :
|
||||
QAction(parent),
|
||||
parent(parent)
|
||||
CapsLockIndicator::CapsLockIndicator(QObject* parent) :
|
||||
QAction(parent)
|
||||
{
|
||||
setIcon(QIcon(":img/caps_lock.svg"));
|
||||
setToolTip(tr("CAPS-LOCK ENABLED"));
|
||||
|
@ -14,6 +13,11 @@ CapsLockIndicator::CapsLockIndicator(QLineEdit *parent) :
|
|||
QCoreApplication::instance()->installEventFilter(this);
|
||||
}
|
||||
|
||||
CapsLockIndicator::~CapsLockIndicator()
|
||||
{
|
||||
QCoreApplication::instance()->removeEventFilter(this);
|
||||
}
|
||||
|
||||
void CapsLockIndicator::updateIndicator()
|
||||
{
|
||||
bool caps = false;
|
||||
|
@ -22,10 +26,7 @@ void CapsLockIndicator::updateIndicator()
|
|||
caps = Platform::capsLockEnabled();
|
||||
#endif
|
||||
|
||||
if (caps)
|
||||
parent->addAction(this, QLineEdit::TrailingPosition);
|
||||
else
|
||||
parent->removeAction(this);
|
||||
setVisible(caps);
|
||||
}
|
||||
|
||||
bool CapsLockIndicator::eventFilter(QObject *obj, QEvent *event)
|
||||
|
|
|
@ -4,18 +4,16 @@
|
|||
#include <QAction>
|
||||
#include <QLineEdit>
|
||||
|
||||
class CapsLockIndicator : QAction
|
||||
class CapsLockIndicator : public QAction
|
||||
{
|
||||
public:
|
||||
CapsLockIndicator(QLineEdit *widget);
|
||||
CapsLockIndicator(QObject *parent);
|
||||
~CapsLockIndicator();
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *obj, QEvent *event);
|
||||
|
||||
private:
|
||||
void updateIndicator();
|
||||
|
||||
private:
|
||||
QLineEdit *parent;
|
||||
};
|
||||
#endif // CAPSLOCKINDICATOR_H
|
||||
|
|
|
@ -58,8 +58,8 @@ LoginScreen::LoginScreen(QWidget *parent) :
|
|||
connect(ui->autoLoginCB, &QCheckBox::stateChanged, this, &LoginScreen::onAutoLoginToggled);
|
||||
connect(ui->importButton, &QPushButton::clicked, this, &LoginScreen::onImportProfile);
|
||||
|
||||
capsIndicator = new CapsLockIndicator(ui->newPass);
|
||||
confimCapsIndicator = new CapsLockIndicator(ui->newPassConfirm);
|
||||
ui->newPass->addAction(new CapsLockIndicator(this), QLineEdit::TrailingPosition);
|
||||
ui->newPassConfirm->addAction(new CapsLockIndicator(this), QLineEdit::TrailingPosition);
|
||||
|
||||
reset();
|
||||
this->setStyleSheet(Style::getStylesheet(":/ui/loginScreen/loginScreen.css"));
|
||||
|
@ -72,8 +72,6 @@ LoginScreen::~LoginScreen()
|
|||
{
|
||||
Translator::unregister(this);
|
||||
delete ui;
|
||||
delete capsIndicator;
|
||||
delete confimCapsIndicator;
|
||||
}
|
||||
|
||||
void LoginScreen::reset()
|
||||
|
|
|
@ -67,8 +67,6 @@ private:
|
|||
private:
|
||||
Ui::LoginScreen *ui;
|
||||
QShortcut quitShortcut;
|
||||
CapsLockIndicator *capsIndicator;
|
||||
CapsLockIndicator *confimCapsIndicator;
|
||||
};
|
||||
|
||||
#endif // LOGINSCREEN_H
|
||||
|
|
Loading…
Reference in New Issue
Block a user