mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
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.
This commit is contained in:
parent
a851a5b18d
commit
653e0b5af2
|
@ -3,40 +3,12 @@
|
||||||
#include "src/platform/capslock.h"
|
#include "src/platform/capslock.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
CapsLockIndicator::CapsLockIndicator(QWidget *parent) : QToolButton(parent)
|
CapsLockIndicator::CapsLockIndicator(QLineEdit *parent) :
|
||||||
|
QAction(parent),
|
||||||
|
parent(parent)
|
||||||
{
|
{
|
||||||
cleanInputStyle = parentWidget()->styleSheet();
|
setIcon(QIcon(":img/caps_lock.svg"));
|
||||||
|
|
||||||
QIcon icon = QIcon(":img/caps_lock.svg");
|
|
||||||
setIcon(icon);
|
|
||||||
setCursor(Qt::ArrowCursor);
|
|
||||||
setStyleSheet("border: none; padding: 0; color: white");
|
|
||||||
setToolTip(tr("CAPS-LOCK ENABLED"));
|
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()
|
void CapsLockIndicator::updateIndicator()
|
||||||
|
@ -48,7 +20,7 @@ void CapsLockIndicator::updateIndicator()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (caps)
|
if (caps)
|
||||||
show();
|
parent->addAction(this, QLineEdit::TrailingPosition);
|
||||||
else
|
else
|
||||||
hide();
|
parent->removeAction(this);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,16 @@
|
||||||
#ifndef CAPSLOCKINDICATOR_H
|
#ifndef CAPSLOCKINDICATOR_H
|
||||||
#define CAPSLOCKINDICATOR_H
|
#define CAPSLOCKINDICATOR_H
|
||||||
|
|
||||||
#include <QToolButton>
|
#include <QAction>
|
||||||
|
#include <QLineEdit>
|
||||||
|
|
||||||
class CapsLockIndicator : QToolButton
|
class CapsLockIndicator : QAction
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CapsLockIndicator(QWidget *widget);
|
CapsLockIndicator(QLineEdit *widget);
|
||||||
void updateIndicator();
|
void updateIndicator();
|
||||||
void updateSize();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void show();
|
QLineEdit *parent;
|
||||||
void hide();
|
|
||||||
|
|
||||||
private:
|
|
||||||
QString cleanInputStyle;
|
|
||||||
QSize inputSize;
|
|
||||||
};
|
};
|
||||||
#endif // CAPSLOCKINDICATOR_H
|
#endif // CAPSLOCKINDICATOR_H
|
||||||
|
|
|
@ -136,8 +136,6 @@ bool LoginScreen::event(QEvent* event)
|
||||||
void LoginScreen::onNewProfilePageClicked()
|
void LoginScreen::onNewProfilePageClicked()
|
||||||
{
|
{
|
||||||
ui->stackedWidget->setCurrentIndex(0);
|
ui->stackedWidget->setCurrentIndex(0);
|
||||||
capsIndicator->updateSize();
|
|
||||||
confimCapsIndicator->updateSize();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoginScreen::onLoginPageClicked()
|
void LoginScreen::onLoginPageClicked()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user