Kstars

ColorSchemePopup.qml
1 // SPDX-FileCopyrightText: 2016 Artem Fedoskin <[email protected]>
2 // SPDX-License-Identifier: GPL-2.0-or-later
3 
4 import QtQuick.Controls 2.0
5 import QtQuick 2.6
6 import QtQuick.Layouts 1.1
7 import "../../constants" 1.0
8 import "../../modules"
9 import QtQuick.Controls.Material 2.0
10 
11 Popup {
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 }
This class loads QML files and connects SkyMapLite and KStarsData Unlike KStars class it is not a mai...
Definition: kstarslite.h:46
void loadColorScheme(const QString &name)
Load a color scheme.
Definition: kstarslite.cpp:297
QString xi18n(const char *text, const TYPE &arg...)
const char * name(StandardAction id)
KJOBWIDGETS_EXPORT QWidget * window(KJob *job)
Q_INVOKABLE QString colorSchemeName()
Definition: kstarsdata.h:186
virtual QVariant get(ScriptableExtension *callerPrincipal, quint64 objId, const QString &propName)
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Fri Aug 12 2022 04:00:53 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.