forked from AngryFender/Remini
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformatdata.h
More file actions
145 lines (127 loc) · 3.86 KB
/
Copy pathformatdata.h
File metadata and controls
145 lines (127 loc) · 3.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#ifndef FORMATDATA_H
#define FORMATDATA_H
#include <QBitArray>
#include <QTextBlockUserData>
#include <QVector>
#define BOLD_SYMBOL_A "**"
#define BOLD_SYMBOL_U "__"
#define ITALIC_SYMBOL_A "*"
#define ITALIC_SYMBOL_U "_"
#define STRIKETHROUGH_SYMBOL "~~"
#define CHECK_SYMBOL_START "- ["
#define CHECKED_SYMBOL_END "x] "
#define UNCHECKED_SYMBOL_END " ] "
#define HEADING1_SYMBOL "# "
#define HEADING2_SYMBOL "## "
#define HEADING3_SYMBOL "### "
#define LINK_SYMBOL_TITLE_START "["
#define LINK_SYMBOL_TITLE_END "]"
#define LINK_SYMBOL_MID "](<"
#define LINK_SYMBOL_URL_START "(<"
#define LINK_SYMBOL_URL_END ">)"
#define CHECKED_PIC "☑"
#define UNCHECKED_PIC "☐"
#define CHECKED_FULL_COUNT 5
#define HEADING1_SYMBOL_COUNT 2
#define HEADING2_SYMBOL_COUNT 3
#define HEADING3_SYMBOL_COUNT 4
class FragmentData
{
public:
enum FormatSymbol
{
BOLD,
ITALIC,
STRIKETHROUGH,
CHECK_START,
CHECKED_END,
UNCHECKED_END,
HEADING1,
HEADING2,
HEADING3,
LINK_TITLE,
LINK_URL,
};
FragmentData(const int start, const int end, const FormatSymbol status)
{
this->start = start;
this->end = end;
this->status = status;
}
int getStart() const;
int getEnd() const;
FormatSymbol getStatus() const;
void setStatus(FormatSymbol status);
private:
int start;
int end;
FormatSymbol status;
};
class FormatData : public QTextBlockUserData
{
public:
FormatData();
~FormatData();
void addFormat(const int start, const int end, const QString &symbol,
const QString *linkUrl = nullptr,
const QString *linkTitle = nullptr);
void addHiddenFormat(const int start, const int end,
const FragmentData::FormatSymbol &status,
const QString &linkUrl, const QString &linkTitle);
QVector<FragmentData *>::Iterator formats_begin()
{
return formats.begin();
};
QVector<FragmentData *>::Iterator formats_end() { return formats.end(); };
QVector<FragmentData *>::reverse_iterator formats_rbegin()
{
return formats.rbegin();
};
QVector<FragmentData *>::reverse_iterator formats_rend()
{
return formats.rend();
};
QVector<FragmentData *>::Iterator hiddenFormats_begin()
{
return hiddenFormats.begin();
};
QVector<FragmentData *>::Iterator hiddenFormats_end()
{
return hiddenFormats.end();
};
bool isEmpty() const;
bool isHidden() const;
bool isFormatted() const;
int getFormatCounts() const;
int hiddenFormatsCount() const;
const QString &getLinkUrl(int key) const;
const QString *getHiddenLinkUrl(int key) const;
const QString *getHiddenTitle(int key) const;
const QString *getLinkUrlFromTitleStart(int key) const;
const QString *getLinkTitleFromTitleStart(int key) const;
void insertLinkText(int key, QString *linkText);
void setHidden(bool hide);
void setFormatted(bool state);
void setMaskSize(const int size);
const QBitArray &getMask() const;
QString getOriginalText() const;
void setOriginalText(const QString &newOriginalText);
int getCalculatedCursorPos(const int posInBlock);
private:
QVector<FragmentData *> formats;
QVector<FragmentData *> hiddenFormats;
QMap<int, QString *> linkMap;
QMap<int, QString *> linkMapHidden;
QMap<int, QString *> linkTitleMapHidden;
QMap<int, QString *> linkUrlMap;
QMap<int, QString *> linkTitleMap;
QBitArray mask;
QString originalText;
bool hidden;
bool formatted;
void addMaskBit(const int start, const QString &startSymbol, const int end,
const QString &endSymbol);
void addMaskBitForLinkContent(const int start, const int end,
const QString &endSymbol);
};
#endif // FORMATDATA_H