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

colorlistitem.h

Go to the documentation of this file.
00001 /*
00002                              This file is part of the Opie Project
00003 
00004                              Copyright (c)  2002 Robert Griebl <sandman@handhelds.org>
00005               =.
00006             .=l.
00007            .>+-=
00008  _;:,     .>    :=|.         This program is free software; you can
00009 .> <`_,   >  .   <=          redistribute it and/or  modify it under
00010 :`=1 )Y*s>-.--   :           the terms of the GNU Library General Public
00011 .="- .-=="i,     .._         License as published by the Free Software
00012  - .   .-<_>     .<>         Foundation; either version 2 of the License,
00013      ._= =}       :          or (at your option) any later version.
00014     .%`+i>       _;_.
00015     .i_,=:_.      -<s.       This program is distributed in the hope that
00016      +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
00017     : ..    .:,     . . .    without even the implied warranty of
00018     =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
00019   _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
00020 ..}^=.=       =       ;      Library General Public License for more
00021 ++=   -.     .`     .:       details.
00022 :     =  ...= . :.=-
00023  -.   .:....=;==+<;          You should have received a copy of the GNU
00024   -_. . .   )=.  =           Library General Public License along with
00025     --        :-=`           this library; see the file COPYING.LIB.
00026                              If not, write to the Free Software Foundation,
00027                              Inc., 59 Temple Place - Suite 330,
00028                              Boston, MA 02111-1307, USA.
00029 */
00030 
00031 #ifndef COLORLISTITEM_H
00032 #define COLORLISTITEM_H
00033 
00034 #include <qlistbox.h>
00035 #include <qpalette.h>
00036 #include <qapplication.h>
00037 
00038 #include <qpe/config.h>
00039 
00040 class Appearance;
00041 
00042 class ColorListItem : public QListBoxText {
00043 public:
00044         ColorListItem ( const QString &t, Config &cfg ) : QListBoxText ( t ) 
00045         {
00046                 m_colors = new QColor [s_colorcount];
00047                 load ( cfg );
00048         }
00049 
00050         virtual ~ColorListItem ( )
00051         {
00052                 delete [] m_colors;
00053         }
00054         
00055         QPalette palette ( )
00056         {
00057                 return m_palette;
00058         }
00059 
00060         bool load ( Config &cfg )
00061         {
00062                 for ( int i = 0; i < s_colorcount; i++ ) 
00063                         m_colors [i] = QColor ( cfg. readEntry ( s_colorlut [i]. m_key, s_colorlut [i]. m_def ));
00064                         
00065                 buildPalette ( );
00066                 return true;
00067         }
00068         
00069         void buildPalette ( )
00070         {
00071                 m_palette = QPalette ( m_colors [r2i(QColorGroup::Button)], m_colors [r2i(QColorGroup::Background)] );
00072                 m_palette. setColor ( QColorGroup::Highlight, m_colors [r2i(QColorGroup::Highlight)] );
00073                 m_palette. setColor ( QColorGroup::HighlightedText, m_colors [r2i(QColorGroup::HighlightedText)] );
00074                 m_palette. setColor ( QColorGroup::Text, m_colors [r2i(QColorGroup::Text)] );
00075                 m_palette. setColor ( QPalette::Active, QColorGroup::ButtonText, m_colors [r2i(QColorGroup::ButtonText)] );
00076                 m_palette. setColor ( QColorGroup::Base, m_colors [r2i(QColorGroup::Base)] );
00077                 m_palette. setColor ( QPalette::Disabled, QColorGroup::Text, m_palette. color ( QPalette::Active, QColorGroup::Background ). dark ( ));
00078         }
00079         
00080         bool save ( Config &cfg )
00081         {
00082                 for ( int i = 0; i < s_colorcount; i++ ) 
00083                         cfg. writeEntry ( s_colorlut [i]. m_key, m_colors [i]. name ( ));
00084                 return true;
00085         }
00086 
00087         QColor color ( QColorGroup::ColorRole role )
00088         {
00089                 int i = r2i ( role );
00090                 return i >= 0 ? m_colors [i] : QColor ( );
00091         }
00092         
00093         void setColor ( QColorGroup::ColorRole role, QColor c )
00094         {
00095                 int i = r2i ( role );
00096                 if ( i >= 0 ) {
00097                         m_colors [i] = c;
00098                         buildPalette ( );
00099                 }
00100         }
00101         
00102         QString label ( QColorGroup::ColorRole role )
00103         {
00104                 int i = r2i ( role );
00105                 return i >= 0 ? qApp-> translate ( "Appearance", s_colorlut [i]. m_label ) : QString::null;
00106         }
00107                 
00108 private:
00109         QPalette m_palette;     
00110         QColor *m_colors;
00111         
00112         static struct colorlut {
00113                 QColorGroup::ColorRole m_role;
00114                 const char *           m_key;
00115                 const char *           m_def;           
00116                 const char *           m_label;
00117         } const s_colorlut [];
00118         static const int s_colorcount;
00119 
00120         static int r2i ( QColorGroup::ColorRole role )
00121         {
00122                 for ( int i = 0; i < s_colorcount; i++ ) {
00123                         if ( s_colorlut [i]. m_role == role )
00124                                 return i;
00125                 }
00126                 return -1;
00127         }
00128 };
00129 
00130 // from etc/colors/Liquid.scheme
00131 const ColorListItem::colorlut ColorListItem::s_colorlut [] = {
00132         { QColorGroup::Base,            "Base",            "#FFFFFF", QT_TRANSLATE_NOOP( "Appearance", "Base" )             },
00133         { QColorGroup::Background,      "Background",      "#E0E0E0", QT_TRANSLATE_NOOP( "Appearance", "Background" )       },
00134         { QColorGroup::Button,          "Button",          "#96c8fa", QT_TRANSLATE_NOOP( "Appearance", "Button" )           },
00135         { QColorGroup::ButtonText,      "ButtonText",      "#000000", QT_TRANSLATE_NOOP( "Appearance", "Button Text" )      }, 
00136         { QColorGroup::Highlight,       "Highlight",       "#73adef", QT_TRANSLATE_NOOP( "Appearance", "Highlight" )        },
00137         { QColorGroup::HighlightedText, "HighlightedText", "#FFFFFF", QT_TRANSLATE_NOOP( "Appearance", "Highlighted Text" ) },
00138         { QColorGroup::Text,            "Text",            "#000000", QT_TRANSLATE_NOOP( "Appearance", "Text" )             }
00139 };
00140 
00141 const int ColorListItem::s_colorcount =  sizeof( s_colorlut ) / sizeof ( s_colorlut [0] );
00142 
00143 
00144 #endif

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