typo fix spotted by Freek de Kruijf
[kdepim.git] / messageviewer / htmlstatusbar.cpp
blob48346805729086f604180b2c22d73a0010e8ac33
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 "htmlstatusbar.h"
34 #include "globalsettings.h"
36 #include "messagecore/globalsettings.h"
38 #include <klocale.h>
39 #include <kconfig.h>
40 #include <kconfiggroup.h>
41 #include <kapplication.h>
43 #include <QColor>
44 #include <QString>
45 #include <QLabel>
46 #include <QMouseEvent>
48 using namespace MessageViewer;
50 HtmlStatusBar::HtmlStatusBar( QWidget * parent, const char * name, Qt::WFlags f )
51 : QLabel( parent, f ),
52 mMode( Util::Normal )
54 setObjectName( name );
55 setAlignment( Qt::AlignHCenter | Qt::AlignTop );
56 setAutoFillBackground( true );
57 update();
60 HtmlStatusBar::~HtmlStatusBar() {}
62 void HtmlStatusBar::update()
64 QPalette pal = palette();
65 pal.setColor( backgroundRole(), bgColor() );
66 pal.setColor( foregroundRole(), fgColor() );
67 setPalette( pal );
68 setText( message() );
69 setToolTip( toolTip() );
72 void HtmlStatusBar::setNormalMode()
74 setMode( Util::Normal );
77 void HtmlStatusBar::setHtmlMode()
79 setMode( Util::Html );
82 void HtmlStatusBar::setMultipartPlainMode()
84 setMode( Util::MultipartPlain );
87 void HtmlStatusBar::setMultipartHtmlMode()
89 setMode( Util::MultipartHtml );
92 void HtmlStatusBar::setMode( Util::HtmlMode m, UpdateMode mode )
94 mMode = m;
95 if ( mode == Update )
96 update();
99 void HtmlStatusBar::mousePressEvent( QMouseEvent * event )
101 if ( event->button() == Qt::LeftButton ) {
102 emit clicked();
106 QString HtmlStatusBar::message() const {
107 switch ( mode() ) {
108 case Util::Html: // bold: "HTML Message"
109 case Util::MultipartHtml:
110 return i18nc( "'HTML Message' with html linebreaks between each letter.",
111 "<br />M<br />e<br />s<br />s<br />a<br />g<br />e</b></qt>" );
112 case Util::Normal: // normal: "No HTML Message"
113 return i18nc("'No HTML Message' with html linebreaks between each letter.",
114 "<qt><br />N<br />o<br /> "
115 "<br />H<br />T<br />M<br />L<br /> "
116 "<br />M<br />e<br />s<br />s<br />a<br />g<br />e</qt>" );
117 case Util::MultipartPlain: // normal: "Plain Message"
118 return i18nc("'Plain Message' with html linebreaks between each letter.",
119 "<qt><br />P<br />l<br />a<br />i<br />n<br /> "
120 "<br />M<br />e<br />s<br />s<br />a<br />g<br />e<br /></qt>" );
121 default:
122 return QString();
126 QString HtmlStatusBar::toolTip() const
128 switch ( mode() )
130 case Util::Html:
131 case Util::MultipartHtml:
132 case Util::MultipartPlain:
133 return i18n( "Click to toggle between HTML and plain text." );
134 default:
135 case Util::Normal:
136 break;
139 return QString();
142 QColor HtmlStatusBar::fgColor() const
144 KConfigGroup conf( GlobalSettings::self()->config(), "Reader" );
145 QColor defaultColor, color;
146 switch ( mode() ) {
147 case Util::Html:
148 case Util::MultipartHtml:
149 defaultColor = Qt::white;
150 color = defaultColor;
151 if ( !MessageCore::GlobalSettings::self()->useDefaultColors() ) {
152 color = conf.readEntry( "ColorbarForegroundHTML", defaultColor );
154 return color;
155 case Util::Normal:
156 case Util::MultipartPlain:
157 defaultColor = Qt::black;
158 color = defaultColor;
159 if ( !MessageCore::GlobalSettings::self()->useDefaultColors() ) {
160 color = conf.readEntry( "ColorbarForegroundPlain", defaultColor );
162 return color;
163 default:
164 return Qt::black;
168 QColor HtmlStatusBar::bgColor() const {
169 KConfigGroup conf( GlobalSettings::self()->config(), "Reader" );
171 QColor defaultColor, color;
172 switch ( mode() ) {
173 case Util::Html:
174 case Util::MultipartHtml:
175 defaultColor = Qt::black;
176 color = defaultColor;
177 if ( !MessageCore::GlobalSettings::self()->useDefaultColors() ) {
178 color = conf.readEntry( "ColorbarBackgroundHTML", defaultColor );
180 return color;
181 case Util::Normal:
182 case Util::MultipartPlain:
183 defaultColor = Qt::lightGray;
184 color = defaultColor;
185 if ( !MessageCore::GlobalSettings::self()->useDefaultColors() ) {
186 color = conf.readEntry( "ColorbarBackgroundPlain", defaultColor );
188 return color;
189 default:
190 return Qt::white;
194 #include "htmlstatusbar.moc"