kilobyte is kB not kb
[kdepim.git] / messageviewer / htmlstatusbar.cpp
blob6f663adb5dec496fdc7f3009a39a3d42158f04e0
1 /* -*- c++ -*-
2 htmlstatusbar.cpp
4 This file is part of KMail, the KDE mail client.
5 Copyright (c) 2002 Ingo Kloecker <kloecker@kde.org>
6 Copyright (c) 2003 Marc Mutz <mutz@kde.org>
8 KMail is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License, version 2, as
10 published by the Free Software Foundation.
12 KMail is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 In addition, as a special exception, the copyright holders give
22 permission to link the code of this program with any edition of
23 the Qt library by Trolltech AS, Norway (or with modified versions
24 of Qt that use the same license as Qt), and distribute linked
25 combinations including the two. You must obey the GNU General
26 Public License in all respects for all of the code used other than
27 Qt. If you modify this file, you may extend this exception to
28 your version of the file, but you are not obligated to do so. If
29 you do not wish to do so, delete this exception statement from
30 your version.
33 #include <config-messageviewer.h>
35 #include "htmlstatusbar.h"
36 #include "globalsettings.h"
38 #include "messagecore/globalsettings.h"
40 #include <klocale.h>
41 #include <kconfig.h>
42 #include <kconfiggroup.h>
43 #include <kapplication.h>
45 #include <QColor>
46 #include <QString>
47 #include <QLabel>
48 #include <QMouseEvent>
50 using namespace MessageViewer;
52 HtmlStatusBar::HtmlStatusBar( QWidget * parent, const char * name, Qt::WFlags f )
53 : QLabel( parent, f ),
54 mMode( Util::Normal )
56 setObjectName( name );
57 setAlignment( Qt::AlignHCenter | Qt::AlignTop );
58 setAutoFillBackground( true );
59 update();
62 HtmlStatusBar::~HtmlStatusBar() {}
64 void HtmlStatusBar::update()
66 QPalette pal = palette();
67 pal.setColor( backgroundRole(), bgColor() );
68 pal.setColor( foregroundRole(), fgColor() );
69 setPalette( pal );
70 setText( message() );
71 setToolTip( toolTip() );
74 void HtmlStatusBar::setNormalMode()
76 setMode( Util::Normal );
79 void HtmlStatusBar::setHtmlMode()
81 setMode( Util::Html );
84 void HtmlStatusBar::setMultipartPlainMode()
86 setMode( Util::MultipartPlain );
89 void HtmlStatusBar::setMultipartHtmlMode()
91 setMode( Util::MultipartHtml );
94 void HtmlStatusBar::setMode( Util::HtmlMode m, UpdateMode mode )
96 mMode = m;
97 if ( mode == Update )
98 update();
101 void HtmlStatusBar::mousePressEvent( QMouseEvent * event )
103 if ( event->button() == Qt::LeftButton ) {
104 emit clicked();
108 QString HtmlStatusBar::message() const {
109 switch ( mode() ) {
110 case Util::Html: // bold: "HTML Message"
111 case Util::MultipartHtml:
112 return i18nc( "'HTML Message' with html linebreaks between each letter and in bold text.",
113 "<qt><b><br />H<br />T<br />M<br />L<br /> "
114 "<br />M<br />e<br />s<br />s<br />a<br />g<br />e</b></qt>" );
115 case Util::Normal: // normal: "No HTML Message"
116 return i18nc("'No HTML Message' with html linebreaks between each letter.",
117 "<qt><br />N<br />o<br /> "
118 "<br />H<br />T<br />M<br />L<br /> "
119 "<br />M<br />e<br />s<br />s<br />a<br />g<br />e</qt>" );
120 case Util::MultipartPlain: // normal: "Plain Message"
121 return i18nc("'Plain Message' with html linebreaks between each letter.",
122 "<qt><br />P<br />l<br />a<br />i<br />n<br /> "
123 "<br />M<br />e<br />s<br />s<br />a<br />g<br />e<br /></qt>" );
124 default:
125 return QString();
129 QString HtmlStatusBar::toolTip() const
131 switch ( mode() )
133 case Util::Html:
134 case Util::MultipartHtml:
135 case Util::MultipartPlain:
136 return i18n( "Click to toggle between HTML and plain text." );
137 default:
138 case Util::Normal:
139 break;
142 return QString();
145 QColor HtmlStatusBar::fgColor() const
147 KConfigGroup conf( GlobalSettings::self()->config(), "Reader" );
148 QColor defaultColor, color;
149 switch ( mode() ) {
150 case Util::Html:
151 case Util::MultipartHtml:
152 defaultColor = Qt::white;
153 color = defaultColor;
154 if ( !MessageCore::GlobalSettings::self()->useDefaultColors() ) {
155 color = conf.readEntry( "ColorbarForegroundHTML", defaultColor );
157 return color;
158 case Util::Normal:
159 case Util::MultipartPlain:
160 defaultColor = Qt::black;
161 color = defaultColor;
162 if ( !MessageCore::GlobalSettings::self()->useDefaultColors() ) {
163 color = conf.readEntry( "ColorbarForegroundPlain", defaultColor );
165 return color;
166 default:
167 return Qt::black;
171 QColor HtmlStatusBar::bgColor() const {
172 KConfigGroup conf( GlobalSettings::self()->config(), "Reader" );
174 QColor defaultColor, color;
175 switch ( mode() ) {
176 case Util::Html:
177 case Util::MultipartHtml:
178 defaultColor = Qt::black;
179 color = defaultColor;
180 if ( !MessageCore::GlobalSettings::self()->useDefaultColors() ) {
181 color = conf.readEntry( "ColorbarBackgroundHTML", defaultColor );
183 return color;
184 case Util::Normal:
185 case Util::MultipartPlain:
186 defaultColor = Qt::lightGray;
187 color = defaultColor;
188 if ( !MessageCore::GlobalSettings::self()->useDefaultColors() ) {
189 color = conf.readEntry( "ColorbarBackgroundPlain", defaultColor );
191 return color;
192 default:
193 return Qt::white;
197 #include "htmlstatusbar.moc"