📄 kconfigbase.cpp
字号:
{ QFont aRetFont; QString aValue = readEntry( pKey ); if( !aValue.isNull() ) { // find first part (font family) int nIndex = aValue.find( ',' ); if( nIndex == -1 ){ if( pDefault ) aRetFont = *pDefault; return aRetFont; } aRetFont.setFamily( aValue.left( nIndex ) ); // find second part (point size) int nOldIndex = nIndex; nIndex = aValue.find( ',', nOldIndex+1 ); if( nIndex == -1 ){ if( pDefault ) aRetFont = *pDefault; return aRetFont; } aRetFont.setPointSize( aValue.mid( nOldIndex+1, nIndex-nOldIndex-1 ).toInt() ); // find third part (style hint) nOldIndex = nIndex; nIndex = aValue.find( ',', nOldIndex+1 ); if( nIndex == -1 ){ if( pDefault ) aRetFont = *pDefault; return aRetFont; } aRetFont.setStyleHint( (QFont::StyleHint)aValue.mid( nOldIndex+1, nIndex-nOldIndex-1 ).toUInt() ); // find fourth part (char set) nOldIndex = nIndex; nIndex = aValue.find( ',', nOldIndex+1 ); if( nIndex == -1 ){ if( pDefault ) aRetFont = *pDefault; return aRetFont; } QString chStr=aValue.mid( nOldIndex+1, nIndex-nOldIndex-1 ); bool chOldEntry; QFont::CharSet chId=(QFont::CharSet)aValue.mid( nOldIndex+1, nIndex-nOldIndex-1 ).toUInt(&chOldEntry); if (chOldEntry) aRetFont.setCharSet( chId ); else if (kapp){ if (chStr=="default") if( kapp->localeConstructed() ) chStr=klocale->charset(); else chStr="iso-8859-1"; kapp->getCharsets()->setQFont(aRetFont,chStr); } // find fifth part (weight) nOldIndex = nIndex; nIndex = aValue.find( ',', nOldIndex+1 ); if( nIndex == -1 ){ if( pDefault ) aRetFont = *pDefault; return aRetFont; } aRetFont.setWeight( aValue.mid( nOldIndex+1, nIndex-nOldIndex-1 ).toUInt() ); // find sixth part (font bits) uint nFontBits = aValue.right( aValue.length()-nIndex-1 ).toUInt(); if( nFontBits & 0x01 ) aRetFont.setItalic( true ); else aRetFont.setItalic( false ); if( nFontBits & 0x02 ) aRetFont.setUnderline( true ); else aRetFont.setUnderline( false ); if( nFontBits & 0x04 ) aRetFont.setStrikeOut( true ); else aRetFont.setStrikeOut( false ); if( nFontBits & 0x08 ) aRetFont.setFixedPitch( true ); else aRetFont.setFixedPitch( false ); if( nFontBits & 0x20 ) aRetFont.setRawMode( true ); else aRetFont.setRawMode( false ); } else { if( pDefault ) aRetFont = *pDefault; } return aRetFont;}QRect KConfigBase::readRectEntry( const char* pKey, const QRect* pDefault ) const{ QStrList list; if( !hasKey( pKey ) ) { if( pDefault ) return *pDefault; else return QRect(); } int count = readListEntry( pKey, list, ',' ); if( count != 4 ) return QRect(); else return QRect( QString( list.at( 0 ) ).toInt(), QString( list.at( 1 ) ).toInt(), QString( list.at( 2 ) ).toInt(), QString( list.at( 3 ) ).toInt() );}QPoint KConfigBase::readPointEntry( const char* pKey, const QPoint* pDefault ) const{ QStrList list; if( !hasKey( pKey ) ) { if( pDefault ) return *pDefault; else return QPoint(); } int count = readListEntry( pKey, list, ',' ); if( count != 2 ) return QPoint(); else return QPoint( QString( list.at( 0 ) ).toInt(), QString( list.at( 1 ) ).toInt() );}QSize KConfigBase::readSizeEntry( const char* pKey, const QSize* pDefault ) const{ QStrList list; if( !hasKey( pKey ) ) { if( pDefault ) return *pDefault; else return QSize(); } int count = readListEntry( pKey, list, ',' ); if( count != 2 ) return QSize(); else return QSize( QString( list.at( 0 ) ).toInt(), QString( list.at( 1 ) ).toInt() );}QColor KConfigBase::readColorEntry( const char* pKey, const QColor* pDefault ) const{ QColor aRetColor; int nRed = 0, nGreen = 0, nBlue = 0; QString aValue = readEntry( pKey ); if( !aValue.isEmpty() ) { if ( aValue.left(1) == "#" ) { aRetColor.setNamedColor(aValue); } else { bool bOK; // find first part (red) int nIndex = aValue.find( ',' ); if( nIndex == -1 ){ // return a sensible default -- Bernd if( pDefault ) aRetColor = *pDefault; return aRetColor; } nRed = aValue.left( nIndex ).toInt( &bOK ); // find second part (green) int nOldIndex = nIndex; nIndex = aValue.find( ',', nOldIndex+1 ); if( nIndex == -1 ){ // return a sensible default -- Bernd if( pDefault ) aRetColor = *pDefault; return aRetColor; } nGreen = aValue.mid( nOldIndex+1, nIndex-nOldIndex-1 ).toInt( &bOK ); // find third part (blue) nBlue = aValue.right( aValue.length()-nIndex-1 ).toInt( &bOK ); aRetColor.setRgb( nRed, nGreen, nBlue ); } } else { if( pDefault ) aRetColor = *pDefault; } return aRetColor;}const char* KConfigBase::writeEntry( const char* pKey, const char* pValue, bool bPersistent, bool bGlobal, bool bNLS ){ if( !data()->bLocaleInitialized && kapp && kapp->localeConstructed() ) { KConfigBase *that = (KConfigBase*)this; that->setLocale(); } // const_cast<KConfigBase*>(this)->setLocale(); QString aValue; // retrieve the current group dictionary KEntryDict* pCurrentGroupDict = data()->aGroupDict[ data()->aGroup.data() ]; if( !pCurrentGroupDict ) { // no such group -> create a new entry dictionary KEntryDict* pNewDict = new KEntryDict( 37, false ); pNewDict->setAutoDelete( true ); data()->aGroupDict.insert( data()->aGroup.data(), pNewDict ); // this is now the current group pCurrentGroupDict = pNewDict; } // if this is localized entry, add the locale QString aLocalizedKey = pKey; if( bNLS ) aLocalizedKey = aLocalizedKey + '[' + data()->aLocaleString + ']'; // try to retrieve the current entry for this key KEntryDictEntry* pEntryData = (*pCurrentGroupDict)[ aLocalizedKey.data() ]; if( pEntryData ) { // there already is such a key aValue = pEntryData->aValue; // save old key as return value pEntryData->aValue = pValue; // set new value pEntryData->bGlobal = bGlobal; pEntryData->bNLS = bNLS; if( bPersistent ) pEntryData->bDirty = TRUE; } else { // the key currently does not exist KEntryDictEntry* pEntry = new KEntryDictEntry; pEntry->bGlobal = bGlobal; pEntry->bNLS = bNLS; pEntry->aValue = pValue; if( bPersistent ) pEntry->bDirty = TRUE; // insert the new entry into group dictionary pCurrentGroupDict->insert( aLocalizedKey, pEntry ); } // the KConfig object is dirty now if( bPersistent ) data()->bDirty = true; return aValue;}void KConfigBase::writeEntry ( const char* pKey, QStrList &list, char sep , bool bPersistent, bool bGlobal, bool bNLS ){ if( list.isEmpty() ) { writeEntry( pKey, "", bPersistent ); return; } QString str_list, value; int i; for( value = list.first(); !value.isNull() ; value = list.next() ) { for( i = 0; i < (int) value.length(); i++ ) { if( value[i] == sep || value[i] == '\\' ) str_list += '\\'; str_list += value[i]; } str_list += sep; } if( str_list.right(1) == sep ) str_list.truncate( str_list.length() -1 ); writeEntry( pKey, str_list, bPersistent, bGlobal, bNLS );}const char* KConfigBase::writeEntry( const char* pKey, int nValue, bool bPersistent, bool bGlobal, bool bNLS ){ QString aValue; aValue.setNum( nValue ); return writeEntry( pKey, aValue, bPersistent, bGlobal, bNLS );}const char* KConfigBase::writeEntry( const char* pKey, unsigned int nValue, bool bPersistent, bool bGlobal, bool bNLS ){ QString aValue; aValue.setNum( nValue ); return writeEntry( pKey, aValue, bPersistent, bGlobal, bNLS );}const char* KConfigBase::writeEntry( const char* pKey, long nValue, bool bPersistent, bool bGlobal, bool bNLS ){ QString aValue; aValue.setNum( nValue ); return writeEntry( pKey, aValue, bPersistent, bGlobal, bNLS );}const char* KConfigBase::writeEntry( const char* pKey, unsigned long nValue, bool bPersistent, bool bGlobal, bool bNLS ){ QString aValue; aValue.setNum( nValue ); return writeEntry( pKey, aValue, bPersistent, bGlobal, bNLS );}const char* KConfigBase::writeEntry( const char* pKey, double nValue, bool bPersistent, bool bGlobal, bool bNLS ){ QString aValue; aValue.setNum( nValue, 'g', 15 ); return writeEntry( pKey, aValue, bPersistent, bGlobal, bNLS );}const char* KConfigBase::writeEntry( const char* pKey, bool bValue, bool bPersistent, bool bGlobal, bool bNLS ){ QString aValue; if( bValue ) aValue = "true"; else aValue = "false"; return writeEntry( pKey, aValue, bPersistent, bGlobal, bNLS );}const char* KConfigBase::writeEntry( const char* pKey, const QFont& rFont, bool bPersistent, bool bGlobal, bool bNLS ){ QString aValue; QString aCharset; UINT8 nFontBits = 0; // this mimics get_font_bits() from qfont.cpp if( rFont.italic() ) nFontBits = nFontBits | 0x01; if( rFont.underline() ) nFontBits = nFontBits | 0x02; if( rFont.strikeOut() ) nFontBits = nFontBits | 0x04; if( rFont.fixedPitch() ) nFontBits = nFontBits | 0x08; if( rFont.rawMode() ) nFontBits = nFontBits | 0x20; if (kapp){ aCharset=kapp->getCharsets()->name(rFont); } else aCharset="default"; aValue.sprintf( "%s,%d,%d,%s,%d,%d", rFont.family(), rFont.pointSize(), rFont.styleHint(), (const char *)aCharset, rFont.weight(), nFontBits ); return writeEntry( pKey, aValue, bPersistent, bGlobal, bNLS );}void KConfigBase::writeEntry( const char* pKey, const QRect& rRect, bool bPersistent, bool bGlobal, bool bNLS ){ QStrList list; QString tempstr; list.insert( 0, tempstr.setNum( rRect.left() ) ); list.insert( 1, tempstr.setNum( rRect.top() ) ); list.insert( 2, tempstr.setNum( rRect.width() ) ); list.insert( 3, tempstr.setNum( rRect.height() ) ); writeEntry( pKey, list, ',', bPersistent, bGlobal, bNLS );}void KConfigBase::writeEntry( const char* pKey, const QPoint& rPoint, bool bPersistent, bool bGlobal, bool bNLS ){ QStrList list; QString tempstr; list.insert( 0, tempstr.setNum( rPoint.x() ) ); list.insert( 1, tempstr.setNum( rPoint.y() ) ); writeEntry( pKey, list, ',', bPersistent, bGlobal, bNLS );}void KConfigBase::writeEntry( const char* pKey, const QSize& rSize, bool bPersistent, bool bGlobal, bool bNLS ){ QStrList list; QString tempstr; list.insert( 0, tempstr.setNum( rSize.width() ) ); list.insert( 1, tempstr.setNum( rSize.height() ) ); writeEntry( pKey, list, ',', bPersistent, bGlobal, bNLS );}void KConfigBase::writeEntry( const char* pKey, const QColor& rColor, bool bPersistent, bool bGlobal, bool bNLS ){ QString aValue; aValue.sprintf( "%d,%d,%d", rColor.red(), rColor.green(), rColor.blue() ); writeEntry( pKey, aValue, bPersistent, bGlobal, bNLS );}void KConfigBase::rollback( bool bDeep ){ // clear the global bDirty flag in all cases data()->bDirty = false; // if bDeep is true, clear the bDirty flags of all the entries if( !bDeep ) return; QDictIterator<KEntryDict> aIt( data()->aGroupDict ); // loop over all the groups const char* pCurrentGroup; while( (pCurrentGroup = aIt.currentKey()) ) { QDictIterator<KEntryDictEntry> aInnerIt( *aIt.current() ); // loop over all the entries KEntryDictEntry* pCurrentEntry; while( (pCurrentEntry = aInnerIt.current()) ) { pCurrentEntry->bDirty = false; ++aInnerIt; } ++aIt; }}bool KConfigBase::hasKey( const char* pKey ) const{ QString aValue = readEntry( pKey ); return !aValue.isNull();}KEntryIterator* KConfigBase::entryIterator( const char* pGroup ){ // find the group KEntryDict* pCurrentGroupDict = data()->aGroupDict[ pGroup ]; if( !pCurrentGroupDict ) return 0L; // that group does not exist return new KEntryIterator( *pCurrentGroupDict );}void KConfigBase::reparseConfiguration(){ data()->aGroupDict.clear(); // setup a group entry for the default group KEntryDict* pDefGroup = new KEntryDict( 37, false ); pDefGroup->setAutoDelete( true ); data()->aGroupDict.insert( "<default>", pDefGroup ); // the next three lines are indeed important. // no longer (Kalle, 04/10/97) // data()->pAppStream->device()->close(); // if (!data()->pAppStream->device()->open( IO_ReadWrite )) // data()->pAppStream->device()->open( IO_ReadOnly ); parseConfigFiles();}void KConfigBase::setDollarExpansion( bool bExpand ){ data()->bExpand = bExpand;}bool KConfigBase::isDollarExpansion() const{ return data()->bExpand;}#include "kconfigbase.moc"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -