22 #include <QTextStream>
24 #include <kactioncollection.h>
25 #include <kapplication.h>
27 #include <knuminput.h>
28 #include <kcombobox.h>
29 #include <kpushbutton.h>
30 #include <kcolordialog.h>
31 #include <kmessagebox.h>
32 #include <kinputdialog.h>
33 #include <kstandarddirs.h>
50 QPixmap col( 30, 20 );
52 col.fill( itemColor );
54 item->setData( Qt::DecorationRole, col );
58 PresetBox->addItem(
i18nc(
"use default color scheme",
"Default Colors" ) );
59 PresetBox->addItem(
i18nc(
"use 'star chart' color scheme",
"Star Chart" ) );
60 PresetBox->addItem(
i18nc(
"use 'night vision' color scheme",
"Night Vision" ) );
61 PresetBox->addItem(
i18nc(
"use 'moonless night' color scheme",
"Moonless Night" ) );
63 PresetFileList.append(
"classic.colors" );
64 PresetFileList.append(
"chart.colors" );
65 PresetFileList.append(
"night.colors" );
66 PresetFileList.append(
"moonless-night.colors" );
69 QString line, schemeName, filename;
70 file.setFileName( KStandardDirs::locate(
"appdata",
"colors.dat" ) );
71 if ( file.exists() && file.open( QIODevice::ReadOnly ) ) {
74 while ( !stream.atEnd() ) {
75 line = stream.readLine();
76 schemeName = line.left( line.indexOf(
':' ) );
77 filename = line.mid( line.indexOf(
':' ) +1, line.length() );
78 PresetBox->addItem( schemeName );
79 PresetFileList.append( filename );
85 kcfg_StarColorMode->addItem(
i18nc(
"use realistic star colors",
"Real Colors" ) );
86 kcfg_StarColorMode->addItem(
i18nc(
"show stars as red circles",
"Solid Red" ) );
87 kcfg_StarColorMode->addItem(
i18nc(
"show stars as black circles",
"Solid Black" ) );
88 kcfg_StarColorMode->addItem(
i18nc(
"show stars as white circles",
"Solid White" ) );
92 kcfg_StarColorIntensity->setEnabled(
false );
94 kcfg_StarColorIntensity->setEnabled(
true );
96 connect( ColorPalette, SIGNAL( itemClicked( QListWidgetItem* ) ),
this, SLOT( newColor( QListWidgetItem* ) ) );
97 connect( kcfg_StarColorIntensity, SIGNAL( valueChanged(
int ) ),
this, SLOT( slotStarColorIntensity(
int ) ) );
98 connect( kcfg_StarColorMode, SIGNAL( activated(
int ) ),
this, SLOT( slotStarColorMode(
int ) ) );
99 connect( PresetBox, SIGNAL( currentRowChanged(
int ) ),
this, SLOT( slotPreset(
int ) ) );
100 connect( AddPreset, SIGNAL( clicked() ),
this, SLOT( slotAddPreset() ) );
101 connect( RemovePreset, SIGNAL( clicked() ),
this, SLOT( slotRemovePreset() ) );
103 RemovePreset->setEnabled(
false );
109 void OpsColors::newColor( QListWidgetItem *item ) {
112 QPixmap pixmap( 30, 20 );
115 int index = ColorPalette->row( item );
116 if ( index < 0 || index >= ColorPalette->count() )
return;
118 if ( KColorDialog::getColor( col ) ) NewColor = col;
121 if ( NewColor.isValid() ) {
122 pixmap.fill( NewColor );
123 item->setData( Qt::DecorationRole, pixmap );
125 ksw->data()->colorScheme()->setColor( ksw->data()->colorScheme()->keyAt( index ), NewColor.name() );
128 ksw->map()->forceUpdate();
131 void OpsColors::slotPreset(
int index ) {
132 QString sPreset = PresetFileList.at( index );
133 setColors( sPreset );
136 bool OpsColors::setColors(
const QString &filename ) {
137 QPixmap temp( 30, 20 );
141 test.setFileName( KStandardDirs::locateLocal(
"appdata", filename ) );
142 if ( test.exists() ) RemovePreset->setEnabled(
true );
143 else RemovePreset->setEnabled(
false );
146 QString actionName = QString(
"cs_" + filename.left(filename.indexOf(
".colors"))).toUtf8();
147 QAction *a = ksw->actionCollection()->action( actionName );
148 if ( a ) a->setChecked(
true );
149 kapp->processEvents();
151 kcfg_StarColorMode->setCurrentIndex( ksw->data()->colorScheme()->starColorMode() );
152 kcfg_StarColorIntensity->setValue( ksw->data()->colorScheme()->starColorIntensity() );
154 for (
unsigned int i=0; i < ksw->data()->colorScheme()->numberOfColors(); ++i ) {
155 QColor itemColor( ksw->data()->colorScheme()->colorAt( i ) );
156 temp.fill( itemColor );
157 ColorPalette->item( i )->setData( Qt::DecorationRole, temp );
158 ColorPalette->item( i )->setData(
ItemColorData, itemColor );
161 ksw->map()->forceUpdate();
165 void OpsColors::slotAddPreset() {
166 bool okPressed =
false;
167 QString schemename = KInputDialog::getText( i18n(
"New Color Scheme" ),
168 i18n(
"Enter a name for the new color scheme:" ),
169 QString(), &okPressed, 0 );
171 if ( okPressed && ! schemename.isEmpty() ) {
172 if ( ksw->data()->colorScheme()->save( schemename ) ) {
173 QListWidgetItem *item =
new QListWidgetItem( schemename, PresetBox );
174 QString fname = ksw->data()->colorScheme()->fileName();
175 PresetFileList.append( fname );
176 QString actionName = QString(
"cs_" + fname.left(fname.indexOf(
".colors"))).toUtf8();
177 ksw->addColorMenuItem( schemename, actionName );
179 QAction *a = ksw->actionCollection()->action( actionName );
180 if ( a ) a->setChecked(
true );
181 PresetBox->setCurrentItem( item );
186 void OpsColors::slotRemovePreset() {
187 QListWidgetItem *current = PresetBox->currentItem();
188 if ( !current )
return;
189 QString name = current->text();
190 QString filename = PresetFileList[ PresetBox->currentRow() ];
192 cdatFile.setFileName( KStandardDirs::locateLocal(
"appdata",
"colors.dat" ) );
195 ksw->removeColorMenuItem( QString(
"cs_" + filename.left( filename.indexOf(
".colors"))).toUtf8() );
197 if ( !cdatFile.exists() || !cdatFile.open( QIODevice::ReadWrite ) ) {
198 QString message = i18n(
"Local color scheme index file could not be opened.\nScheme cannot be removed." );
199 KMessageBox::sorry( 0, message, i18n(
"Could Not Open File" ) );
204 PresetBox->setCurrentRow(0);
206 RemovePreset->setEnabled(
false );
211 bool removed =
false;
213 while ( !stream.atEnd() ) {
214 QString line = stream.readLine();
215 if ( line.left( line.indexOf(
':') ) != name ) slist.append( line );
221 colorFile.setFileName( KStandardDirs::locateLocal(
"appdata", filename ) );
222 if ( !colorFile.remove() ) {
223 QString message = i18n(
"Could not delete the file: %1", colorFile.fileName() );
224 KMessageBox::sorry( 0, message, i18n(
"Error Deleting File" ) );
229 cdatFile.open( QIODevice::ReadWrite );
231 for(
int i=0; i<slist.count(); ++i )
232 stream << slist[i] << endl;
234 QString message = i18n(
"Could not find an entry named %1 in colors.dat.", name );
235 KMessageBox::sorry( 0, message, i18n(
"Scheme Not Found" ) );
241 void OpsColors::slotStarColorMode(
int i ) {
242 ksw->data()->colorScheme()->setStarColorMode( i );
244 if ( ksw->data()->colorScheme()->starColorMode() != 0 )
245 kcfg_StarColorIntensity->setEnabled(
false );
247 kcfg_StarColorIntensity->setEnabled(
true );
250 void OpsColors::slotStarColorIntensity(
int i ) {
251 ksw->data()->colorScheme()->setStarColorIntensity( i );
254 #include "opscolors.moc"
QString nameAt(int i) const
i the index of the long name to retrieve
ColorScheme * colorScheme()
This is the main window for KStars.
int starColorIntensity() const
unsigned int numberOfColors() const
QColor colorAt(int i) const
i the index of the color to retrieve
i18nc("string from libindi, used in the config dialog","100x")
KStarsData * data() const
int starColorMode() const