| 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: colorThemePage |
| 25 |
height: colorThemeSetting.height |
| 26 |
|
| 27 |
ListModel { |
| 28 |
id: colorThemeModel |
| 29 |
function initialize() { |
| 30 |
colorThemeModel.append({"colors": "no colors", "text": i18n.tr("no colors")}) |
| 31 |
colorThemeModel.append({"colors": "blue/yellow", "text": i18n.tr("blue/yellow")}) |
| 32 |
colorThemeModel.append({"colors": "blue/orange", "text": i18n.tr("blue/orange")}) |
| 33 |
colorThemeModel.append({"colors": "blue/red", "text": i18n.tr("blue/red")}) |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
OptionSelector { |
| 38 |
id: colorThemeSetting |
| 39 |
text: i18n.tr("Temperature colors") |
| 40 |
model: colorThemeModel |
| 41 |
containerHeight: itemHeight * colorThemeModel.count |
| 42 |
delegate: OptionSelectorDelegate { |
| 43 |
text: i18n.tr(model.text) |
| 44 |
height: units.gu(4) |
| 45 |
} |
| 46 |
onDelegateClicked: setTemperatureColors(model.get(index).colors) |
| 47 |
Component.onCompleted: { |
| 48 |
/* |
| 49 |
The Component.onCompleted of the OptionSelector finishes BEFORE |
| 50 |
the onCompleted events of the delegates or the model. |
| 51 |
That is why the initialize() needs to be called here rather than |
| 52 |
in the Component.onCompleted of the ListModel. |
| 53 |
*/ |
| 54 |
colorThemeModel.initialize() |
| 55 |
for (var i = 0; i < colorThemeModel.count; ++i) { |
| 56 |
if (colorThemeModel.get(i).colors === settings.colorTheme) { |
| 57 |
colorThemeSetting.selectedIndex = i |
| 58 |
return |
| 59 |
} |
| 60 |
} |
| 61 |
colorThemeSetting.selectedIndex = 0 // in case no match is found due to broken settings |
| 62 |
} |
| 63 |
} |
| 64 |
} |