Messagelib

htmlblock.cpp
1/*
2 SPDX-FileCopyrightText: 2015 Sandro Knauß <sknauss@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "htmlblock.h"
8
9#include "interfaces/htmlwriter.h"
10
11#include <KMime/Content>
12
13#include <QApplication>
14
15using namespace MessageViewer;
16
17HTMLBlock::HTMLBlock() = default;
18
19HTMLBlock::~HTMLBlock() = default;
20
21QString HTMLBlock::dir() const
22{
23 return QApplication::isRightToLeft() ? QStringLiteral("rtl") : QStringLiteral("ltr");
24}
25
26QString HTMLBlock::enter()
27{
28 if (!entered) {
29 entered = true;
30 return enterString();
31 }
32 return {};
33}
34
35QString HTMLBlock::exit()
36{
37 if (entered) {
38 entered = false;
39 return exitString();
40 }
41 return {};
42}
43
44AttachmentMarkBlock::AttachmentMarkBlock(HtmlWriter *writer, KMime::Content *node)
45 : mNode(node)
46 , mWriter(writer)
47{
48 internalEnter();
49}
50
51AttachmentMarkBlock::~AttachmentMarkBlock()
52{
53 internalExit();
54}
55
56void AttachmentMarkBlock::internalEnter()
57{
58 if (mWriter) {
59 mWriter->write(enter());
60 }
61}
62
63void AttachmentMarkBlock::internalExit()
64{
65 if (mWriter) {
66 mWriter->write(exit());
67 }
68}
69
70QString AttachmentMarkBlock::enterString() const
71{
72 const QString index = mNode->index().toString();
73 return QStringLiteral("<a name=\"att%1\"></a>").arg(index) + QStringLiteral("<div id=\"attachmentDiv%1\">\n").arg(index);
74}
75
76QString AttachmentMarkBlock::exitString() const
77{
78 return QStringLiteral("</div>");
79}
80
81RootBlock::RootBlock(HtmlWriter *writer)
82 : HTMLBlock()
83 , mWriter(writer)
84{
85 internalEnter();
86}
87
88RootBlock::~RootBlock()
89{
90 internalExit();
91}
92
93void RootBlock::internalEnter()
94{
95 if (mWriter) {
96 mWriter->write(enter());
97 }
98}
99
100void RootBlock::internalExit()
101{
102 if (mWriter) {
103 mWriter->write(exit());
104 }
105}
106
107QString RootBlock::enterString() const
108{
109 return QStringLiteral("<div style=\"position: relative; word-wrap: break-word\">\n");
110}
111
112QString RootBlock::exitString() const
113{
114 return QStringLiteral("</div>\n");
115}
QString toString() const
ContentIndex index() const
The HTMLBlock class.
Definition htmlblock.h:26
An interface for HTML sinks.
Definition htmlwriter.h:29
void write(const QString &html)
Write out a chunk of text.
bool isRightToLeft()
QString arg(Args &&... args) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:33:26 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.