1 #ifndef SELECTIONPART_H
2 #define SELECTIONPART_H
3 
4 #include <QRectF>
5 #if QT_VERSION >= 0x050000
6 #	include <poppler-qt5.h>
7 #else
8 #	include <poppler-qt4.h>
9 #endif
10 
11 
12 namespace Selection {
13 	enum Mode {
14 		Start,
15 		StartWord,
16 		StartLine,
17 		End
18 	};
19 }
20 
21 
22 class SelectionPart {
23 public:
24 	SelectionPart(Poppler::TextBox *box);
25 	~SelectionPart();
26 
27 	void add_word(Poppler::TextBox *box);
28 	Poppler::TextBox *get_text() const;
29 	QRectF get_bbox() const;
30 
31 private:
32 	Poppler::TextBox *text_box;
33 	QRectF bbox;
34 };
35 
36 bool selection_less_y(const SelectionPart *a, const SelectionPart *b);
37 
38 
39 class SelectionLine {
40 public:
41 	SelectionLine(SelectionPart *part);
42 	~SelectionLine();
43 
44 	void add_part(SelectionPart *part);
45 	const QList<SelectionPart *> &get_parts() const;
46 	QRectF get_bbox() const;
47 
48 	void sort();
49 
50 private:
51 	QList<SelectionPart *> parts;
52 	QRectF bbox;
53 };
54 
55 bool selection_less_x(const SelectionPart *a, const SelectionPart *b);
56 
57 
58 class Cursor {
59 public:
60 	int page;
61 	QPointF click;
62 	int line;
63 	int part;
64 	int word;
65 	int character;
66 	bool inclusive;
67 	float x;
68 	SelectionLine *selectionline;
69 
70 private:
71 	void find_part(bool from, enum Selection::Mode mode);
72 	void find_word(const Poppler::TextBox *text_box, bool from, enum Selection::Mode mode);
73 	void find_character(const Poppler::TextBox *text, bool from);
74 
75 	void set_beginning_of_line(const SelectionLine *line, bool from);
76 	void set_end_of_line(const SelectionLine *line, bool from);
77 
78 	void increment();
79 	void decrement();
80 
81 	friend class MouseSelection;
82 };
83 
84 
85 class MouseSelection {
86 public:
87 	MouseSelection();
88 
89 	void set_cursor(const QList<SelectionLine *> *lines, std::pair<int, QPointF> pos, enum Selection::Mode mode);
90 	Cursor get_cursor(bool from) const;
91 	QString get_selection_text(int page, const QList<SelectionLine *> *lines) const;
92 
93 	void deactivate();
94 	bool is_active() const;
95 
96 private:
97 	int bsearch(const QList<SelectionLine *> *lines, float value);
98 	void update_reversed(Cursor &c, const SelectionLine *line) ;
99 	bool calculate_reversed(Cursor &c, const SelectionLine *line) const;
100 
101 	Cursor cursor[2];
102 
103 	bool active;
104 	bool reversed;
105 	enum Selection::Mode mode;
106 };
107 
108 
109 #endif
110 
111