diff --git a/img/caps_lock.svg b/img/caps_lock.svg new file mode 100644 index 000000000..19bf26738 --- /dev/null +++ b/img/caps_lock.svg @@ -0,0 +1,113 @@ + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/res.qrc b/res.qrc index c2dd97f24..1e08d310e 100644 --- a/res.qrc +++ b/res.qrc @@ -128,5 +128,6 @@ ui/notificationEdge/notificationEdge.css ui/loginScreen/loginScreen.css img/others/logout-icon.svg + img/caps_lock.svg diff --git a/src/widget/loginscreen.cpp b/src/widget/loginscreen.cpp index 474b4c551..2eedad673 100644 --- a/src/widget/loginscreen.cpp +++ b/src/widget/loginscreen.cpp @@ -24,11 +24,15 @@ #include "src/persistence/profilelocker.h" #include "src/nexus.h" #include "src/persistence/settings.h" +#ifdef QTOX_PLATFORM_EXT +#include "src/platform/capslock.h" +#endif #include "src/widget/form/setpassworddialog.h" #include "src/widget/translator.h" #include "src/widget/style.h" #include "src/widget/tool/profileimporter.h" #include +#include #include LoginScreen::LoginScreen(QWidget *parent) : @@ -57,6 +61,17 @@ LoginScreen::LoginScreen(QWidget *parent) : connect(ui->autoLoginCB, &QCheckBox::stateChanged, this, &LoginScreen::onAutoLoginToggled); connect(ui->importButton, &QPushButton::clicked, this, &LoginScreen::onImportProfile); + int width = 130; + int height = 23; + + capsIndicator = new QToolButton(ui->newPass); + QIcon icon = QIcon(":img/caps_lock.svg"); + capsIndicator->setIcon(icon); + capsIndicator->setIconSize(QSize(height, height)); + capsIndicator->setCursor(Qt::ArrowCursor); + capsIndicator->move(width - height, 0); + capsIndicator->setStyleSheet("border: none; padding: 0;"); + reset(); this->setStyleSheet(Style::getStylesheet(":/ui/loginScreen/loginScreen.css")); @@ -64,10 +79,38 @@ LoginScreen::LoginScreen(QWidget *parent) : Translator::registerHandler(std::bind(&LoginScreen::retranslateUi, this), this); } +void LoginScreen::showCapsIndicator() { + capsIndicator->show(); + + int height = 23; + // TODO: get correct style + QString style = QString("padding-right: %1px").arg(height); + capsIndicator->parentWidget()->setStyleSheet(style); +} + +void LoginScreen::hideCapsIndicator() { + capsIndicator->hide(); + + capsIndicator->parentWidget()->setStyleSheet(""); +} + +void LoginScreen::checkCapsLock() { + bool caps = false; +#ifdef QTOX_PLATFORM_EXT + caps = Platform::capsLockEnabled(); +#endif + if (caps) + showCapsIndicator(); + else + hideCapsIndicator(); +} + LoginScreen::~LoginScreen() { Translator::unregister(this); delete ui; + delete capsIndicator; + //delete confimCapsIndicator; } void LoginScreen::reset() @@ -104,15 +147,27 @@ void LoginScreen::reset() ui->autoLoginCB->blockSignals(false); } -#ifdef Q_OS_MAC bool LoginScreen::event(QEvent* event) { - if (event->type() == QEvent::WindowActivate || event->type() == QEvent::WindowStateChange) - emit windowStateChanged(windowState()); + switch (event->type()) + { +#ifdef Q_OS_MAC + case QEvent::WindowActivate: + case QEvent::WindowStateChange: + emit windowStateChanged(windowState()); + break; +#endif + case QEvent::Show: + case QEvent::KeyRelease: + checkCapsLock(); + break; + default: + break; + } + return QWidget::event(event); } -#endif void LoginScreen::onNewProfilePageClicked() { diff --git a/src/widget/loginscreen.h b/src/widget/loginscreen.h index 0a8361a09..51c040062 100644 --- a/src/widget/loginscreen.h +++ b/src/widget/loginscreen.h @@ -23,6 +23,7 @@ #include #include +#include namespace Ui { class LoginScreen; @@ -37,9 +38,9 @@ public: ~LoginScreen(); void reset(); ///< Resets the UI, clears all fields -#ifdef Q_OS_MAC bool event(QEvent* event) final override; +#ifdef Q_OS_MAC signals: void windowStateChanged(Qt::WindowStates states); #endif @@ -58,10 +59,15 @@ private slots: private: void retranslateUi(); + void showCapsIndicator(); + void hideCapsIndicator(); + void checkCapsLock(); private: Ui::LoginScreen *ui; QShortcut quitShortcut; + QToolButton *capsIndicator; + QToolButton *confimCapsIndicator; }; #endif // LOGINSCREEN_H