File indexing completed on 2024-04-21 03:42:13
0001 /* 0002 SPDX-FileCopyrightText: 2002 Jason Harris <kstars@30doradus.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <QColor> 0010 #include <QMap> 0011 #include <QStringList> 0012 0013 /** 0014 * @class ColorScheme 0015 * This class stores all of the adjustable colors in KStars, in 0016 * a QMap object keyed by the names of the colors. It also stores 0017 * information on how stars are to be rendered in the map 0018 * (with realistic colors, or as solid red/whit/black circles). 0019 * In addition to the brief "Key names" used to index the colors in 0020 * the QMap, each color has a "long name" description that is a bit 0021 * more verbose, and suitable for UI display. 0022 * 0023 * @author Jason Harris 0024 * @version 1.0 0025 */ 0026 class ColorScheme 0027 { 0028 public: 0029 /** 0030 * Constructor. Enter all adjustable colors and their default 0031 * values into the QMap. Also assign the corresponding long names. 0032 */ 0033 ColorScheme(); 0034 0035 /** @return true if the Palette contains the given key name */ 0036 bool hasColorNamed(const QString &name) const { return (Palette.contains(name)); } 0037 0038 /** 0039 * @short Retrieve a color by name. 0040 * @p name the key name of the color to be retrieved. 0041 * @return the requested color, or Qt::white if color name not found. 0042 */ 0043 QColor colorNamed(const QString &name) const; 0044 0045 /** 0046 * @p i the index of the color to retrieve 0047 * @return a color by its index in the QMap 0048 */ 0049 QColor colorAt(int i) const; 0050 0051 /** 0052 * @p i the index of the long name to retrieve 0053 * @return the name of the color at index i 0054 */ 0055 QString nameAt(int i) const; 0056 0057 /** 0058 * @p i the index of the key name to retrieve 0059 * @return the key name of the color at index i 0060 */ 0061 QString keyAt(int i) const; 0062 0063 /** 0064 * @return the long name of the color whose key name is given 0065 * @p key the key name identifying the color. 0066 */ 0067 QString nameFromKey(const QString &key) const; 0068 0069 /** 0070 * Change the color with the given key to the given value 0071 * @p key the key-name of the color to be changed 0072 * @p color the new color value 0073 */ 0074 void setColor(const QString &key, const QString &color); 0075 0076 /** 0077 * Load a color scheme from a *.colors file 0078 * @p filename the filename of the color scheme to be loaded. 0079 * @return true if the scheme was successfully loaded 0080 */ 0081 bool load(const QString &filename); 0082 0083 /** 0084 * Save the current color scheme to a *.colors file. 0085 * @p name the filename to create 0086 * @return true if the color scheme is successfully writen to a file 0087 */ 0088 bool save(const QString &name); 0089 0090 /** @return the Filename associated with the color scheme. */ 0091 QString fileName() const { return FileName; } 0092 0093 /** Read color-scheme data from the Config object. */ 0094 void loadFromConfig(); 0095 0096 /** Save color-scheme data to the Config object. */ 0097 void saveToConfig(); 0098 0099 /** @return the number of colors in the color scheme. */ 0100 unsigned int numberOfColors() const { return (int)Palette.size(); } 0101 0102 /** @return the star color mode used by the color scheme */ 0103 int starColorMode() const { return StarColorMode; } 0104 0105 /** @return True if dark palette colors are used by the color scheme */ 0106 bool useDarkPalette() const { return DarkPalette == 1; } 0107 0108 /** @return the star color intensity value used by the color scheme */ 0109 int starColorIntensity() const { return StarColorIntensity; } 0110 0111 /** 0112 * Set the star color mode used by the color scheme 0113 * @p mode the star color mode to use 0114 */ 0115 void setStarColorMode(int mode); 0116 0117 /** 0118 * Set the star color intensity value used by the color scheme 0119 * @p intens The star color intensity value 0120 */ 0121 void setStarColorIntensity(int intens); 0122 0123 /** 0124 * Set the star color mode and intensity value used by the color scheme 0125 * @p mode the star color mode to use 0126 * @p intens The star color intensity value 0127 */ 0128 void setStarColorModeIntensity(int mode, int intens); 0129 0130 /** 0131 * @brief setDarkPalette Set whether the color schemes uses dark palette 0132 * @param enable True to use dark palette. False to use application default palette 0133 */ 0134 void setDarkPalette(bool enable); 0135 0136 private: 0137 /** Append items to all string lists. */ 0138 void appendItem(const QString &key, const QString &name, const QString &def); 0139 0140 int StarColorMode { 0 }; 0141 int StarColorIntensity { 0 }; 0142 int DarkPalette { 0 }; 0143 QString FileName; 0144 QStringList KeyName, Name, Default; 0145 QMap<QString, QString> Palette; 0146 };