Debian Codegraph @

src/app/qml/ui/settings/ThemePage.qml

raw
1 /*
2 * Copyright (C) 2019-2020 UBports Foundation
3 *
4 * This file is part of Lomiri Weather App
5 *
6 * Lomiri Weather App is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 3 as
8 * published by the Free Software Foundation.
9 *
10 * Lomiri Weather App is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 import QtQuick 2.12
20 import Lomiri.Components 1.3
21 import "../../components"
22
23 Item {
24 id: themePage
25 height: themeSetting.height
26
27 ListModel {
28 id: themeModel
29 function initialize() {
30 themeModel.append({"text": i18n.tr("System theme"), "value": "System"})
31 themeModel.append({"text": i18n.tr("SuruDark theme"), "value": "SuruDark"})
32 themeModel.append({"text": i18n.tr("Ambiance theme"), "value": "Ambiance"})
33 }
34 }
35
36 OptionSelector {
37 id: themeSetting
38 text: i18n.tr("Style")
39 model: themeModel
40 containerHeight: itemHeight * themeModel.count
41 delegate: OptionSelectorDelegate {
42 text: model.text
43 height: units.gu(4)
44 }
45 onDelegateClicked: {
46 settings.selectedTheme = model.get(index).value
47 weatherApp.setCurrentTheme();
48 }
49 }
50 Component.onCompleted: {
51 /*
52 The Component.onCompleted of the OptionSelector finishes BEFORE
53 the onCompleted events of the delegates or the model.
54 That is why the initialize() needs to be called here rather than
55 in the Component.onCompleted of the ListModel.
56 */
57 themeModel.initialize()
58 for (var i = 0; i < themeModel.count; ++i) {
59 if (themeModel.get(i).value === settings.selectedTheme) {
60 themeSetting.selectedIndex = i
61 return
62 }
63 }
64 themeSetting.selectedIndex = 0 // in case no match is found due to broken settings
65 }
66 }