Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
fix(capslockindicator): fix altering the line edit height
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
b4n committed Jun 12, 2016
1 parent a851a5b commit 653e0b5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 46 deletions.
40 changes: 6 additions & 34 deletions src/widget/capslockindicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -48,7 +20,7 @@ void CapsLockIndicator::updateIndicator()
#endif

if (caps)
show();
parent->addAction(this, QLineEdit::TrailingPosition);
else
hide();
parent->removeAction(this);
}
15 changes: 5 additions & 10 deletions src/widget/capslockindicator.h
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
#ifndef CAPSLOCKINDICATOR_H
#define CAPSLOCKINDICATOR_H

#include <QToolButton>
#include <QAction>
#include <QLineEdit>

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
2 changes: 0 additions & 2 deletions src/widget/loginscreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@ bool LoginScreen::event(QEvent* event)
void LoginScreen::onNewProfilePageClicked()
{
ui->stackedWidget->setCurrentIndex(0);
capsIndicator->updateSize();
confimCapsIndicator->updateSize();
}

void LoginScreen::onLoginPageClicked()
Expand Down

0 comments on commit 653e0b5

Please sign in to comment.