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 <kloecker@kde.org>
6 SPDX-FileCopyrightText: 2003 Marc Mutz <mutz@kde.org>
7 SPDX-FileCopyrightText: 2013-2024 Laurent Montel <montel@kde.org>
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
23using namespace MessageViewer;
24namespace
25{
26static const char myHtmlStatusBarConfigGroupName[] = "Reader";
27}
28HtmlStatusBar::HtmlStatusBar(QWidget *parent)
29 : QLabel(parent)
30 , mMode(MimeTreeParser::Util::Normal)
31{
32 setAlignment(Qt::AlignHCenter | Qt::AlignTop);
33 setAutoFillBackground(true);
35 update();
36}
37
38HtmlStatusBar::~HtmlStatusBar() = default;
39
41{
42 return mMode;
43}
44
45bool HtmlStatusBar::isHtml() const
46{
48}
49
50bool HtmlStatusBar::isNormal() const
51{
53}
54
55void 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
69
70void HtmlStatusBar::setHtmlMode()
71{
73}
74
75void HtmlStatusBar::setAvailableModes(const QList<MimeTreeParser::Util::HtmlMode> &availableModes)
76{
77 mAvailableModes = availableModes;
78}
79
80const 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
95void HtmlStatusBar::mousePressEvent(QMouseEvent *event)
96{
97 if (event->button() == Qt::LeftButton) {
99 }
100}
101
102QString 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
128QString 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
144QColor HtmlStatusBar::fgColor() const
145{
146 KConfigGroup conf(KSharedConfig::openConfig(), QLatin1StringView(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
171QColor HtmlStatusBar::bgColor() const
172{
173 KConfigGroup conf(KSharedConfig::openConfig(), QLatin1StringView(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}
198
199#include "moc_htmlstatusbar.cpp"
static KSharedConfig::Ptr openConfig(const QString &fileName=QString(), OpenFlags mode=FullConfig, QStandardPaths::StandardLocation type=QStandardPaths::GenericConfigLocation)
void setMode(MimeTreeParser::Util::HtmlMode m, MessageViewer::HtmlStatusBar::UpdateMode mode=Update)
Switch to mode m.
void setNormalMode()
Switch to "normal mode".
void clicked()
The user has clicked the status bar.
MimeTreeParser::Util::HtmlMode mode() const
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
void update(Part *part, const QByteArray &data, qint64 dataSize)
HtmlMode
Describes the type of the displayed message.
@ Html
A HTML message, non-multipart.
@ Normal
A normal plaintext message, non-multipart.
@ MultipartPlain
A multipart/alternative message, the plain text part is currently displayed.
@ MultipartIcal
A multipart/alternative message, the ICal part is currently displayed.
@ MultipartHtml
A multipart/alternative message, the HTML part is currently displayed.
virtual bool event(QEvent *e) override
void setText(const QString &)
Q_EMITQ_EMIT
void setColor(ColorGroup group, ColorRole role, const QColor &color)
AlignHCenter
PointingHandCursor
LeftButton
QPalette::ColorRole backgroundRole() const const
QPalette::ColorRole foregroundRole() const const
void setToolTip(const QString &)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:07:25 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.