1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

refactor(loginscreen, capslockindicator): Caps Lock indicator class was made independent

This commit is contained in:
Diadlo 2016-05-15 15:17:40 +03:00
parent 6489afaf4b
commit af497a9efd
No known key found for this signature in database
GPG Key ID: 5AF9F2E29107C727
5 changed files with 66 additions and 58 deletions

View File

@ -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

View File

@ -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();
}

View File

@ -0,0 +1,19 @@
#ifndef CAPSLOCKINDICATOR_H
#define CAPSLOCKINDICATOR_H
#include <QToolButton>
class CapsLockIndicator : QToolButton {
public:
CapsLockIndicator(QWidget *widget);
void updateIndicator();
private:
void show();
void hide();
private:
QString cleanInputStyle;
QSize inputSize;
};
#endif // CAPSLOCKINDICATOR_H

View File

@ -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);

View File

@ -21,6 +21,7 @@
#ifndef LOGINSCREEN_H
#define LOGINSCREEN_H
#include "capslockindicator.h"
#include <QWidget>
#include <QShortcut>
#include <QToolButton>
@ -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;