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

feat(loginscreen): Created new CapsLockIndicator class

This commit is contained in:
Diadlo 2016-05-11 12:08:26 +03:00
parent cbe8fb8ef9
commit fb7fcaaa8c
No known key found for this signature in database
GPG Key ID: 5AF9F2E29107C727
2 changed files with 44 additions and 26 deletions

View File

@ -61,16 +61,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);
int width = 130; capsIndicator = new CapsLockIndicator(ui->newPass);
int height = 23; confimCapsIndicator = new CapsLockIndicator(ui->newPassConfirm);
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(); reset();
this->setStyleSheet(Style::getStylesheet(":/ui/loginScreen/loginScreen.css")); this->setStyleSheet(Style::getStylesheet(":/ui/loginScreen/loginScreen.css"));
@ -79,30 +71,40 @@ LoginScreen::LoginScreen(QWidget *parent) :
Translator::registerHandler(std::bind(&LoginScreen::retranslateUi, this), this); Translator::registerHandler(std::bind(&LoginScreen::retranslateUi, this), this);
} }
void LoginScreen::showCapsIndicator() { LoginScreen::CapsLockIndicator::CapsLockIndicator(QWidget *parent) : QToolButton(parent) {
capsIndicator->show(); inputSize = QSize(130, 23);
cleanInputStyle = parentWidget()->styleSheet();
int height = 23; QIcon icon = QIcon(":img/caps_lock.svg");
// TODO: get correct style setIcon(icon);
QString style = QString("padding-right: %1px").arg(height); QSize iconSize(inputSize.height(), inputSize.height());
capsIndicator->parentWidget()->setStyleSheet(style); setIconSize(iconSize);
setCursor(Qt::ArrowCursor);
move(inputSize.width() - inputSize.height(), 0);
setStyleSheet("border: none; padding: 0;");
} }
void LoginScreen::hideCapsIndicator() { void LoginScreen::CapsLockIndicator::show() {
capsIndicator->hide(); QToolButton::show();
capsIndicator->parentWidget()->setStyleSheet(""); QString style = QString("padding: -3px %1px -3px -6px").arg(iconSize().width() - 3);
parentWidget()->setStyleSheet(style);
} }
void LoginScreen::checkCapsLock() { void LoginScreen::CapsLockIndicator::hide() {
QToolButton::hide();
parentWidget()->setStyleSheet(cleanInputStyle);
}
void LoginScreen::CapsLockIndicator::updateIndicator() {
bool caps = false; bool caps = false;
#ifdef QTOX_PLATFORM_EXT #ifdef QTOX_PLATFORM_EXT
caps = Platform::capsLockEnabled(); caps = Platform::capsLockEnabled();
#endif #endif
if (caps) if (caps)
showCapsIndicator(); show();
else else
hideCapsIndicator(); hide();
} }
LoginScreen::~LoginScreen() LoginScreen::~LoginScreen()
@ -110,7 +112,7 @@ LoginScreen::~LoginScreen()
Translator::unregister(this); Translator::unregister(this);
delete ui; delete ui;
delete capsIndicator; delete capsIndicator;
//delete confimCapsIndicator; delete confimCapsIndicator;
} }
void LoginScreen::reset() void LoginScreen::reset()
@ -159,7 +161,8 @@ bool LoginScreen::event(QEvent* event)
#endif #endif
case QEvent::Show: case QEvent::Show:
case QEvent::KeyRelease: case QEvent::KeyRelease:
checkCapsLock(); capsIndicator->updateIndicator();
confimCapsIndicator->updateIndicator();
break; break;
default: default:
break; break;

View File

@ -63,11 +63,26 @@ private:
void hideCapsIndicator(); void hideCapsIndicator();
void checkCapsLock(); void checkCapsLock();
private:
class CapsLockIndicator : QToolButton {
public:
CapsLockIndicator(QWidget *widget);
void updateIndicator();
private:
void show();
void hide();
private:
QString cleanInputStyle;
QSize inputSize;
};
private: private:
Ui::LoginScreen *ui; Ui::LoginScreen *ui;
QShortcut quitShortcut; QShortcut quitShortcut;
QToolButton *capsIndicator; CapsLockIndicator *capsIndicator;
QToolButton *confimCapsIndicator; CapsLockIndicator *confimCapsIndicator;
}; };
#endif // LOGINSCREEN_H #endif // LOGINSCREEN_H