21 #include <QTextStream>
26 #include <kmessagebox.h>
27 #include <kstandarddirs.h>
28 #include <kconfiggroup.h>
43 appendItem(
"SkyColor", i18n(
"Sky"),
"#000000");
44 appendItem(
"MessColor", i18n(
"Messier Object"),
"#008f00");
45 appendItem(
"NGCColor",
i18nc(
"New General Catalog object",
"NGC Object"),
"#006666");
46 appendItem(
"ICColor",
i18nc(
"Index Catalog object",
"IC Object"),
"#382a7d");
47 appendItem(
"HSTColor",
48 i18nc(
"Object with extra attached URLs",
"Object w/ Links"),
"#930000");
49 appendItem(
"SNameColor", i18n(
"Star Name"),
"#577d7d");
50 appendItem(
"DSNameColor", i18n(
"Deep Sky Object Name"),
"#75759c");
51 appendItem(
"PNameColor", i18n(
"Planet Name"),
"#ac9800");
52 appendItem(
"CNameColor",
53 i18nc(
"Constellation Name",
"Constell. Name"),
"#718488");
54 appendItem(
"CLineColor",
55 i18nc(
"Constellation Line",
"Constell. Line"),
"#3d3d3d");
56 appendItem(
"CBoundColor",
57 i18nc(
"Constellation Boundary",
"Constell. Boundary"),
"#222f2f");
58 appendItem(
"CBoundHighColor",
59 i18nc(
"Highlighted Constellation Boundary",
"Constell. Boundary Highlight"),
"#445555");
61 i18nc(
"refers to the band of stars in the sky due to the Galactic plane",
"Milky Way"),
"#0d1115");
62 appendItem(
"EqColor", i18n(
"Equator"),
"#909090");
63 appendItem(
"EclColor", i18n(
"Ecliptic"),
"#613d12");
64 appendItem(
"HorzColor", i18n(
"Horizon"),
"#091f14");
65 appendItem(
"CompassColor", i18n(
"Compass Labels"),
"#909055");
66 appendItem(
"EquatorialGridColor", i18n(
"Equatorial Coordinate Grid"),
"#445566");
67 appendItem(
"HorizontalGridColor", i18n(
"Horizontal Coordinate Grid"),
"#091f14");
68 appendItem(
"BoxTextColor", i18n(
"Info Box Text"),
"#d2dbef");
69 appendItem(
"BoxGrabColor", i18n(
"Info Box Selected"),
"#900000");
70 appendItem(
"BoxBGColor", i18n(
"Info Box Background"),
"#000000");
71 appendItem(
"TargetColor", i18n(
"Target Indicator"),
"#DD0000");
72 appendItem(
"UserLabelColor", i18n(
"User Labels"),
"#AAAAAA");
73 appendItem(
"PlanetTrailColor", i18n(
"Planet Trails"),
"#993311");
74 appendItem(
"AngularRuler", i18n(
"Angular Distance Ruler"),
"#445566");
75 appendItem(
"ObsListColor", i18n(
"Observing List Label"),
"#FF0000");
76 appendItem(
"StarHopRouteColor", i18n(
"Star-Hop Route"),
"#00FFFF");
77 appendItem(
"VisibleSatColor", i18n(
"Visible Satellites"),
"#00FF00");
78 appendItem(
"SatColor", i18n(
"Satellites"),
"#FF0000");
79 appendItem(
"SatLabelColor", i18n(
"Satellites Labels"),
"#640000");
80 appendItem(
"SupernovaColor", i18n(
"Supernovae"),
"#FFA500");
87 StarColorIntensity = 4;
90 void ColorScheme::appendItem(QString key, QString name, QString def) {
91 KeyName.append( key );
93 Default.append( def );
99 kWarning() << i18n(
"No color named \"%1\" found in color scheme.", name ) ;
101 return QColor( Qt::white );
103 return QColor( Palette[ name ] );
107 return QColor( Palette[ KeyName.at(i) ] );
115 return KeyName.at(i);
119 return nameAt( KeyName.indexOf( key ) );
124 Palette.insert( key, color );
126 KConfigGroup cg = KGlobal::config()->group(
"Colors" );
127 cg.writeEntry( key, color );
131 QString filename = name.toLower().trimmed();
133 int inew = 0, iold = 0;
137 if ( name ==
i18nc(
"use default color scheme",
"Default Colors") )
138 filename =
"classic.colors";
139 if ( name ==
i18nc(
"use 'star chart' color scheme",
"Star Chart") )
140 filename =
"chart.colors";
141 if ( name ==
i18nc(
"use 'night vision' color scheme",
"Night Vision") )
142 filename =
"night.colors";
145 if ( filename.endsWith( QLatin1String(
".colors" ) ) )
151 if ( !filename.isEmpty() ) {
152 filename.replace(
' ',
'-' ).append(
".colors" );
157 kDebug() << i18n(
"Unable to load color scheme named %1. Also tried %2.", name, filename );
166 QString line = stream.readLine();
167 int newmode = line.left(1).toInt( &ok );
170 if( line.contains(
':') ) {
171 int newintens = line.mid( line.indexOf(
':')+1, 2 ).toInt( &ok );
178 while ( !stream.atEnd() ) {
179 line = stream.readLine();
181 if ( line.count(
':')==1 ) {
183 if ( iold )
return false;
186 QString tkey = line.mid( line.indexOf(
':')+1 ).trimmed();
187 QString tname = line.left( line.indexOf(
':')-1 );
189 if ( KeyName.contains( tkey ) ) {
192 QString k( line.mid( 5 ).trimmed() +
"Color" );
193 if ( KeyName.contains( k ) ) {
196 kWarning() <<
"Could not use the key \"" << tkey
197 <<
"\" from the color scheme file \"" << filename
198 <<
"\". I also tried \"" << k <<
"\"." << endl;
204 if ( inew )
return false;
209 foreach(
const QString& key, KeyName)
223 QString filename = name.toLower().trimmed();
224 if ( !filename.isEmpty() ) {
225 for(
int i=0; i<filename.length(); ++i)
226 if ( filename.at(i)==
' ' ) filename.replace( i, 1,
"-" );
228 filename = filename.append(
".colors" );
229 file.setFileName( KStandardDirs::locateLocal(
"appdata", filename ) );
231 if ( file.exists() || !file.open( QIODevice::ReadWrite | QIODevice::Append ) ) {
232 QString message = i18n(
"Local color scheme file could not be opened.\nScheme cannot be recorded." );
233 KMessageBox::sorry( 0, message, i18n(
"Could Not Open File" ) );
237 stream << StarColorMode <<
":" << StarColorIntensity << endl;
239 foreach(
const QString& key, KeyName )
240 stream << Palette[ key ] <<
" :" << key << endl;
244 file.setFileName( KStandardDirs::locateLocal(
"appdata",
"colors.dat" ) );
246 if ( !file.open( QIODevice::ReadWrite | QIODevice::Append ) ) {
247 QString message = i18n(
"Local color scheme index file could not be opened.\nScheme cannot be recorded." );
248 KMessageBox::sorry( 0, message, i18n(
"Could Not Open File" ) );
252 stream << name <<
":" << filename << endl;
256 QString message = i18n(
"Invalid filename requested.\nScheme cannot be recorded." );
257 KMessageBox::sorry( 0, message, i18n(
"Invalid Filename" ) );
267 KConfigGroup cg = KGlobal::config()->group(
"Colors" );
269 for (
int i=0; i < KeyName.size(); ++i )
270 setColor( KeyName.at(i), cg.readEntry( KeyName.at(i).toUtf8().constData(), Default.at( i ) ) );
274 FileName = cg.readEntry(
"ColorSchemeFile",
"classic.colors" );
278 KConfigGroup cg = KGlobal::config()->group(
"Colors" );
279 for (
int i=0; i < KeyName.size(); ++i ) {
280 QString c =
colorNamed( KeyName.at(i) ).name();
281 cg.writeEntry( KeyName.at(i), c );
289 StarColorMode = mode;
295 StarColorIntensity = intens;
301 StarColorMode = mode;
302 StarColorIntensity = intens;
static void initStarImages()
Recalculates the star pixmaps.
void setStarColorMode(int mode)
Set the star color mode used by the color scheme mode the star color mode to use. ...
void setStarColorModeIntensity(int mode, int intens)
Set the star color mode and intensity value used by the color scheme mode the star color mode to use ...
QString nameAt(int i) const
i the index of the long name to retrieve
static void setStarColorIntensity(uint v)
Set Saturation level of star colors.
QColor colorNamed(const QString &name) const
Retrieve a color by name.
bool openDataFile(QFile &file, const QString &filename)
Attempt to open the data file named filename, using the QFile object "file".
int starColorIntensity() const
void loadFromConfig()
Read color-scheme data from the Config object.
QString keyAt(int i) const
i the index of the key name to retrieve
QColor colorAt(int i) const
i the index of the color to retrieve
bool hasColorNamed(const QString &name) const
i18nc("string from libindi, used in the config dialog","100x")
static void setStarColorMode(uint v)
Set Mode for rendering stars.
bool load(const QString &filename)
Load a color scheme from a *.colors file filename the filename of the color scheme to be loaded...
void setColor(const QString &key, const QString &color)
Change the color with the given key to the given value key the key-name of the color to be changed co...
void setStarColorIntensity(int intens)
Set the star color intensity value used by the color scheme intens The star color intensity value...
void saveToConfig()
Save color-scheme data to the Config object.
bool save(const QString &name)
Save the current color scheme to a *.colors file.
int starColorMode() const
ColorScheme()
Constructor.
QString nameFromKey(const QString &key) const