Changeset View
Changeset View
Standalone View
Standalone View
kcms/keyboard/kcmui/layout_config_model.cpp
- This file was added.
1 | #include "layout_config_model.h" | ||||
---|---|---|---|---|---|
2 | | ||||
3 | #include <QDebug> | ||||
4 | #include <algorithm> | ||||
5 | #include <KLocalizedString> | ||||
6 | | ||||
7 | #include "../xkb_rules.h" | ||||
8 | | ||||
9 | #include "layout_list_model_selected.h" | ||||
10 | | ||||
11 | const char* LayoutConfigModel::switch_modes[4] = { | ||||
12 | "Global", "Desktop", "Application", "Window" | ||||
13 | }; | ||||
14 | | ||||
15 | LayoutConfigModel::LayoutConfigModel(QObject* parent) | ||||
16 | : QObject(parent) | ||||
17 | , m_layoutListModels(new LayoutListModels(this)) | ||||
18 | { | ||||
19 | m_mainShiftKeyIndex = 0; | ||||
20 | m_thirdLevelShortcutIndex = 0; | ||||
21 | } | ||||
22 | | ||||
23 | bool LayoutConfigModel::showLayoutIndicator() const | ||||
24 | { | ||||
25 | return m_showLayoutIndicator; | ||||
26 | } | ||||
27 | | ||||
28 | void LayoutConfigModel::setShowLayoutIndicator(bool showLayoutIndicator) | ||||
29 | { | ||||
30 | if (showLayoutIndicator != m_showLayoutIndicator) { | ||||
31 | m_showLayoutIndicator = showLayoutIndicator; | ||||
32 | emit showLayoutIndicatorChanged(); | ||||
33 | } | ||||
34 | } | ||||
35 | | ||||
36 | bool LayoutConfigModel::showForSingleLayout() const | ||||
37 | { | ||||
38 | return m_showForSingleLayout; | ||||
39 | } | ||||
40 | | ||||
41 | void LayoutConfigModel::setShowForSingleLayout(bool showForSingleLayout) | ||||
42 | { | ||||
43 | if (m_showForSingleLayout != showForSingleLayout) { | ||||
44 | m_showForSingleLayout = showForSingleLayout; | ||||
45 | emit showForSingleLayoutChanged(); | ||||
46 | } | ||||
47 | } | ||||
48 | | ||||
49 | bool LayoutConfigModel::layoutIndicatorShowFlag() const | ||||
50 | { | ||||
51 | return m_layoutIndicatorShowFlag; | ||||
52 | } | ||||
53 | | ||||
54 | void LayoutConfigModel::setLayoutIndicatorShowFlag(bool b) | ||||
55 | { | ||||
56 | if (m_layoutIndicatorShowFlag != b) { | ||||
57 | m_layoutIndicatorShowFlag = b; | ||||
58 | emit layoutIndicatorShowFlagChanged(); | ||||
59 | } | ||||
60 | } | ||||
61 | | ||||
62 | bool LayoutConfigModel::layoutIndicatorShowLabel() const | ||||
63 | { | ||||
64 | return m_layoutIndicatorShowLabel; | ||||
65 | } | ||||
66 | | ||||
67 | void LayoutConfigModel::setLayoutIndicatorShowLabel(bool b) | ||||
68 | { | ||||
69 | if (m_layoutIndicatorShowLabel != b) { | ||||
70 | m_layoutIndicatorShowLabel = b; | ||||
71 | emit layoutIndicatorShowLabelChanged(); | ||||
72 | } | ||||
73 | } | ||||
74 | | ||||
75 | int LayoutConfigModel::switchingPolicyIndex() const | ||||
76 | { | ||||
77 | return m_switchingPolicyIndex; | ||||
78 | } | ||||
79 | | ||||
80 | void LayoutConfigModel::setSwitchingPolicyIndex(int switchingPolicyIndex) | ||||
81 | { | ||||
82 | if (m_switchingPolicyIndex != switchingPolicyIndex) { | ||||
83 | m_switchingPolicyIndex = switchingPolicyIndex; | ||||
84 | emit switchingPolicyIndexChanged(); | ||||
85 | } | ||||
86 | } | ||||
87 | | ||||
88 | QString LayoutConfigModel::alternativeShortcut() const | ||||
89 | { | ||||
90 | return m_alternativeShortcuts; | ||||
91 | } | ||||
92 | | ||||
93 | void LayoutConfigModel::setAlternativeShortcut(QString alternativeShortcut) | ||||
94 | { | ||||
95 | if (m_alternativeShortcuts != alternativeShortcut) { | ||||
96 | m_alternativeShortcuts = alternativeShortcut; | ||||
97 | emit alternativeShortcutChanged(); | ||||
98 | } | ||||
99 | } | ||||
100 | | ||||
101 | LayoutListFilterDuplicatesProxyModel* LayoutConfigModel::layoutListModel() const | ||||
102 | { | ||||
103 | return m_layoutListModels->entireLayoutListModel(); | ||||
104 | } | ||||
105 | | ||||
106 | LayoutListSortByPriorityProxyModel* LayoutConfigModel::currentLayoutListModel() const | ||||
107 | { | ||||
108 | return m_layoutListModels->configuredLayoutListModel(); | ||||
109 | } | ||||
110 | | ||||
111 | void LayoutConfigModel::loadEnabledLayouts() | ||||
112 | { | ||||
113 | m_layoutListModels->loadConfig(); | ||||
114 | } | ||||
115 | | ||||
116 | void LayoutConfigModel::saveEnabledLayouts() | ||||
117 | { | ||||
118 | m_layoutListModels->saveConfig(); | ||||
119 | } | ||||
120 | | ||||
121 | QStringList LayoutConfigModel::mainShiftKeyModel() const | ||||
122 | { | ||||
123 | QStringList list; | ||||
124 | list << i18n("None"); | ||||
125 | for (auto const& item : XkbRules::self()->optionGroupInfos) { | ||||
126 | if (item->name == "grp") { | ||||
127 | for (auto const& option : item->optionInfos) { | ||||
128 | list << option->description; | ||||
129 | } | ||||
130 | break; | ||||
131 | } | ||||
132 | } | ||||
133 | return list; | ||||
134 | } | ||||
135 | | ||||
136 | QStringList LayoutConfigModel::thirdLevelShortcutModel() const | ||||
137 | { | ||||
138 | QStringList list; | ||||
139 | list << i18n("None"); | ||||
140 | for (auto const& item : XkbRules::self()->optionGroupInfos) { | ||||
141 | qDebug() << item ->name << item ->description; | ||||
142 | if (item->name == "lv3") { | ||||
143 | for (auto const& option : item->optionInfos) { | ||||
144 | list << option->description; | ||||
145 | } | ||||
146 | break; | ||||
147 | } | ||||
148 | } | ||||
149 | return list; | ||||
150 | } | ||||
151 | | ||||
152 | int LayoutConfigModel::mainShiftKeyIndex() const | ||||
153 | { | ||||
154 | return m_mainShiftKeyIndex; | ||||
155 | } | ||||
156 | | ||||
157 | QString LayoutConfigModel::mainShiftKey() const | ||||
158 | { | ||||
159 | if (m_mainShiftKeyIndex > 0) { | ||||
160 | for (auto const& item : XkbRules::self()->optionGroupInfos) { | ||||
161 | if (item->name == "grp") { | ||||
162 | return item->optionInfos[m_mainShiftKeyIndex - 1]->name; | ||||
163 | } | ||||
164 | } | ||||
165 | } | ||||
166 | return ""; | ||||
167 | } | ||||
168 | | ||||
169 | void LayoutConfigModel::setMainShiftKeyIndex(int mainShiftKeyIndex) | ||||
170 | { | ||||
171 | if (m_mainShiftKeyIndex != mainShiftKeyIndex) { | ||||
172 | m_mainShiftKeyIndex = mainShiftKeyIndex; | ||||
173 | emit mainShiftKeyIndexChanged(); | ||||
174 | } | ||||
175 | } | ||||
176 | | ||||
177 | void LayoutConfigModel::setMainShiftKey(const QString &name) | ||||
178 | { | ||||
179 | for (auto const& item : XkbRules::self()->optionGroupInfos) { | ||||
180 | if (item->name == "grp") { | ||||
181 | for (int i = 0; i < item->optionInfos.size(); ++i) { | ||||
182 | if (item->optionInfos[i]->name == name) { | ||||
183 | setMainShiftKeyIndex(i); | ||||
184 | } | ||||
185 | } | ||||
186 | break; | ||||
187 | } | ||||
188 | } | ||||
189 | } | ||||
190 | | ||||
191 | int LayoutConfigModel::thirdLevelShortcutIndex() const | ||||
192 | { | ||||
193 | return m_thirdLevelShortcutIndex; | ||||
194 | } | ||||
195 | | ||||
196 | QString LayoutConfigModel::thirdLevelShortcut() const | ||||
197 | { | ||||
198 | if (m_thirdLevelShortcutIndex > 0) { | ||||
199 | for (auto const& item : XkbRules::self()->optionGroupInfos) { | ||||
200 | if (item->name == "lv3") { | ||||
201 | return item->optionInfos[m_thirdLevelShortcutIndex - 1]->name; | ||||
202 | } | ||||
203 | } | ||||
204 | } | ||||
205 | return ""; | ||||
206 | } | ||||
207 | | ||||
208 | void LayoutConfigModel::setThirdLevelShortcutIndex(int thirdLevelShortcut) | ||||
209 | { | ||||
210 | if (m_thirdLevelShortcutIndex != thirdLevelShortcut) { | ||||
211 | m_thirdLevelShortcutIndex = thirdLevelShortcut; | ||||
212 | emit thirdLevelShortcutChanged(); | ||||
213 | } | ||||
214 | } | ||||
215 | | ||||
216 | void LayoutConfigModel::setThirdLevelShortcut(const QString &name) | ||||
217 | { | ||||
218 | for (auto const& item : XkbRules::self()->optionGroupInfos) { | ||||
219 | if (item->name == "lv3") { | ||||
220 | for (int i = 0; i < item->optionInfos.size(); ++i) { | ||||
221 | if (item->optionInfos[i]->name == name) { | ||||
222 | setThirdLevelShortcutIndex(i); | ||||
223 | } | ||||
224 | } | ||||
225 | break; | ||||
226 | } | ||||
227 | } | ||||
228 | } |