diff --git a/qtox.pro b/qtox.pro index 6c8afc298..b67e2e40a 100644 --- a/qtox.pro +++ b/qtox.pro @@ -378,7 +378,8 @@ HEADERS += \ src/widget/tool/movablewidget.h \ src/widget/about/aboutuser.h \ src/widget/form/groupinviteform.h \ - src/widget/tool/profileimporter.h + src/widget/tool/profileimporter.h \ + src/widget/capslockindicator.h SOURCES += \ src/ipc.cpp \ @@ -494,4 +495,5 @@ SOURCES += \ src/widget/tool/removefrienddialog.cpp \ src/widget/about/aboutuser.cpp \ src/widget/form/groupinviteform.cpp \ - src/widget/tool/profileimporter.cpp + src/widget/tool/profileimporter.cpp \ + src/widget/capslockindicator.cpp diff --git a/src/widget/capslockindicator.cpp b/src/widget/capslockindicator.cpp new file mode 100644 index 000000000..7989b7225 --- /dev/null +++ b/src/widget/capslockindicator.cpp @@ -0,0 +1,42 @@ +#include "capslockindicator.h" +#ifdef QTOX_PLATFORM_EXT +#include "src/platform/capslock.h" +#endif + +CapsLockIndicator::CapsLockIndicator(QWidget *parent) : QToolButton(parent) { + inputSize = QSize(130, 23); + cleanInputStyle = parentWidget()->styleSheet(); + + QIcon icon = QIcon(":img/caps_lock.svg"); + setIcon(icon); + QSize iconSize(inputSize.height(), inputSize.height()); + setIconSize(iconSize); + setCursor(Qt::ArrowCursor); + move(inputSize.width() - inputSize.height(), 0); + setStyleSheet("border: none; padding: 0;"); + setToolTip("CAPS-LOCK ENABLED"); +} + +void CapsLockIndicator::show() { + QToolButton::show(); + + QString style = QString("padding: -3px %1px -3px -6px").arg(iconSize().width() - 3); + parentWidget()->setStyleSheet(style); +} + +void CapsLockIndicator::hide() { + QToolButton::hide(); + parentWidget()->setStyleSheet(cleanInputStyle); +} + +void CapsLockIndicator::updateIndicator() { + bool caps = false; + // It doesn't needed for OSX, because it shows indicator by default +#if defined(QTOX_PLATFORM_EXT) && !defined(Q_OS_OSX) + caps = Platform::capsLockEnabled(); +#endif + if (caps) + show(); + else + hide(); +} diff --git a/src/widget/capslockindicator.h b/src/widget/capslockindicator.h new file mode 100644 index 000000000..5c242fe8b --- /dev/null +++ b/src/widget/capslockindicator.h @@ -0,0 +1,19 @@ +#ifndef CAPSLOCKINDICATOR_H +#define CAPSLOCKINDICATOR_H + +#include + +class CapsLockIndicator : QToolButton { +public: + CapsLockIndicator(QWidget *widget); + void updateIndicator(); + +private: + void show(); + void hide(); + +private: + QString cleanInputStyle; + QSize inputSize; +}; +#endif // CAPSLOCKINDICATOR_H diff --git a/src/widget/loginscreen.cpp b/src/widget/loginscreen.cpp index c85b7345b..706f32ac5 100644 --- a/src/widget/loginscreen.cpp +++ b/src/widget/loginscreen.cpp @@ -24,9 +24,6 @@ #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" @@ -71,44 +68,6 @@ LoginScreen::LoginScreen(QWidget *parent) : Translator::registerHandler(std::bind(&LoginScreen::retranslateUi, this), this); } -LoginScreen::CapsLockIndicator::CapsLockIndicator(QWidget *parent) : QToolButton(parent) { - inputSize = QSize(130, 23); - cleanInputStyle = parentWidget()->styleSheet(); - - QIcon icon = QIcon(":img/caps_lock.svg"); - setIcon(icon); - QSize iconSize(inputSize.height(), inputSize.height()); - setIconSize(iconSize); - setCursor(Qt::ArrowCursor); - move(inputSize.width() - inputSize.height(), 0); - setStyleSheet("border: none; padding: 0;"); - setToolTip(tr("CAPS-LOCK ENABLED")); -} - -void LoginScreen::CapsLockIndicator::show() { - QToolButton::show(); - - QString style = QString("padding: -3px %1px -3px -6px").arg(iconSize().width() - 3); - parentWidget()->setStyleSheet(style); -} - -void LoginScreen::CapsLockIndicator::hide() { - QToolButton::hide(); - parentWidget()->setStyleSheet(cleanInputStyle); -} - -void LoginScreen::CapsLockIndicator::updateIndicator() { - bool caps = false; - // It doesn't needed for OSX, because it shows indicator by default -#ifdef QTOX_PLATFORM_EXT && !defined(Q_OS_OSX) - caps = Platform::capsLockEnabled(); -#endif - if (caps) - show(); - else - hide(); -} - LoginScreen::~LoginScreen() { Translator::unregister(this); diff --git a/src/widget/loginscreen.h b/src/widget/loginscreen.h index 0be1f834e..2f958583d 100644 --- a/src/widget/loginscreen.h +++ b/src/widget/loginscreen.h @@ -21,6 +21,7 @@ #ifndef LOGINSCREEN_H #define LOGINSCREEN_H +#include "capslockindicator.h" #include #include #include @@ -63,21 +64,6 @@ private: void hideCapsIndicator(); void checkCapsLock(); -private: - class CapsLockIndicator : QToolButton { - public: - CapsLockIndicator(QWidget *widget); - void updateIndicator(); - - private: - void show(); - void hide(); - - private: - QString cleanInputStyle; - QSize inputSize; - }; - private: Ui::LoginScreen *ui; QShortcut quitShortcut;