forked from unruhschuh/MrWriter
-
Notifications
You must be signed in to change notification settings - Fork 2
/
page.h
233 lines (196 loc) · 6.96 KB
/
page.h
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#ifndef PAGE_H
#define PAGE_H
#include "stroke.h"
#include <poppler-qt5.h>
#include <poppler-link.h>
#include <QDebug>
#include <QImage>
#include <QTextEdit>
#include <QTextDocument>
#include <memory>
#include <algorithm>
#include <math.h>
extern "C" {
#include<mkdio.h>
}
namespace MrDoc
{
/**
* @brief The Page class is the class containing all information about a page. A page can be blank or contain a pdf page to draw on.
*/
class Page
{
public:
Page();
enum class backgroundType {
PLAIN,
SQUARED,
RULED
};
qreal width() const;
qreal height() const;
void setWidth(qreal width);
void setHeight(qreal height);
void setBackgroundColor(QColor backgroundColor);
QColor backgroundColor(void) const;
void setBackgroundType(backgroundType type);
backgroundType getBackgroundType() const;
const QRectF &dirtyRect() const;
void clearDirtyRect();
bool changePenWidth(int strokeNum, qreal penWidth);
bool changeStrokeColor(int strokeNum, QColor color);
bool changeStrokePattern(int strokeNum, QVector<qreal> pattern);
/**
* @brief textIndexFromMouseClick tests if a (mouse click) coordinate is on text
* @param x x-coordinate of mouse click
* @param y y-coordinate of mouse click
* @return index of text in @ref m_texts if found, otherwise -1
*/
int textIndexFromMouseClick(int x, int y);
/**
* @brief textByIndex
* @param i index in @ref m_texts
* @return text string
*/
const QString& textByIndex(int i);
/**
* @brief appendText appends a tuple to @ref m_texts
* @param rect is the rect bounding the text
* @param font
* @param color font color
* @param text
* @return index of the appended tuple
*/
int appendText(const QRectF& rect, const QFont& font, const QColor& color, const QString& text);
/**
* @brief setText changes the text of tuple provided by @param index or removes the tuple if text is empty.
* @param index
* @param font
* @param color
* @param text new text. If text is empty, the tuple is removed
*/
void setText(int index, const QFont &font, const QColor &color, const QString& text);
/**
* @brief textRectByIndex
* @param i
* @return bounding rect of the text at index @param i
*/
const QRectF& textRectByIndex(int i);
/**
* @brief textColorByIndex
* @param i
* @return text color of the text at index @param i
*/
const QColor& textColorByIndex(int i);
/**
* @brief textFontByIndex
* @param i
* @return text font of the text at index @param i
*/
const QFont& textFontByIndex(int i);
/**
* @brief markdownIndexFromMouseClick tests if a (mouse click) coordinate is on a inserted markdown document element
* @param x x-coordinate of mouse click
* @param y y-coordinate of mouse click
* @return index of document in @ref m_markdownDocs if found, otherwise -1
*/
int markdownIndexFromMouseClick(int x, int y);
/**
* @brief appendMarkdown appends a tuple to @ref m_texts
* @param rect is the bounding rect. If width and height are 0, then width and height are calculated by appendMarkdown.
* @param text
* @return index of the new appended tuple
*/
int appendMarkdown(const QRectF &rect, const QString& text);
/**
* @brief insertMarkdown inserts a markdown document at given @param index. If text is empty nothing happens.
* @param index
* @param text new text. If text is empty, the tuple is removed.
*/
void insertMarkdown(int index, const QString& text, const QRectF &rect);
/**
* @brief resetMarkdown changes the text of a markdown document at given @param index. If text is empty the document will be deleted.
* @param index
* @param text
* @param rect
*/
void resetMarkdown(int index, const QString& text, const QRectF &rect);
QString markdownByIndex(int i);
QRectF markdownRectByIndex(int i);
const QVector<Stroke> &strokes();
const QVector<std::tuple<QRectF, QFont, QColor, QString> > &texts();
const QVector<std::tuple<QRectF, QString>>& markdowns();
QVector<QPair<Stroke, int>> getStrokes(QPolygonF selectionPolygon);
QVector<QPair<Stroke, int>> removeStrokes(QPolygonF selectionPolygon);
void removeStrokeAt(int i);
void removeLastStroke();
void insertStrokes(const QVector<QPair<Stroke, int>> &strokesAndPositions);
void insertStroke(int position, const Stroke &stroke);
void appendStroke(const Stroke &stroke);
void appendStrokes(const QVector<Stroke> &strokes);
void prependStroke(const Stroke &stroke);
/**
* @brief setPdf sets a pdf page as "background" for the page
* @param page is the pointer to pdf page (provided by poppler)
* @param pageNum is the page number (first page is 0)
* @param adjustSize if true, the size will adjusted to pdf's size
*/
void setPdf(Poppler::Page *page, int pageNum, bool adjustSize);
//void setPdfPath(const QString path);
/**
* @brief searchPdfNext searches for all occurences of @param text in the page
* @return true if some text was found, else false
*/
bool searchPdfNext(const QString& text);
/**
* @brief searchPdfPrev searches for all occurences of @param text in the page
* @return true if some text was found, else false
* @see searchPdfNext
*/
bool searchPdfPrev(const QString& text);
/**
* @brief clearPdfSearch clears the text search
*/
void clearPdfSearch();
/**
* @brief linkFromMouseClick tests if a (mouse click) coordinate is on a pdf goto-link
* @param x x-coordinate of mouse click
* @param y y-coordinate of mouse click
* @return pointer to the link in if clicked on a link, otherwise nullptr
*/
Poppler::LinkGoto* linkFromMouseClick(qreal x, qreal y);
// virtual void paint(QPainter &painter, qreal zoom);
/**
* @brief paint paints the page with @param painter
* @param painter
* @param zoom
* @param region
*/
virtual void paint(QPainter &painter, qreal zoom, QRectF region = QRect(0, 0, 0, 0));
void paintForPdfExport(QPainter &painter, qreal zoom);
// QVector<Stroke> strokes;
bool isPdf() const{
return m_pdfPointer != nullptr;
}
int pageNum(){
return pageno;
}
static char* compileMarkdown(const QString& text);
protected:
QVector<Stroke> m_strokes;
std::shared_ptr<Poppler::Page> m_pdfPointer = std::shared_ptr<Poppler::Page>(nullptr); /**< pointer to the pdf page to draw on (nullptr, if blank page) */
int pageno; //pageNumber in the document
QList<QRectF> searchResultRects; /**< list of the (yellow) rectangles around search results */
QVector<std::tuple<QRectF, QFont, QColor, QString>> m_texts; /**< contains the texts */
QVector<std::tuple<QRectF, QString>> m_markdownDocs; /**< contains the inserted markdown documents, QRectF is the bounding rect (zoom factor 1)*/
private:
QSizeF adjustMarkdownSize(int x, int y, QSizeF oldSize);
QColor m_backgroundColor;
backgroundType m_backgroundType;
qreal m_width; // post script units
qreal m_height; // post script units
QRectF m_dirtyRect;
bool rectIsPoint = true; //in m_texts
};
}
#endif // PAGE_H