Kstars

ColorSchemePopup.qml
1// SPDX-FileCopyrightText: 2016 Artem Fedoskin <afedoskin3@gmail.com>
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4import QtQuick.Controls 2.0
5import QtQuick 2.6
6import QtQuick.Layouts 1.1
7import "../../constants" 1.0
8import "../../modules"
9import QtQuick.Controls.Material 2.0
10
11Popup {
12 //Change it to Popup when it will become more stable
13 id: colorSPopup
14 focus: true
15 modal: true
16 height: parent.height > colorsList.implicitHeight ? colorsList.implicitHeight : parent.height
17 signal colorSchemeChanged()
18
19 property string currentCScheme: colorsModel.get(colorsList.currentIndex).scheme
20
21 onCurrentCSchemeChanged: {
22 updateTheme(currentCScheme)
23 }
24
25 function updateTheme(colorScheme) {
26 if ( Qt.platform.os == "android" ) {
27 if ( colorScheme == "cs_night") {
28 window.Material.theme = Material.Dark //On Android we want to have dark theme only for cs_night
29 } else {
30 window.Material.theme = Material.Light //Light theme for all other color schemes as on Android they are light
31 }
32 } else {
33 window.Material.theme = Material.Dark //Dark theme is suitable for all color themes
34 }
35 }
36
37 function formatColorScheme(schemeName) {
38 return schemeName.substring(3) + ".colors"
39 }
40
41 background: Rectangle {
42 anchors.fill: parent
43 color: Num.sysPalette.base
44 }
45
46 KSListView {
47 id: colorsList
48 anchors.centerIn: parent
49 checkCurrent: true
50
51 model: ListModel {
52 id: colorsModel
53
54 Component.onCompleted: {
55 append({ name: xi18n("Classic"), scheme: "cs_classic" });
56 append({ name: xi18n("Star Chart"), scheme: "cs_chart" });
57 append({ name: xi18n("Night Vision"), scheme: "cs_night" });
58 append({ name: xi18n("Moonless Night"), scheme: "cs_moonless-night" });
59 }
60 }
61
62 Connections {
63 target: KStarsLite
64 onDataLoadFinished: {
65 //Set current index to current scheme color
66 var colorScheme = KStarsData.colorSchemeName()
67 for(var i = 0; i < colorsList.model.count; ++i) {
68 if(formatColorScheme(colorsList.model.get(i).scheme) == colorScheme) {
69 colorsList.currentIndex = i
70 //KStarsLite.loadColorScheme(colorScheme)
71 }
72 }
73 }
74 }
75
76 onClicked: {
77 var item = colorsModel.get(colorsList.currentIndex)
78
79 KStarsLite.loadColorScheme(formatColorScheme(item.scheme));
80 skyMapLite.notification.showNotification("Set color scheme to " + item.name)
81
82 colorSchemeChanged()
83 close()
84 }
85
86 textRole: "name"
87 }
88}
KStarsData is the backbone of KStars.
Definition kstarsdata.h:74
Q_INVOKABLE QString colorSchemeName()
Definition kstarsdata.h:189
This class loads QML files and connects SkyMapLite and KStarsData Unlike KStars class it is not a mai...
Definition kstarslite.h:47
void loadColorScheme(const QString &name)
Load a color scheme.
QString xi18n(const char *text, const TYPE &arg...)
QWidget * window(QObject *job)
QString name(StandardAction id)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:16:41 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.