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
|
#endif
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
|
|
||||||
CapsLockIndicator::CapsLockIndicator(QLineEdit *parent) :
|
CapsLockIndicator::CapsLockIndicator(QObject* parent) :
|
||||||
QAction(parent),
|
QAction(parent)
|
||||||
parent(parent)
|
|
||||||
{
|
{
|
||||||
setIcon(QIcon(":img/caps_lock.svg"));
|
setIcon(QIcon(":img/caps_lock.svg"));
|
||||||
setToolTip(tr("CAPS-LOCK ENABLED"));
|
setToolTip(tr("CAPS-LOCK ENABLED"));
|
||||||
|
@ -14,6 +13,11 @@ CapsLockIndicator::CapsLockIndicator(QLineEdit *parent) :
|
||||||
QCoreApplication::instance()->installEventFilter(this);
|
QCoreApplication::instance()->installEventFilter(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CapsLockIndicator::~CapsLockIndicator()
|
||||||
|
{
|
||||||
|
QCoreApplication::instance()->removeEventFilter(this);
|
||||||
|
}
|
||||||
|
|
||||||
void CapsLockIndicator::updateIndicator()
|
void CapsLockIndicator::updateIndicator()
|
||||||
{
|
{
|
||||||
bool caps = false;
|
bool caps = false;
|
||||||
|
@ -22,10 +26,7 @@ void CapsLockIndicator::updateIndicator()
|
||||||
caps = Platform::capsLockEnabled();
|
caps = Platform::capsLockEnabled();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (caps)
|
setVisible(caps);
|
||||||
parent->addAction(this, QLineEdit::TrailingPosition);
|
|
||||||
else
|
|
||||||
parent->removeAction(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CapsLockIndicator::eventFilter(QObject *obj, QEvent *event)
|
bool CapsLockIndicator::eventFilter(QObject *obj, QEvent *event)
|
||||||
|
|
|
@ -4,18 +4,16 @@
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
|
|
||||||
class CapsLockIndicator : QAction
|
class CapsLockIndicator : public QAction
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CapsLockIndicator(QLineEdit *widget);
|
CapsLockIndicator(QObject *parent);
|
||||||
|
~CapsLockIndicator();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool eventFilter(QObject *obj, QEvent *event);
|
bool eventFilter(QObject *obj, QEvent *event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateIndicator();
|
void updateIndicator();
|
||||||
|
|
||||||
private:
|
|
||||||
QLineEdit *parent;
|
|
||||||
};
|
};
|
||||||
#endif // CAPSLOCKINDICATOR_H
|
#endif // CAPSLOCKINDICATOR_H
|
||||||
|
|
|
@ -58,8 +58,8 @@ LoginScreen::LoginScreen(QWidget *parent) :
|
||||||
connect(ui->autoLoginCB, &QCheckBox::stateChanged, this, &LoginScreen::onAutoLoginToggled);
|
connect(ui->autoLoginCB, &QCheckBox::stateChanged, this, &LoginScreen::onAutoLoginToggled);
|
||||||
connect(ui->importButton, &QPushButton::clicked, this, &LoginScreen::onImportProfile);
|
connect(ui->importButton, &QPushButton::clicked, this, &LoginScreen::onImportProfile);
|
||||||
|
|
||||||
capsIndicator = new CapsLockIndicator(ui->newPass);
|
ui->newPass->addAction(new CapsLockIndicator(this), QLineEdit::TrailingPosition);
|
||||||
confimCapsIndicator = new CapsLockIndicator(ui->newPassConfirm);
|
ui->newPassConfirm->addAction(new CapsLockIndicator(this), QLineEdit::TrailingPosition);
|
||||||
|
|
||||||
reset();
|
reset();
|
||||||
this->setStyleSheet(Style::getStylesheet(":/ui/loginScreen/loginScreen.css"));
|
this->setStyleSheet(Style::getStylesheet(":/ui/loginScreen/loginScreen.css"));
|
||||||
|
@ -72,8 +72,6 @@ LoginScreen::~LoginScreen()
|
||||||
{
|
{
|
||||||
Translator::unregister(this);
|
Translator::unregister(this);
|
||||||
delete ui;
|
delete ui;
|
||||||
delete capsIndicator;
|
|
||||||
delete confimCapsIndicator;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoginScreen::reset()
|
void LoginScreen::reset()
|
||||||
|
|
|
@ -67,8 +67,6 @@ private:
|
||||||
private:
|
private:
|
||||||
Ui::LoginScreen *ui;
|
Ui::LoginScreen *ui;
|
||||||
QShortcut quitShortcut;
|
QShortcut quitShortcut;
|
||||||
CapsLockIndicator *capsIndicator;
|
|
||||||
CapsLockIndicator *confimCapsIndicator;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // LOGINSCREEN_H
|
#endif // LOGINSCREEN_H
|
||||||
|
|
Loading…
Reference in New Issue
Block a user