Warning, /education/kstars/kstars/kstarslite/qml/modules/popups/ColorSchemePopup.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-FileCopyrightText: 2016 Artem Fedoskin <afedoskin3@gmail.com>
0002 // SPDX-License-Identifier: GPL-2.0-or-later
0003 
0004 import QtQuick.Controls 2.0
0005 import QtQuick 2.6
0006 import QtQuick.Layouts 1.1
0007 import "../../constants" 1.0
0008 import "../../modules"
0009 import QtQuick.Controls.Material 2.0
0010 
0011 Popup {
0012     //Change it to Popup when it will become more stable
0013     id: colorSPopup
0014     focus: true
0015     modal: true
0016     height: parent.height > colorsList.implicitHeight ? colorsList.implicitHeight : parent.height
0017     signal colorSchemeChanged()
0018 
0019     property string currentCScheme: colorsModel.get(colorsList.currentIndex).scheme
0020 
0021     onCurrentCSchemeChanged: {
0022         updateTheme(currentCScheme)
0023     }
0024 
0025     function updateTheme(colorScheme) {
0026         if ( Qt.platform.os == "android" )  {
0027             if ( colorScheme == "cs_night") {
0028                 window.Material.theme = Material.Dark //On Android we want to have dark theme only for cs_night
0029             } else {
0030                 window.Material.theme = Material.Light //Light theme for all other color schemes as on Android they are light
0031             }
0032         } else {
0033             window.Material.theme = Material.Dark //Dark theme is suitable for all color themes
0034         }
0035     }
0036 
0037     function formatColorScheme(schemeName) {
0038         return schemeName.substring(3) + ".colors"
0039     }
0040 
0041     background: Rectangle {
0042         anchors.fill: parent
0043         color: Num.sysPalette.base
0044     }
0045 
0046     KSListView {
0047         id: colorsList
0048         anchors.centerIn: parent
0049         checkCurrent: true
0050 
0051         model: ListModel {
0052             id: colorsModel
0053 
0054             Component.onCompleted: {
0055                 append({ name: xi18n("Classic"), scheme: "cs_classic" });
0056                 append({ name: xi18n("Star Chart"), scheme: "cs_chart" });
0057                 append({ name: xi18n("Night Vision"), scheme: "cs_night" });
0058                 append({ name: xi18n("Moonless Night"), scheme: "cs_moonless-night" });
0059             }
0060         }
0061 
0062         Connections {
0063             target: KStarsLite
0064             onDataLoadFinished: {
0065                 //Set current index to current scheme color
0066                 var colorScheme = KStarsData.colorSchemeName()
0067                 for(var i = 0; i < colorsList.model.count; ++i) {
0068                     if(formatColorScheme(colorsList.model.get(i).scheme) == colorScheme) {
0069                         colorsList.currentIndex = i
0070                         //KStarsLite.loadColorScheme(colorScheme)
0071                     }
0072                 }
0073             }
0074         }
0075 
0076         onClicked: {
0077             var item = colorsModel.get(colorsList.currentIndex)
0078 
0079             KStarsLite.loadColorScheme(formatColorScheme(item.scheme));
0080             skyMapLite.notification.showNotification("Set color scheme to " + item.name)
0081 
0082             colorSchemeChanged()
0083             close()
0084         }
0085 
0086         textRole: "name"
0087     }
0088 }