Skip to content

Commit 251ce76

Browse files
committed
Create language.{ui,h,cpp}
1 parent 6bdd1e8 commit 251ce76

File tree

7 files changed

+182
-122
lines changed

7 files changed

+182
-122
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ set(PROJECT_SOURCES
4949
src/appearance.cpp src/appearance.h src/appearance.ui
5050
src/behaviour.cpp src/behaviour.h src/behaviour.ui
5151
src/mouse.cpp src/mouse.h src/mouse.ui
52+
src/language.cpp src/language.h src/language.ui
5253
)
5354
set(PROJECT_OTHER_FILES
5455
.github/workflows/build.yml

src/language.cpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#include "language.h"
2+
#include "evdev-lst-layouts.h"
3+
#include "environment.h"
4+
#include "find-themes.h"
5+
#include "layoutmodel.h"
6+
#include "macros.h"
7+
#include "settings.h"
8+
#include "./ui_language.h"
9+
10+
Language::Language(QWidget *parent) : QWidget(parent), ui(new Ui::pageLanguage)
11+
{
12+
ui->setupUi(this);
13+
14+
m_model = new LayoutModel(this);
15+
ui->layoutView->setModel(m_model);
16+
connect(ui->layoutAdd, &QPushButton::pressed, this, &Language::addSelectedLayout);
17+
connect(ui->layoutRemove, &QPushButton::pressed, this, &Language::deleteSelectedLayout);
18+
}
19+
20+
Language::~Language()
21+
{
22+
delete ui;
23+
}
24+
25+
void Language::activate()
26+
{
27+
/* Keyboard Layout */
28+
ui->layoutCombo->addItem(tr("Select layout to add..."));
29+
for (auto layout : evdev_lst_layouts) {
30+
ui->layoutCombo->addItem(QString(layout.description));
31+
}
32+
}
33+
34+
void Language::onApply()
35+
{
36+
/*
37+
* We include variants in XKB_DEFAULT_LAYOUT, for example
38+
* "latam(deadtilde),ru(phonetic),gr", so XKB_DEFAULT_VARIANT is set to
39+
* empty.
40+
*/
41+
QString layout = m_model->getXkbDefaultLayout();
42+
if (!layout.isEmpty()) {
43+
environmentSet("XKB_DEFAULT_LAYOUT", layout);
44+
environmentSet("XKB_DEFAULT_VARIANT", "");
45+
}
46+
}
47+
48+
void Language::addSelectedLayout(void)
49+
{
50+
const char *description = ui->layoutCombo->currentText().toLatin1().data();
51+
for (auto layout : evdev_lst_layouts) {
52+
if (!strcmp(description, layout.description)) {
53+
m_model->addLayout(QString(layout.code), QString(layout.description));
54+
}
55+
}
56+
}
57+
58+
void Language::deleteSelectedLayout(void)
59+
{
60+
m_model->deleteLayout(ui->layoutView->currentIndex().row());
61+
}
62+

src/language.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#ifndef LANGUAGE_H
2+
#define LANGUAGE_H
3+
#include <QWidget>
4+
#include "layoutmodel.h"
5+
6+
QT_BEGIN_NAMESPACE
7+
namespace Ui {
8+
class pageLanguage;
9+
}
10+
QT_END_NAMESPACE
11+
12+
class Language : public QWidget
13+
{
14+
Q_OBJECT
15+
16+
public:
17+
Language(QWidget *parent = nullptr);
18+
~Language();
19+
20+
void activate();
21+
void onApply();
22+
23+
private slots:
24+
void addSelectedLayout(void);
25+
void deleteSelectedLayout(void);
26+
27+
private:
28+
Ui::pageLanguage *ui;
29+
LayoutModel *m_model;
30+
};
31+
#endif // LANGUAGE_H

src/language.ui

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>pageLanguage</class>
4+
<widget class="QWidget" name="pageLanguage">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>251</width>
10+
<height>153</height>
11+
</rect>
12+
</property>
13+
<layout class="QFormLayout" name="layPage3">
14+
<property name="leftMargin">
15+
<number>6</number>
16+
</property>
17+
<property name="topMargin">
18+
<number>6</number>
19+
</property>
20+
<property name="rightMargin">
21+
<number>6</number>
22+
</property>
23+
<property name="bottomMargin">
24+
<number>6</number>
25+
</property>
26+
<item row="0" column="0">
27+
<widget class="QLabel" name="label_6">
28+
<property name="text">
29+
<string>Keyboard Layout</string>
30+
</property>
31+
</widget>
32+
</item>
33+
<item row="0" column="1">
34+
<layout class="QVBoxLayout" name="multiKeyboardLayout">
35+
<item>
36+
<widget class="QListView" name="layoutView">
37+
<property name="maximumSize">
38+
<size>
39+
<width>16777215</width>
40+
<height>72</height>
41+
</size>
42+
</property>
43+
</widget>
44+
</item>
45+
<item>
46+
<widget class="QComboBox" name="layoutCombo"/>
47+
</item>
48+
<item>
49+
<layout class="QHBoxLayout" name="horizontalLayout_2">
50+
<item>
51+
<widget class="QPushButton" name="layoutAdd">
52+
<property name="text">
53+
<string>Add</string>
54+
</property>
55+
</widget>
56+
</item>
57+
<item>
58+
<widget class="QPushButton" name="layoutRemove">
59+
<property name="text">
60+
<string>Remove</string>
61+
</property>
62+
</widget>
63+
</item>
64+
</layout>
65+
</item>
66+
<item>
67+
<spacer name="verticalSpacer">
68+
<property name="orientation">
69+
<enum>Qt::Orientation::Vertical</enum>
70+
</property>
71+
<property name="sizeHint" stdset="0">
72+
<size>
73+
<width>20</width>
74+
<height>40</height>
75+
</size>
76+
</property>
77+
</spacer>
78+
</item>
79+
</layout>
80+
</item>
81+
</layout>
82+
</widget>
83+
<resources/>
84+
<connections/>
85+
</ui>

src/maindialog.cpp

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
#include <string>
88
#include <unistd.h>
99
#include "environment.h"
10-
#include "evdev-lst-layouts.h"
1110
#include "find-themes.h"
12-
#include "layoutmodel.h"
1311
#include "log.h"
1412
#include "macros.h"
1513
#include "maindialog.h"
@@ -19,21 +17,12 @@
1917
MainDialog::MainDialog(QWidget *parent) : QDialog(parent), ui(new Ui::MainDialog)
2018
{
2119
ui->setupUi(this);
22-
2320
ui->list->setFixedWidth(ui->list->sizeHintForColumn(0) + 2 * ui->list->frameWidth());
24-
25-
m_model = new LayoutModel(this);
26-
ui->layoutView->setModel(m_model);
27-
2821
QObject::connect(ui->buttonBox, &QDialogButtonBox::clicked, [&](QAbstractButton *button) {
2922
if (ui->buttonBox->standardButton(button) == QDialogButtonBox::Apply) {
3023
onApply();
3124
}
3225
});
33-
34-
connect(ui->layoutAdd, &QPushButton::pressed, this, &MainDialog::addSelectedLayout);
35-
connect(ui->layoutRemove, &QPushButton::pressed, this, &MainDialog::deleteSelectedLayout);
36-
3726
activate();
3827
}
3928

@@ -43,51 +32,20 @@ MainDialog::~MainDialog()
4332
xml_finish();
4433
}
4534

46-
void MainDialog::addSelectedLayout(void)
47-
{
48-
const char *description = ui->layoutCombo->currentText().toLatin1().data();
49-
for (auto layout : evdev_lst_layouts) {
50-
if (!strcmp(description, layout.description)) {
51-
m_model->addLayout(QString(layout.code), QString(layout.description));
52-
}
53-
}
54-
}
55-
56-
void MainDialog::deleteSelectedLayout(void)
57-
{
58-
m_model->deleteLayout(ui->layoutView->currentIndex().row());
59-
}
60-
6135
void MainDialog::activate()
6236
{
6337
ui->pageAppearance->activate();
6438
ui->pageBehaviour->activate();
6539
ui->pageMouse->activate();
66-
67-
/* # LANGUAGE */
68-
69-
/* Keyboard Layout */
70-
ui->layoutCombo->addItem(tr("Select layout to add..."));
71-
for (auto layout : evdev_lst_layouts) {
72-
ui->layoutCombo->addItem(QString(layout.description));
73-
}
40+
ui->pageLanguage->activate();
7441
}
7542

7643
void MainDialog::onApply()
7744
{
7845
ui->pageAppearance->onApply();
7946
ui->pageBehaviour->onApply();
8047
ui->pageMouse->onApply();
81-
82-
/*
83-
* We include variants in XKB_DEFAULT_LAYOUT, for example "latam(deadtilde),ru(phonetic),gr",
84-
* so XKB_DEFAULT_VARIANT is set to empty.
85-
*/
86-
QString layout = m_model->getXkbDefaultLayout();
87-
if (!layout.isEmpty()) {
88-
environmentSet("XKB_DEFAULT_LAYOUT", layout);
89-
environmentSet("XKB_DEFAULT_VARIANT", "");
90-
}
48+
ui->pageLanguage->onApply();
9149

9250
// TODO: Get filename in a more consistent way - share common code with main.cpp
9351
std::string config_home = std::getenv("HOME") + std::string("/.config/labwc");

src/maindialog.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#ifndef MAINDIALOG_H
22
#define MAINDIALOG_H
33
#include <QDialog>
4-
#include "layoutmodel.h"
54
#include "settings.h"
65

76
QT_BEGIN_NAMESPACE
@@ -19,14 +18,8 @@ class MainDialog : public QDialog
1918
~MainDialog();
2019
void activate();
2120

22-
private slots:
23-
void addSelectedLayout(void);
24-
void deleteSelectedLayout(void);
25-
2621
private:
27-
LayoutModel *m_model;
2822
void onApply();
29-
3023
Ui::MainDialog *ui;
3124
};
3225
#endif // MAINDIALOG_H

src/maindialog.ui

Lines changed: 1 addition & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -91,77 +91,7 @@
9191
<widget class="Appearance" name="pageAppearance"/>
9292
<widget class="Behaviour" name="pageBehaviour"/>
9393
<widget class="Mouse" name="pageMouse"/>
94-
<widget class="QWidget" name="page3">
95-
<layout class="QFormLayout" name="layPage3">
96-
<property name="leftMargin">
97-
<number>6</number>
98-
</property>
99-
<property name="topMargin">
100-
<number>6</number>
101-
</property>
102-
<property name="rightMargin">
103-
<number>6</number>
104-
</property>
105-
<property name="bottomMargin">
106-
<number>6</number>
107-
</property>
108-
<item row="0" column="0">
109-
<widget class="QLabel" name="label_6">
110-
<property name="text">
111-
<string>Keyboard Layout</string>
112-
</property>
113-
</widget>
114-
</item>
115-
<item row="0" column="1">
116-
<layout class="QVBoxLayout" name="multiKeyboardLayout">
117-
<item>
118-
<widget class="QListView" name="layoutView">
119-
<property name="maximumSize">
120-
<size>
121-
<width>16777215</width>
122-
<height>72</height>
123-
</size>
124-
</property>
125-
</widget>
126-
</item>
127-
<item>
128-
<widget class="QComboBox" name="layoutCombo"/>
129-
</item>
130-
<item>
131-
<layout class="QHBoxLayout" name="horizontalLayout_2">
132-
<item>
133-
<widget class="QPushButton" name="layoutAdd">
134-
<property name="text">
135-
<string>Add</string>
136-
</property>
137-
</widget>
138-
</item>
139-
<item>
140-
<widget class="QPushButton" name="layoutRemove">
141-
<property name="text">
142-
<string>Remove</string>
143-
</property>
144-
</widget>
145-
</item>
146-
</layout>
147-
</item>
148-
<item>
149-
<spacer name="verticalSpacer">
150-
<property name="orientation">
151-
<enum>Qt::Orientation::Vertical</enum>
152-
</property>
153-
<property name="sizeHint" stdset="0">
154-
<size>
155-
<width>20</width>
156-
<height>40</height>
157-
</size>
158-
</property>
159-
</spacer>
160-
</item>
161-
</layout>
162-
</item>
163-
</layout>
164-
</widget>
94+
<widget class="Language" name="pageLanguage"/>
16595
</widget>
16696
</item>
16797
</layout>

0 commit comments

Comments
 (0)