⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kgcolors.cpp

📁 LINUX 下, 以 QT/KDE 写的档案管理员
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    // create local color settings instance, which initially contains the setings from krConfig    KrColorSettings colorSettings;    // copy over local settings to color settings instance, which does not affect the persisted krConfig settings    QValueList<QString> names = KrColorSettings::getColorNames();    for ( QStringList::Iterator it = names.begin(); it != names.end(); ++it )    {        KonfiguratorColorChooser * chooser = getColorSelector( *it );        if (!chooser)            continue;        colorSettings.setColorTextValue( *it, chooser->getValue());        if (chooser->isValueRGB())            colorSettings.setColorValue( *it, chooser->getColor());        else            colorSettings.setColorValue( *it, QColor());    }    colorSettings.setBoolValue("KDE Default", generals->find( "KDE Default" )->isChecked());    colorSettings.setBoolValue("Enable Alternate Background", generals->find( "Enable Alternate Background" )->isChecked());    colorSettings.setBoolValue("Show Current Item Always", generals->find( "Show Current Item Always" )->isChecked());    colorSettings.setBoolValue("Dim Inactive Colors", generals->find( "Dim Inactive Colors" )->isChecked());    colorSettings.setNumValue("Dim Factor", dimFactor->value());    // let the color cache use the local color settings    colCache.setColors( colorSettings );    // ask the local color cache for certain color groups and use them to color the preview    QColorGroup cg;    colCache.getColors(cg, KrColorItemType(KrColorItemType::Directory, false, isActive, false, false));    pwDir->setColor( cg.text(), cg.background() );    colCache.getColors(cg, KrColorItemType(KrColorItemType::File, true, isActive, false, false));    pwFile->setColor( cg.text(), cg.background() );    colCache.getColors(cg, KrColorItemType(KrColorItemType::Executable, false, isActive, false, false));    pwApp->setColor( cg.text(), cg.background() );    colCache.getColors(cg, KrColorItemType(KrColorItemType::Symlink, true, isActive, false, false));    pwSymLink->setColor( cg.text(), cg.background() );    colCache.getColors(cg, KrColorItemType(KrColorItemType::InvalidSymlink, false, isActive, false, false));    pwInvLink->setColor( cg.text(), cg.background() );    colCache.getColors(cg, KrColorItemType(KrColorItemType::File, true, isActive, true, false));    pwCurrent->setColor( cg.highlightedText(), cg.highlight() );    colCache.getColors(cg, KrColorItemType(KrColorItemType::File, false, isActive, false, true));    pwMark1->setColor( cg.highlightedText(), cg.highlight() );    colCache.getColors(cg, KrColorItemType(KrColorItemType::File, true, isActive, false, true));    pwMark2->setColor( cg.highlightedText(), cg.highlight() );    colCache.getColors(cg, KrColorItemType(KrColorItemType::File, false, isActive, true, true));    pwMarkCur->setColor( cg.highlightedText(), cg.highlight() );  }else if( currentPage == 2 )  {    PreviewItem *pwDelete    = new PreviewItem( preview, i18n( "Delete" ) );    PreviewItem *pwRightCopy = new PreviewItem( preview, i18n( "Copy to right" ) );    PreviewItem *pwLeftCopy  = new PreviewItem( preview, i18n( "Copy to left" ) );    PreviewItem *pwDiffers   = new PreviewItem( preview, i18n( "Differing" ) );    PreviewItem *pwEquals    = new PreviewItem( preview, i18n( "Equals" ) );    pwEquals->setColor(    getColorSelector( "Synchronizer Equals Foreground" )->getColor(),                           getColorSelector( "Synchronizer Equals Background" )->getColor() );    pwDiffers->setColor(   getColorSelector( "Synchronizer Differs Foreground" )->getColor(),                           getColorSelector( "Synchronizer Differs Background" )->getColor() );    pwLeftCopy->setColor ( getColorSelector( "Synchronizer LeftCopy Foreground" )->getColor(),                           getColorSelector( "Synchronizer LeftCopy Background" )->getColor() );    pwRightCopy->setColor( getColorSelector( "Synchronizer RightCopy Foreground" )->getColor(),                           getColorSelector( "Synchronizer RightCopy Background" )->getColor() );    pwDelete->setColor(    getColorSelector( "Synchronizer Delete Foreground" )->getColor(),                           getColorSelector( "Synchronizer Delete Background" )->getColor() );  }}bool KgColors::apply(){  bool result = KonfiguratorPage::apply();  KrColorCache::getColorCache().refreshColors();  return result;}void KgColors::slotImportColors() {	// find $KDEDIR/share/apps/krusader	QString basedir = KGlobal::dirs()->findResourceDir("appdata", "total_commander.keymap");	// let the user select a file to load	QString file = KFileDialog::getOpenFileName(basedir, "*.color", 0, i18n("Select a color-scheme file"));	if (file == QString::null) return;	QFile f(file);	if (!f.open(IO_ReadOnly)) {		KMessageBox::error(this, i18n("Error: unable to read from file"), i18n("Error"));		return;	}	QDataStream stream(&f);	// ok, import away	deserialize(stream);	generatePreview();}void KgColors::slotExportColors() {	QString file = KFileDialog::getSaveFileName(QString::null, "*", 0, i18n("Select a color scheme file"));	if (file == QString::null) return;	QFile f(file);	if (f.exists() && KMessageBox::warningContinueCancel(this,		i18n("File ")+file+i18n(" already exists. Are you sure you want to overwrite it?"),		i18n("Warning"), i18n("Overwrite")) != KMessageBox::Continue) return;	if (!f.open(IO_WriteOnly)) {		KMessageBox::error(this, i18n("Error: unable to write to file"), i18n("Error"));		return;	}	QDataStream stream(&f);	serialize(stream);}void KgColors::serialize(QDataStream & stream){   serializeItem(stream, "Alternate Background");   serializeItem(stream, "Alternate Marked Background");   serializeItem(stream, "Background");   serializeItem(stream, "Current Background");   serializeItem(stream, "Current Foreground");   serializeItem(stream, "Enable Alternate Background");   serializeItem(stream, "Foreground");   serializeItem(stream, "Directory Foreground");   serializeItem(stream, "Executable Foreground");   serializeItem(stream, "Symlink Foreground");   serializeItem(stream, "Invalid Symlink Foreground");   serializeItem(stream, "Inactive Alternate Background");   serializeItem(stream, "Inactive Alternate Marked Background");   serializeItem(stream, "Inactive Background");   serializeItem(stream, "Inactive Current Foreground");   serializeItem(stream, "Inactive Current Background");   serializeItem(stream, "Inactive Marked Background");   serializeItem(stream, "Inactive Marked Current Foreground");   serializeItem(stream, "Inactive Marked Foreground");   serializeItem(stream, "Inactive Foreground");   serializeItem(stream, "Inactive Directory Foreground");   serializeItem(stream, "Inactive Executable Foreground");   serializeItem(stream, "Inactive Symlink Foreground");   serializeItem(stream, "Inactive Invalid Symlink Foreground");   serializeItem(stream, "Dim Inactive Colors");   serializeItem(stream, "Dim Target Color");   serializeItem(stream, "Dim Factor");   serializeItem(stream, "KDE Default");   serializeItem(stream, "Marked Background");   serializeItem(stream, "Marked Current Foreground");   serializeItem(stream, "Marked Foreground");   serializeItem(stream, "Show Current Item Always");   serializeItem(stream, "Synchronizer Equals Foreground");   serializeItem(stream, "Synchronizer Equals Background");   serializeItem(stream, "Synchronizer Differs Foreground");   serializeItem(stream, "Synchronizer Differs Background");   serializeItem(stream, "Synchronizer LeftCopy Foreground");   serializeItem(stream, "Synchronizer LeftCopy Background");   serializeItem(stream, "Synchronizer RightCopy Foreground");   serializeItem(stream, "Synchronizer RightCopy Background");   serializeItem(stream, "Synchronizer Delete Foreground");   serializeItem(stream, "Synchronizer Delete Background");   stream << QString("") << QString("");}void KgColors::deserialize(QDataStream & stream){   for (;;)   {      QString name, value;      stream >> name >> value;      if (name == "")         break;      if (name == "KDE Default" || name == "Enable Alternate Background" ||          name == "Show Current Item Always" || name == "Dim Inactive Colors" )      {        bool bValue = false;        value = value.lower();        if( value == "true" || value == "yes" || value == "on" || value == "1" )          bValue = true;        generals->find( name )->setChecked( bValue );        continue;      }      if( name == "Dim Factor" )      {        dimFactor->setValue( value.toInt() );        continue;      }      KonfiguratorColorChooser *selector = getColorSelector( name );      if( selector == 0 )        break;      selector->setValue( value );   }}void KgColors::serializeItem(class QDataStream & stream, const char * name){   stream << QString(name);   if( (strcmp( name, "KDE Default") == 0)        || (strcmp( name, "Enable Alternate Background") == 0)        || (strcmp( name, "Show Current Item Always") == 0)        || (strcmp( name, "Dim Inactive Colors") == 0) )   {     bool bValue = generals->find( name )->isChecked();     stream << QString( bValue ? "true" : "false" );   }   else if( strcmp( name, "Dim Factor") == 0 )     stream << QString::number(dimFactor->value());   else   {     KonfiguratorColorChooser *selector = getColorSelector( name );     stream << selector->getValue();   }}#include "kgcolors.moc"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -