Skip to content

Commit 93d1498

Browse files
committed
Implement new Language selection menu
WE2-990 Signed-off-by: Raul Metsma <raul@metsma.ee>
1 parent 1c5ac2d commit 93d1498

18 files changed

Lines changed: 759 additions & 93 deletions

src/ui/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
add_library(ui STATIC
22
certificatewidget.cpp
33
certificatewidget.hpp
4+
languageselect.cpp
5+
languageselect.hpp
6+
languageselect.ui
47
punycode.hpp
58
ui.cpp
69
webeiddialog.cpp
@@ -12,6 +15,7 @@ file(GLOB FONTS fonts/*.ttf)
1215
qt_add_resources(ui resources BASE ${CMAKE_CURRENT_SOURCE_DIR} PREFIX / FILES
1316
../../install/appicon_128.png
1417
dark.qss
18+
dark-languageselect.qss
1519
${IMAGES}
1620
${FONTS}
1721
)

src/ui/dark-languageselect.qss

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
#LanguageSelect {
3+
background-color: #232325;
4+
}
5+
#label {
6+
color: white;
7+
}
8+
QPushButton {
9+
color: #FF5C79;
10+
border-color: #FF5C79;
11+
}
12+
QPushButton:hover, QPushButton:pressed {
13+
background-color: #232325;
14+
}
15+
QToolButton {
16+
color: white;
17+
border-color: #92A0B7;
18+
}
19+
QToolButton:checked {
20+
background-color: #415982;
21+
}

src/ui/dark.qss

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,6 @@ background-image: url(:images/down_dark.svg);
4141
#langButton::hover {
4242
background-color: #4E4E53;
4343
}
44-
#langMenu {
45-
border-color: #4E4E53;
46-
background-color: #4E4E53;
47-
}
48-
#langMenu > QPushButton {
49-
color: #FFFFFF;
50-
}
5144
CertificateButton, CertificateWidget {
5245
border-color: #4E4E53;
5346
}

src/ui/dialog.ui

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -83,23 +83,6 @@ background-image: url(:images/down.svg);
8383
#langButton::hover {
8484
background-color: #EFEFEF;
8585
}
86-
#langMenu {
87-
border: 3px solid #EFEFEF;
88-
border-radius: 3px;
89-
background-color: #EFEFEF;
90-
}
91-
#langMenu &gt; QPushButton {
92-
color: #003168;
93-
border: 0px;
94-
max-height: 22px;
95-
padding-left: 7px;
96-
padding-right: 6px;
97-
font-size: 14px;
98-
text-align: left;
99-
}
100-
#langMenu &gt; QPushButton:checked {
101-
font-weight: bold;
102-
}
10386
CertificateButton, CertificateWidget {
10487
border: 1px solid rgba(0,49,104,0.1);
10588
border-radius: 4px;

src/ui/languageselect.cpp

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright (c) 2020-2024 Estonian Information System Authority
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in all
12+
* copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
21+
*/
22+
23+
#include "languageselect.hpp"
24+
#include "ui_languageselect.h"
25+
26+
#include "application.hpp"
27+
28+
#include <QFile>
29+
#include <QSettings>
30+
#include <QStyle>
31+
32+
LanguageSelect::LanguageSelect(QWidget* parent) :
33+
QDialog(parent), ui(std::make_unique<Ui::LanguageSelect>())
34+
{
35+
ui->setupUi(this);
36+
if (Application::isDarkTheme()) {
37+
if (QFile f(QStringLiteral(":dark-languageselect.qss")); f.open(QFile::ReadOnly | QFile::Text)) {
38+
style()->unpolish(this);
39+
setStyleSheet(styleSheet() + QTextStream(&f).readAll());
40+
style()->polish(this);
41+
}
42+
}
43+
auto current = QSettings().value(QStringLiteral("lang")).toString();
44+
if (auto* btn = findChild<QToolButton*>(current)) {
45+
btn->setChecked(true);
46+
}
47+
connect(ui->langGroup, qOverload<QAbstractButton*>(&QButtonGroup::buttonClicked), this,
48+
[this](QAbstractButton* action) {
49+
QSettings().setValue(QStringLiteral("lang"), action->objectName());
50+
qApp->loadTranslations();
51+
ui->retranslateUi(this);
52+
});
53+
connect(ui->select, &QPushButton::clicked, this, &LanguageSelect::accept);
54+
connect(ui->cancel, &QPushButton::clicked, this, [this, current] {
55+
if (current.isEmpty()) {
56+
QSettings().remove(QStringLiteral("lang"));
57+
} else {
58+
QSettings().setValue(QStringLiteral("lang"), current);
59+
}
60+
qApp->loadTranslations();
61+
reject();
62+
});
63+
}
64+
65+
LanguageSelect::~LanguageSelect() noexcept = default;

src/ui/languageselect.hpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (c) 2020-2024 Estonian Information System Authority
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in all
12+
* copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
21+
*/
22+
23+
#pragma once
24+
25+
#include <QDialog>
26+
27+
#include <memory>
28+
29+
namespace Ui
30+
{
31+
class LanguageSelect;
32+
}
33+
34+
class LanguageSelect : public QDialog
35+
{
36+
Q_OBJECT
37+
public:
38+
explicit LanguageSelect(QWidget* parent = nullptr);
39+
~LanguageSelect() noexcept;
40+
41+
private:
42+
std::unique_ptr<Ui::LanguageSelect> ui;
43+
};

0 commit comments

Comments
 (0)