1 #include "kpage.h"
2 #include <QList>
3 #include "selection.h"
4 
5 using namespace std;
6 
KPage()7 KPage::KPage() :
8 		links(NULL),
9 		inverted_colors(false),
10 		text(NULL) {
11 	for (int i = 0; i < 3; i++) {
12 		status[i] = 0;
13 		rotation[i] = 0;
14 	}
15 }
16 
~KPage()17 KPage::~KPage() {
18 	if (links != NULL) {
19 		Q_FOREACH(Poppler::Link *l, *links) {
20 			delete l;
21 		}
22 	}
23 	delete links;
24 	if (text != NULL) {
25 		Q_FOREACH(SelectionLine *line, *text) {
26 			delete line;
27 		}
28 	}
29 	delete text;
30 }
31 
get_image(int index) const32 const QImage *KPage::get_image(int index) const {
33 	// return any available image, try the right index first
34 	for (int i = 3; i > 0; i--) {
35 		if (!img[(index + i) % 3].isNull()) {
36 			return &img[(index + i) % 3];
37 		}
38 	}
39 	if (thumbnail.isNull()) {
40 		return NULL;
41 	} else {
42 		return &thumbnail;
43 	}
44 }
45 
get_width(int index) const46 int KPage::get_width(int index) const {
47 	// status might contain the information for img_other, but no inverted version is available yet
48 	if (img[index].isNull()) {
49 		return 0;
50 	} else {
51 		return status[index];
52 	}
53 }
54 
get_rotation(int index) const55 char KPage::get_rotation(int index) const {
56 	// return rotation of next available image, try the right index first
57 	for (int i = 3; i > 0; i--) {
58 		if (!img[(index + i) % 3].isNull()) {
59 			return rotation[(index + i) % 3];
60 		}
61 	}
62 	// no image available? use thumbnail (always 0)
63 	return 0;
64 }
65 
get_text() const66 const QList<SelectionLine *> *KPage::get_text() const {
67 	return text;
68 }
69 
70 //QString KPage::get_label() const {
71 //	return label;
72 //}
73 
toggle_invert_colors()74 void KPage::toggle_invert_colors() {
75 	for (int i = 0; i < 3; i++) {
76 		img[i].swap(img_other[i]);
77 	}
78 	thumbnail.swap(thumbnail_other);
79 	inverted_colors = !inverted_colors;
80 }
81 
82