From 653e0b5af2dc176e80eb617df89f32bf8a00427e Mon Sep 17 00:00:00 2001 From: Colomban Wendling Date: Sun, 12 Jun 2016 23:57:10 +0200 Subject: [PATCH] fix(capslockindicator): fix altering the line edit height Fix altering the Line Edit widget height when the indicator is on (e.g. when caps lock is active). To avoid messing with the style and all the complex issues that arise from it, use an action to display the icon inside the line edit, as it is a built-in feature that work just fine. Fixes #3379. --- src/widget/capslockindicator.cpp | 40 +++++--------------------------- src/widget/capslockindicator.h | 15 ++++-------- src/widget/loginscreen.cpp | 2 -- 3 files changed, 11 insertions(+), 46 deletions(-) diff --git a/src/widget/capslockindicator.cpp b/src/widget/capslockindicator.cpp index 0028acd07..6fe4ec917 100644 --- a/src/widget/capslockindicator.cpp +++ b/src/widget/capslockindicator.cpp @@ -3,40 +3,12 @@ #include "src/platform/capslock.h" #endif -CapsLockIndicator::CapsLockIndicator(QWidget *parent) : QToolButton(parent) +CapsLockIndicator::CapsLockIndicator(QLineEdit *parent) : + QAction(parent), + parent(parent) { - cleanInputStyle = parentWidget()->styleSheet(); - - QIcon icon = QIcon(":img/caps_lock.svg"); - setIcon(icon); - setCursor(Qt::ArrowCursor); - setStyleSheet("border: none; padding: 0; color: white"); + setIcon(QIcon(":img/caps_lock.svg")); setToolTip(tr("CAPS-LOCK ENABLED")); - updateSize(); -} - -void CapsLockIndicator::updateSize() -{ - inputSize = parentWidget()->size(); - move(inputSize.width() - inputSize.height(), 0); - - int side = inputSize.height() - 5; - QSize iconSize(side, side); - setIconSize(iconSize); -} - -void CapsLockIndicator::show() -{ - QToolButton::show(); - - QString style = QString("padding: -3px %1px -3px -6px; color: white").arg(iconSize().width() - 3); - parentWidget()->setStyleSheet(style); -} - -void CapsLockIndicator::hide() -{ - QToolButton::hide(); - parentWidget()->setStyleSheet(cleanInputStyle); } void CapsLockIndicator::updateIndicator() @@ -48,7 +20,7 @@ void CapsLockIndicator::updateIndicator() #endif if (caps) - show(); + parent->addAction(this, QLineEdit::TrailingPosition); else - hide(); + parent->removeAction(this); } diff --git a/src/widget/capslockindicator.h b/src/widget/capslockindicator.h index a01874fa9..d7566464d 100644 --- a/src/widget/capslockindicator.h +++ b/src/widget/capslockindicator.h @@ -1,21 +1,16 @@ #ifndef CAPSLOCKINDICATOR_H #define CAPSLOCKINDICATOR_H -#include +#include +#include -class CapsLockIndicator : QToolButton +class CapsLockIndicator : QAction { public: - CapsLockIndicator(QWidget *widget); + CapsLockIndicator(QLineEdit *widget); void updateIndicator(); - void updateSize(); private: - void show(); - void hide(); - -private: - QString cleanInputStyle; - QSize inputSize; + QLineEdit *parent; }; #endif // CAPSLOCKINDICATOR_H diff --git a/src/widget/loginscreen.cpp b/src/widget/loginscreen.cpp index 61b10d6d4..706f32ac5 100644 --- a/src/widget/loginscreen.cpp +++ b/src/widget/loginscreen.cpp @@ -136,8 +136,6 @@ bool LoginScreen::event(QEvent* event) void LoginScreen::onNewProfilePageClicked() { ui->stackedWidget->setCurrentIndex(0); - capsIndicator->updateSize(); - confimCapsIndicator->updateSize(); } void LoginScreen::onLoginPageClicked()