Messagelib

htmlstatusbar.cpp
1 /* -*- c++ -*-
2  htmlstatusbar.cpp
3 
4  This file is part of KMail, the KDE mail client.
5  SPDX-FileCopyrightText: 2002 Ingo Kloecker <[email protected]>
6  SPDX-FileCopyrightText: 2003 Marc Mutz <[email protected]>
7  SPDX-FileCopyrightText: 2013-2021 Laurent Montel <[email protected]>
8 
9  SPDX-License-Identifier: GPL-2.0-or-later
10 */
11 
12 #include "htmlstatusbar.h"
13 #include "settings/messageviewersettings.h"
14 
15 #include "MessageCore/MessageCoreSettings"
16 
17 #include <KConfigGroup>
18 #include <KLocalizedString>
19 
20 #include <KSharedConfig>
21 #include <QMouseEvent>
22 
23 using namespace MessageViewer;
24 namespace
25 {
26 static const char myHtmlStatusBarConfigGroupName[] = "Reader";
27 }
28 HtmlStatusBar::HtmlStatusBar(QWidget *parent)
29  : QLabel(parent)
30  , mMode(MimeTreeParser::Util::Normal)
31 {
32  setAlignment(Qt::AlignHCenter | Qt::AlignTop);
33  setAutoFillBackground(true);
34  setCursor(QCursor(Qt::PointingHandCursor));
35  update();
36 }
37 
38 HtmlStatusBar::~HtmlStatusBar() = default;
39 
41 {
42  return mMode;
43 }
44 
45 bool HtmlStatusBar::isHtml() const
46 {
47  return mode() == MimeTreeParser::Util::Html;
48 }
49 
50 bool HtmlStatusBar::isNormal() const
51 {
52  return mode() == MimeTreeParser::Util::Normal;
53 }
54 
55 void HtmlStatusBar::update()
56 {
57  QPalette pal = palette();
58  pal.setColor(backgroundRole(), bgColor());
59  pal.setColor(foregroundRole(), fgColor());
60  setPalette(pal);
61  setText(message());
62  setToolTip(toolTip());
63 }
64 
66 {
68 }
69 
70 void HtmlStatusBar::setHtmlMode()
71 {
73 }
74 
75 void HtmlStatusBar::setAvailableModes(const QList<MimeTreeParser::Util::HtmlMode> &availableModes)
76 {
77  mAvailableModes = availableModes;
78 }
79 
80 const QList<MimeTreeParser::Util::HtmlMode> &HtmlStatusBar::availableModes()
81 {
82  return mAvailableModes;
83 }
84 
86 {
87  if (mMode != m) {
88  mMode = m;
89  if (mode == Update) {
90  update();
91  }
92  }
93 }
94 
95 void HtmlStatusBar::mousePressEvent(QMouseEvent *event)
96 {
97  if (event->button() == Qt::LeftButton) {
98  Q_EMIT clicked();
99  }
100 }
101 
102 QString HtmlStatusBar::message() const
103 {
104  switch (mode()) {
105  case MimeTreeParser::Util::Html: // bold: "HTML Message"
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 MimeTreeParser::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 MimeTreeParser::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  case MimeTreeParser::Util::MultipartIcal: // normal: "Calendar Message"
120  return i18nc("'Calendar Message' with html linebreaks between each letter.",
121  "<qt><br />C<br />a<br />l<br />e<br />n<br />d<br />a<br />r<br /> "
122  "<br />M<br />e<br />s<br />s<br />a<br />g<br />e<br /></qt>");
123  default:
124  return {};
125  }
126 }
127 
128 QString HtmlStatusBar::toolTip() const
129 {
130  switch (mode()) {
135  return i18n("Click to toggle between HTML, plain text and calendar.");
136  default:
138  break;
139  }
140 
141  return {};
142 }
143 
144 QColor HtmlStatusBar::fgColor() const
145 {
146  KConfigGroup conf(KSharedConfig::openConfig(), myHtmlStatusBarConfigGroupName);
147  QColor defaultColor;
148  QColor color;
149  switch (mode()) {
152  defaultColor = Qt::white;
153  color = defaultColor;
154  if (!MessageCore::MessageCoreSettings::self()->useDefaultColors()) {
155  color = conf.readEntry("ColorbarForegroundHTML", defaultColor);
156  }
157  return color;
161  defaultColor = Qt::black;
162  color = defaultColor;
163  if (!MessageCore::MessageCoreSettings::self()->useDefaultColors()) {
164  color = conf.readEntry("ColorbarForegroundPlain", defaultColor);
165  }
166  return color;
167  }
168  return Qt::black;
169 }
170 
171 QColor HtmlStatusBar::bgColor() const
172 {
173  KConfigGroup conf(KSharedConfig::openConfig(), myHtmlStatusBarConfigGroupName);
174 
175  QColor defaultColor;
176  QColor color;
177  switch (mode()) {
180  defaultColor = Qt::black;
181  color = defaultColor;
182  if (!MessageCore::MessageCoreSettings::self()->useDefaultColors()) {
183  color = conf.readEntry("ColorbarBackgroundHTML", defaultColor);
184  }
185  return color;
189  defaultColor = Qt::lightGray;
190  color = defaultColor;
191  if (!MessageCore::MessageCoreSettings::self()->useDefaultColors()) {
192  color = conf.readEntry("ColorbarBackgroundPlain", defaultColor);
193  }
194  return color;
195  }
196  return Qt::white;
197 }
HtmlMode
Describes the type of the displayed message.
void setColor(QPalette::ColorGroup group, QPalette::ColorRole role, const QColor &color)
void setNormalMode()
Switch to "normal mode".
A HTML message, non-multipart.
LeftButton
A multipart/alternative message, the HTML part is currently displayed.
AlignHCenter
void setMode(MimeTreeParser::Util::HtmlMode m, MessageViewer::HtmlStatusBar::UpdateMode mode=Update)
Switch to mode m.
QString i18nc(const char *context, const char *text, const TYPE &arg...)
Qt::MouseButton button() const const
PointingHandCursor
MimeTreeParser::Util::HtmlMode mode() const
static KSharedConfig::Ptr openConfig(const QString &fileName=QString(), OpenFlags mode=FullConfig, QStandardPaths::StandardLocation type=QStandardPaths::GenericConfigLocation)
QString i18n(const char *text, const TYPE &arg...)
A multipart/alternative message, the ICal part is currently displayed.
void update(Part *part, const QByteArray &data, qint64 dataSize)
A normal plaintext message, non-multipart.
T readEntry(const QString &key, const T &aDefault) const
A multipart/alternative message, the plain text part is currently displayed.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Dec 4 2021 23:12:53 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.