• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

messageviewer

  • sources
  • kde-4.14
  • kdepim
  • messageviewer
  • widgets
htmlstatusbar.cpp
Go to the documentation of this file.
1 /* -*- c++ -*-
2  htmlstatusbar.cpp
3 
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>
7  Copyright (C) 2013-2015 Laurent Montel <montel@kde.org>
8 
9  KMail is free software; you can redistribute it and/or modify it
10  under the terms of the GNU General Public License, version 2, as
11  published by the Free Software Foundation.
12 
13  KMail is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 
22  In addition, as a special exception, the copyright holders give
23  permission to link the code of this program with any edition of
24  the Qt library by Trolltech AS, Norway (or with modified versions
25  of Qt that use the same license as Qt), and distribute linked
26  combinations including the two. You must obey the GNU General
27  Public License in all respects for all of the code used other than
28  Qt. If you modify this file, you may extend this exception to
29  your version of the file, but you are not obligated to do so. If
30  you do not wish to do so, delete this exception statement from
31  your version.
32 */
33 
34 #include "htmlstatusbar.h"
35 #include "settings/globalsettings.h"
36 
37 #include "messagecore/settings/globalsettings.h"
38 
39 #include <klocale.h>
40 #include <kconfiggroup.h>
41 
42 #include <QMouseEvent>
43 
44 using namespace MessageViewer;
45 
46 HtmlStatusBar::HtmlStatusBar(QWidget * parent)
47  : QLabel( parent ),
48  mMode( Util::Normal )
49 {
50  setAlignment( Qt::AlignHCenter | Qt::AlignTop );
51  setAutoFillBackground( true );
52  update();
53 }
54 
55 HtmlStatusBar::~HtmlStatusBar() {}
56 
57 void HtmlStatusBar::update()
58 {
59  QPalette pal = palette();
60  pal.setColor( backgroundRole(), bgColor() );
61  pal.setColor( foregroundRole(), fgColor() );
62  setPalette( pal );
63  setText( message() );
64  setToolTip( toolTip() );
65 }
66 
67 void HtmlStatusBar::setNormalMode()
68 {
69  setMode( Util::Normal );
70 }
71 
72 void HtmlStatusBar::setHtmlMode()
73 {
74  setMode( Util::Html );
75 }
76 
77 void HtmlStatusBar::setMultipartPlainMode()
78 {
79  setMode( Util::MultipartPlain );
80 }
81 
82 void HtmlStatusBar::setMultipartHtmlMode()
83 {
84  setMode( Util::MultipartHtml );
85 }
86 
87 void HtmlStatusBar::setMode( Util::HtmlMode m, UpdateMode mode )
88 {
89  if (mMode != m) {
90  mMode = m;
91  if ( mode == Update )
92  update();
93  }
94 }
95 
96 void HtmlStatusBar::mousePressEvent( QMouseEvent * event )
97 {
98  if ( event->button() == Qt::LeftButton ) {
99  emit clicked();
100  }
101 }
102 
103 QString HtmlStatusBar::message() const {
104  switch ( mode() ) {
105  case Util::Html: // bold: "HTML Message"
106  case Util::MultipartHtml:
107  return i18nc( "'HTML Message' with html linebreaks between each letter and in bold text.",
108  "<qt><b><br />H<br />T<br />M<br />L<br /> "
109  "<br />M<br />e<br />s<br />s<br />a<br />g<br />e</b></qt>" );
110  case Util::Normal: // normal: "No HTML Message"
111  return i18nc("'No HTML Message' with html linebreaks between each letter.",
112  "<qt><br />N<br />o<br /> "
113  "<br />H<br />T<br />M<br />L<br /> "
114  "<br />M<br />e<br />s<br />s<br />a<br />g<br />e</qt>" );
115  case Util::MultipartPlain: // normal: "Plain Message"
116  return i18nc("'Plain Message' with html linebreaks between each letter.",
117  "<qt><br />P<br />l<br />a<br />i<br />n<br /> "
118  "<br />M<br />e<br />s<br />s<br />a<br />g<br />e<br /></qt>" );
119  default:
120  return QString();
121  }
122 }
123 
124 QString HtmlStatusBar::toolTip() const
125 {
126  switch ( mode() )
127  {
128  case Util::Html:
129  case Util::MultipartHtml:
130  case Util::MultipartPlain:
131  return i18n( "Click to toggle between HTML and plain text." );
132  default:
133  case Util::Normal:
134  break;
135  }
136 
137  return QString();
138 }
139 
140 QColor HtmlStatusBar::fgColor() const
141 {
142  KConfigGroup conf( GlobalSettings::self()->config(), "Reader" );
143  QColor defaultColor, color;
144  switch ( mode() ) {
145  case Util::Html:
146  case Util::MultipartHtml:
147  defaultColor = Qt::white;
148  color = defaultColor;
149  if ( !MessageCore::GlobalSettings::self()->useDefaultColors() ) {
150  color = conf.readEntry( "ColorbarForegroundHTML", defaultColor );
151  }
152  return color;
153  case Util::Normal:
154  case Util::MultipartPlain:
155  defaultColor = Qt::black;
156  color = defaultColor;
157  if ( !MessageCore::GlobalSettings::self()->useDefaultColors() ) {
158  color = conf.readEntry( "ColorbarForegroundPlain", defaultColor );
159  }
160  return color;
161  default:
162  return Qt::black;
163  }
164 }
165 
166 QColor HtmlStatusBar::bgColor() const {
167  KConfigGroup conf( GlobalSettings::self()->config(), "Reader" );
168 
169  QColor defaultColor, color;
170  switch ( mode() ) {
171  case Util::Html:
172  case Util::MultipartHtml:
173  defaultColor = Qt::black;
174  color = defaultColor;
175  if ( !MessageCore::GlobalSettings::self()->useDefaultColors() ) {
176  color = conf.readEntry( "ColorbarBackgroundHTML", defaultColor );
177  }
178  return color;
179  case Util::Normal:
180  case Util::MultipartPlain:
181  defaultColor = Qt::lightGray;
182  color = defaultColor;
183  if ( !MessageCore::GlobalSettings::self()->useDefaultColors() ) {
184  color = conf.readEntry( "ColorbarBackgroundPlain", defaultColor );
185  }
186  return color;
187  default:
188  return Qt::white;
189  }
190 }
191 
globalsettings.h
QWidget
QWidget::palette
const QPalette & palette() const
MessageViewer::HtmlStatusBar::Update
Definition: htmlstatusbar.h:67
MessageViewer::HtmlStatusBar::HtmlStatusBar
HtmlStatusBar(QWidget *parent=0)
Definition: htmlstatusbar.cpp:46
MessageViewer::Util::HtmlMode
HtmlMode
Describes the type of the displayed message.
Definition: util.h:73
MessageViewer::Util::MultipartPlain
A multipart/alternative message, the plain text part is currently displayed.
Definition: util.h:76
MessageViewer::HtmlStatusBar::setMode
void setMode(Util::HtmlMode m, UpdateMode mode=Update)
Switch to mode m.
Definition: htmlstatusbar.cpp:87
QPalette::setColor
void setColor(ColorGroup group, ColorRole role, const QColor &color)
MessageViewer::HtmlStatusBar::setNormalMode
void setNormalMode()
Switch to "normal mode".
Definition: htmlstatusbar.cpp:67
MessageViewer::HtmlStatusBar::update
void update()
Definition: htmlstatusbar.cpp:57
htmlstatusbar.h
QLabel::setAlignment
void setAlignment(QFlags< Qt::AlignmentFlag >)
QMouseEvent
QWidget::foregroundRole
QPalette::ColorRole foregroundRole() const
MessageViewer::HtmlStatusBar::mousePressEvent
void mousePressEvent(QMouseEvent *event)
Definition: htmlstatusbar.cpp:96
QMouseEvent::button
Qt::MouseButton button() const
QWidget::backgroundRole
QPalette::ColorRole backgroundRole() const
MessageViewer::GlobalSettings::self
static GlobalSettings * self()
Definition: globalsettings.cpp:34
MessageViewer::HtmlStatusBar::setMultipartHtmlMode
void setMultipartHtmlMode()
Switch to "multipart html mode".
Definition: htmlstatusbar.cpp:82
MessageViewer::Util::Normal
A normal plaintext message, non-multipart.
Definition: util.h:74
QLabel::setText
void setText(const QString &)
QString
QColor
MessageViewer::Util::Html
A HTML message, non-multipart.
Definition: util.h:75
MessageViewer::HtmlStatusBar::clicked
void clicked()
The user has clicked the status bar.
MessageViewer::HtmlStatusBar::mode
Util::HtmlMode mode() const
Definition: htmlstatusbar.h:74
MessageViewer::HtmlStatusBar::UpdateMode
UpdateMode
Definition: htmlstatusbar.h:65
MessageViewer::HtmlStatusBar::setMultipartPlainMode
void setMultipartPlainMode()
Switch to "multipart plain mode".
Definition: htmlstatusbar.cpp:77
MessageViewer::HtmlStatusBar::setHtmlMode
void setHtmlMode()
Definition: htmlstatusbar.cpp:72
QWidget::setAutoFillBackground
void setAutoFillBackground(bool enabled)
MessageViewer::HtmlStatusBar::~HtmlStatusBar
~HtmlStatusBar()
Definition: htmlstatusbar.cpp:55
QWidget::setToolTip
void setToolTip(const QString &)
QLabel
QPalette
MessageViewer::Util::MultipartHtml
A multipart/altervative message, the HTML part is currently displayed.
Definition: util.h:77
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:32:45 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

messageviewer

Skip menu "messageviewer"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal