kmail

htmlstatusbar.cpp

Go to the documentation of this file.
00001 /*  -*- c++ -*-
00002     htmlstatusbar.cpp
00003 
00004     This file is part of KMail, the KDE mail client.
00005     Copyright (c) 2002 Ingo Kloecker <kloecker@kde.org>
00006     Copyright (c) 2003 Marc Mutz <mutz@kde.org>
00007 
00008     KMail is free software; you can redistribute it and/or modify it
00009     under the terms of the GNU General Public License, version 2, as
00010     published by the Free Software Foundation.
00011 
00012     KMail is distributed in the hope that it will be useful, but
00013     WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program; if not, write to the Free Software
00019     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00020 
00021     In addition, as a special exception, the copyright holders give
00022     permission to link the code of this program with any edition of
00023     the Qt library by Trolltech AS, Norway (or with modified versions
00024     of Qt that use the same license as Qt), and distribute linked
00025     combinations including the two.  You must obey the GNU General
00026     Public License in all respects for all of the code used other than
00027     Qt.  If you modify this file, you may extend this exception to
00028     your version of the file, but you are not obligated to do so.  If
00029     you do not wish to do so, delete this exception statement from
00030     your version.
00031 */
00032 
00033 #ifdef HAVE_CONFIG_H
00034 #include <config.h>
00035 #endif
00036 
00037 #include "htmlstatusbar.h"
00038 
00039 #ifndef KMAIL_TESTING
00040 #include "kmkernel.h"
00041 #else
00042 #include <kapplication.h>
00043 #endif
00044 
00045 #include <klocale.h>
00046 #include <kconfig.h>
00047 
00048 #include <qcolor.h>
00049 #include <qstring.h>
00050 
00051 KMail::HtmlStatusBar::HtmlStatusBar( QWidget * parent, const char * name, WFlags f )
00052   : QLabel( parent, name, f ),
00053     mMode( Normal )
00054 {
00055   setAlignment( AlignHCenter|AlignTop );
00056   // Don't force a minimum height to the reader widget
00057   setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Ignored ) );
00058   upd();
00059 }
00060 
00061 KMail::HtmlStatusBar::~HtmlStatusBar() {}
00062 
00063 void KMail::HtmlStatusBar::upd() {
00064   setEraseColor( bgColor() );
00065   setPaletteForegroundColor( fgColor() );
00066   setText( message() );
00067 }
00068 
00069 void KMail::HtmlStatusBar::setNormalMode() {
00070   setMode( Normal );
00071 }
00072 
00073 void KMail::HtmlStatusBar::setHtmlMode() {
00074   setMode( Html );
00075 }
00076 
00077 void KMail::HtmlStatusBar::setNeutralMode() {
00078   setMode( Neutral );
00079 }
00080 
00081 void KMail::HtmlStatusBar::setMode( Mode m ) {
00082   if ( m == mode() )
00083     return;
00084   mMode = m;
00085   upd();
00086 }
00087 
00088 QString KMail::HtmlStatusBar::message() const {
00089   switch ( mode() ) {
00090   case Html: // bold: "HTML Message"
00091     return i18n( "<qt><b><br>H<br>T<br>M<br>L<br> "
00092          "<br>M<br>e<br>s<br>s<br>a<br>g<br>e</b></qt>" );
00093   case Normal: // normal: "No HTML Message"
00094     return i18n( "<qt><br>N<br>o<br> "
00095          "<br>H<br>T<br>M<br>L<br> "
00096          "<br>M<br>e<br>s<br>s<br>a<br>g<br>e</qt>" );
00097   default:
00098   case Neutral:
00099     return QString::null;
00100   }
00101 }
00102 
00103 namespace {
00104   inline KConfig * config() {
00105 #ifndef KMAIL_TESTING
00106     return KMKernel::config();
00107 #else
00108     return kApp->config();
00109 #endif
00110   }
00111 }
00112 
00113 QColor KMail::HtmlStatusBar::fgColor() const {
00114   KConfigGroup conf( config(), "Reader" );
00115   switch ( mode() ) {
00116   case Html:
00117     return conf.readColorEntry( "ColorbarForegroundHTML", &Qt::white );
00118   case Normal:
00119     return conf.readColorEntry( "ColorbarForegroundPlain", &Qt::black );
00120   default:
00121   case Neutral:
00122     return Qt::black;
00123   }
00124 }
00125 
00126 QColor KMail::HtmlStatusBar::bgColor() const {
00127   KConfigGroup conf( config(), "Reader" );
00128 
00129   switch ( mode() ) {
00130   case Html:
00131     return conf.readColorEntry( "ColorbarBackgroundHTML", &Qt::black );
00132   case Normal:
00133     return conf.readColorEntry( "ColorbarBackgroundPlain", &Qt::lightGray );
00134   default:
00135   case Neutral:
00136     return Qt::white;
00137   }
00138 }
00139 
00140 #include "htmlstatusbar.moc"