Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

oconfig.cpp

Go to the documentation of this file.
00001 /*
00002                              This file is part of the Opie Project
00003 
00004                              (C) 2003 Michael Lauer <mickey@tm.informatik.uni-frankfurt.de>
00005                              Inspired by the config classes from the KDE Project which are
00006               =.             (C) 1997 Matthias Kalle Dalheimer <kalle@kde.org>
00007             .=l.
00008            .>+-=
00009  _;:,     .>    :=|.         This program is free software; you can
00010 .> <`_,   >  .   <=          redistribute it and/or  modify it under
00011 :`=1 )Y*s>-.--   :           the terms of the GNU Library General Public
00012 .="- .-=="i,     .._         License as published by the Free Software
00013  - .   .-<_>     .<>         Foundation; either version 2 of the License,
00014      ._= =}       :          or (at your option) any later version.
00015     .%`+i>       _;_.
00016     .i_,=:_.      -<s.       This program is distributed in the hope that
00017      +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
00018     : ..    .:,     . . .    without even the implied warranty of
00019     =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
00020   _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
00021 ..}^=.=       =       ;      Library General Public License for more
00022 ++=   -.     .`     .:       details.
00023  :     =  ...= . :.=-
00024  -.   .:....=;==+<;          You should have received a copy of the GNU
00025   -_. . .   )=.  =           Library General Public License along with
00026     --        :-=`           this library; see the file COPYING.LIB.
00027                              If not, write to the Free Software Foundation,
00028                              Inc., 59 Temple Place - Suite 330,
00029                              Boston, MA 02111-1307, USA.
00030 */
00031 
00032 /* QT */
00033 
00034 #include <qfont.h>
00035 #include <qcolor.h>
00036 
00037 /* OPIE */
00038 
00039 #include <opie2/oconfig.h>
00040 
00041 using namespace Opie::Core;
00042 
00043 OConfig::OConfig( const QString &name, Domain domain )
00044         :Config( name, domain )
00045 {
00046     qDebug( "OConfig::OConfig()" );
00047 }
00048 
00049 OConfig::~OConfig()
00050 {
00051     qDebug( "OConfig::~OConfig()" );
00052 }
00053 
00054 QColor OConfig::readColorEntry( const QString& key, const QColor* pDefault ) const
00055 {
00056   QColor aRetColor;
00057   int nRed = 0, nGreen = 0, nBlue = 0;
00058 
00059   QString aValue = readEntry( key );
00060   if( !aValue.isEmpty() )
00061   {
00062       if ( aValue.at(0) == '#' )
00063       {
00064           aRetColor.setNamedColor(aValue);
00065       }
00066       else
00067       {
00068           bool bOK;
00069 
00070           // find first part (red)
00071           int nIndex = aValue.find( ',' );
00072 
00073           if( nIndex == -1 )
00074           {
00075             // return a sensible default -- Bernd
00076             if( pDefault )
00077               aRetColor = *pDefault;
00078             return aRetColor;
00079           }
00080 
00081           nRed = aValue.left( nIndex ).toInt( &bOK );
00082 
00083           // find second part (green)
00084           int nOldIndex = nIndex;
00085           nIndex = aValue.find( ',', nOldIndex+1 );
00086 
00087           if( nIndex == -1 )
00088           {
00089             // return a sensible default -- Bernd
00090             if( pDefault )
00091               aRetColor = *pDefault;
00092             return aRetColor;
00093           }
00094           nGreen = aValue.mid( nOldIndex+1,
00095                                nIndex-nOldIndex-1 ).toInt( &bOK );
00096 
00097           // find third part (blue)
00098           nBlue = aValue.right( aValue.length()-nIndex-1 ).toInt( &bOK );
00099 
00100           aRetColor.setRgb( nRed, nGreen, nBlue );
00101         }
00102     }
00103   else {
00104 
00105     if( pDefault )
00106       aRetColor = *pDefault;
00107   }
00108 
00109   return aRetColor;
00110 }
00111 
00112 // FIXME: The whole font handling has to be revised for Opie
00113 
00114 QFont OConfig::readFontEntry( const QString& key, const QFont* pDefault ) const
00115 {
00116     Q_CONST_UNUSED( key )
00117     Q_CONST_UNUSED( pDefault )
00118   /*
00119   QFont aRetFont;
00120 
00121   QString aValue = readEntry( key );
00122   if( !aValue.isNull() ) {
00123     if ( aValue.contains( ',' ) > 5 ) {
00124       // KDE3 and upwards entry
00125       if ( !aRetFont.fromString( aValue ) && pDefault )
00126         aRetFont = *pDefault;
00127     }
00128     else {
00129       // backward compatibility with older font formats
00130       // ### remove KDE 3.1 ?
00131       // find first part (font family)
00132       int nIndex = aValue.find( ',' );
00133       if( nIndex == -1 ){
00134         if( pDefault )
00135           aRetFont = *pDefault;
00136         return aRetFont;
00137       }
00138       aRetFont.setFamily( aValue.left( nIndex ) );
00139 
00140       // find second part (point size)
00141       int nOldIndex = nIndex;
00142       nIndex = aValue.find( ',', nOldIndex+1 );
00143       if( nIndex == -1 ){
00144         if( pDefault )
00145           aRetFont = *pDefault;
00146         return aRetFont;
00147       }
00148 
00149       aRetFont.setPointSize( aValue.mid( nOldIndex+1,
00150                                          nIndex-nOldIndex-1 ).toInt() );
00151 
00152       // find third part (style hint)
00153       nOldIndex = nIndex;
00154       nIndex = aValue.find( ',', nOldIndex+1 );
00155 
00156       if( nIndex == -1 ){
00157         if( pDefault )
00158           aRetFont = *pDefault;
00159         return aRetFont;
00160       }
00161 
00162       aRetFont.setStyleHint( (QFont::StyleHint)aValue.mid( nOldIndex+1, nIndex-nOldIndex-1 ).toUInt() );
00163 
00164       // find fourth part (char set)
00165       nOldIndex = nIndex;
00166       nIndex = aValue.find( ',', nOldIndex+1 );
00167 
00168       if( nIndex == -1 ){
00169         if( pDefault )
00170           aRetFont = *pDefault;
00171         return aRetFont;
00172       }
00173 
00174       QString chStr=aValue.mid( nOldIndex+1,
00175                                 nIndex-nOldIndex-1 );
00176       // find fifth part (weight)
00177       nOldIndex = nIndex;
00178       nIndex = aValue.find( ',', nOldIndex+1 );
00179 
00180       if( nIndex == -1 ){
00181         if( pDefault )
00182           aRetFont = *pDefault;
00183         return aRetFont;
00184       }
00185 
00186       aRetFont.setWeight( aValue.mid( nOldIndex+1,
00187                                       nIndex-nOldIndex-1 ).toUInt() );
00188 
00189       // find sixth part (font bits)
00190       uint nFontBits = aValue.right( aValue.length()-nIndex-1 ).toUInt();
00191 
00192       aRetFont.setItalic( nFontBits & 0x01 );
00193       aRetFont.setUnderline( nFontBits & 0x02 );
00194       aRetFont.setStrikeOut( nFontBits & 0x04 );
00195       aRetFont.setFixedPitch( nFontBits & 0x08 );
00196       aRetFont.setRawMode( nFontBits & 0x20 );
00197     }
00198   }
00199   else
00200     {
00201       if( pDefault )
00202         aRetFont = *pDefault;
00203     }
00204   return aRetFont;
00205   */
00206   return QFont("Helvetica",10);
00207 }

Generated on Sat Nov 5 16:16:07 2005 for OPIE by  doxygen 1.4.2