bool ColorSchemeManager::loadColorScheme( const QString &filePath ) { if ( !filePath.endsWith( QLatin1String( ".colorscheme" ) ) || !QFile::exists( filePath ) ) return false; QFileInfo info( filePath ); const QString &schemeName = info.baseName(); ColorScheme *scheme = new ColorScheme(); scheme->setName( schemeName ); scheme->read( filePath ); if ( scheme->name().isEmpty() ) { qDebug() << "Color scheme in" << filePath << "does not have a valid name and was not loaded."; delete scheme; return false; } if ( !_colorSchemes.contains( schemeName ) ) { _colorSchemes.insert( schemeName, scheme ); } else { qDebug() << "color scheme with name" << schemeName << "has already been" << "found, ignoring."; delete scheme; } return true; }
void FontSettingsPage::copyColorScheme(const QString &name) { int index = d_ptr->m_ui->schemeComboBox->currentIndex(); if (index == -1) return; const ColorSchemeEntry &entry = d_ptr->m_schemeListModel->colorSchemeAt(index); QString baseFileName = QFileInfo(entry.fileName).completeBaseName(); baseFileName += QLatin1String("_copy%1.xml"); QString fileName = createColorSchemeFileName(baseFileName); if (!fileName.isEmpty()) { // Ask about saving any existing modifactions maybeSaveColorScheme(); // Make sure we're copying the current version d_ptr->m_value.setColorScheme(d_ptr->m_ui->schemeEdit->colorScheme()); ColorScheme scheme = d_ptr->m_value.colorScheme(); scheme.setDisplayName(name); if (scheme.save(fileName, Core::ICore::mainWindow())) d_ptr->m_value.setColorSchemeFileName(fileName); refreshColorSchemeList(); } }
bool ColorSchemeManager::loadKDE3ColorScheme( const QString &filePath ) { QFile file( filePath ); if ( !filePath.endsWith( QLatin1String( ".schema" ) ) || !file.open( QIODevice::ReadOnly ) ) return false; KDE3ColorSchemeReader reader( &file ); ColorScheme *scheme = reader.read(); scheme->setName( QFileInfo( file ).baseName() ); file.close(); if ( scheme->name().isEmpty() ) { qDebug() << "color scheme name is not valid."; delete scheme; return false; } QFileInfo info( filePath ); if ( !_colorSchemes.contains( info.baseName() ) ) _colorSchemes.insert( scheme->name(), scheme ); else { qDebug() << "color scheme with name" << scheme->name() << "has already been" << "found, ignoring."; delete scheme; } return true; }
void KStars::setColor( const QString &name, const QString &value ) { ColorScheme *cs = data()->colorScheme(); if ( cs->hasColorNamed( name ) ) { cs->setColor( name, value ); map()->forceUpdate(); } }
inline void sample(const Point& sample, const TileState& tile) { m_pointset.push_back(sample); switch(m_colorization) { case 0: //none m_colors.push_back(m_colorScheme.black()); break; case 1: //subdiv level m_colors.push_back(m_colorScheme[ tile.lvl()//*4+2 ]); break; case 2: //parent m_colors.push_back(m_colorScheme[ tile.offsetId()%37 ]); break; case 3: //rank m_colors.push_back(m_colorScheme[ tile.rank() ]); break; default: //default m_colors.push_back(m_colorScheme.black()); } }
void SettingsDialog::updateSchemeButton_clicked() { int index; QString oldName = schemeComboBox->currentText(); QString newName = schemeLineEdit->text(); if (schemeComboBox->currentIndex() > 1) { // Edit scheme if (newName != oldName) { if (ColorScheme::lookupScheme(newName) == true) goto conflict; index = schemeComboBox->currentIndex(); schemeComboBox->setItemText(index, newName); } for (int i = 0; i < globalSettings.colorSchemes.size(); i++) { if (oldName == globalSettings.colorSchemes[i].name()) { globalSettings.colorSchemes[i].setName(newName); updateSchemeColors(&globalSettings.colorSchemes[i]); break; } } } else if (schemeComboBox->currentIndex() == 1) { // New Scheme if (ColorScheme::lookupScheme(newName) == true) goto conflict; ColorScheme scheme; my.newScheme = newName; scheme.setName(newName); updateSchemeColors(&scheme); index = globalSettings.colorSchemes.size(); globalSettings.colorSchemes.append(scheme); pmchart->newScheme(my.newScheme); schemeComboBox->blockSignals(true); schemeComboBox->addItem(newName); schemeComboBox->setCurrentIndex(index + 2); schemeComboBox->blockSignals(false); } else if (schemeComboBox->currentIndex() == 0) { // Default updateSchemeColors(&globalSettings.defaultScheme); } globalSettings.colorSchemesModified = true; writeSettings(); return; conflict: QString msg = newName; msg.prepend("New scheme name \""); msg.append("\" conflicts with an existing name"); QMessageBox::warning(this, pmProgname, msg); }
void EditProfileDialog::showColorSchemeEditor(bool isNewScheme) { QModelIndexList selected = _ui->colorSchemeList->selectionModel()->selectedIndexes(); QAbstractItemModel* model = _ui->colorSchemeList->model(); const ColorScheme* colors = 0; if ( !selected.isEmpty() ) colors = model->data(selected.first(),Qt::UserRole+1).value<const ColorScheme*>(); else colors = ColorSchemeManager::instance()->defaultColorScheme(); Q_ASSERT(colors); KDialog* dialog = new KDialog(this); if ( isNewScheme ) dialog->setCaption(i18n("New Color Scheme")); else dialog->setCaption(i18n("Edit Color Scheme")); ColorSchemeEditor* editor = new ColorSchemeEditor; dialog->setMainWidget(editor); editor->setup(colors); if ( isNewScheme ) editor->setDescription(i18n("New Color Scheme")); if ( dialog->exec() == QDialog::Accepted ) { ColorScheme* newScheme = new ColorScheme(*editor->colorScheme()); // if this is a new color scheme, pick a name based on the description if ( isNewScheme ) newScheme->setName(newScheme->description()); ColorSchemeManager::instance()->addColorScheme( newScheme ); updateColorSchemeList(true); preview(Profile::ColorScheme,newScheme->name()); } }
ColorScheme::ColorScheme(const ColorScheme& other) : _table(0) , _randomTable(0) , _opacity(other._opacity) , _wallpaper(other._wallpaper) { setName(other.name()); setDescription(other.description()); if (other._table != 0) { for (int i = 0 ; i < TABLE_COLORS ; i++) setColorTableEntry(i, other._table[i]); } if (other._randomTable != 0) { for (int i = 0 ; i < TABLE_COLORS ; i++) { const RandomizationRange& range = other._randomTable[i]; setRandomizationRange(i, range.hue, range.saturation, range.value); } } }
void PListDocumentTest::testColorsCheme() { ColorScheme scheme; SubScheme value; bool result = scheme.loadColorScheme("Amy.xml"); value = scheme.scheme("comment.block"); QCOMPARE(result,true); QCOMPARE(scheme.name(),QString("Amy")); QCOMPARE(scheme.background(),QColor("#200020")); QCOMPARE(scheme.caret(),QColor("#7070FF")); QCOMPARE(value.name,QString("Comment")); QCOMPARE(value.scope,QString("comment.block")); QCOMPARE(value.background,QColor("#200020")); QCOMPARE(value.fontStyle,QString("italic")); QCOMPARE(value.foreground,QColor("#404080")); value = scheme.scheme("string"); QCOMPARE(value.foreground,QColor("#999999")); }
void ColorsPreflet::MessageReceived(BMessage *msg) { switch(msg->what) { case M_POINTSIZE_CHANGED: { int newsize = fFontSize->Value(); MainWindow->main.editarea->SetFontSize(newsize); fParent->SettingsChanged(); } break; case M_SCHEMESEL_CHANGED: { int32 newindex; msg->FindInt32("newindex", &newindex); if (CurrentColorScheme.GetLoadedSchemeIndex() == newindex) break; BMenuItem *item = fSchemeMenu->ItemAt(newindex); if (item) item->SetMarked(true); CurrentColorScheme.SaveScheme(); CurrentColorScheme.LoadScheme(newindex); editor.curev->FullRedrawView(); fColorsList->ResetRevertBuffer(); ReloadSettings(); } break; case M_SCHEME_DELETE: { int numschemes = ColorScheme::GetNumColorSchemes(); if (numschemes <= 1) { (new BAlert("", "Cannot delete that color scheme. There must always least one scheme available.", "OK", NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go(); break; } BString prompt; prompt << "Are you sure you want to delete the scheme \"" << CurrentColorScheme.GetSchemeName() << "\"?"; BAlert *alert = new BAlert("", prompt.String(), "No", "Yes"); if (alert->Go()) { int newindex; int curscheme = CurrentColorScheme.GetLoadedSchemeIndex(); // make some other scheme active if (curscheme == numschemes - 1) newindex = curscheme - 1; else newindex = curscheme + 1; BMessage msg(M_SCHEMESEL_CHANGED); msg.AddInt32("newindex", newindex); MessageReceived(&msg); // now, delete the scheme ColorScheme::DeleteScheme(curscheme); // fixup loaded index for the deletion if (newindex > curscheme) CurrentColorScheme.LoadScheme(curscheme); UpdateSchemesMenu(); fColorsList->ResetRevertBuffer(); ReloadSettings(); } } break; case M_SCHEME_NEW: { BString *schemeName; BString defaultName(CurrentColorScheme.GetSchemeName()); defaultName.Append(" Copy"); schemeName = InputBox::Go(MainWindow, "New Scheme", "Name of new scheme:", defaultName.String()); if (!schemeName) break; if (!schemeName->String()[0]) break; stat("creating new scheme '%s'", schemeName->String()); // duplicate current scheme into the next available index CurrentColorScheme.SaveScheme(); ColorScheme tempscheme = CurrentColorScheme; int count = ColorScheme::GetNumColorSchemes(); tempscheme.SetSchemeName(schemeName->String()); tempscheme.SaveScheme(count); UpdateSchemesMenu(); // set the new scheme to be active CurrentColorScheme.LoadScheme(count); BMenuItem *item = fSchemeMenu->ItemAt(count); if (item) item->SetMarked(true); // clean up and we're done fColorsList->ResetRevertBuffer(); delete schemeName; } break; case M_SCHEME_DEFAULTS: { BAlert *alert = new BAlert("", "This will erase all user color-schemes and reset" " colors to the built-in defaults. Is that want you" " want to do?", "Cancel", "Set Defaults", NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT); if (alert->Go()) { ColorScheme::ResetToDefaults(); CurrentColorScheme.LoadScheme(1); UpdateSchemesMenu(); editor.curev->FullRedrawView(); ReloadSettings(); fColorsList->ResetRevertBuffer(); fParent->SettingsChanged(); } } break; default: MessageView::MessageReceived(msg); break; } }