Skip to content

Commit

Permalink
Set focus on dialogs (open-eid#1191)
Browse files Browse the repository at this point in the history
IB-7732

Signed-off-by: Raul Metsma <[email protected]>
  • Loading branch information
metsma authored May 19, 2023
1 parent c3c7332 commit 8b07a7f
Show file tree
Hide file tree
Showing 13 changed files with 85 additions and 105 deletions.
45 changes: 17 additions & 28 deletions client/dialogs/MobileDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ MobileDialog::MobileDialog(QWidget *parent) :
static const QStringList countryCodes {QStringLiteral("372"), QStringLiteral("370")};
new Overlay(this, parent);
ui->setupUi(this);
setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint);
setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint);
setFixedSize(size());
#ifdef Q_OS_WIN
ui->buttonLayout->setDirection(QBoxLayout::RightToLeft);
Expand All @@ -58,6 +58,7 @@ MobileDialog::MobileDialog(QWidget *parent) :
ui->phoneNo->setValidator(new NumberValidator(ui->phoneNo));
ui->phoneNo->setText(Settings::MOBILEID_NUMBER.value(countryCodes[0]));
ui->phoneNo->setAttribute(Qt::WA_MacShowFocusRect, false);
ui->phoneNo->setFocus();
ui->cbRemember->setChecked(Settings::MOBILEID_REMEMBER);
ui->cbRemember->setAttribute(Qt::WA_MacShowFocusRect, false);
auto saveSettings = [this] {
Expand All @@ -66,45 +67,33 @@ MobileDialog::MobileDialog(QWidget *parent) :
Settings::MOBILEID_CODE = checked ? ui->idCode->text() : QString();
Settings::MOBILEID_NUMBER = checked ? ui->phoneNo->text() : QString();
};
auto setError = [](QLineEdit *input, QLabel *error, const QString &msg) {
input->setStyleSheet(msg.isEmpty() ? QString() :QStringLiteral("border-color: #c53e3e"));
error->setFocusPolicy(msg.isEmpty() ? Qt::NoFocus : Qt::TabFocus);
error->setText(msg);
};
connect(ui->idCode, &QLineEdit::returnPressed, ui->sign, &QPushButton::click);
connect(ui->idCode, &QLineEdit::textEdited, this, saveSettings);
connect(ui->idCode, &QLineEdit::textEdited, ui->errorCode, [this] {
ui->errorCode->clear();
ui->idCode->setStyleSheet({});
connect(ui->idCode, &QLineEdit::textEdited, ui->errorCode, [this, setError] {
setError(ui->idCode, ui->errorCode, {});
});
connect(ui->phoneNo, &QLineEdit::returnPressed, ui->sign, &QPushButton::click);
connect(ui->phoneNo, &QLineEdit::textEdited, this, saveSettings);
connect(ui->phoneNo, &QLineEdit::textEdited, ui->errorPhone, [this] {
ui->errorPhone->clear();
ui->phoneNo->setStyleSheet({});
connect(ui->phoneNo, &QLineEdit::textEdited, ui->errorPhone, [this, setError] {
setError(ui->phoneNo, ui->errorPhone, {});
});
connect(ui->cbRemember, &QCheckBox::clicked, this, saveSettings);
connect(ui->sign, &QPushButton::clicked, this, [this] {
connect(ui->sign, &QPushButton::clicked, this, [this, setError] {
if(!IKValidator::isValid(idCode()))
{
ui->idCode->setStyleSheet(QStringLiteral("border-color: #c53e3e"));
ui->errorCode->setText(tr("Personal code is not valid"));
}
setError(ui->idCode, ui->errorCode, tr("Personal code is not valid"));
else
{
ui->idCode->setStyleSheet({});
ui->errorCode->clear();
}
setError(ui->idCode, ui->errorCode, {});
if(phoneNo().size() < 8 || countryCodes.contains(phoneNo()))
{
ui->phoneNo->setStyleSheet(QStringLiteral("border-color: #c53e3e"));
ui->errorPhone->setText(tr("Phone number is not entered"));
}
setError(ui->phoneNo, ui->errorPhone, tr("Phone number is not entered"));
else if(!countryCodes.contains(phoneNo().left(3)))
{
ui->phoneNo->setStyleSheet(QStringLiteral("border-color: #c53e3e"));
ui->errorPhone->setText(tr("Invalid country code"));
}
setError(ui->phoneNo, ui->errorPhone, tr("Invalid country code"));
else
{
ui->phoneNo->setStyleSheet({});
ui->errorPhone->clear();
}
setError(ui->phoneNo, ui->errorPhone, {});
if(ui->errorCode->text().isEmpty() && ui->errorPhone->text().isEmpty())
accept();
});
Expand Down
9 changes: 3 additions & 6 deletions client/dialogs/MobileDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
<ui version="4.0">
<class>MobileDialog</class>
<widget class="QDialog" name="MobileDialog">
<property name="windowModality">
<enum>Qt::WindowModal</enum>
</property>
<property name="geometry">
<rect>
<x>0</x>
Expand Down Expand Up @@ -162,9 +165,6 @@ background-color: #BEDBED;
<pointsize>12</pointsize>
</font>
</property>
<property name="focusPolicy">
<enum>Qt::TabFocus</enum>
</property>
</widget>
</item>
<item>
Expand Down Expand Up @@ -203,9 +203,6 @@ background-color: #BEDBED;
<pointsize>12</pointsize>
</font>
</property>
<property name="focusPolicy">
<enum>Qt::TabFocus</enum>
</property>
</widget>
</item>
<item>
Expand Down
2 changes: 1 addition & 1 deletion client/dialogs/PinPopup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ PinPopup::PinPopup(PinFlags flags, const QString &title, TokenFlags count, QWidg
, ui(new Ui::PinPopup)
{
ui->setupUi(this);
setWindowFlag(Qt::FramelessWindowHint);
setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint);
for(QLineEdit *w: findChildren<QLineEdit*>())
w->setAttribute(Qt::WA_MacShowFocusRect, false);

Expand Down
5 changes: 4 additions & 1 deletion client/dialogs/PinPopup.ui
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
<ui version="4.0">
<class>PinPopup</class>
<widget class="QDialog" name="PinPopup">
<property name="windowModality">
<enum>Qt::WindowModal</enum>
</property>
<property name="geometry">
<rect>
<x>0</x>
Expand Down Expand Up @@ -214,7 +217,7 @@ QPushButton:disabled {
}</string>
</property>
<property name="text">
<string>OK</string>
<string notr="true">OK</string>
</property>
<property name="default">
<bool>true</bool>
Expand Down
45 changes: 23 additions & 22 deletions client/dialogs/PinUnblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ PinUnblock::PinUnblock(WorkMode mode, QWidget *parent, QSmartCardData::PinType t
#if defined (Q_OS_WIN)
ui->buttonLayout->setDirection(QBoxLayout::RightToLeft);
#endif
setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint);
for(QLineEdit *w: findChildren<QLineEdit*>())
setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint);
auto list = findChildren<QLineEdit*>();
if(!list.isEmpty())
list.first()->setFocus();
for(QLineEdit *w: list)
w->setAttribute(Qt::WA_MacShowFocusRect, false);
new Overlay(this, parent);

Expand Down Expand Up @@ -98,10 +101,10 @@ PinUnblock::PinUnblock(WorkMode mode, QWidget *parent, QSmartCardData::PinType t
? tr("PIN2 code is used to digitally sign documents.")
: tr("PIN1 code is used for confirming the identity of a person."));
ui->line2_text->setText(
tr("If %1 is inserted incorrectly 3 times the %2 certificate will be blocked and it will be impossible to use ID-card to %3, until it is unblocked via the PUK code.")
.arg(QSmartCardData::typeString(type))
.arg(type == QSmartCardData::Pin2Type ? tr("signing") : tr("identification"))
.arg(type == QSmartCardData::Pin2Type ? tr("digital signing") : tr("verify identification"))
tr("If %1 is inserted incorrectly 3 times the %2 certificate will be blocked and it will be impossible to use ID-card to %3, until it is unblocked via the PUK code.").arg(
QSmartCardData::typeString(type),
type == QSmartCardData::Pin2Type ? tr("signing") : tr("identification"),
type == QSmartCardData::Pin2Type ? tr("digital signing") : tr("verify identification"))
);
}
setWindowTitle(ui->labelNameId->text());
Expand All @@ -125,28 +128,29 @@ PinUnblock::PinUnblock(WorkMode mode, QWidget *parent, QSmartCardData::PinType t
for(int i = 1; i < 4; i++)
{
bool isHidden = true;
if(QLabel *text = findChild<QLabel*>(QStringLiteral("line%1_text").arg(i)))
if(auto *text = findChild<QLabel*>(QStringLiteral("line%1_text").arg(i)))
text->setHidden(isHidden = text->text().isEmpty());
if(QLabel *bullet = findChild<QLabel*>(QStringLiteral("line%1_bullet").arg(i)))
if(auto *bullet = findChild<QLabel*>(QStringLiteral("line%1_bullet").arg(i)))
bullet->setHidden(isHidden);
}

auto setError = [](QLineEdit *input, QLabel *error, const QString &msg) {
input->setStyleSheet(msg.isEmpty() ? QString() :QStringLiteral("border-color: #c53e3e"));
error->setFocusPolicy(msg.isEmpty() ? Qt::NoFocus : Qt::TabFocus);
error->setText(msg);
};
connect(ui->cancel, &QPushButton::clicked, this, &PinUnblock::reject);
connect(this, &PinUnblock::finished, this, &PinUnblock::close);
connect(ui->pin, &QLineEdit::returnPressed, ui->change, &QPushButton::click);
connect(ui->pin, &QLineEdit::textEdited, ui->errorPin, [this] {
ui->errorPin->clear();
ui->pin->setStyleSheet({});
connect(ui->pin, &QLineEdit::textEdited, ui->errorPin, [this, setError] {
setError(ui->pin, ui->errorPin, {});
});
connect(ui->repeat, &QLineEdit::returnPressed, ui->change, &QPushButton::click);
connect(ui->repeat, &QLineEdit::textEdited, ui->errorRepeat, [this] {
ui->errorRepeat->clear();
ui->repeat->setStyleSheet({});
connect(ui->repeat, &QLineEdit::textEdited, ui->errorRepeat, [this, setError] {
setError(ui->repeat, ui->errorRepeat, {});
});
connect(ui->puk, &QLineEdit::returnPressed, ui->change, &QPushButton::click);
connect(ui->puk, &QLineEdit::textEdited, ui->errorPuk, [this] {
ui->errorPuk->clear();
ui->puk->setStyleSheet({});
connect(ui->puk, &QLineEdit::textEdited, ui->errorPuk, [this, setError] {
setError(ui->puk, ui->errorPuk, {});
});
connect(ui->change, &QPushButton::clicked, this, [=] {
const static QString SEQUENCE_ASCENDING = QStringLiteral("1234567890123456789012");
Expand All @@ -157,10 +161,7 @@ PinUnblock::PinUnblock(WorkMode mode, QWidget *parent, QSmartCardData::PinType t
ui->errorPuk->clear();
ui->errorPin->clear();
ui->errorRepeat->clear();
auto setError = [](QLineEdit *input, QLabel *error, const QString &msg) {
input->setStyleSheet(QStringLiteral("border-color: #c53e3e"));
error->setText(msg);
};

auto pinError = [](auto type) {
return tr("%1 length has to be between %2 and 12")
.arg(QSmartCardData::typeString(type)).arg(QSmartCardData::minPinLen(type));
Expand Down
9 changes: 0 additions & 9 deletions client/dialogs/PinUnblock.ui
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,6 @@ line-height: 24px;</string>
<pointsize>12</pointsize>
</font>
</property>
<property name="focusPolicy">
<enum>Qt::TabFocus</enum>
</property>
<property name="styleSheet">
<string notr="true">color: #c53e3e</string>
</property>
Expand Down Expand Up @@ -413,9 +410,6 @@ line-height: 24px;</string>
<pointsize>12</pointsize>
</font>
</property>
<property name="focusPolicy">
<enum>Qt::TabFocus</enum>
</property>
<property name="styleSheet">
<string notr="true">color: #c53e3e</string>
</property>
Expand Down Expand Up @@ -479,9 +473,6 @@ line-height: 24px;</string>
<pointsize>12</pointsize>
</font>
</property>
<property name="focusPolicy">
<enum>Qt::TabFocus</enum>
</property>
<property name="styleSheet">
<string notr="true">color: #c53e3e</string>
</property>
Expand Down
16 changes: 7 additions & 9 deletions client/dialogs/RoleAddressDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

#include <QtWidgets/QCompleter>
#include <QtWidgets/QListView>
#include <QtWidgets/QPushButton>

class RoleAddressDialog::Private: public Ui::RoleAddressDialog {};

Expand All @@ -47,23 +46,22 @@ RoleAddressDialog::RoleAddressDialog(QWidget *parent)

connect( d->cancel, &QPushButton::clicked, this, &RoleAddressDialog::reject );
d->cancel->setFont(condensed);
d->cancel->setText(tr("CANCEL"));
d->cancel->setCursor(QCursor(Qt::PointingHandCursor));

connect( d->sign, &QPushButton::clicked, this, &RoleAddressDialog::accept );
d->sign->setFont(condensed);
d->sign->setText(tr("SIGN"));
d->sign->setCursor(QCursor(Qt::PointingHandCursor));

for(QLabel *label: findChildren<QLabel*>())
for(auto *label: findChildren<QLabel*>())
label->setFont(regularFont);

d->title->setFont(Styles::font(Styles::Regular, 16, QFont::DemiBold));

for(QLineEdit *line: findChildren<QLineEdit*>())
auto list = findChildren<QLineEdit*>();
if(!list.isEmpty())
list.first()->setFocus();
for(QLineEdit *line: list)
{
Settings::Option<QStringList> s{line->objectName()};
QCompleter *completer = new QCompleter(s, line);
auto *completer = new QCompleter(s, line);
completer->setMaxVisibleItems(10);
completer->setCompletionMode(QCompleter::PopupCompletion);
completer->setCaseSensitivity(Qt::CaseInsensitive);
Expand All @@ -79,7 +77,7 @@ RoleAddressDialog::RoleAddressDialog(QWidget *parent)
s.clear(); // Uses on Windows MULTI_STRING registry
s = list;
});
completer->popup()->setStyleSheet("background-color:#FFFFFF; color: #000000;");
completer->popup()->setStyleSheet(QStringLiteral("background-color:#FFFFFF; color: #000000;"));
}
}

Expand Down
16 changes: 14 additions & 2 deletions client/dialogs/RoleAddressDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,12 @@ QLabel {
<height>34</height>
</size>
</property>
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="accessibleName">
<string>Cancel</string>
</property>
<property name="styleSheet">
<string notr="true">QPushButton {
border-radius: 2px;
Expand All @@ -326,7 +332,7 @@ QPushButton:disabled {
}</string>
</property>
<property name="text">
<string>Cancel</string>
<string>CANCEL</string>
</property>
</widget>
</item>
Expand All @@ -344,9 +350,15 @@ QPushButton:disabled {
<height>34</height>
</size>
</property>
<property name="text">
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="accessibleName">
<string>Sign</string>
</property>
<property name="text">
<string>SIGN</string>
</property>
<property name="default">
<bool>true</bool>
</property>
Expand Down
25 changes: 13 additions & 12 deletions client/dialogs/SmartIDDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ SmartIDDialog::SmartIDDialog(QWidget *parent)
new Overlay(this, parent);

ui->setupUi(this);
setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint);
setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint);
setFixedSize(size());
#ifdef Q_OS_WIN
ui->buttonLayout->setDirection(QBoxLayout::RightToLeft);
Expand All @@ -48,13 +48,14 @@ SmartIDDialog::SmartIDDialog(QWidget *parent)
ui->errorCountry->setFont(regularFont);
ui->idCode->setFont(regularFont);
ui->idCode->setAttribute(Qt::WA_MacShowFocusRect, false);
ui->idCode->setFocus();
ui->idCountry->setFont(regularFont);
ui->cbRemember->setFont(regularFont);
ui->cbRemember->setAttribute(Qt::WA_MacShowFocusRect, false);
ui->sign->setFont(condensed);
ui->cancel->setFont(condensed);

QValidator *ik = new NumberValidator(ui->idCode);
auto *ik = new NumberValidator(ui->idCode);
ui->idCode->setValidator(ik);
ui->idCode->setText(Settings::SMARTID_CODE);
for(int i = 0, count = Settings::SMARTID_COUNTRY_LIST.size(); i < count; ++i)
Expand All @@ -67,26 +68,26 @@ SmartIDDialog::SmartIDDialog(QWidget *parent)
Settings::SMARTID_CODE = checked ? idCode() : QString();
Settings::SMARTID_COUNTRY = checked ? country() : EE;
};
auto setError = [](QLineEdit *input, QLabel *error, const QString &msg) {
input->setStyleSheet(msg.isEmpty() ? QString() :QStringLiteral("border-color: #c53e3e"));
error->setFocusPolicy(msg.isEmpty() ? Qt::NoFocus : Qt::TabFocus);
error->setText(msg);
};
connect(ui->idCode, &QLineEdit::returnPressed, ui->sign, &QPushButton::click);
connect(ui->idCode, &QLineEdit::textEdited, this, saveSettings);
connect(ui->idCode, &QLineEdit::textEdited, ui->errorCode, [this] {
ui->errorCode->clear();
ui->idCode->setStyleSheet({});
connect(ui->idCode, &QLineEdit::textEdited, ui->errorCode, [this, setError] {
setError(ui->idCode, ui->errorCode, {});
});
connect(ui->idCountry, &QComboBox::currentTextChanged, this, saveSettings);
connect(ui->cbRemember, &QCheckBox::clicked, this, saveSettings);
connect(ui->cancel, &QPushButton::clicked, this, &QDialog::reject);
connect(ui->sign, &QPushButton::clicked, this, [this,ik] {
connect(ui->sign, &QPushButton::clicked, this, [this, ik, setError] {
ui->idCode->setValidator(country() == EE ? ik : nullptr);
if(ui->idCode->validator() && !IKValidator::isValid(idCode()))
{
ui->idCode->setStyleSheet(QStringLiteral("border-color: #c53e3e"));
ui->errorCode->setText(tr("Personal code is not valid"));
}
setError(ui->idCode, ui->errorCode, tr("Personal code is not valid"));
else
{
ui->idCode->setStyleSheet({});
ui->errorCode->clear();
setError(ui->idCode, ui->errorCode, {});
accept();
}
});
Expand Down
Loading

0 comments on commit 8b07a7f

Please sign in to comment.