Skip to content

Commit 9a7acb7

Browse files
authored
Update dialogs to new UI guidlines (#1311)
* WarningDialog IB-7969 Signed-off-by: Raul Metsma <raul@metsma.ee>
1 parent dd9587d commit 9a7acb7

File tree

14 files changed

+270
-313
lines changed

14 files changed

+270
-313
lines changed

client/Application.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -467,9 +467,9 @@ Application::Application( int &argc, char **argv )
467467
{
468468
auto *dlg = new WarningDialog(tr(
469469
"In order to authenticate and sign in e-services with an ID-card you need to install the web browser components."), mainWindow());
470-
dlg->setCancelText(tr("Ignore forever").toUpper());
471-
dlg->addButton(tr("Remind later").toUpper(), QMessageBox::Ignore);
472-
dlg->addButton(tr("Install").toUpper(), QMessageBox::Open);
470+
dlg->setCancelText(tr("Ignore forever"));
471+
dlg->addButton(tr("Remind later"), QMessageBox::Ignore);
472+
dlg->addButton(tr("Install"), QMessageBox::Open);
473473
connect(dlg, &WarningDialog::finished, this, [](int result) {
474474
switch(result)
475475
{
@@ -658,7 +658,7 @@ void Application::loadTranslation( const QString &lang )
658658

659659
void(d->appTranslator.load(QLatin1String(":/translations/%1.qm").arg(lang)));
660660
void(d->commonTranslator.load(QLatin1String(":/translations/common_%1.qm").arg(lang)));
661-
void(d->qtTranslator.load(QLatin1String(":/translations/qt_%1.qm").arg(lang)));
661+
void(d->qtTranslator.load(QLatin1String(":/translations/qtbase_%1.qm").arg(lang)));
662662
if( d->closeAction ) d->closeAction->setText( tr("Close Window") );
663663
if( d->newClientAction ) d->newClientAction->setText( tr("New Window") );
664664
if(d->helpAction) d->helpAction->setText(tr("DigiDoc4 Client Help"));

client/CryptoDoc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ bool CryptoDoc::decrypt()
381381
"Second PIN entry is required to decrypt the CDOC2 container."), Application::mainWindow());
382382
dlg->setCancelText(WarningDialog::Cancel);
383383
dlg->addButton(WarningDialog::OK, QMessageBox::Ok);
384-
dlg->addButton(tr("DON'T SHOW AGAIN"), QMessageBox::Ignore);
384+
dlg->addButton(tr("Don't show again"), QMessageBox::Ignore);
385385
switch (dlg->exec())
386386
{
387387
case QMessageBox::Ok: break;

client/DigiDoc.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include <QtCore/QStringList>
4040
#include <QtCore/QUrl>
4141
#include <QtGui/QDesktopServices>
42+
#include <QtWidgets/QMessageBox>
4243

4344
#include <algorithm>
4445

@@ -65,8 +66,8 @@ struct ServiceConfirmation final: public ContainerOpenCB
6566
"<a href=\"https://www.id.ee/en/article/data-protection-conditions-for-the-id-software-of-the-national-information-system-authority/\">here</a>.<br />"
6667
"Do you want to continue?"), parent);
6768
dlg->setCancelText(WarningDialog::Cancel);
68-
dlg->addButton(WarningDialog::YES, 1);
69-
return dlg->exec() == 1;
69+
dlg->addButton(WarningDialog::YES, QMessageBox::Yes);
70+
return dlg->exec() == QMessageBox::Yes;
7071
});
7172
}
7273
Q_DISABLE_COPY(ServiceConfirmation)

client/MainWindow.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -685,20 +685,20 @@ void MainWindow::resetDigiDoc(DigiDoc *doc, bool warnOnChange)
685685
if(digiDoc->state() == UnsignedContainer)
686686
{
687687
warning = tr("You've added file(s) to container, but these are not signed yet. Keep the unsigned container or remove it?");
688-
cancelTxt = tr("REMOVE");
689-
saveTxt = tr("KEEP");
688+
cancelTxt = WarningDialog::buttonLabel(WarningDialog::Remove);
689+
saveTxt = tr("Keep");
690690
}
691691
else
692692
{
693693
warning = tr("You've changed the open container but have not saved any changes. Save the changes or close without saving?");
694-
cancelTxt = tr("DO NOT SAVE");
695-
saveTxt = tr("SAVE");
694+
cancelTxt = tr("Do not save");
695+
saveTxt = tr("Save");
696696
}
697697

698698
auto *dlg = new WarningDialog(warning, this);
699699
dlg->setCancelText(cancelTxt);
700-
dlg->addButton(saveTxt, ContainerSave);
701-
if(dlg->exec() == ContainerSave)
700+
dlg->addButton(saveTxt, QMessageBox::Save);
701+
if(dlg->exec() == QMessageBox::Save)
702702
save();
703703
}
704704

@@ -892,9 +892,9 @@ bool MainWindow::removeFile(DocumentModel *model, int index)
892892
{
893893
auto *dlg = new WarningDialog(tr("You are about to delete the last file in the container, it is removed along with the container."), this);
894894
dlg->setCancelText(WarningDialog::Cancel);
895-
dlg->resetCancelStyle();
896-
dlg->addButton(tr("REMOVE"), ContainerSave, true);
897-
if (dlg->exec() == ContainerSave) {
895+
dlg->resetCancelStyle(false);
896+
dlg->addButton(WarningDialog::Remove, QMessageBox::Ok, true);
897+
if (dlg->exec() == QMessageBox::Ok) {
898898
window()->setWindowFilePath({});
899899
window()->setWindowTitle(tr("DigiDoc4 Client"));
900900
return true;
@@ -1004,8 +1004,8 @@ bool MainWindow::wrapContainer(bool signing)
10041004
tr("Files can not be added to the cryptocontainer. The system will create a new container which shall contain the cypto-document and the files you wish to add.");
10051005
auto *dlg = new WarningDialog(msg, this);
10061006
dlg->setCancelText(WarningDialog::Cancel);
1007-
dlg->addButton(tr("CONTINUE"), ContainerSave);
1008-
return dlg->exec() == ContainerSave;
1007+
dlg->addButton(tr("Continue"), QMessageBox::Ok);
1008+
return dlg->exec() == QMessageBox::Ok;
10091009
}
10101010

10111011
void MainWindow::updateSelector()

client/dialogs/SettingsDialog.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include <QtGui/QDesktopServices>
4848
#include <QtNetwork/QNetworkProxy>
4949
#include <QtWidgets/QInputDialog>
50+
#include <QtWidgets/QMessageBox>
5051

5152
#include <algorithm>
5253

@@ -326,9 +327,9 @@ SettingsDialog::SettingsDialog(int page, QWidget *parent)
326327
auto *dlg = WarningDialog::show(this, tr("Restart DigiDoc4 Client to activate logging. Read more "
327328
"<a href=\"https://www.id.ee/en/article/log-file-generation-in-digidoc4-client/\">here</a>. Restart now?"));
328329
dlg->setCancelText(WarningDialog::NO);
329-
dlg->addButton(WarningDialog::YES, 1);
330+
dlg->addButton(WarningDialog::YES, QMessageBox::Yes);
330331
connect(dlg, &WarningDialog::finished, qApp, [](int result) {
331-
if(result == 1) {
332+
if(result == QMessageBox::Yes) {
332333
qApp->setProperty("restart", true);
333334
QApplication::quit();
334335
}

client/dialogs/WarningDialog.cpp

Lines changed: 64 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
#include "ui_WarningDialog.h"
2222

2323
#include "Application.h"
24-
#include "Styles.h"
2524

25+
#include <QPushButton>
2626
#include <QStyle>
2727

2828
WarningDialog::WarningDialog(const QString &text, const QString &details, QWidget *parent)
@@ -36,16 +36,15 @@ WarningDialog::WarningDialog(const QString &text, const QString &details, QWidge
3636
setParent(parent, Qt::Sheet);
3737
#endif
3838

39-
connect( ui->cancel, &QPushButton::clicked, this, &WarningDialog::reject );
40-
connect( this, &WarningDialog::finished, this, &WarningDialog::close );
41-
42-
ui->cancel->setFont(Styles::font(Styles::Condensed, 14));
43-
ui->text->setFont(Styles::font(Styles::Regular, 14));
39+
ui->buttonBox->layout()->setSpacing(40);
4440
ui->text->setText(text);
45-
ui->details->setFont(ui->text->font());
4641
ui->details->setText(details);
4742
ui->details->setHidden(details.isEmpty());
4843
ui->showDetails->setHidden(details.isEmpty());
44+
cancel = ui->buttonBox->button(QDialogButtonBox::Close);
45+
cancel->setCursor(Qt::PointingHandCursor);
46+
connect(cancel, &QPushButton::clicked, this, &QDialog::reject);
47+
resetCancelStyle(true);
4948

5049
if(!details.isEmpty())
5150
{
@@ -72,63 +71,86 @@ void WarningDialog::addButton(ButtonText label, int ret, bool red)
7271

7372
void WarningDialog::addButton(const QString& label, int ret, bool red)
7473
{
75-
auto *button = new QPushButton(label, this);
76-
button->setAccessibleName(label.toLower());
77-
button->setCursor(ui->cancel->cursor());
78-
button->setFont(ui->cancel->font());
79-
button->setMinimumSize(
80-
std::max<int>(ui->cancel->minimumWidth(), ui->cancel->fontMetrics().boundingRect(label).width() + 16),
81-
ui->cancel->minimumHeight());
82-
83-
if(red) {
74+
if(ui->buttonBox->buttons().size() > 3)
75+
ui->buttonBox->layout()->setSpacing(5);
76+
77+
QDialogButtonBox::ButtonRole role = red ? QDialogButtonBox::RejectRole : [ret] {
78+
switch (ret) {
79+
case QDialogButtonBox::Ok:
80+
case QDialogButtonBox::Save:
81+
case QDialogButtonBox::Open:
82+
case QDialogButtonBox::SaveAll:
83+
case QDialogButtonBox::Retry:
84+
case QDialogButtonBox::Ignore:
85+
return QDialogButtonBox::AcceptRole;
86+
case QDialogButtonBox::Cancel:
87+
case QDialogButtonBox::Close:
88+
case QDialogButtonBox::Abort:
89+
return QDialogButtonBox::RejectRole;
90+
case QDialogButtonBox::Discard:
91+
return QDialogButtonBox::DestructiveRole;
92+
case QDialogButtonBox::Help:
93+
return QDialogButtonBox::HelpRole;
94+
case QDialogButtonBox::Apply:
95+
return QDialogButtonBox::ApplyRole;
96+
case QDialogButtonBox::Yes:
97+
case QDialogButtonBox::YesToAll:
98+
return QDialogButtonBox::YesRole;
99+
case QDialogButtonBox::No:
100+
case QDialogButtonBox::NoToAll:
101+
return QDialogButtonBox::NoRole;
102+
case QDialogButtonBox::RestoreDefaults:
103+
case QDialogButtonBox::Reset:
104+
return QDialogButtonBox::ResetRole;
105+
default:
106+
return QDialogButtonBox::ActionRole;
107+
}
108+
}();
109+
110+
QPushButton *button = ui->buttonBox->addButton(label, role);
111+
button->setCursor(Qt::PointingHandCursor);
112+
switch(role) {
113+
case QDialogButtonBox::NoRole:
114+
case QDialogButtonBox::RejectRole:
115+
case QDialogButtonBox::ResetRole:
116+
case QDialogButtonBox::DestructiveRole:
117+
style()->unpolish(button);
84118
button->setProperty("warning", true);
85-
#ifdef Q_OS_WIN // For Windows this button should be on the left side of the dialog window
86-
setLayoutDirection(Qt::RightToLeft);
87-
#endif
88-
} else {
89-
#ifdef Q_OS_UNIX // For macOS, Linux and BSD all positive buttons should be on the right side of the dialog window
90-
setLayoutDirection(Qt::RightToLeft);
91-
#endif
119+
style()->polish(button);
120+
break;
121+
default:
122+
break;
92123
}
93-
94124
connect(button, &QPushButton::clicked, this, [this, ret] { done(ret); });
95-
ui->buttonBarLayout->insertWidget(ui->buttonBarLayout->findChildren<QPushButton>().size() + 1, button);
96125
}
97126

98127
QString WarningDialog::buttonLabel(ButtonText label)
99128
{
100129
switch (label) {
101-
case NO: return tr("NO");
130+
case NO: return tr("No");
102131
case OK: return QStringLiteral("OK");
103-
case Cancel: return tr("CANCEL");
104-
case YES: return tr("YES");
132+
case Cancel: return tr("Cancel");
133+
case YES: return tr("Yes");
134+
case Remove: return tr("Remove");
105135
default: return {};
106136
}
107137
}
108138

109-
void WarningDialog::resetCancelStyle()
110-
{
111-
style()->unpolish(ui->cancel);
112-
ui->cancel->setProperty("warning", false);
113-
style()->polish(ui->cancel);
114-
}
115-
116-
void WarningDialog::setButtonSize(int width, int margin)
139+
void WarningDialog::resetCancelStyle(bool warning)
117140
{
118-
ui->buttonBarLayout->setSpacing(margin);
119-
ui->cancel->setMinimumSize(width, ui->cancel->minimumHeight());
120-
ui->cancel->setMaximumSize(width, ui->cancel->minimumHeight());
141+
style()->unpolish(cancel);
142+
cancel->setProperty("warning", warning);
143+
style()->polish(cancel);
121144
}
122145

123146
void WarningDialog::setCancelText(ButtonText label)
124147
{
125148
setCancelText(buttonLabel(label));
126149
}
127150

128-
void WarningDialog::setCancelText(const QString& label)
151+
void WarningDialog::setCancelText(const QString &label)
129152
{
130-
ui->cancel->setText(label);
131-
ui->cancel->setAccessibleName(label.toLower());
153+
cancel->setText(label);
132154
}
133155

134156
WarningDialog* WarningDialog::show(const QString &text, const QString &details)

client/dialogs/WarningDialog.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,24 @@ class WarningDialog final: public QDialog
3737
OK,
3838
NO,
3939
YES,
40+
Remove,
4041
};
4142
explicit WarningDialog(const QString &text, const QString &details, QWidget *parent = nullptr);
4243
explicit WarningDialog(const QString &text, QWidget *parent = nullptr);
4344
~WarningDialog() final;
4445

4546
void addButton(ButtonText label, int ret, bool red = false);
4647
void addButton(const QString& label, int ret, bool red = false);
47-
void setButtonSize(int width, int margin);
4848
void setCancelText(ButtonText label);
4949
void setCancelText(const QString& label);
50-
void resetCancelStyle();
50+
void resetCancelStyle(bool warning);
5151
static WarningDialog *show(const QString &text, const QString &details = {});
5252
static WarningDialog *show(QWidget *parent, const QString &text, const QString &details = {});
5353

54-
private:
5554
static QString buttonLabel(ButtonText label);
5655

56+
private:
5757
Ui::WarningDialog *ui;
5858
WaitDialogHider hider;
59+
QPushButton *cancel;
5960
};

0 commit comments

Comments
 (0)