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; }
bool ColorSchemeManager::loadColorScheme(const QString& filePath) { if (!filePath.endsWith(QLatin1String(".colorscheme")) || !QFile::exists(filePath)) return false; QFileInfo info(filePath); KConfig config(filePath , KConfig::NoGlobals); ColorScheme* scheme = new ColorScheme(); scheme->setName(info.baseName()); scheme->read(config); if (scheme->name().isEmpty()) { qWarning() << "Color scheme in" << filePath << "does not have a valid name and was not loaded."; delete scheme; return false; } 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 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()); } }
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")); }
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); } } }