35 files changed, 3111 insertions, 985 deletions
diff --git a/noncore/apps/opie-reader/Aportis.cpp b/noncore/apps/opie-reader/Aportis.cpp index 595b385..1327ff8 100644 --- a/noncore/apps/opie-reader/Aportis.cpp +++ b/noncore/apps/opie-reader/Aportis.cpp | |||
@@ -1,11 +1,57 @@ | |||
1 | #include <stdio.h> | 1 | #include <stdio.h> |
2 | #include <string.h> | 2 | #include <string.h> |
3 | #include "Aportis.h" | 3 | #include "Aportis.h" |
4 | #include "my_list.h" | ||
5 | #include "Bkmks.h" | ||
4 | 6 | ||
5 | Aportis::Aportis() { /*printf("constructing:%x\n",fin);*/ } | 7 | Aportis::Aportis() : peanutfile(false) { /*printf("constructing:%x\n",fin);*/ } |
8 | |||
9 | void Aportis::dePeanut(int& ch) | ||
10 | { | ||
11 | if (peanutfile && ch != EOF) | ||
12 | { | ||
13 | unsigned char c = ch; | ||
14 | if (peanutfile) c ^= 0xa5; | ||
15 | ch = c; | ||
16 | } | ||
17 | } | ||
6 | 18 | ||
7 | CList<Bkmk>* Aportis::getbkmklist() | 19 | CList<Bkmk>* Aportis::getbkmklist() |
8 | { | 20 | { |
21 | /* | ||
22 | if (peanutfile) | ||
23 | { | ||
24 | if (nRecs2 > nRecs) | ||
25 | { | ||
26 | CList<Bkmk>* t = new CList<Bkmk>; | ||
27 | for (int i = nRecs; i < nRecs2; i++) | ||
28 | { | ||
29 | char name[17]; | ||
30 | name[16] = '\0'; | ||
31 | qDebug("Record:%d, Length:%u",i,recordlength(i)); | ||
32 | gotorecordnumber(i); | ||
33 | fread(name,1,16,fin); | ||
34 | unsigned long lcn; | ||
35 | fread(&lcn,sizeof(lcn),1,fin); | ||
36 | lcn ^= 0xa5a5a5a5; | ||
37 | lcn = SwapLong(lcn); | ||
38 | qDebug("Bookmark:%s:%u", name,lcn); | ||
39 | tchar tname[17]; | ||
40 | memset(tname, 0, sizeof(tname)); | ||
41 | for (int i = 0; name[i] != 0; i++) | ||
42 | { | ||
43 | tname[i] = name[i] ^ 0xa5; | ||
44 | } | ||
45 | t->push_back(Bkmk(tname, NULL, lcn)); | ||
46 | } | ||
47 | return t; | ||
48 | } | ||
49 | else | ||
50 | { | ||
51 | return NULL; | ||
52 | } | ||
53 | } | ||
54 | */ | ||
9 | if (bCompressed != 4) return NULL; | 55 | if (bCompressed != 4) return NULL; |
10 | CList<Bkmk>* t = new CList<Bkmk>; | 56 | CList<Bkmk>* t = new CList<Bkmk>; |
11 | size_t cur = ftell(fin); | 57 | size_t cur = ftell(fin); |
@@ -34,7 +80,7 @@ CList<Bkmk>* Aportis::getbkmklist() | |||
34 | { | 80 | { |
35 | tname[i] = name[i]; | 81 | tname[i] = name[i]; |
36 | } | 82 | } |
37 | t->push_back(Bkmk(tname,lcn)); | 83 | t->push_back(Bkmk(tname, NULL, lcn)); |
38 | #else | 84 | #else |
39 | t->push_back(Bkmk(name,lcn)); | 85 | t->push_back(Bkmk(name,lcn)); |
40 | #endif | 86 | #endif |
@@ -46,7 +92,6 @@ CList<Bkmk>* Aportis::getbkmklist() | |||
46 | 92 | ||
47 | int Aportis::openfile(const char *src) | 93 | int Aportis::openfile(const char *src) |
48 | { | 94 | { |
49 | |||
50 | // printf("In openfile\n"); | 95 | // printf("In openfile\n"); |
51 | int ret = 0; | 96 | int ret = 0; |
52 | 97 | ||
@@ -55,9 +100,42 @@ int Aportis::openfile(const char *src) | |||
55 | if (head.creator != 0x64414552 // 'dAER' | 100 | if (head.creator != 0x64414552 // 'dAER' |
56 | || head.type != 0x74584554) // 'tXET') | 101 | || head.type != 0x74584554) // 'tXET') |
57 | { | 102 | { |
103 | |||
104 | if (memcmp(&head.creator, "PPrs", 4) == 0 && memcmp(&head.type, "PNRd", 4) == 0) | ||
105 | { | ||
106 | peanutfile = true; | ||
107 | } | ||
108 | else | ||
109 | { | ||
58 | return -2; | 110 | return -2; |
59 | } | 111 | } |
112 | } | ||
113 | |||
114 | nRecs2 = nRecs = SwapWord(head.recordList.numRecords) - 1; | ||
115 | fseek(fin,0,SEEK_END); | ||
116 | dwLen = ftell(fin); | ||
117 | |||
118 | if (peanutfile) | ||
119 | { | ||
60 | 120 | ||
121 | PeanutHeader hdr0; | ||
122 | gotorecordnumber(0); | ||
123 | fread(&hdr0, sizeof(hdr0), 1, fin); | ||
124 | qDebug("Version:%x", ntohs(hdr0.Version)); | ||
125 | if (hdr0.Version && 0x0200) | ||
126 | { | ||
127 | bCompressed = 2; | ||
128 | } | ||
129 | else | ||
130 | { | ||
131 | bCompressed = 1; | ||
132 | } | ||
133 | BlockSize = 4096; | ||
134 | nRecs = SwapWord(hdr0.Records)-1; | ||
135 | dwTLen = nRecs*BlockSize; | ||
136 | } | ||
137 | else | ||
138 | { | ||
61 | gotorecordnumber(0); | 139 | gotorecordnumber(0); |
62 | tDocRecord0 hdr0; | 140 | tDocRecord0 hdr0; |
63 | fread(&hdr0, sizeof(hdr0), 1, fin); | 141 | fread(&hdr0, sizeof(hdr0), 1, fin); |
@@ -66,11 +144,6 @@ int Aportis::openfile(const char *src) | |||
66 | ret = bCompressed; | 144 | ret = bCompressed; |
67 | bCompressed = 2; | 145 | bCompressed = 2; |
68 | } | 146 | } |
69 | |||
70 | fseek(fin,0,SEEK_END); | ||
71 | dwLen = ftell(fin); | ||
72 | nRecs2 = nRecs = SwapWord(head.recordList.numRecords) - 1; | ||
73 | |||
74 | switch (bCompressed) | 147 | switch (bCompressed) |
75 | { | 148 | { |
76 | case 4: | 149 | case 4: |
@@ -90,6 +163,7 @@ int Aportis::openfile(const char *src) | |||
90 | case 1: | 163 | case 1: |
91 | case 2: | 164 | case 2: |
92 | default: | 165 | default: |
166 | nRecs = SwapWord(hdr0.wNumRecs); | ||
93 | dwTLen = SwapLong(hdr0.dwStoryLen); | 167 | dwTLen = SwapLong(hdr0.dwStoryLen); |
94 | BlockSize = SwapWord(hdr0.wRecSize); | 168 | BlockSize = SwapWord(hdr0.wRecSize); |
95 | if (BlockSize == 0) | 169 | if (BlockSize == 0) |
@@ -98,6 +172,8 @@ int Aportis::openfile(const char *src) | |||
98 | printf("WARNING: Blocksize not set in source file\n"); | 172 | printf("WARNING: Blocksize not set in source file\n"); |
99 | } | 173 | } |
100 | } | 174 | } |
175 | } | ||
176 | |||
101 | 177 | ||
102 | 178 | ||
103 | // this is the main record buffer | 179 | // this is the main record buffer |
@@ -106,6 +182,7 @@ int Aportis::openfile(const char *src) | |||
106 | cbptr = 0; | 182 | cbptr = 0; |
107 | outptr = 0; | 183 | outptr = 0; |
108 | refreshbuffer(); | 184 | refreshbuffer(); |
185 | qDebug("Number of records:[%u,%u]", nRecs, nRecs2); | ||
109 | return ret; | 186 | return ret; |
110 | } | 187 | } |
111 | 188 | ||
@@ -117,6 +194,7 @@ int Aportis::getch() | |||
117 | else | 194 | else |
118 | { | 195 | { |
119 | int c = getc(fin); | 196 | int c = getc(fin); |
197 | dePeanut(c); | ||
120 | dwRecLen--; | 198 | dwRecLen--; |
121 | currentpos++; | 199 | currentpos++; |
122 | return c; | 200 | return c; |
@@ -129,10 +207,11 @@ int Aportis::getch() | |||
129 | } | 207 | } |
130 | if ((dwRecLen == 0) && !refreshbuffer()) return EOF; | 208 | if ((dwRecLen == 0) && !refreshbuffer()) return EOF; |
131 | currentpos++; | 209 | currentpos++; |
132 | unsigned int c; | 210 | int c; |
133 | 211 | ||
134 | // take a char from the input buffer | 212 | // take a char from the input buffer |
135 | c = getc(fin); | 213 | c = getc(fin); |
214 | dePeanut(c); | ||
136 | dwRecLen--; | 215 | dwRecLen--; |
137 | // separate the char into zones: 0, 1...8, 9...0x7F, 0x80...0xBF, 0xC0...0xFF | 216 | // separate the char into zones: 0, 1...8, 9...0x7F, 0x80...0xBF, 0xC0...0xFF |
138 | 217 | ||
@@ -152,7 +231,9 @@ int Aportis::getch() | |||
152 | dwRecLen -= c; | 231 | dwRecLen -= c; |
153 | while(c--) | 232 | while(c--) |
154 | { | 233 | { |
155 | circbuf[cbptr = (cbptr+1)%2048] = getc(fin); | 234 | int c = getc(fin); |
235 | dePeanut(c); | ||
236 | circbuf[cbptr = (cbptr+1)%2048] = c; | ||
156 | } | 237 | } |
157 | return circbuf[outptr = (outptr+1)%2048]; | 238 | return circbuf[outptr = (outptr+1)%2048]; |
158 | } | 239 | } |
@@ -160,7 +241,9 @@ int Aportis::getch() | |||
160 | { | 241 | { |
161 | int m,n; | 242 | int m,n; |
162 | c <<= 8; | 243 | c <<= 8; |
163 | c += getc(fin); | 244 | int c1 = getc(fin); |
245 | dePeanut(c1); | ||
246 | c += c1; | ||
164 | dwRecLen--; | 247 | dwRecLen--; |
165 | m = (c & 0x3FFF) >> COUNT_BITS; | 248 | m = (c & 0x3FFF) >> COUNT_BITS; |
166 | n = c & ((1<<COUNT_BITS) - 1); | 249 | n = c & ((1<<COUNT_BITS) - 1); |
diff --git a/noncore/apps/opie-reader/Aportis.h b/noncore/apps/opie-reader/Aportis.h index 08016f4..1ca5e73 100644 --- a/noncore/apps/opie-reader/Aportis.h +++ b/noncore/apps/opie-reader/Aportis.h | |||
@@ -40,6 +40,14 @@ struct tDocRecord0 { | |||
40 | DWORD dwSpare2; | 40 | DWORD dwSpare2; |
41 | }; | 41 | }; |
42 | 42 | ||
43 | struct PeanutHeader | ||
44 | { | ||
45 | UInt16 Version; | ||
46 | UInt8 Junk1[6]; | ||
47 | UInt16 Records; | ||
48 | UInt8 Junk2[106]; | ||
49 | }; | ||
50 | |||
43 | ////////////// utilities ////////////////////////////////////// | 51 | ////////////// utilities ////////////////////////////////////// |
44 | 52 | ||
45 | inline WORD SwapWord(WORD r) | 53 | inline WORD SwapWord(WORD r) |
@@ -53,6 +61,8 @@ inline DWORD SwapLong(DWORD r) | |||
53 | } | 61 | } |
54 | 62 | ||
55 | class Aportis : public CExpander, Cpdb { | 63 | class Aportis : public CExpander, Cpdb { |
64 | bool peanutfile; | ||
65 | void dePeanut(int&); | ||
56 | DWORD dwLen; | 66 | DWORD dwLen; |
57 | WORD nRecs2; | 67 | WORD nRecs2; |
58 | DWORD dwTLen; | 68 | DWORD dwTLen; |
@@ -78,6 +88,10 @@ public: | |||
78 | virtual unsigned int locate(); | 88 | virtual unsigned int locate(); |
79 | virtual void locate(unsigned int n); | 89 | virtual void locate(unsigned int n); |
80 | virtual CList<Bkmk>* getbkmklist(); | 90 | virtual CList<Bkmk>* getbkmklist(); |
91 | virtual MarkupType PreferredMarkup() | ||
92 | { | ||
93 | return (peanutfile) ? cPML : cTEXT; | ||
94 | } | ||
81 | private: | 95 | private: |
82 | bool refreshbuffer(); | 96 | bool refreshbuffer(); |
83 | unsigned int GetBS(unsigned int bn); | 97 | unsigned int GetBS(unsigned int bn); |
diff --git a/noncore/apps/opie-reader/Bkmks.cpp b/noncore/apps/opie-reader/Bkmks.cpp new file mode 100644 index 0000000..92ed69f --- a/dev/null +++ b/noncore/apps/opie-reader/Bkmks.cpp | |||
@@ -0,0 +1,240 @@ | |||
1 | #include <qmessagebox.h> | ||
2 | |||
3 | #include "Bkmks.h" | ||
4 | |||
5 | #include "StyleConsts.h" | ||
6 | #include "Markups.h" | ||
7 | #include "my_list.h" | ||
8 | #include "version.h" | ||
9 | |||
10 | const unsigned long BkmkFile::magic = ((unsigned long)'q' << 24) | ((unsigned long)'t' << 16) | ((unsigned long)'r' << 8) | ((unsigned long)BKMKTYPE); | ||
11 | |||
12 | |||
13 | Bkmk::Bkmk(const tchar* _nm, const tchar* _anno, unsigned int _p) : m_position(_p) | ||
14 | { | ||
15 | int len = ustrlen(_nm)+1; | ||
16 | m_name = new tchar[len]; | ||
17 | for (int i = 0; i < len; i++) m_name[i] = _nm[i]; | ||
18 | |||
19 | if (_anno == NULL) | ||
20 | { | ||
21 | m_anno = new tchar[1]; | ||
22 | m_anno[0] = 0; | ||
23 | } | ||
24 | else | ||
25 | { | ||
26 | len = ustrlen(_anno)+1; | ||
27 | m_anno = new tchar[len]; | ||
28 | for (int i = 0; i < len; i++) m_anno[i] = _anno[i]; | ||
29 | } | ||
30 | } | ||
31 | |||
32 | Bkmk::~Bkmk() | ||
33 | { | ||
34 | if (m_name != NULL) delete [] m_name; | ||
35 | m_name = NULL; | ||
36 | if (m_anno != NULL) delete [] m_anno; | ||
37 | m_anno = NULL; | ||
38 | } | ||
39 | |||
40 | Bkmk& Bkmk::operator=(const Bkmk& rhs) | ||
41 | { | ||
42 | if (m_name != NULL) | ||
43 | { | ||
44 | delete [] m_name; | ||
45 | m_name = NULL; | ||
46 | } | ||
47 | if (m_anno != NULL) | ||
48 | { | ||
49 | delete [] m_anno; | ||
50 | m_anno = NULL; | ||
51 | } | ||
52 | if (rhs.m_name != NULL) | ||
53 | { | ||
54 | int len = ustrlen(rhs.m_name)+1; | ||
55 | m_name = new tchar[len]; | ||
56 | for (int i = 0; i < len; i++) m_name[i] = rhs.m_name[i]; | ||
57 | } | ||
58 | else | ||
59 | m_name = NULL; | ||
60 | if (rhs.m_anno != NULL) | ||
61 | { | ||
62 | int len = ustrlen(rhs.m_anno)+1; | ||
63 | m_anno = new tchar[len]; | ||
64 | for (int i = 0; i < len; i++) m_anno[i] = rhs.m_anno[i]; | ||
65 | } | ||
66 | else | ||
67 | m_anno = NULL; | ||
68 | m_position = rhs.m_position; | ||
69 | return *this; | ||
70 | } | ||
71 | |||
72 | bool Bkmk::operator==(const Bkmk& rhs) | ||
73 | { | ||
74 | return (m_position == rhs.m_position && ustrcmp(m_name,rhs.m_name) == 0); | ||
75 | } | ||
76 | |||
77 | void Bkmk::setAnno(tchar* t) | ||
78 | { | ||
79 | if (m_anno != NULL) | ||
80 | { | ||
81 | delete [] m_anno; | ||
82 | m_anno = NULL; | ||
83 | } | ||
84 | if (t != NULL) | ||
85 | { | ||
86 | int len = ustrlen(t)+1; | ||
87 | m_anno = new tchar[len]; | ||
88 | for (int i = 0; i < len; i++) m_anno[i] = t[i]; | ||
89 | } | ||
90 | else | ||
91 | m_anno = NULL; | ||
92 | } | ||
93 | |||
94 | BkmkFile::BkmkFile(const char *fnm, bool w = false) | ||
95 | : | ||
96 | wt(w), isUpgraded(false) | ||
97 | { | ||
98 | if (w) | ||
99 | { | ||
100 | f = fopen(fnm, "wb"); | ||
101 | } | ||
102 | else | ||
103 | { | ||
104 | f = fopen(fnm, "rb"); | ||
105 | } | ||
106 | } | ||
107 | |||
108 | BkmkFile::~BkmkFile() | ||
109 | { | ||
110 | if (f != NULL) fclose(f); | ||
111 | } | ||
112 | |||
113 | void BkmkFile::write(tchar* nm, tchar* an, const unsigned int& pos) | ||
114 | { | ||
115 | if (f != NULL) | ||
116 | { | ||
117 | unsigned short ln = ustrlen(nm); | ||
118 | fwrite(&ln,sizeof(ln),1,f); | ||
119 | fwrite(nm,sizeof(tchar),ln,f); | ||
120 | ln = ustrlen(an); | ||
121 | fwrite(&ln,sizeof(ln),1,f); | ||
122 | if (ln > 0) fwrite(an,sizeof(tchar),ln,f); | ||
123 | fwrite(&pos,sizeof(pos),1,f); | ||
124 | } | ||
125 | } | ||
126 | |||
127 | void BkmkFile::write(const Bkmk& b) { write(b.name(), b.anno(), b.value()); } | ||
128 | |||
129 | void BkmkFile::write(CList<Bkmk>& bl) | ||
130 | { | ||
131 | if (f != NULL) | ||
132 | { | ||
133 | fwrite(&magic, sizeof(magic), 1, f); | ||
134 | for (CList<Bkmk>::iterator i = bl.begin(); i != bl.end(); i++) | ||
135 | { | ||
136 | write(*i); | ||
137 | } | ||
138 | } | ||
139 | } | ||
140 | |||
141 | Bkmk* BkmkFile::read() | ||
142 | { | ||
143 | Bkmk* b = NULL; | ||
144 | if (f != NULL) | ||
145 | { | ||
146 | unsigned short ln; | ||
147 | if (fread(&ln,sizeof(ln),1,f) == 1) | ||
148 | { | ||
149 | b = new Bkmk; | ||
150 | b->m_name = new tchar[ln+1]; | ||
151 | fread(b->m_name,sizeof(tchar),ln,f); | ||
152 | b->m_name[ln] = 0; | ||
153 | |||
154 | fread(&ln,sizeof(ln),1,f); | ||
155 | b->m_anno = new tchar[ln+1]; | ||
156 | if (ln > 0) fread(b->m_anno,sizeof(tchar),ln,f); | ||
157 | b->m_anno[ln] = 0; | ||
158 | fread(&b->m_position,sizeof(b->m_position),1,f); | ||
159 | } | ||
160 | } | ||
161 | return b; | ||
162 | } | ||
163 | |||
164 | CList<Bkmk>* BkmkFile::readall() | ||
165 | { | ||
166 | CList<Bkmk>* bl = NULL; | ||
167 | if (f != NULL) | ||
168 | { | ||
169 | unsigned long newmagic; | ||
170 | fread(&newmagic, sizeof(newmagic), 1, f); | ||
171 | if (newmagic != magic) | ||
172 | { | ||
173 | if (QMessageBox::warning(NULL, "Old bookmark file!", "Which version of QTReader\ndid you upgrade from?", "0_4*", "Any other version") == 0) | ||
174 | { | ||
175 | fseek(f,0,SEEK_SET); | ||
176 | bl = readall04(); | ||
177 | } | ||
178 | else | ||
179 | { | ||
180 | fseek(f,0,SEEK_SET); | ||
181 | bl = readall03(); | ||
182 | } | ||
183 | isUpgraded = true; | ||
184 | } | ||
185 | else | ||
186 | { | ||
187 | bl = readall04(); | ||
188 | } | ||
189 | } | ||
190 | return bl; | ||
191 | } | ||
192 | |||
193 | CList<Bkmk>* BkmkFile::readall04() | ||
194 | { | ||
195 | CList<Bkmk>* bl = new CList<Bkmk>; | ||
196 | while (1) | ||
197 | { | ||
198 | Bkmk* b = read(); | ||
199 | if (b == NULL) break; | ||
200 | bl->push_back(*b); | ||
201 | delete b; | ||
202 | } | ||
203 | return bl; | ||
204 | } | ||
205 | |||
206 | CList<Bkmk>* BkmkFile::readall03() | ||
207 | { | ||
208 | CList<Bkmk>* bl = new CList<Bkmk>; | ||
209 | while (1) | ||
210 | { | ||
211 | Bkmk* b = read03(); | ||
212 | if (b == NULL) break; | ||
213 | bl->push_back(*b); | ||
214 | delete b; | ||
215 | } | ||
216 | return bl; | ||
217 | } | ||
218 | |||
219 | Bkmk* BkmkFile::read03() | ||
220 | { | ||
221 | Bkmk* b = NULL; | ||
222 | if (f != NULL) | ||
223 | { | ||
224 | unsigned short ln; | ||
225 | if (fread(&ln,sizeof(ln),1,f) == 1) | ||
226 | { | ||
227 | b = new Bkmk; | ||
228 | b->m_name = new tchar[ln+1]; | ||
229 | fread(b->m_name,sizeof(tchar),ln,f); | ||
230 | b->m_name[ln] = 0; | ||
231 | |||
232 | ln = 0; | ||
233 | b->m_anno = new tchar[ln+1]; | ||
234 | b->m_anno[ln] = 0; | ||
235 | |||
236 | fread(&b->m_position,sizeof(b->m_position),1,f); | ||
237 | } | ||
238 | } | ||
239 | return b; | ||
240 | } | ||
diff --git a/noncore/apps/opie-reader/Bkmks.h b/noncore/apps/opie-reader/Bkmks.h new file mode 100644 index 0000000..b38184a --- a/dev/null +++ b/noncore/apps/opie-reader/Bkmks.h | |||
@@ -0,0 +1,53 @@ | |||
1 | #ifndef __Bkmks_h | ||
2 | #define __Bkmks_h | ||
3 | |||
4 | #include "config.h" | ||
5 | #include <stdio.h> | ||
6 | |||
7 | template<class T> | ||
8 | class CList; | ||
9 | |||
10 | class Bkmk | ||
11 | { | ||
12 | friend class BkmkFile; | ||
13 | tchar* m_name; | ||
14 | tchar* m_anno; | ||
15 | unsigned int m_position; | ||
16 | public: | ||
17 | Bkmk() : m_name(NULL), m_anno(NULL), m_position(0) {}; | ||
18 | Bkmk(const tchar* _nm, const tchar* _anno, unsigned int _p); | ||
19 | Bkmk(const Bkmk& rhs) : m_name(NULL), m_anno(NULL) | ||
20 | { | ||
21 | *this = rhs; | ||
22 | } | ||
23 | ~Bkmk(); | ||
24 | unsigned int value() const { return m_position; } | ||
25 | tchar *name() const { return m_name; } | ||
26 | tchar *anno() const { return m_anno; } | ||
27 | bool operator<(const Bkmk& rhs) { return (m_position < rhs.m_position); } | ||
28 | Bkmk& operator=(const Bkmk& rhs); | ||
29 | bool operator==(const Bkmk& rhs); | ||
30 | void setAnno(tchar* t); | ||
31 | }; | ||
32 | |||
33 | class BkmkFile | ||
34 | { | ||
35 | FILE* f; | ||
36 | bool wt; | ||
37 | bool isUpgraded; | ||
38 | static const unsigned long magic; | ||
39 | private: | ||
40 | Bkmk* read(); | ||
41 | Bkmk* read03(); | ||
42 | CList<Bkmk>* readall03(); | ||
43 | CList<Bkmk>* readall04(); | ||
44 | void write(tchar* nm, tchar* an, const unsigned int& pos); | ||
45 | void write(const Bkmk& b); | ||
46 | public: | ||
47 | bool upgraded() { return isUpgraded; } | ||
48 | BkmkFile(const char *fnm, bool w = false); | ||
49 | ~BkmkFile(); | ||
50 | void write(CList<Bkmk>& bl); | ||
51 | CList<Bkmk>* readall(); | ||
52 | }; | ||
53 | #endif | ||
diff --git a/noncore/apps/opie-reader/BuffDoc.cpp b/noncore/apps/opie-reader/BuffDoc.cpp index df2f4eb..e37b136 100644 --- a/noncore/apps/opie-reader/BuffDoc.cpp +++ b/noncore/apps/opie-reader/BuffDoc.cpp | |||
@@ -1,12 +1,28 @@ | |||
1 | #include "BuffDoc.h" | 1 | #include "BuffDoc.h" |
2 | //#include <FL/fl_draw.h> | 2 | //#include <FL/fl_draw.h> |
3 | #include "config.h" | 3 | #include "config.h" |
4 | #include "CDrawBuffer.h" | ||
5 | #include "plucker.h" | ||
6 | |||
7 | |||
8 | bool BuffDoc::hyperlink(unsigned int n) | ||
9 | { | ||
10 | bool bRet = false; | ||
11 | lastword.empty(); | ||
12 | lastsizes[0] = laststartline = n; | ||
13 | lastispara = false; | ||
14 | if (exp != NULL) | ||
15 | { | ||
16 | bRet = exp->hyperlink(n); | ||
17 | lastsizes[0] = laststartline = exp->locate(); | ||
18 | } | ||
19 | return bRet; | ||
20 | } | ||
4 | 21 | ||
5 | void BuffDoc::locate(unsigned int n) | 22 | void BuffDoc::locate(unsigned int n) |
6 | { | 23 | { |
7 | // qDebug("BuffDoc:locating:%u",n); | 24 | // qDebug("BuffDoc:locating:%u",n); |
8 | 25 | lastword.empty(); | |
9 | lastword[0] = '\0'; | ||
10 | lastsizes[0] = laststartline = n; | 26 | lastsizes[0] = laststartline = n; |
11 | lastispara = false; | 27 | lastispara = false; |
12 | // tchar linebuf[1024]; | 28 | // tchar linebuf[1024]; |
@@ -14,52 +30,52 @@ void BuffDoc::locate(unsigned int n) | |||
14 | // qDebug("BuffDoc:Located"); | 30 | // qDebug("BuffDoc:Located"); |
15 | } | 31 | } |
16 | 32 | ||
17 | bool BuffDoc::getline(CBuffer* buff, int w) | 33 | bool BuffDoc::getline(CDrawBuffer* buff, int w) |
18 | { | 34 | { |
35 | tchar ch = 32; | ||
36 | CStyle cs; | ||
37 | buff->empty(); | ||
19 | if (exp == NULL) | 38 | if (exp == NULL) |
20 | { | 39 | { |
21 | (*buff)[0] = '\0'; | 40 | //(*buff)[0] = '\0'; |
41 | buff->empty(); | ||
22 | return false; | 42 | return false; |
23 | } | 43 | } |
24 | int len = 0, ch, lastcheck = 0; | 44 | int len = 0, lastcheck = 0; |
25 | *buff = lastword.data(); | 45 | if (lastword.length() > 0) |
46 | { | ||
47 | *buff = lastword; | ||
48 | cs = lastword.laststyle(); | ||
49 | } | ||
50 | else buff->empty(); | ||
51 | // qDebug("Buff:%s Lastword:%s", (const char*)toQString(buff->data()), (const char*)toQString(lastword.data())); | ||
26 | lastcheck = len = buff->length(); | 52 | lastcheck = len = buff->length(); |
27 | // unsigned int slen = fl_widthi(buff->data(),len); | 53 | unsigned int slen = buff->width(len); |
28 | #ifdef _UNICODE | ||
29 | unsigned int slen = m_fm->width(toQString(buff->data()),len); | ||
30 | #else | ||
31 | unsigned int slen = m_fm->width(buff->data(),len); | ||
32 | #endif | ||
33 | if (slen > w) | 54 | if (slen > w) |
34 | { | 55 | { |
35 | for ( ; len > 0; len--) | 56 | for ( ; len > 0; len--) |
36 | { | 57 | { |
37 | // if (fl_widthi(buff->data(),len) < w) break; | 58 | if (buff->width(len) < w) break; |
38 | #ifdef _UNICODE | ||
39 | if (m_fm->width(toQString(buff->data()),len) < w) break; | ||
40 | #else | ||
41 | if (m_fm->width(buff->data(),len) < w) break; | ||
42 | #endif | ||
43 | } | 59 | } |
44 | lastword = buff->data() + len - 1; | 60 | // lastword = buff->data() + len - 1; |
61 | laststartline = lastsizes[len-1]; | ||
62 | lastword.setright(*buff, len - 1); | ||
45 | for (int i = 0; i < buff->length(); i++) lastsizes[i] = lastsizes[i+len-1]; | 63 | for (int i = 0; i < buff->length(); i++) lastsizes[i] = lastsizes[i+len-1]; |
46 | (*buff)[len-1] = '-'; | 64 | // (*buff)[len-1] = '-'; |
65 | buff->truncate(len-1); | ||
66 | buff->addch('-', cs); | ||
47 | (*buff)[len] = '\0'; | 67 | (*buff)[len] = '\0'; |
48 | laststartline = lastsizes[len-1]; | ||
49 | return true; | 68 | return true; |
50 | } | 69 | } |
51 | if (lastispara) | 70 | if (lastispara) |
52 | { | 71 | { |
53 | lastispara = false; | 72 | lastispara = false; |
54 | lastword[0] = '\0'; | 73 | // lastword[0] = '\0'; |
74 | lastword.empty(); | ||
55 | len = buff->length(); | 75 | len = buff->length(); |
56 | // while (fl_widthi(buff->data(),len) > w) len--; | 76 | while (buff->width(len) > w) len--; |
57 | #ifdef _UNICODE | 77 | // (*buff)[len] = '\0'; |
58 | while (m_fm->width(toQString(buff->data()),len) > w) len--; | 78 | buff->truncate(len); |
59 | #else | ||
60 | while (m_fm->width(buff->data(),len) > w) len--; | ||
61 | #endif | ||
62 | (*buff)[len] = '\0'; | ||
63 | laststartline = exp->locate(); | 79 | laststartline = exp->locate(); |
64 | return true; | 80 | return true; |
65 | } | 81 | } |
@@ -69,18 +85,18 @@ bool BuffDoc::getline(CBuffer* buff, int w) | |||
69 | { | 85 | { |
70 | lastcheck = len; | 86 | lastcheck = len; |
71 | allsizes[len] = exp->locate(); | 87 | allsizes[len] = exp->locate(); |
72 | while ((ch = getch()) != ' ' && ch != '\012' && ch != UEOF && len < 128) | 88 | getch(ch, cs); |
89 | while (ch != ' ' && ch != '\012' && ch != UEOF && len < 128) | ||
73 | { | 90 | { |
74 | (*buff)[len++] = ch; | 91 | len++; |
92 | buff->addch(ch,cs); | ||
75 | allsizes[len] = exp->locate(); | 93 | allsizes[len] = exp->locate(); |
94 | getch(ch, cs); | ||
76 | } | 95 | } |
77 | (*buff)[len] = 0; | 96 | (*buff)[len] = 0; |
78 | #ifdef _UNICODE | 97 | slen = buff->width(len); |
79 | slen = m_fm->width(toQString(buff->data()),len); | 98 | len++; |
80 | #else | 99 | buff->addch(' ', cs); |
81 | slen = m_fm->width(buff->data(),len); | ||
82 | #endif | ||
83 | (*buff)[len++] = ' '; | ||
84 | allsizes[len] = exp->locate(); | 100 | allsizes[len] = exp->locate(); |
85 | if (slen < w && ch != ' ') | 101 | if (slen < w && ch != ' ') |
86 | { | 102 | { |
@@ -90,37 +106,119 @@ bool BuffDoc::getline(CBuffer* buff, int w) | |||
90 | lastispara = (ch == '\012'); | 106 | lastispara = (ch == '\012'); |
91 | } | 107 | } |
92 | (*buff)[len] = '\0'; | 108 | (*buff)[len] = '\0'; |
93 | lastword = buff->data()+lastcheck; | 109 | // lastword = buff->data()+lastcheck; |
110 | lastword.setright(*buff, lastcheck); | ||
94 | for (int i = 0; i < lastword.length(); i++) lastsizes[i] = allsizes[i+lastcheck]; | 111 | for (int i = 0; i < lastword.length(); i++) lastsizes[i] = allsizes[i+lastcheck]; |
95 | if (lastcheck > 0) | 112 | if (lastcheck > 0) |
96 | { | 113 | { |
97 | laststartline = allsizes[lastcheck]; | 114 | laststartline = allsizes[lastcheck]; |
98 | (*buff)[lastcheck-1] = '\0'; | 115 | // (*buff)[lastcheck-1] = '\0'; |
116 | buff->truncate(lastcheck-1); | ||
99 | } | 117 | } |
100 | else | 118 | else |
101 | { | 119 | { |
102 | laststartline = (lastcheck == len) ? exp->locate() : allsizes[lastcheck+1]; | 120 | laststartline = (lastcheck == len) ? exp->locate() : allsizes[lastcheck+1]; |
103 | (*buff)[lastcheck] = '\0'; | 121 | // (*buff)[lastcheck] = '\0'; |
122 | buff->truncate(lastcheck); | ||
104 | } | 123 | } |
105 | // laststartline = sizes[lastcheck+1]; | 124 | // buff->frig(); |
106 | // (*buff)[(lastcheck > 0) ? lastcheck-1:lastcheck] = '\0'; | ||
107 | return (ch != UEOF); | 125 | return (ch != UEOF); |
108 | } | 126 | } |
109 | 127 | ||
110 | bool BuffDoc::getline(CBuffer* buff, int w, int cw) | 128 | bool BuffDoc::getline(CDrawBuffer* buff, int w, int cw) |
111 | { | 129 | { |
130 | buff->empty(); | ||
112 | if (exp == NULL) | 131 | if (exp == NULL) |
113 | { | 132 | { |
114 | (*buff)[0] = '\0'; | ||
115 | return false; | 133 | return false; |
116 | } | 134 | } |
117 | tchar ch; | 135 | tchar ch; |
136 | CStyle cs; | ||
118 | int i = 0; | 137 | int i = 0; |
119 | while ((i < w/cw) && ((ch = getch()) != '\012') && (ch != UEOF)) | 138 | while (i*cw < w) |
120 | { | 139 | { |
121 | (*buff)[i++] = ch; | 140 | getch(ch, cs); |
141 | if (ch == '\12' || ch == UEOF) break; | ||
142 | buff->addch(ch,cs); | ||
143 | i++; | ||
122 | } | 144 | } |
123 | (*buff)[i] = '\0'; | 145 | buff->truncate(i); |
124 | laststartline = exp->locate(); | 146 | laststartline = exp->locate(); |
125 | return (ch != UEOF); | 147 | return (ch != UEOF); |
126 | } | 148 | } |
149 | |||
150 | int BuffDoc::openfile(QWidget* _parent, const char *src) | ||
151 | { | ||
152 | // qDebug("BuffDoc:Openfile:%s", src); | ||
153 | // qDebug("Trying aportis %x",exp); | ||
154 | if (exp != NULL) delete exp; | ||
155 | lastword.empty(); | ||
156 | lastsizes[0] = laststartline = 0; | ||
157 | lastispara = false; | ||
158 | /* | ||
159 | exp = new Text; | ||
160 | int ret = exp->openfile(src); | ||
161 | */ | ||
162 | |||
163 | exp = new Aportis; | ||
164 | int ret = exp->openfile(src); | ||
165 | if (ret == -1) | ||
166 | { | ||
167 | delete exp; | ||
168 | exp = NULL; | ||
169 | return ret; | ||
170 | } | ||
171 | if (ret == -2) | ||
172 | { | ||
173 | |||
174 | delete exp; | ||
175 | exp = new ztxt; | ||
176 | ret = exp->openfile(src); | ||
177 | } | ||
178 | if (ret != 0) | ||
179 | { | ||
180 | |||
181 | delete exp; | ||
182 | exp = new CPlucker; | ||
183 | ret = exp->openfile(src); | ||
184 | } | ||
185 | #ifndef SMALL | ||
186 | if (ret != 0) | ||
187 | { | ||
188 | delete exp; | ||
189 | qDebug("Trying ppms"); | ||
190 | exp = new ppm_expander; | ||
191 | ret = exp->openfile(src); | ||
192 | } | ||
193 | |||
194 | if (ret != 0) | ||
195 | { | ||
196 | delete exp; | ||
197 | exp = new Text; | ||
198 | // qDebug("Trying text"); | ||
199 | ret = exp->openfile(src); | ||
200 | } | ||
201 | #else | ||
202 | if (ret != 0) | ||
203 | { | ||
204 | delete exp; | ||
205 | exp = new Text; | ||
206 | ret = exp->openfile(src); | ||
207 | } | ||
208 | #endif | ||
209 | if (ret != 0) | ||
210 | { | ||
211 | delete exp; | ||
212 | QMessageBox::information(_parent, "QTReader", "Unknown file compression type","Try another file"); | ||
213 | return ret; | ||
214 | } | ||
215 | // qDebug("Doing final open:%x:%x",exp,filt); | ||
216 | |||
217 | lastword.empty(); | ||
218 | lastsizes[0] = laststartline = 0; | ||
219 | lastispara = false; | ||
220 | exp->locate(0); | ||
221 | filt->setsource(exp); | ||
222 | // qDebug("BuffDoc:file opened"); | ||
223 | return 0; | ||
224 | } | ||
diff --git a/noncore/apps/opie-reader/BuffDoc.h b/noncore/apps/opie-reader/BuffDoc.h index 7c5ef9a..1aac817 100644 --- a/noncore/apps/opie-reader/BuffDoc.h +++ b/noncore/apps/opie-reader/BuffDoc.h | |||
@@ -1,42 +1,37 @@ | |||
1 | #ifndef __BuffDoc_h | 1 | #ifndef __BuffDoc_h |
2 | #define __BuffDoc_h | 2 | #define __BuffDoc_h |
3 | 3 | ||
4 | #include "CBuffer.h" | ||
5 | #include "ZText.h" | 4 | #include "ZText.h" |
6 | #include "Aportis.h" | 5 | #include "Aportis.h" |
7 | #include "ztxt.h" | 6 | #include "ztxt.h" |
8 | #include "ppm_expander.h" | 7 | #include "ppm_expander.h" |
8 | #include "CDrawBuffer.h" | ||
9 | #include "CFilter.h" | 9 | #include "CFilter.h" |
10 | #include <qfontmetrics.h> | 10 | #include <qfontmetrics.h> |
11 | #include <qmessagebox.h> | 11 | #include <qmessagebox.h> |
12 | 12 | ||
13 | class BuffDoc | 13 | class BuffDoc |
14 | { | 14 | { |
15 | CBuffer lastword; | 15 | CDrawBuffer lastword; |
16 | CSizeBuffer lastsizes, allsizes; | 16 | CSizeBuffer lastsizes, allsizes; |
17 | size_t laststartline; | 17 | size_t laststartline; |
18 | bool lastispara; | 18 | bool lastispara; |
19 | CExpander* exp; | 19 | CExpander* exp; |
20 | CFilterChain* filt; | 20 | CFilterChain* filt; |
21 | QFontMetrics* m_fm; | ||
22 | public: | 21 | public: |
23 | ~BuffDoc() | 22 | ~BuffDoc() |
24 | { | 23 | { |
25 | delete filt; | 24 | delete filt; |
26 | delete exp; | 25 | delete exp; |
27 | } | 26 | } |
28 | BuffDoc() : m_fm(NULL) | 27 | BuffDoc() |
29 | { | 28 | { |
30 | exp = NULL; | 29 | exp = NULL; |
31 | filt = NULL; | 30 | filt = NULL; |
31 | lastword.empty(); | ||
32 | // qDebug("Buffdoc created"); | 32 | // qDebug("Buffdoc created"); |
33 | } | 33 | } |
34 | bool empty() { return (exp == NULL); } | 34 | bool empty() { return (exp == NULL); } |
35 | void setfm(QFontMetrics* fm) | ||
36 | { | ||
37 | m_fm = fm; | ||
38 | // qDebug("Buffdoc:setfm"); | ||
39 | } | ||
40 | void setfilter(CFilterChain* _f) | 35 | void setfilter(CFilterChain* _f) |
41 | { | 36 | { |
42 | if (filt != NULL) delete filt; | 37 | if (filt != NULL) delete filt; |
@@ -46,87 +41,38 @@ class BuffDoc | |||
46 | CList<Bkmk>* getbkmklist() { return exp->getbkmklist(); } | 41 | CList<Bkmk>* getbkmklist() { return exp->getbkmklist(); } |
47 | bool hasrandomaccess() { return (exp == NULL) ? false : exp->hasrandomaccess(); } | 42 | bool hasrandomaccess() { return (exp == NULL) ? false : exp->hasrandomaccess(); } |
48 | bool iseol() { return (lastword[0] == '\0'); } | 43 | bool iseol() { return (lastword[0] == '\0'); } |
49 | int openfile(QWidget* _parent, const char *src) | 44 | int openfile(QWidget* _parent, const char *src); |
45 | tchar getch() | ||
50 | { | 46 | { |
51 | // qDebug("BuffDoc:Openfile:%s", src); | 47 | tchar ch = UEOF; |
52 | // qDebug("Trying aportis %x",exp); | 48 | CStyle sty; |
53 | if (exp != NULL) delete exp; | 49 | if (exp != NULL) |
54 | lastword[0] = '\0'; | ||
55 | lastsizes[0] = laststartline = 0; | ||
56 | lastispara = false; | ||
57 | /* | ||
58 | exp = new Text; | ||
59 | int ret = exp->openfile(src); | ||
60 | */ | ||
61 | |||
62 | exp = new Aportis; | ||
63 | // qDebug("Calling openfile"); | ||
64 | int ret = exp->openfile(src); | ||
65 | // qDebug("Called openfile"); | ||
66 | if (ret == -1) | ||
67 | { | 50 | { |
68 | // qDebug("problem opening source file:%s",src); | 51 | filt->getch(ch, sty); |
69 | delete exp; | ||
70 | exp = NULL; | ||
71 | return ret; | ||
72 | } | 52 | } |
73 | if (ret == -2) | 53 | return ch; |
74 | { | ||
75 | |||
76 | delete exp; | ||
77 | // qDebug("Trying ztxt"); | ||
78 | exp = new ztxt; | ||
79 | ret = exp->openfile(src); | ||
80 | } | 54 | } |
81 | #ifndef SMALL | 55 | void getch(tchar& ch, CStyle& sty) |
82 | if (ret != 0) | ||
83 | { | 56 | { |
84 | delete exp; | 57 | if (exp != NULL) |
85 | // qDebug("Trying ppms"); | ||
86 | exp = new ppm_expander; | ||
87 | ret = exp->openfile(src); | ||
88 | } | ||
89 | |||
90 | if (ret != 0) | ||
91 | { | 58 | { |
92 | delete exp; | 59 | filt->getch(ch, sty); |
93 | exp = new Text; | ||
94 | // qDebug("Trying text"); | ||
95 | ret = exp->openfile(src); | ||
96 | } | ||
97 | #else | ||
98 | if (ret != 0) | ||
99 | { | ||
100 | delete exp; | ||
101 | exp = new Text; | ||
102 | ret = exp->openfile(src); | ||
103 | } | ||
104 | #endif | ||
105 | if (ret != 0) | ||
106 | { | ||
107 | delete exp; | ||
108 | QMessageBox::information(_parent, "QTReader", "Unknown file compression type","Try another file"); | ||
109 | return ret; | ||
110 | } | 60 | } |
111 | // qDebug("Doing final open:%x:%x",exp,filt); | 61 | else |
112 | 62 | ch = UEOF; | |
113 | lastword[0] = '\0'; | ||
114 | lastsizes[0] = laststartline = 0; | ||
115 | lastispara = false; | ||
116 | exp->locate(0); | ||
117 | filt->setsource(exp); | ||
118 | // qDebug("BuffDoc:file opened"); | ||
119 | return 0; | ||
120 | } | 63 | } |
121 | int getch() { return (exp == NULL) ? UEOF : filt->getch(); } | ||
122 | unsigned int locate() { return (exp == NULL) ? 0 : laststartline; } | 64 | unsigned int locate() { return (exp == NULL) ? 0 : laststartline; } |
65 | unsigned int explocate() { return (exp == NULL) ? 0 : exp->locate(); } | ||
66 | MarkupType PreferredMarkup() { return (exp == NULL) ? cTEXT : exp->PreferredMarkup(); } | ||
67 | bool hyperlink(unsigned int n); | ||
123 | void locate(unsigned int n); | 68 | void locate(unsigned int n); |
124 | bool getline(CBuffer* buff, int w); | 69 | bool getline(CDrawBuffer* buff, int w); |
125 | bool getline(CBuffer* buff, int w, int cw); | 70 | bool getline(CDrawBuffer* buff, int w, int cw); |
126 | void sizes(unsigned long& fs, unsigned long& ts) { exp->sizes(fs,ts); } | 71 | void sizes(unsigned long& fs, unsigned long& ts) { exp->sizes(fs,ts); } |
127 | int getpara(CBuffer& buff) | 72 | int getpara(CBuffer& buff) |
128 | { | 73 | { |
129 | int ch, i = 0; | 74 | tchar ch; |
75 | int i = 0; | ||
130 | while ((ch = getch()) != 10 && ch != UEOF) buff[i++] = ch; | 76 | while ((ch = getch()) != 10 && ch != UEOF) buff[i++] = ch; |
131 | buff[i] = '\0'; | 77 | buff[i] = '\0'; |
132 | if (i == 0 && ch == UEOF) i = -1; | 78 | if (i == 0 && ch == UEOF) i = -1; |
diff --git a/noncore/apps/opie-reader/CAnnoEdit.h b/noncore/apps/opie-reader/CAnnoEdit.h new file mode 100644 index 0000000..3cc9f78 --- a/dev/null +++ b/noncore/apps/opie-reader/CAnnoEdit.h | |||
@@ -0,0 +1,58 @@ | |||
1 | #ifndef __CANNOEDIT_H | ||
2 | #define __CANNOEDIT_H | ||
3 | #include <qlabel.h> | ||
4 | #include <qlayout.h> | ||
5 | #include <qpushbutton.h> | ||
6 | #include <qlineedit.h> | ||
7 | #include <qmultilineedit.h> | ||
8 | |||
9 | class CAnnoEdit : public QWidget | ||
10 | { | ||
11 | Q_OBJECT | ||
12 | |||
13 | QLineEdit* m_name; | ||
14 | QMultiLineEdit* m_anno; | ||
15 | size_t m_posn; | ||
16 | public: | ||
17 | void setPosn(size_t p) { m_posn = p; } | ||
18 | size_t getPosn() { return m_posn; } | ||
19 | void setName(const QString& name) | ||
20 | { | ||
21 | m_name->setText(name); | ||
22 | } | ||
23 | void setAnno(const QString& name) | ||
24 | { | ||
25 | m_anno->setText(name); | ||
26 | m_anno->setEdited(false); | ||
27 | } | ||
28 | bool edited() { return m_anno->edited(); } | ||
29 | CAnnoEdit(QWidget *parent=0, const char *name=0, WFlags f = 0) : | ||
30 | QWidget(parent, name, f) | ||
31 | { | ||
32 | QVBoxLayout* grid = new QVBoxLayout(this); | ||
33 | m_name = new QLineEdit(this, "Name"); | ||
34 | m_anno = new QMultiLineEdit(this, "Annotation"); | ||
35 | QPushButton* exitButton = new QPushButton("Okay", this); | ||
36 | connect(exitButton, SIGNAL( released() ), this, SLOT( slotOkay() ) ); | ||
37 | QPushButton* cancelButton = new QPushButton("Cancel", this); | ||
38 | connect(cancelButton, SIGNAL( released() ), this, SLOT( slotCancel() ) ); | ||
39 | QLabel *l = new QLabel("Text",this); | ||
40 | grid->addWidget(l); | ||
41 | grid->addWidget(m_name); | ||
42 | l = new QLabel("Annotation",this); | ||
43 | grid->addWidget(l); | ||
44 | grid->addWidget(m_anno,1); | ||
45 | QHBoxLayout* hgrid = new QHBoxLayout(grid); | ||
46 | hgrid->addWidget(cancelButton); | ||
47 | hgrid->addWidget(exitButton); | ||
48 | } | ||
49 | private slots: | ||
50 | void slotOkay() { emit finished(m_name->text(), m_anno->text()); } | ||
51 | void slotCancel() { emit cancelled(); } | ||
52 | public: | ||
53 | signals: | ||
54 | void finished(const QString&, const QString&); | ||
55 | void cancelled(); | ||
56 | }; | ||
57 | |||
58 | #endif | ||
diff --git a/noncore/apps/opie-reader/CBuffer.cpp b/noncore/apps/opie-reader/CBuffer.cpp index db52476..526b25f 100644 --- a/noncore/apps/opie-reader/CBuffer.cpp +++ b/noncore/apps/opie-reader/CBuffer.cpp | |||
@@ -1,35 +1,46 @@ | |||
1 | #include "CBuffer.h" | 1 | #include "CBuffer.h" |
2 | 2 | ||
3 | CBuffer& CBuffer::operator=(const tchar*sztmp) | 3 | CBufferBase& CBufferBase::assign(const void* sztmp, size_t ms) |
4 | { | 4 | { |
5 | int i; | 5 | if (ms*membersize > len) |
6 | for (i = 0; sztmp[i] != '\0'; i++) (*this)[i] = sztmp[i]; | 6 | { |
7 | (*this)[i] = '\0'; | 7 | delete [] buffer; |
8 | buffer = new unsigned char[len = ms*membersize]; | ||
9 | } | ||
10 | memcpy(buffer, sztmp, ms*membersize); | ||
8 | return *this; | 11 | return *this; |
9 | } | 12 | } |
10 | 13 | ||
11 | tchar& CBuffer::operator[](int i) | 14 | CBufferBase::CBufferBase(size_t ms, size_t n = 16) : len(n), membersize(ms) |
15 | { | ||
16 | buffer = new unsigned char[len*membersize]; | ||
17 | memset(buffer, 0, len*membersize); | ||
18 | } | ||
19 | |||
20 | void* CBufferBase::operator[](int i) | ||
12 | { | 21 | { |
13 | if (i >= len) | 22 | if ((i+1)*membersize > len) |
14 | { | 23 | { |
15 | tchar *newbuff = new tchar[i+1]; | 24 | unsigned char* oldbuffer = buffer; |
16 | memcpy(newbuff,buffer,sizeof(tchar)*len); | 25 | buffer = new unsigned char[(i+1)*membersize]; |
17 | delete [] buffer; | 26 | memcpy(buffer, oldbuffer, len); |
18 | buffer = newbuff; | 27 | memset(buffer+len, 0, (i+1)*membersize-len); |
19 | len = i+1; | 28 | len = (i+1)*membersize; |
29 | delete [] oldbuffer; | ||
20 | } | 30 | } |
21 | return buffer[i]; | 31 | return buffer+i*membersize; |
22 | } | 32 | } |
23 | 33 | ||
24 | size_t& CSizeBuffer::operator[](int i) | 34 | size_t CBufferBase::bstrlen(unsigned char* _buffer = NULL) |
25 | { | 35 | { |
26 | if (i >= len) | 36 | if (_buffer == NULL) _buffer = buffer; |
37 | unsigned char* zero = new unsigned char[membersize]; | ||
38 | memset(zero,0,membersize); | ||
39 | unsigned char* element = _buffer; | ||
40 | while (memcmp(element, zero, membersize) != 0) | ||
27 | { | 41 | { |
28 | size_t *newbuff = new size_t[i+1]; | 42 | element += membersize; |
29 | memcpy(newbuff,buffer,sizeof(size_t)*len); | ||
30 | delete [] buffer; | ||
31 | buffer = newbuff; | ||
32 | len = i+1; | ||
33 | } | 43 | } |
34 | return buffer[i]; | 44 | delete [] zero; |
45 | return (element - _buffer)/membersize; | ||
35 | } | 46 | } |
diff --git a/noncore/apps/opie-reader/CBuffer.h b/noncore/apps/opie-reader/CBuffer.h index 9807d27..252f3ac 100644 --- a/noncore/apps/opie-reader/CBuffer.h +++ b/noncore/apps/opie-reader/CBuffer.h | |||
@@ -5,41 +5,51 @@ | |||
5 | #include <string.h> | 5 | #include <string.h> |
6 | #include "config.h" | 6 | #include "config.h" |
7 | 7 | ||
8 | class CBuffer | 8 | |
9 | class CBufferBase | ||
9 | { | 10 | { |
11 | protected: | ||
10 | size_t len; | 12 | size_t len; |
11 | tchar *buffer; | 13 | unsigned char *buffer; |
12 | CBuffer(const CBuffer&); | 14 | size_t membersize; |
15 | CBufferBase(const CBufferBase&); | ||
13 | public: | 16 | public: |
14 | CBuffer& operator=(const tchar*sztmp); | 17 | CBufferBase& assign(const void* sztmp, size_t ms); |
15 | #ifdef _UNICODE | 18 | void* data() { return buffer; } |
16 | size_t length() { return ustrlen(buffer); } | 19 | CBufferBase(size_t ms, size_t n = 16); |
17 | #else | 20 | ~CBufferBase() { delete [] buffer; } |
18 | size_t length() { return strlen(buffer); } | 21 | void* operator[](int i); |
19 | #endif | 22 | size_t bstrlen(unsigned char* _buffer = NULL); |
20 | tchar* data() { return buffer; } | 23 | size_t totallen() { return len; } |
21 | CBuffer(size_t n = 16) : len(n) | ||
22 | { | ||
23 | buffer = new tchar[len]; | ||
24 | buffer[0] = '\0'; | ||
25 | } | ||
26 | ~CBuffer() { delete [] buffer; } | ||
27 | tchar& operator[](int i); | ||
28 | }; | 24 | }; |
29 | 25 | ||
30 | class CSizeBuffer | 26 | template<class T> |
27 | class CBufferFace | ||
31 | { | 28 | { |
32 | size_t len; | 29 | CBufferBase m_buffer; |
33 | size_t *buffer; | 30 | protected: |
34 | CSizeBuffer(const CSizeBuffer&); | 31 | CBufferFace(const CBufferFace&); |
35 | public: | 32 | public: |
36 | size_t* data() { return buffer; } | 33 | CBufferFace& operator=(const T* sztmp) |
37 | CSizeBuffer(size_t n = 16) : len(n) | ||
38 | { | 34 | { |
39 | buffer = new size_t[len]; | 35 | m_buffer.assign(sztmp, m_buffer.bstrlen(sztmp)); |
36 | return *this; | ||
37 | } | ||
38 | void assign(const T* sztmp, size_t n) | ||
39 | { | ||
40 | m_buffer.assign(sztmp, n); | ||
41 | } | ||
42 | size_t length() { return m_buffer.bstrlen(); } | ||
43 | size_t totallen() { return m_buffer.totallen(); } | ||
44 | T* data() { return (T*)m_buffer.data(); } | ||
45 | CBufferFace(size_t n = 16) : m_buffer(sizeof(T), n) {} | ||
46 | T& operator[](int i) | ||
47 | { | ||
48 | return *((T*)m_buffer[i]); | ||
40 | } | 49 | } |
41 | ~CSizeBuffer() { delete [] buffer; } | ||
42 | size_t& operator[](int i); | ||
43 | }; | 50 | }; |
44 | 51 | ||
52 | typedef CBufferFace<tchar> CBuffer; | ||
53 | typedef CBufferFace<size_t> CSizeBuffer; | ||
54 | |||
45 | #endif | 55 | #endif |
diff --git a/noncore/apps/opie-reader/CEncoding.cpp b/noncore/apps/opie-reader/CEncoding.cpp index 18d18d3..c1dcfe8 100644 --- a/noncore/apps/opie-reader/CEncoding.cpp +++ b/noncore/apps/opie-reader/CEncoding.cpp | |||
@@ -1,10 +1,15 @@ | |||
1 | #include <stdio.h> | 1 | #include <stdio.h> |
2 | #include "CEncoding.h" | 2 | #include "CEncoding.h" |
3 | 3 | ||
4 | tchar CUtf8::getch() | 4 | void CUtf8::getch(tchar& ch, CStyle& sty) |
5 | { | 5 | { |
6 | int iret = parent->getch(); | 6 | int iret; |
7 | if (iret == EOF) return UEOF; | 7 | parent->getch(iret, sty); |
8 | if (iret == EOF) | ||
9 | { | ||
10 | ch = UEOF; | ||
11 | return; | ||
12 | } | ||
8 | tchar ret = iret; | 13 | tchar ret = iret; |
9 | int count = 0; | 14 | int count = 0; |
10 | if (ret & (1 << 7)) | 15 | if (ret & (1 << 7)) |
@@ -13,7 +18,8 @@ tchar CUtf8::getch() | |||
13 | while ((flags & (1 << 7)) != 0) | 18 | while ((flags & (1 << 7)) != 0) |
14 | { | 19 | { |
15 | ret <<= 6; | 20 | ret <<= 6; |
16 | ret += parent->getch() & 0x3f; | 21 | parent->getch(iret, sty); |
22 | ret += iret & 0x3f; | ||
17 | flags <<= 1; | 23 | flags <<= 1; |
18 | count++; | 24 | count++; |
19 | } | 25 | } |
@@ -33,118 +39,172 @@ tchar CUtf8::getch() | |||
33 | printf("Only 16bit unicode supported..."); | 39 | printf("Only 16bit unicode supported..."); |
34 | } | 40 | } |
35 | } | 41 | } |
36 | return ret; | 42 | ch = ret; |
43 | return; | ||
37 | } | 44 | } |
38 | 45 | ||
39 | 46 | void CUcs16be::getch(tchar& ch, CStyle& sty) | |
40 | tchar CUcs16be::getch() | ||
41 | { | 47 | { |
42 | int iret = parent->getch(); | 48 | int iret; |
43 | if (iret == EOF) return UEOF; | 49 | parent->getch(iret, sty); |
50 | if (iret == EOF) | ||
51 | { | ||
52 | ch = UEOF; | ||
53 | return; | ||
54 | } | ||
44 | tchar ret = iret; | 55 | tchar ret = iret; |
45 | return (ret << 8) + parent->getch(); | 56 | parent->getch(iret, sty); |
57 | ch = (ret << 8) + iret; | ||
46 | } | 58 | } |
47 | 59 | ||
48 | tchar CUcs16le::getch() | 60 | void CUcs16le::getch(tchar& ch, CStyle& sty) |
61 | { | ||
62 | int iret; | ||
63 | parent->getch(iret, sty); | ||
64 | if (iret == EOF) | ||
49 | { | 65 | { |
50 | int iret = parent->getch(); | 66 | ch = UEOF; |
51 | if (iret == EOF) return UEOF; | 67 | return; |
68 | } | ||
52 | tchar ret = iret; | 69 | tchar ret = iret; |
53 | return ret + (parent->getch() << 8); | 70 | parent->getch(iret, sty); |
71 | ch = ret + (iret << 8); | ||
54 | } | 72 | } |
55 | 73 | ||
56 | tchar Ccp1252::getch() | 74 | void Ccp1252::getch(tchar& ch, CStyle& sty) |
57 | { | 75 | { |
58 | int iret = parent->getch(); | 76 | int iret; |
59 | switch (iret) | 77 | parent->getch(iret, sty); |
78 | ch = iret; | ||
79 | switch (ch) | ||
60 | { | 80 | { |
61 | case EOF: | 81 | case EOF: |
62 | return UEOF; | 82 | ch = UEOF; |
83 | break; | ||
63 | case 0x80: | 84 | case 0x80: |
64 | return 0x20ac; | 85 | ch = 0x20ac; |
86 | break; | ||
65 | case 0x82: | 87 | case 0x82: |
66 | return 0x201a; | 88 | ch = 0x201a; |
89 | break; | ||
67 | case 0x83: | 90 | case 0x83: |
68 | return 0x0192; | 91 | ch = 0x0192; |
92 | break; | ||
69 | case 0x84: | 93 | case 0x84: |
70 | return 0x201e; | 94 | ch = 0x201e; |
95 | break; | ||
71 | case 0x85: | 96 | case 0x85: |
72 | return 0x2026; | 97 | ch = 0x2026; |
98 | break; | ||
73 | case 0x86: | 99 | case 0x86: |
74 | return 0x2020; | 100 | ch = 0x2020; |
101 | break; | ||
75 | case 0x87: | 102 | case 0x87: |
76 | return 0x2021; | 103 | ch = 0x2021; |
104 | break; | ||
77 | case 0x88: | 105 | case 0x88: |
78 | return 0x02c6; | 106 | ch = 0x02c6; |
107 | break; | ||
79 | case 0x89: | 108 | case 0x89: |
80 | return 0x2030; | 109 | ch = 0x2030; |
110 | break; | ||
81 | case 0x8a: | 111 | case 0x8a: |
82 | return 0x0160; | 112 | ch = 0x0160; |
113 | break; | ||
83 | case 0x8b: | 114 | case 0x8b: |
84 | return 0x2039; | 115 | ch = 0x2039; |
116 | break; | ||
85 | case 0x8c: | 117 | case 0x8c: |
86 | return 0x0152; | 118 | ch = 0x0152; |
119 | break; | ||
87 | case 0x8e: | 120 | case 0x8e: |
88 | return 0x017d; | 121 | ch = 0x017d; |
122 | break; | ||
89 | case 0x91: | 123 | case 0x91: |
90 | return 0x2018; | 124 | ch = 0x2018; |
125 | break; | ||
91 | case 0x92: | 126 | case 0x92: |
92 | return 0x2019; | 127 | ch = 0x2019; |
128 | break; | ||
93 | case 0x93: | 129 | case 0x93: |
94 | return 0x201c; | 130 | ch = 0x201c; |
131 | break; | ||
95 | case 0x94: | 132 | case 0x94: |
96 | return 0x201d; | 133 | ch = 0x201d; |
134 | break; | ||
97 | case 0x95: | 135 | case 0x95: |
98 | return 0x2022; | 136 | ch = 0x2022; |
137 | break; | ||
99 | case 0x96: | 138 | case 0x96: |
100 | return 0x2013; | 139 | ch = 0x2013; |
140 | break; | ||
101 | case 0x97: | 141 | case 0x97: |
102 | return 0x2014; | 142 | ch = 0x2014; |
143 | break; | ||
103 | case 0x98: | 144 | case 0x98: |
104 | return 0x02dc; | 145 | ch = 0x02dc; |
146 | break; | ||
105 | case 0x99: | 147 | case 0x99: |
106 | return 0x2122; | 148 | ch = 0x2122; |
149 | break; | ||
107 | case 0x9a: | 150 | case 0x9a: |
108 | return 0x0161; | 151 | ch = 0x0161; |
152 | break; | ||
109 | case 0x9b: | 153 | case 0x9b: |
110 | return 0x203a; | 154 | ch = 0x203a; |
155 | break; | ||
111 | case 0x9c: | 156 | case 0x9c: |
112 | return 0x0153; | 157 | ch = 0x0153; |
158 | break; | ||
113 | case 0x9e: | 159 | case 0x9e: |
114 | return 0x017e; | 160 | ch = 0x017e; |
161 | break; | ||
115 | case 0x9f: | 162 | case 0x9f: |
116 | return 0x0178; | 163 | ch = 0x0178; |
164 | break; | ||
117 | default: | 165 | default: |
118 | return iret; | 166 | break; |
119 | } | 167 | } |
120 | } | 168 | } |
121 | 169 | ||
122 | tchar CPalm::getch() | 170 | void CPalm::getch(tchar& ch, CStyle& sty) |
123 | { | 171 | { |
124 | tchar iret = Ccp1252::getch(); | 172 | Ccp1252::getch(ch, sty); |
125 | switch (iret) | 173 | switch (ch) |
126 | { | 174 | { |
127 | case 0x18: | 175 | case 0x18: |
128 | return 0x2026; | 176 | ch = 0x2026; |
177 | break; | ||
129 | case 0x19: | 178 | case 0x19: |
130 | return 0x2007; | 179 | ch = 0x2007; |
180 | break; | ||
131 | case 0x8d: | 181 | case 0x8d: |
132 | return 0x2662; | 182 | ch = 0x2662; |
183 | break; | ||
133 | case 0x8e: | 184 | case 0x8e: |
134 | return 0x2663; | 185 | ch = 0x2663; |
186 | break; | ||
135 | case 0x8f: | 187 | case 0x8f: |
136 | return 0x2661; | 188 | ch = 0x2661; |
189 | break; | ||
137 | case 0x90: | 190 | case 0x90: |
138 | return 0x2660; | 191 | ch = 0x2660; |
192 | break; | ||
139 | default: | 193 | default: |
140 | return iret; | 194 | break; |
141 | } | 195 | } |
142 | } | 196 | } |
143 | 197 | ||
144 | tchar CAscii::getch() | 198 | void CAscii::getch(tchar& ch, CStyle& sty) |
199 | { | ||
200 | int iret; | ||
201 | parent->getch(iret, sty); | ||
202 | if (iret == EOF) | ||
145 | { | 203 | { |
146 | int iret = parent->getch(); | 204 | ch = UEOF; |
147 | if (iret == EOF) return UEOF; | 205 | } |
148 | return iret; | 206 | else |
207 | { | ||
208 | ch = iret; | ||
209 | } | ||
149 | } | 210 | } |
150 | |||
diff --git a/noncore/apps/opie-reader/CEncoding.h b/noncore/apps/opie-reader/CEncoding.h index 1eee29e..86562e7 100644 --- a/noncore/apps/opie-reader/CEncoding.h +++ b/noncore/apps/opie-reader/CEncoding.h | |||
@@ -17,37 +17,37 @@ public: | |||
17 | class CUtf8 : public CEncoding | 17 | class CUtf8 : public CEncoding |
18 | { | 18 | { |
19 | public: | 19 | public: |
20 | tchar getch(); | 20 | void getch(tchar& ch, CStyle& sty); |
21 | }; | 21 | }; |
22 | 22 | ||
23 | class CUcs16be : public CEncoding | 23 | class CUcs16be : public CEncoding |
24 | { | 24 | { |
25 | public: | 25 | public: |
26 | tchar getch(); | 26 | void getch(tchar& ch, CStyle& sty); |
27 | }; | 27 | }; |
28 | 28 | ||
29 | class CUcs16le : public CEncoding | 29 | class CUcs16le : public CEncoding |
30 | { | 30 | { |
31 | public: | 31 | public: |
32 | tchar getch(); | 32 | void getch(tchar& ch, CStyle& sty); |
33 | }; | 33 | }; |
34 | 34 | ||
35 | class Ccp1252 : public CEncoding | 35 | class Ccp1252 : public CEncoding |
36 | { | 36 | { |
37 | public: | 37 | public: |
38 | virtual tchar getch(); | 38 | void getch(tchar& ch, CStyle& sty); |
39 | }; | 39 | }; |
40 | 40 | ||
41 | class CPalm : public Ccp1252 | 41 | class CPalm : public Ccp1252 |
42 | { | 42 | { |
43 | public: | 43 | public: |
44 | tchar getch(); | 44 | void getch(tchar& ch, CStyle& sty); |
45 | }; | 45 | }; |
46 | 46 | ||
47 | class CAscii : public CEncoding | 47 | class CAscii : public CEncoding |
48 | { | 48 | { |
49 | public: | 49 | public: |
50 | tchar getch(); | 50 | void getch(tchar& ch, CStyle& sty); |
51 | }; | 51 | }; |
52 | 52 | ||
53 | #endif | 53 | #endif |
diff --git a/noncore/apps/opie-reader/CExpander.h b/noncore/apps/opie-reader/CExpander.h index 07c14fa..b1147a6 100644 --- a/noncore/apps/opie-reader/CExpander.h +++ b/noncore/apps/opie-reader/CExpander.h | |||
@@ -1,132 +1,19 @@ | |||
1 | #ifndef __CExpander_h | 1 | #ifndef __CExpander_h |
2 | #define __CExpander_h | 2 | #define __CExpander_h |
3 | 3 | ||
4 | #include "my_list.h" | ||
5 | #include "config.h" | 4 | #include "config.h" |
5 | #include "StyleConsts.h" | ||
6 | #include "Markups.h" | ||
6 | 7 | ||
7 | class Bkmk | 8 | class Bkmk; |
8 | { | ||
9 | friend class BkmkFile; | ||
10 | tchar* m_name; | ||
11 | unsigned int m_position; | ||
12 | public: | ||
13 | Bkmk() : m_name(NULL), m_position(0) {}; | ||
14 | Bkmk(const tchar* _nm, unsigned int _p) : m_position(_p) | ||
15 | { | ||
16 | int len = ustrlen(_nm)+1; | ||
17 | m_name = new tchar[len]; | ||
18 | for (int i = 0; i < len; i++) m_name[i] = _nm[i]; | ||
19 | } | ||
20 | Bkmk(const Bkmk& rhs) : m_name(NULL) | ||
21 | { | ||
22 | *this = rhs; | ||
23 | } | ||
24 | ~Bkmk() { if (m_name != NULL) delete [] m_name; } | ||
25 | unsigned int value() const { return m_position; } | ||
26 | tchar *name() const { return m_name; } | ||
27 | bool operator<(const Bkmk& rhs) { return (m_position < rhs.m_position); } | ||
28 | Bkmk& operator=(const Bkmk& rhs) | ||
29 | { | ||
30 | if (m_name != NULL) delete [] m_name; | ||
31 | if (rhs.m_name != NULL) | ||
32 | { | ||
33 | int len = ustrlen(rhs.m_name)+1; | ||
34 | m_name = new tchar[len]; | ||
35 | for (int i = 0; i < len; i++) m_name[i] = rhs.m_name[i]; | ||
36 | } | ||
37 | else | ||
38 | m_name = NULL; | ||
39 | m_position = rhs.m_position; | ||
40 | return *this; | ||
41 | } | ||
42 | bool operator==(const Bkmk& rhs) | ||
43 | { | ||
44 | return (m_position == rhs.m_position && ustrcmp(m_name,rhs.m_name) == 0); | ||
45 | } | ||
46 | }; | ||
47 | 9 | ||
48 | class BkmkFile | 10 | template<class T> |
49 | { | 11 | class CList; |
50 | FILE* f; | ||
51 | bool wt; | ||
52 | public: | ||
53 | BkmkFile(const char *fnm, bool w = false) | ||
54 | : | ||
55 | wt(w) | ||
56 | { | ||
57 | if (w) | ||
58 | f = fopen(fnm, "wb"); | ||
59 | else | ||
60 | f = fopen(fnm, "rb"); | ||
61 | } | ||
62 | ~BkmkFile() | ||
63 | { | ||
64 | if (f != NULL) fclose(f); | ||
65 | } | ||
66 | void write(tchar* nm, const unsigned int& pos) | ||
67 | { | ||
68 | if (f != NULL) | ||
69 | { | ||
70 | unsigned short ln = ustrlen(nm); | ||
71 | fwrite(&ln,sizeof(ln),1,f); | ||
72 | fwrite(nm,sizeof(tchar),ln,f); | ||
73 | fwrite(&pos,sizeof(pos),1,f); | ||
74 | } | ||
75 | } | ||
76 | void write(const Bkmk& b) { write(b.name(), b.value()); } | ||
77 | void write(CList<Bkmk>& bl) | ||
78 | { | ||
79 | if (f != NULL) | ||
80 | { | ||
81 | for (CList<Bkmk>::iterator i = bl.begin(); i != bl.end(); i++) | ||
82 | { | ||
83 | write(*i); | ||
84 | } | ||
85 | } | ||
86 | } | ||
87 | Bkmk* read() | ||
88 | { | ||
89 | Bkmk* b = NULL; | ||
90 | if (f != NULL) | ||
91 | { | ||
92 | unsigned short ln; | ||
93 | if (fread(&ln,sizeof(ln),1,f) == 1) | ||
94 | { | ||
95 | b = new Bkmk; | ||
96 | b->m_name = new tchar[ln+1]; | ||
97 | fread(b->m_name,sizeof(tchar),ln,f); | ||
98 | b->m_name[ln] = 0; | ||
99 | fread(&b->m_position,sizeof(b->m_position),1,f); | ||
100 | } | ||
101 | } | ||
102 | return b; | ||
103 | } | ||
104 | CList<Bkmk>* readall() | ||
105 | { | ||
106 | CList<Bkmk>* bl = NULL; | ||
107 | if (f != NULL) | ||
108 | { | ||
109 | bl = new CList<Bkmk>; | ||
110 | while (1) | ||
111 | { | ||
112 | Bkmk* b = read(); | ||
113 | if (b == NULL) break; | ||
114 | bl->push_back(*b); | ||
115 | delete b; | ||
116 | } | ||
117 | } | ||
118 | return bl; | ||
119 | } | ||
120 | }; | ||
121 | 12 | ||
122 | class CCharacterSource | 13 | class CCharacterSource |
123 | { | 14 | { |
124 | public: | 15 | public: |
125 | #ifdef _UNICODE | 16 | virtual void getch(tchar&, CStyle&) = 0; |
126 | virtual tchar getch() = 0; | ||
127 | #else | ||
128 | virtual int getch() = 0; | ||
129 | #endif | ||
130 | }; | 17 | }; |
131 | 18 | ||
132 | class CExpander | 19 | class CExpander |
@@ -140,6 +27,17 @@ class CExpander | |||
140 | virtual bool hasrandomaccess() = 0; | 27 | virtual bool hasrandomaccess() = 0; |
141 | virtual void sizes(unsigned long& file, unsigned long& text) = 0; | 28 | virtual void sizes(unsigned long& file, unsigned long& text) = 0; |
142 | virtual CList<Bkmk>* getbkmklist() { return NULL; } | 29 | virtual CList<Bkmk>* getbkmklist() { return NULL; } |
30 | virtual void getch(int& ch, CStyle& sty) | ||
31 | { | ||
32 | ch = getch(); | ||
33 | sty.unset(); | ||
34 | } | ||
143 | virtual int getch() = 0; | 35 | virtual int getch() = 0; |
36 | virtual bool hyperlink(unsigned int n) | ||
37 | { | ||
38 | locate(n); | ||
39 | return true; | ||
40 | } | ||
41 | virtual MarkupType PreferredMarkup() = 0; | ||
144 | }; | 42 | }; |
145 | #endif | 43 | #endif |
diff --git a/noncore/apps/opie-reader/CFilter.cpp b/noncore/apps/opie-reader/CFilter.cpp new file mode 100644 index 0000000..c17cf61 --- a/dev/null +++ b/noncore/apps/opie-reader/CFilter.cpp | |||
@@ -0,0 +1,561 @@ | |||
1 | #include "CDrawBuffer.h" | ||
2 | #include "CFilter.h" | ||
3 | |||
4 | unsigned short striphtml::skip_ws() | ||
5 | { | ||
6 | tchar ch; | ||
7 | CStyle sty; | ||
8 | do | ||
9 | { | ||
10 | parent->getch(ch, sty); | ||
11 | } | ||
12 | while (ch < 33); | ||
13 | return ch; | ||
14 | } | ||
15 | |||
16 | unsigned short striphtml::skip_ws_end() | ||
17 | { | ||
18 | tchar ch; | ||
19 | CStyle sty; | ||
20 | parent->getch(ch, sty); | ||
21 | if (ch == ' ') | ||
22 | { | ||
23 | do | ||
24 | { | ||
25 | parent->getch(ch, sty); | ||
26 | } | ||
27 | while (ch != '>'); | ||
28 | } | ||
29 | return ch; | ||
30 | } | ||
31 | |||
32 | unsigned short striphtml::parse_m() | ||
33 | { | ||
34 | tchar ch; | ||
35 | CStyle sty; | ||
36 | parent->getch(ch, sty); | ||
37 | if (ch == 'm' || ch == 'M') | ||
38 | { | ||
39 | ch = skip_ws_end(); | ||
40 | if (ch == '>') | ||
41 | { | ||
42 | return 0; | ||
43 | } | ||
44 | } | ||
45 | return ch; | ||
46 | } | ||
47 | |||
48 | void striphtml::mygetch(tchar& ch, CStyle& sty) | ||
49 | { | ||
50 | parent->getch(ch, sty); | ||
51 | if (ch == 10) ch = ' '; | ||
52 | } | ||
53 | |||
54 | void striphtml::getch(tchar& ch, CStyle& sty) | ||
55 | { | ||
56 | CStyle dummy; | ||
57 | mygetch(ch, dummy); | ||
58 | if (ch == 10) ch = ' '; | ||
59 | while (ch == '<') | ||
60 | { | ||
61 | ch = skip_ws(); | ||
62 | |||
63 | switch (ch) | ||
64 | { | ||
65 | case 'p': | ||
66 | case 'P': | ||
67 | ch = skip_ws_end(); | ||
68 | if (ch == '>') | ||
69 | { | ||
70 | ch = 10; | ||
71 | continue; | ||
72 | } | ||
73 | break; | ||
74 | case 'b': | ||
75 | case 'B': | ||
76 | ch = skip_ws_end(); | ||
77 | if (ch == '>') | ||
78 | { | ||
79 | currentstyle.setBold(); | ||
80 | mygetch(ch, dummy); | ||
81 | continue; | ||
82 | } | ||
83 | else if (ch == 'r' || ch == 'R') | ||
84 | { | ||
85 | ch = skip_ws_end(); | ||
86 | if (ch == '>') | ||
87 | { | ||
88 | ch = 10; | ||
89 | continue; | ||
90 | } | ||
91 | } | ||
92 | break; | ||
93 | case 'i': | ||
94 | case 'I': | ||
95 | ch = skip_ws_end(); | ||
96 | if (ch == '>') | ||
97 | { | ||
98 | currentstyle.setItalic(); | ||
99 | mygetch(ch, dummy); | ||
100 | continue; | ||
101 | } | ||
102 | break; | ||
103 | case 'e': | ||
104 | case 'E': | ||
105 | if ((ch = parse_m()) == 0) | ||
106 | { | ||
107 | currentstyle.setItalic(); | ||
108 | mygetch(ch, dummy); | ||
109 | continue; | ||
110 | } | ||
111 | break; | ||
112 | case 'h': | ||
113 | case 'H': | ||
114 | mygetch(ch, dummy); | ||
115 | if ('0' < ch && ch <= '9') | ||
116 | { | ||
117 | tchar hs = ch; | ||
118 | ch = skip_ws_end(); | ||
119 | if (ch == '>') | ||
120 | { | ||
121 | switch (hs) | ||
122 | { | ||
123 | case '1': | ||
124 | // currentstyle = ucBold | ucFontBase+2 | (ucAlignCentre << ucAlignShift); | ||
125 | currentstyle.unset(); | ||
126 | currentstyle.setFontSize(2); | ||
127 | currentstyle.setBold(); | ||
128 | currentstyle.setCentreJustify(); | ||
129 | break; | ||
130 | case '2': | ||
131 | // currentstyle = ucBold | ucFontBase+1; | ||
132 | currentstyle.unset(); | ||
133 | currentstyle.setFontSize(1); | ||
134 | currentstyle.setBold(); | ||
135 | break; | ||
136 | default: | ||
137 | // currentstyle = ucBold | ucFontBase; | ||
138 | currentstyle.unset(); | ||
139 | currentstyle.setBold(); | ||
140 | } | ||
141 | ch = 10; | ||
142 | // mygetch(ch, dummy); | ||
143 | continue; | ||
144 | } | ||
145 | } | ||
146 | break; | ||
147 | case '/': | ||
148 | mygetch(ch, dummy); | ||
149 | switch (ch) | ||
150 | { | ||
151 | case 'b': | ||
152 | case 'B': | ||
153 | ch = skip_ws_end(); | ||
154 | if (ch == '>') | ||
155 | { | ||
156 | currentstyle.unsetBold(); | ||
157 | mygetch(ch, dummy); | ||
158 | continue; | ||
159 | } | ||
160 | break; | ||
161 | case 'i': | ||
162 | case 'I': | ||
163 | ch = skip_ws_end(); | ||
164 | if (ch == '>') | ||
165 | { | ||
166 | currentstyle.unsetItalic(); | ||
167 | mygetch(ch, dummy); | ||
168 | continue; | ||
169 | } | ||
170 | break; | ||
171 | case 'e': | ||
172 | case 'E': | ||
173 | if ((ch = parse_m()) == 0) | ||
174 | { | ||
175 | currentstyle.unsetItalic(); | ||
176 | mygetch(ch, dummy); | ||
177 | continue; | ||
178 | } | ||
179 | break; | ||
180 | case 'h': | ||
181 | case 'H': | ||
182 | mygetch(ch, dummy); | ||
183 | if ('0' < ch && ch <= '9') | ||
184 | { | ||
185 | ch = skip_ws_end(); | ||
186 | if (ch == '>') | ||
187 | { | ||
188 | currentstyle.unset(); | ||
189 | //mygetch(ch, dummy); | ||
190 | ch = 10; | ||
191 | continue; | ||
192 | } | ||
193 | } | ||
194 | break; | ||
195 | default: | ||
196 | break; | ||
197 | } | ||
198 | break; | ||
199 | default: | ||
200 | break; | ||
201 | } | ||
202 | while (ch != '>' && ch != UEOF) | ||
203 | { | ||
204 | mygetch(ch, dummy); | ||
205 | } | ||
206 | mygetch(ch, dummy); | ||
207 | } | ||
208 | if (ch == '&') | ||
209 | { | ||
210 | mygetch(ch, dummy); | ||
211 | if (ch == '#') | ||
212 | { | ||
213 | int id = 0; | ||
214 | mygetch(ch, dummy); | ||
215 | while (ch != ';' && ch != UEOF) | ||
216 | { | ||
217 | id = 10*id+ch-'0'; | ||
218 | mygetch(ch, dummy); | ||
219 | } | ||
220 | ch = id; | ||
221 | } | ||
222 | } | ||
223 | // sty = (dummy == ucFontBase) ? currentstyle : dummy; | ||
224 | sty = currentstyle; | ||
225 | return; | ||
226 | } | ||
227 | |||
228 | |||
229 | void textfmt::mygetch(tchar& ch, CStyle& sty) | ||
230 | { | ||
231 | if (uselast) | ||
232 | { | ||
233 | ch = lastchar; | ||
234 | uselast = false; | ||
235 | } | ||
236 | else | ||
237 | { | ||
238 | parent->getch(ch, sty); | ||
239 | } | ||
240 | } | ||
241 | |||
242 | void textfmt::getch(tchar& ch, CStyle& sty) | ||
243 | { | ||
244 | mygetch(ch, sty); | ||
245 | do | ||
246 | { | ||
247 | sty = currentstyle; | ||
248 | switch (ch) | ||
249 | { | ||
250 | case 10: | ||
251 | currentstyle.unset(); | ||
252 | sty = currentstyle; | ||
253 | break; | ||
254 | // Use this if you want to replace -- by em-dash | ||
255 | case '-': | ||
256 | // parent->getch(ch, sty); | ||
257 | mygetch(ch, sty); | ||
258 | if (ch == '-') | ||
259 | { | ||
260 | ch = 0x2014; | ||
261 | } | ||
262 | else | ||
263 | { | ||
264 | lastchar = ch; | ||
265 | uselast = true; | ||
266 | ch = '-'; | ||
267 | } | ||
268 | break; | ||
269 | case '*': | ||
270 | if (currentstyle.isBold()) | ||
271 | { | ||
272 | // Already bold - time to turn it off? | ||
273 | // The next two lines ensure that * follows a character but it works better without | ||
274 | // QChar c(lastchar); | ||
275 | // if ((lastchar != '*') && (c.isPunct() || c.isLetterOrNumber())) | ||
276 | if (lastchar != '*') | ||
277 | { | ||
278 | currentstyle.unsetBold(); | ||
279 | CStyle dummy; | ||
280 | // parent->getch(ch, dummy); | ||
281 | mygetch(ch, dummy); | ||
282 | } | ||
283 | } | ||
284 | else | ||
285 | { | ||
286 | // not bold - time to turn it on? | ||
287 | CStyle dummy; | ||
288 | // parent->getch(ch, dummy); | ||
289 | mygetch(ch, dummy); | ||
290 | QChar c(ch); | ||
291 | if ((ch != '*') && (c.isPunct() || c.isLetterOrNumber())) | ||
292 | { | ||
293 | currentstyle.setBold(); | ||
294 | } | ||
295 | else | ||
296 | { | ||
297 | lastchar = ch; | ||
298 | uselast = true; | ||
299 | ch = '*'; | ||
300 | } | ||
301 | |||
302 | } | ||
303 | break; | ||
304 | case '_': | ||
305 | if (currentstyle.isItalic()) | ||
306 | { | ||
307 | // Already bold - time to turn it off? | ||
308 | // The next two lines ensure that * follows a character but it works better without | ||
309 | // QChar c(lastchar); | ||
310 | // if ((lastchar != '_') && (c.isPunct() || c.isLetterOrNumber())) | ||
311 | if (lastchar != '_') | ||
312 | { | ||
313 | currentstyle.unsetItalic(); | ||
314 | CStyle dummy; | ||
315 | // parent->getch(ch, dummy); | ||
316 | mygetch(ch, dummy); | ||
317 | } | ||
318 | } | ||
319 | else | ||
320 | { | ||
321 | // not bold - time to turn it on? | ||
322 | CStyle dummy; | ||
323 | // parent->getch(ch, dummy); | ||
324 | mygetch(ch, dummy); | ||
325 | QChar c(ch); | ||
326 | if ((ch != '_') && (c.isPunct() || c.isLetterOrNumber())) | ||
327 | { | ||
328 | currentstyle.setItalic(); | ||
329 | } | ||
330 | else | ||
331 | { | ||
332 | lastchar = ch; | ||
333 | uselast = true; | ||
334 | ch = '_'; | ||
335 | } | ||
336 | |||
337 | } | ||
338 | break; | ||
339 | } | ||
340 | } | ||
341 | while (sty != currentstyle); | ||
342 | if (!uselast) lastchar = ch; | ||
343 | return; | ||
344 | } | ||
345 | |||
346 | void remap::getch(tchar& ch, CStyle& sty) | ||
347 | { | ||
348 | if (q[offset] != 0) | ||
349 | { | ||
350 | q[offset++]; | ||
351 | sty = currentstyle; | ||
352 | return; | ||
353 | } | ||
354 | parent->getch(ch, sty); | ||
355 | switch (ch) | ||
356 | { | ||
357 | case 0x201a: | ||
358 | ch = '\''; | ||
359 | break; | ||
360 | case 0x0192: | ||
361 | ch = 'f'; | ||
362 | break; | ||
363 | case 0x201e: | ||
364 | ch = '"'; | ||
365 | break; | ||
366 | case 0x2026: | ||
367 | offset = 0; | ||
368 | q[0] = '.'; | ||
369 | q[1] = '.'; | ||
370 | q[2] = 0; | ||
371 | ch = '.'; // should be ... | ||
372 | break; | ||
373 | case 0x0160: | ||
374 | ch = 'S'; | ||
375 | break; | ||
376 | case 0x2039: | ||
377 | ch = '<'; | ||
378 | break; | ||
379 | case 0x0152: | ||
380 | offset = 0; | ||
381 | q[0] = 'E'; | ||
382 | q[1] = 0; | ||
383 | ch = 'O'; | ||
384 | break; | ||
385 | case 0x017d: | ||
386 | ch = 'Z'; | ||
387 | break; | ||
388 | case 0x2018: | ||
389 | ch = '\''; | ||
390 | break; | ||
391 | case 0x2019: | ||
392 | ch = '\''; | ||
393 | break; | ||
394 | case 0x201c: | ||
395 | ch = '"'; | ||
396 | break; | ||
397 | case 0x201d: | ||
398 | ch = '"'; | ||
399 | break; | ||
400 | case 0x2022: | ||
401 | ch = '>'; | ||
402 | break; | ||
403 | case 0x2013: | ||
404 | ch = '-'; | ||
405 | break; | ||
406 | case 0x2014: | ||
407 | offset = 0; | ||
408 | q[0] = '-'; | ||
409 | q[1] = 0; | ||
410 | ch = '-'; // should be -- | ||
411 | break; | ||
412 | case 0x02dc: | ||
413 | ch = '~'; | ||
414 | break; | ||
415 | case 0x0161: | ||
416 | ch = 's'; | ||
417 | break; | ||
418 | case 0x203a: | ||
419 | ch = '>'; | ||
420 | break; | ||
421 | case 0x0153: | ||
422 | offset = 0; | ||
423 | q[0] = 'e'; | ||
424 | q[1] = 0; | ||
425 | ch = 'o';// should be oe | ||
426 | break; | ||
427 | case 0x017e: | ||
428 | ch = 'z'; | ||
429 | break; | ||
430 | case 0x0178: | ||
431 | ch = 'Y'; | ||
432 | break; | ||
433 | } | ||
434 | currentstyle = sty; | ||
435 | } | ||
436 | |||
437 | void PeanutFormatter::getch(tchar& ch, CStyle& sty) | ||
438 | { | ||
439 | CStyle dummy; | ||
440 | currentstyle.setColour(0,0,0); | ||
441 | parent->getch(ch, dummy); | ||
442 | while (ch == '\\') | ||
443 | { | ||
444 | parent->getch(ch, dummy); | ||
445 | if (ch == '\\') break; | ||
446 | switch(ch) | ||
447 | { | ||
448 | case 'a': | ||
449 | { | ||
450 | int code = 0; | ||
451 | for (int i = 0; i < 3; i++) | ||
452 | { | ||
453 | parent->getch(ch, dummy); | ||
454 | code = 10*code + ch - '0'; | ||
455 | } | ||
456 | ch = code; | ||
457 | } | ||
458 | break; | ||
459 | case 'v': | ||
460 | { | ||
461 | while (1) | ||
462 | { | ||
463 | parent->getch(ch, dummy); | ||
464 | if (ch == '\\') | ||
465 | { | ||
466 | parent->getch(ch, dummy); | ||
467 | if (ch == 'v') | ||
468 | { | ||
469 | parent->getch(ch, dummy); | ||
470 | break; | ||
471 | } | ||
472 | } | ||
473 | } | ||
474 | } | ||
475 | break; | ||
476 | case 's': | ||
477 | case 'n': | ||
478 | currentstyle.setFontSize(0); | ||
479 | parent->getch(ch,dummy); | ||
480 | break; | ||
481 | case 'p': | ||
482 | currentstyle.unset(); | ||
483 | // parent->getch(ch,dummy); | ||
484 | ch = 10; | ||
485 | break; | ||
486 | case 'l': | ||
487 | if (currentstyle.getFontSize() == 1) | ||
488 | { | ||
489 | currentstyle.setFontSize(0); | ||
490 | } | ||
491 | else | ||
492 | { | ||
493 | currentstyle.setFontSize(1); | ||
494 | } | ||
495 | parent->getch(ch, dummy); | ||
496 | break; | ||
497 | case 'x': | ||
498 | if (currentstyle.getFontSize() == 0) | ||
499 | { | ||
500 | // currentstyle.unset(); | ||
501 | // currentstyle.setBold(); | ||
502 | currentstyle.setFontSize(1); | ||
503 | } | ||
504 | else | ||
505 | { | ||
506 | currentstyle.unset(); | ||
507 | } | ||
508 | // parent->getch(ch, dummy); | ||
509 | ch = 10; | ||
510 | break; | ||
511 | case 'i': | ||
512 | if (currentstyle.isItalic()) | ||
513 | { | ||
514 | currentstyle.unsetItalic(); | ||
515 | } | ||
516 | else | ||
517 | { | ||
518 | currentstyle.setItalic(); | ||
519 | } | ||
520 | parent->getch(ch, dummy); | ||
521 | break; | ||
522 | case 'b': | ||
523 | case 'B': | ||
524 | if (currentstyle.isBold()) | ||
525 | { | ||
526 | currentstyle.unsetBold(); | ||
527 | } | ||
528 | else | ||
529 | { | ||
530 | currentstyle.setBold(); | ||
531 | } | ||
532 | parent->getch(ch, dummy); | ||
533 | break; | ||
534 | case 'c': | ||
535 | if (currentstyle.getJustify() == CStyle::m_AlignCentre) | ||
536 | { | ||
537 | currentstyle.setLeftJustify(); | ||
538 | } | ||
539 | else | ||
540 | { | ||
541 | currentstyle.setCentreJustify(); | ||
542 | } | ||
543 | parent->getch(ch, dummy); | ||
544 | break; | ||
545 | case 'r': | ||
546 | if (currentstyle.getJustify() == CStyle::m_AlignRight) | ||
547 | { | ||
548 | currentstyle.setLeftJustify(); | ||
549 | } | ||
550 | else | ||
551 | { | ||
552 | currentstyle.setRightJustify(); | ||
553 | } | ||
554 | parent->getch(ch, dummy); | ||
555 | break; | ||
556 | default: | ||
557 | currentstyle.setColour(255,0,0); | ||
558 | } | ||
559 | } | ||
560 | sty = currentstyle; | ||
561 | } | ||
diff --git a/noncore/apps/opie-reader/CFilter.h b/noncore/apps/opie-reader/CFilter.h index 4f609dc..8cfd7eb 100644 --- a/noncore/apps/opie-reader/CFilter.h +++ b/noncore/apps/opie-reader/CFilter.h | |||
@@ -15,21 +15,6 @@ public: | |||
15 | virtual ~CFilter() {}; | 15 | virtual ~CFilter() {}; |
16 | }; | 16 | }; |
17 | 17 | ||
18 | class vanilla : public CFilter | ||
19 | { | ||
20 | public: | ||
21 | vanilla() {} | ||
22 | virtual ~vanilla() {} | ||
23 | #ifdef _UNICODE | ||
24 | virtual tchar getch() | ||
25 | #else | ||
26 | virtual int getch() | ||
27 | #endif | ||
28 | { | ||
29 | return parent->getch(); | ||
30 | } | ||
31 | }; | ||
32 | |||
33 | class CFilterChain | 18 | class CFilterChain |
34 | { | 19 | { |
35 | CExpander* expander; | 20 | CExpander* expander; |
@@ -49,7 +34,10 @@ class CFilterChain | |||
49 | } | 34 | } |
50 | delete encoder; | 35 | delete encoder; |
51 | } | 36 | } |
52 | int getch() { return front->getch(); } | 37 | void getch(tchar& ch, CStyle& sty) |
38 | { | ||
39 | front->getch(ch, sty); | ||
40 | } | ||
53 | void addfilter(CFilter* p) | 41 | void addfilter(CFilter* p) |
54 | { | 42 | { |
55 | if (first == NULL) | 43 | if (first == NULL) |
@@ -82,113 +70,57 @@ class stripcr : public CFilter | |||
82 | public: | 70 | public: |
83 | stripcr() {} | 71 | stripcr() {} |
84 | virtual ~stripcr() {} | 72 | virtual ~stripcr() {} |
85 | #ifdef _UNICODE | 73 | virtual void getch(tchar& ch, CStyle& sty) |
86 | virtual tchar getch() | ||
87 | { | ||
88 | tchar ch; | ||
89 | do | ||
90 | { | ||
91 | ch = parent->getch(); | ||
92 | } | ||
93 | while (ch == 13); | ||
94 | return ch; | ||
95 | } | ||
96 | #else | ||
97 | virtual int getch() | ||
98 | { | 74 | { |
99 | int ch; | ||
100 | do | 75 | do |
101 | { | 76 | { |
102 | ch = parent->getch(); | 77 | parent->getch(ch, sty); |
103 | } | 78 | } |
104 | while (ch == 13); | 79 | while (ch == 13); |
105 | return ch; | ||
106 | } | 80 | } |
107 | #endif | ||
108 | }; | 81 | }; |
109 | 82 | ||
110 | class dehyphen : public CFilter | 83 | class dehyphen : public CFilter |
111 | { | 84 | { |
112 | bool m_bCharWaiting; | 85 | bool m_bCharWaiting; |
113 | tchar m_nextChar; | 86 | tchar m_nextChar; |
87 | CStyle m_nextSty; | ||
114 | public: | 88 | public: |
115 | dehyphen() : m_bCharWaiting(false) {} | 89 | dehyphen() : m_bCharWaiting(false) {} |
116 | virtual ~dehyphen() {} | 90 | virtual ~dehyphen() {} |
117 | virtual tchar getch() | 91 | virtual void getch(tchar& ch, CStyle& sty) |
118 | { | 92 | { |
119 | if (m_bCharWaiting) | 93 | if (m_bCharWaiting) |
120 | { | 94 | { |
121 | m_bCharWaiting = false; | 95 | m_bCharWaiting = false; |
122 | return m_nextChar; | 96 | ch = m_nextChar; |
97 | sty = m_nextSty; | ||
98 | return; | ||
123 | } | 99 | } |
124 | tchar ch = parent->getch(); | 100 | parent->getch(ch, sty); |
125 | if (ch != '-') return ch; | 101 | if (ch != '-') return; |
126 | m_nextChar = parent->getch(); | 102 | parent->getch(m_nextChar, m_nextSty); |
127 | if (m_nextChar != 10) | 103 | if (m_nextChar != 10) |
128 | { | 104 | { |
129 | m_bCharWaiting = true; | 105 | m_bCharWaiting = true; |
130 | return '-'; | 106 | ch = '-'; |
107 | return; | ||
131 | } | 108 | } |
132 | return parent->getch(); | 109 | parent->getch(ch, sty); |
133 | } | 110 | } |
134 | }; | 111 | }; |
135 | 112 | ||
136 | class striphtml : public CFilter | 113 | class striphtml : public CFilter |
137 | { | 114 | { |
115 | CStyle currentstyle; | ||
116 | unsigned short skip_ws(); | ||
117 | unsigned short skip_ws_end(); | ||
118 | unsigned short parse_m(); | ||
119 | void mygetch(tchar& ch, CStyle& sty); | ||
138 | public: | 120 | public: |
139 | striphtml() {} | 121 | striphtml() {} |
140 | virtual ~striphtml() {} | 122 | virtual ~striphtml() {} |
141 | #ifdef _UNICODE | 123 | virtual void getch(tchar& ch, CStyle& sty); |
142 | virtual tchar getch() | ||
143 | { | ||
144 | tchar ch; | ||
145 | ch = parent->getch(); | ||
146 | while (ch == '<') | ||
147 | { | ||
148 | while (ch != '>') | ||
149 | { | ||
150 | ch = parent->getch(); | ||
151 | } | ||
152 | ch = parent->getch(); | ||
153 | } | ||
154 | if (ch == '&') | ||
155 | { | ||
156 | ch = parent->getch(); | ||
157 | if (ch == '#') | ||
158 | { | ||
159 | int id = 0; | ||
160 | while ((ch = parent->getch()) != ';') id = 10*id+ch-'0'; | ||
161 | ch = id; | ||
162 | } | ||
163 | } | ||
164 | return ch; | ||
165 | } | ||
166 | #else | ||
167 | virtual int getch() | ||
168 | { | ||
169 | int ch; | ||
170 | ch = parent->getch(); | ||
171 | while (ch == '<') | ||
172 | { | ||
173 | while (ch != '>') | ||
174 | { | ||
175 | ch = parent->getch(); | ||
176 | } | ||
177 | ch = parent->getch(); | ||
178 | } | ||
179 | if (ch == '&') | ||
180 | { | ||
181 | ch = parent->getch(); | ||
182 | if (ch == '#') | ||
183 | { | ||
184 | int id = 0; | ||
185 | while ((ch = parent->getch()) != ';') id = 10*id+ch-'0'; | ||
186 | ch = id; | ||
187 | } | ||
188 | } | ||
189 | return ch; | ||
190 | } | ||
191 | #endif | ||
192 | }; | 124 | }; |
193 | 125 | ||
194 | class unindent : public CFilter | 126 | class unindent : public CFilter |
@@ -197,158 +129,141 @@ class unindent : public CFilter | |||
197 | public: | 129 | public: |
198 | unindent() : lc(0) {} | 130 | unindent() : lc(0) {} |
199 | virtual ~unindent() {} | 131 | virtual ~unindent() {} |
200 | #ifdef _UNICODE | 132 | virtual void getch(tchar& ch, CStyle& sty) |
201 | virtual tchar getch() | ||
202 | { | 133 | { |
203 | tchar ch; | ||
204 | if (lc == 10) | 134 | if (lc == 10) |
205 | { | 135 | { |
206 | while ((ch = parent->getch()) == ' '); | 136 | do |
207 | } | ||
208 | else ch = parent->getch(); | ||
209 | lc = ch; | ||
210 | return ch; | ||
211 | } | ||
212 | #else | ||
213 | virtual int getch() | ||
214 | { | ||
215 | int ch; | ||
216 | if (lc == 10) | ||
217 | { | 137 | { |
218 | while ((ch = parent->getch()) == ' '); | 138 | parent->getch(ch, sty); |
139 | } | ||
140 | while (ch == ' '); | ||
219 | } | 141 | } |
220 | else ch = parent->getch(); | 142 | else parent->getch(ch, sty); |
221 | lc = ch; | 143 | lc = ch; |
222 | return ch; | 144 | return; |
223 | } | 145 | } |
224 | #endif | ||
225 | }; | 146 | }; |
226 | 147 | ||
227 | #ifdef _UNICODE | ||
228 | class repara : public CFilter | 148 | class repara : public CFilter |
229 | { | 149 | { |
230 | tchar tch; | 150 | tchar tch; |
231 | public: | 151 | public: |
232 | repara() : tch(0) {} | 152 | repara() : tch(0) {} |
233 | virtual ~repara() {} | 153 | virtual ~repara() {} |
234 | virtual tchar getch() | 154 | virtual void getch(tchar& ch, CStyle& sty) |
235 | { | ||
236 | tchar ch = parent->getch(); | ||
237 | if (ch == 10) | ||
238 | { | ||
239 | if (tch == 10) | ||
240 | { | ||
241 | return ch; | ||
242 | } | ||
243 | else | ||
244 | { | ||
245 | tch = ch; | ||
246 | return ' '; | ||
247 | } | ||
248 | } | ||
249 | tch = ch; | ||
250 | return ch; | ||
251 | } | ||
252 | }; | ||
253 | #else | ||
254 | class repara : public CFilter | ||
255 | { | ||
256 | int tch; | ||
257 | public: | ||
258 | repara() : tch(0) {} | ||
259 | virtual ~repara() {} | ||
260 | virtual int getch() | ||
261 | { | 155 | { |
262 | int ch = parent->getch(); | 156 | parent->getch(ch, sty); |
263 | if (ch == 10) | 157 | if (ch == 10) |
264 | { | 158 | { |
265 | if (tch == 10) | 159 | if (tch == 10) |
266 | { | 160 | { |
267 | return ch; | 161 | return; |
268 | } | 162 | } |
269 | else | 163 | else |
270 | { | 164 | { |
271 | tch = ch; | 165 | tch = ch; |
272 | return ' '; | 166 | ch = ' '; |
167 | return; | ||
273 | } | 168 | } |
274 | } | 169 | } |
275 | tch = ch; | 170 | tch = ch; |
276 | return ch; | 171 | return; |
277 | } | 172 | } |
278 | }; | 173 | }; |
279 | #endif | ||
280 | 174 | ||
281 | class indenter : public CFilter | 175 | class indenter : public CFilter |
282 | { | 176 | { |
283 | int amnt; | 177 | int amnt; |
284 | int indent; | 178 | int indent; |
179 | CStyle lsty; | ||
285 | public: | 180 | public: |
286 | indenter(int _a=5) : amnt(_a), indent(0) {} | 181 | indenter(int _a=5) : amnt(_a), indent(0) {} |
287 | virtual ~indenter() {} | 182 | virtual ~indenter() {} |
288 | #ifdef _UNICODE | 183 | virtual void getch(tchar& ch, CStyle& sty) |
289 | virtual tchar getch() | ||
290 | { | ||
291 | if (indent > 0) | ||
292 | { | ||
293 | indent--; | ||
294 | return ' '; | ||
295 | } | ||
296 | tchar ch = parent->getch(); | ||
297 | if (ch == 10) | ||
298 | { | ||
299 | indent = amnt; | ||
300 | } | ||
301 | return ch; | ||
302 | } | ||
303 | #else | ||
304 | virtual int getch() | ||
305 | { | 184 | { |
306 | if (indent > 0) | 185 | if (indent > 0) |
307 | { | 186 | { |
308 | indent--; | 187 | indent--; |
309 | return ' '; | 188 | ch = ' '; |
189 | sty = lsty; | ||
190 | return; | ||
310 | } | 191 | } |
311 | int ch = parent->getch(); | 192 | parent->getch(ch, sty); |
312 | if (ch == 10) | 193 | if (ch == 10) |
313 | { | 194 | { |
314 | indent = amnt; | 195 | indent = amnt; |
196 | lsty = sty; | ||
315 | } | 197 | } |
316 | return ch; | 198 | return; |
317 | } | 199 | } |
318 | #endif | ||
319 | }; | 200 | }; |
320 | 201 | ||
321 | class dblspce : public CFilter | 202 | class dblspce : public CFilter |
322 | { | 203 | { |
323 | bool lastlf; | 204 | bool lastlf; |
205 | CStyle lsty; | ||
324 | public: | 206 | public: |
325 | dblspce() : lastlf(false) {} | 207 | dblspce() : lastlf(false) {} |
326 | virtual ~dblspce() {} | 208 | virtual ~dblspce() {} |
327 | #ifdef _UNICODE | 209 | virtual void getch(tchar& ch, CStyle& sty) |
328 | virtual tchar getch() | ||
329 | { | 210 | { |
330 | if (lastlf) | 211 | if (lastlf) |
331 | { | 212 | { |
332 | lastlf = false; | 213 | lastlf = false; |
333 | return 10; | 214 | ch = 10; |
215 | sty = lsty; | ||
216 | return; | ||
217 | } | ||
218 | parent->getch(ch, sty); | ||
219 | if (lastlf = (ch == 10)) | ||
220 | { | ||
221 | lsty = sty; | ||
334 | } | 222 | } |
335 | tchar ch = parent->getch(); | 223 | return; |
336 | lastlf = (ch == 10); | ||
337 | return ch; | ||
338 | } | 224 | } |
339 | #else | 225 | }; |
340 | virtual int getch() | 226 | |
227 | class textfmt : public CFilter | ||
341 | { | 228 | { |
342 | if (lastlf) | 229 | CStyle currentstyle; |
230 | tchar lastchar; | ||
231 | bool uselast; | ||
232 | void mygetch(tchar&, CStyle&); | ||
233 | public: | ||
234 | textfmt() : lastchar(0), uselast(false) {} | ||
235 | virtual ~textfmt() {} | ||
236 | virtual void getch(tchar& ch, CStyle& sty); | ||
237 | }; | ||
238 | |||
239 | class embolden : public CFilter | ||
343 | { | 240 | { |
344 | lastlf = false; | 241 | public: |
345 | return 10; | 242 | embolden() {} |
346 | } | 243 | virtual ~embolden() {} |
347 | int ch = parent->getch(); | 244 | virtual void getch(tchar& ch, CStyle& sty) |
348 | lastlf = (ch == 10); | 245 | { |
349 | return ch; | 246 | parent->getch(ch, sty); |
247 | sty.setBold(); | ||
350 | } | 248 | } |
351 | #endif | ||
352 | }; | 249 | }; |
353 | 250 | ||
251 | class remap : public CFilter | ||
252 | { | ||
253 | tchar q[3]; | ||
254 | int offset; | ||
255 | CStyle currentstyle; | ||
256 | public: | ||
257 | remap() : offset(0) { q[0] = 0; } | ||
258 | virtual ~remap() {} | ||
259 | virtual void getch(tchar& ch, CStyle& sty); | ||
260 | }; | ||
261 | |||
262 | class PeanutFormatter : public CFilter | ||
263 | { | ||
264 | CStyle currentstyle; | ||
265 | public: | ||
266 | virtual ~PeanutFormatter() {} | ||
267 | virtual void getch(tchar& ch, CStyle& sty); | ||
268 | }; | ||
354 | #endif | 269 | #endif |
diff --git a/noncore/apps/opie-reader/FontControl.h b/noncore/apps/opie-reader/FontControl.h new file mode 100644 index 0000000..ed6c33f --- a/dev/null +++ b/noncore/apps/opie-reader/FontControl.h | |||
@@ -0,0 +1,121 @@ | |||
1 | #ifndef __FONTCONTROL_H | ||
2 | #define __FONTCONTROL_H | ||
3 | |||
4 | #include <qfontdatabase.h> | ||
5 | #include <qfontmetrics.h> | ||
6 | #include "StyleConsts.h" | ||
7 | |||
8 | class FontControl | ||
9 | { | ||
10 | int * m_fontsizes; | ||
11 | int m_size; | ||
12 | QString m_fontname; | ||
13 | int m_maxsize; | ||
14 | public: | ||
15 | FontControl(QString n = "helvetica", int size = 10) | ||
16 | : | ||
17 | m_fontsizes(NULL) | ||
18 | { | ||
19 | ChangeFont(n, size); | ||
20 | } | ||
21 | ~FontControl() | ||
22 | { | ||
23 | if (m_fontsizes != NULL) delete [] m_fontsizes; | ||
24 | } | ||
25 | QString name() { return m_fontname; } | ||
26 | int currentsize() { return m_fontsizes[m_size]; } | ||
27 | int getsize(CStyle size) | ||
28 | { | ||
29 | return m_fontsizes[m_size+size.getFontSize()]; | ||
30 | } | ||
31 | int ascent() | ||
32 | { | ||
33 | QFont f(name(), currentsize()); | ||
34 | QFontMetrics fm(f); | ||
35 | return fm.ascent(); | ||
36 | } | ||
37 | int ascent(CStyle ch) | ||
38 | { | ||
39 | QFont f(name(), getsize(ch)); | ||
40 | QFontMetrics fm(f); | ||
41 | return fm.ascent(); | ||
42 | } | ||
43 | int descent() | ||
44 | { | ||
45 | QFont f(name(), currentsize()); | ||
46 | QFontMetrics fm(f); | ||
47 | return fm.descent(); | ||
48 | } | ||
49 | int descent(CStyle ch) | ||
50 | { | ||
51 | QFont f(name(), getsize(ch)); | ||
52 | QFontMetrics fm(f); | ||
53 | return fm.descent(); | ||
54 | } | ||
55 | int lineSpacing() | ||
56 | { | ||
57 | QFont f(name(), currentsize()); | ||
58 | QFontMetrics fm(f); | ||
59 | return fm.lineSpacing(); | ||
60 | } | ||
61 | int lineSpacing(CStyle ch) | ||
62 | { | ||
63 | QFont f(name(), getsize(ch)); | ||
64 | QFontMetrics fm(f); | ||
65 | return fm.lineSpacing(); | ||
66 | } | ||
67 | bool decreasesize() | ||
68 | { | ||
69 | if (--m_size < 0) | ||
70 | { | ||
71 | m_size = 0; | ||
72 | return false; | ||
73 | } | ||
74 | else return true; | ||
75 | } | ||
76 | bool increasesize() | ||
77 | { | ||
78 | if (++m_size >= m_maxsize) | ||
79 | { | ||
80 | m_size = m_maxsize - 1; | ||
81 | return false; | ||
82 | } | ||
83 | else return true; | ||
84 | } | ||
85 | bool ChangeFont(QString& n) | ||
86 | { | ||
87 | return ChangeFont(n, currentsize()); | ||
88 | } | ||
89 | bool ChangeFont(QString& n, int tgt) | ||
90 | { | ||
91 | QValueList<int>::Iterator it; | ||
92 | QFontDatabase fdb; | ||
93 | QValueList<int> sizes = fdb.pointSizes(n); | ||
94 | if (sizes.count() == 0) | ||
95 | { | ||
96 | return false; | ||
97 | } | ||
98 | else | ||
99 | { | ||
100 | m_fontname = n; | ||
101 | m_maxsize = sizes.count(); | ||
102 | if (m_fontsizes != NULL) delete [] m_fontsizes; | ||
103 | m_fontsizes = new int[m_maxsize]; | ||
104 | uint i = 0; | ||
105 | uint best = 0; | ||
106 | for (it = sizes.begin(); it != sizes.end(); it++) | ||
107 | { | ||
108 | m_fontsizes[i] = (*it)/10; | ||
109 | if (abs(tgt-m_fontsizes[i]) < abs(tgt-m_fontsizes[best])) | ||
110 | { | ||
111 | best = i; | ||
112 | } | ||
113 | i++; | ||
114 | } | ||
115 | m_size = best; | ||
116 | } | ||
117 | return true; | ||
118 | } | ||
119 | }; | ||
120 | |||
121 | #endif | ||
diff --git a/noncore/apps/opie-reader/Markups.h b/noncore/apps/opie-reader/Markups.h new file mode 100644 index 0000000..960489f --- a/dev/null +++ b/noncore/apps/opie-reader/Markups.h | |||
@@ -0,0 +1,7 @@ | |||
1 | enum MarkupType | ||
2 | { | ||
3 | cNONE, | ||
4 | cTEXT, | ||
5 | cHTML, | ||
6 | cPML | ||
7 | }; | ||
diff --git a/noncore/apps/opie-reader/QFloatBar.h b/noncore/apps/opie-reader/QFloatBar.h new file mode 100644 index 0000000..bc70566 --- a/dev/null +++ b/noncore/apps/opie-reader/QFloatBar.h | |||
@@ -0,0 +1,19 @@ | |||
1 | #ifndef __QFLOATBAR_H | ||
2 | #define __QFLOATBAR_H | ||
3 | |||
4 | #include <qtoolbar.h> | ||
5 | |||
6 | class QFloatBar : public QToolBar | ||
7 | { | ||
8 | Q_OBJECT | ||
9 | virtual void hideEvent(QHideEvent* e) | ||
10 | { | ||
11 | /*if (e->spontaneous())*/ emit OnHide(); | ||
12 | } | ||
13 | public: | ||
14 | QFloatBar(char* t, QMainWindow* mw, QMainWindow::ToolBarDock td, bool f) : QToolBar(t, mw, td, f) {} | ||
15 | signals: | ||
16 | void OnHide(); | ||
17 | }; | ||
18 | |||
19 | #endif | ||
diff --git a/noncore/apps/opie-reader/QTReader.cpp b/noncore/apps/opie-reader/QTReader.cpp index 6335ea2..e7bfc28 100644 --- a/noncore/apps/opie-reader/QTReader.cpp +++ b/noncore/apps/opie-reader/QTReader.cpp | |||
@@ -8,9 +8,11 @@ | |||
8 | ** | 8 | ** |
9 | *****************************************************************************/ | 9 | *****************************************************************************/ |
10 | 10 | ||
11 | #include <qpainter.h> | ||
11 | #include "config.h" | 12 | #include "config.h" |
12 | #include "QTReader.h" | 13 | #include "QTReader.h" |
13 | #include "QTReaderApp.h" | 14 | #include "QTReaderApp.h" |
15 | #include "CDrawBuffer.h" | ||
14 | #include <qpe/qpeapplication.h> | 16 | #include <qpe/qpeapplication.h> |
15 | #include <math.h> | 17 | #include <math.h> |
16 | #include <ctype.h> | 18 | #include <ctype.h> |
@@ -36,16 +38,19 @@ const char *QTReader::fonts[] = { "Helvetica", "Courier", "Times", 0 }; | |||
36 | QTReader::QTReader( QWidget *parent=0, const char *name=0, WFlags f = 0) : | 38 | QTReader::QTReader( QWidget *parent=0, const char *name=0, WFlags f = 0) : |
37 | QWidget(parent, name, f), | 39 | QWidget(parent, name, f), |
38 | m_delay(100), | 40 | m_delay(100), |
39 | m_scrolldy(0), | 41 | m_scrolldy1(0), |
42 | m_scrolldy2(0), | ||
40 | m_autoScroll(false), | 43 | m_autoScroll(false), |
41 | textarray(NULL), | 44 | //textarray(NULL), |
42 | locnarray(NULL), | 45 | //locnarray(NULL), |
43 | numlines(0), | 46 | numlines(0), |
44 | m_fontname("unifont"), | 47 | m_fontname("unifont"), |
45 | m_fm(NULL) | 48 | m_fm(NULL), |
49 | mouseUpOn(true), | ||
50 | m_twotouch(true), | ||
51 | m_touchone(true) | ||
46 | { | 52 | { |
47 | m_overlap = 1; | 53 | m_overlap = 1; |
48 | fontsizes = NULL; | ||
49 | // init(); | 54 | // init(); |
50 | } | 55 | } |
51 | /* | 56 | /* |
@@ -74,16 +79,129 @@ long QTReader::real_delay() | |||
74 | return ( 8976 + m_delay ) / ( m_linespacing * m_linespacing ); | 79 | return ( 8976 + m_delay ) / ( m_linespacing * m_linespacing ); |
75 | } | 80 | } |
76 | 81 | ||
77 | void QTReader::mouseReleaseEvent( QMouseEvent* _e ) | 82 | void QTReader::mousePressEvent( QMouseEvent* _e ) |
78 | //void QTReader::mouseDoubleClickEvent( QMouseEvent* _e ) | 83 | { |
84 | if (_e->button() == RightButton) | ||
85 | { | ||
86 | mouseUpOn = false; | ||
87 | if (_e->y() > height()/2) | ||
88 | { | ||
89 | goDown(); | ||
90 | } | ||
91 | else | ||
92 | { | ||
93 | goUp(); | ||
94 | } | ||
95 | } | ||
96 | } | ||
97 | |||
98 | bool QTReader::getcurrentpos(int x, int y, size_t& start, size_t& offset, size_t& tgt) | ||
79 | { | 99 | { |
80 | if (textarray != NULL) | 100 | int lineno = 0; |
101 | int ht = textarray[0]->lineSpacing(); | ||
102 | while ((ht < y) && (lineno < numlines)) | ||
81 | { | 103 | { |
82 | // printf("(%u, %u)\n", _e->x(), _e->y()); | 104 | ht += textarray[++lineno]->lineSpacing(); |
83 | QString wrd = QString::null; | 105 | } |
84 | int lineno = _e->y()/m_linespacing; | 106 | start = locnarray[lineno]; |
85 | if (m_bMonoSpaced) | 107 | if (m_bMonoSpaced) |
86 | { | 108 | { |
109 | offset = x/m_charWidth; | ||
110 | } | ||
111 | else | ||
112 | { | ||
113 | int i; | ||
114 | CDrawBuffer* t = textarray[lineno]; | ||
115 | for (i = t->length(); t->width(i) > x; i--); | ||
116 | offset = i; | ||
117 | } | ||
118 | return textarray[lineno]->isLink(offset, tgt); | ||
119 | } | ||
120 | |||
121 | void QTReader::setTwoTouch(bool _b) | ||
122 | { | ||
123 | setBackgroundColor( white ); | ||
124 | m_twotouch = m_touchone = _b; | ||
125 | } | ||
126 | |||
127 | void QTReader::mouseReleaseEvent( QMouseEvent* _e ) | ||
128 | { | ||
129 | if (_e->button() == LeftButton) | ||
130 | { | ||
131 | if (mouseUpOn) | ||
132 | { | ||
133 | if (textarray[0] != NULL) | ||
134 | { | ||
135 | QString wrd, line; | ||
136 | // int lineno = _e->y()/m_linespacing; | ||
137 | int lineno = 0; | ||
138 | int ht = textarray[0]->lineSpacing(); | ||
139 | while ((ht < _e->y()) && (lineno < numlines)) | ||
140 | { | ||
141 | ht += textarray[++lineno]->lineSpacing(); | ||
142 | } | ||
143 | size_t startpos, startoffset, tgt; | ||
144 | if (getcurrentpos(_e->x(), _e->y(), startpos, startoffset, tgt)) | ||
145 | { | ||
146 | if (buffdoc.hyperlink(tgt)) | ||
147 | { | ||
148 | fillbuffer(); | ||
149 | update(); | ||
150 | } | ||
151 | else | ||
152 | { | ||
153 | locate(pagelocate()); | ||
154 | } | ||
155 | return; | ||
156 | } | ||
157 | if (m_twotouch) | ||
158 | { | ||
159 | if (m_touchone) | ||
160 | { | ||
161 | m_touchone = false; | ||
162 | m_startpos = startpos; | ||
163 | m_startoffset = startoffset; | ||
164 | setBackgroundColor( lightGray ); | ||
165 | } | ||
166 | else | ||
167 | { | ||
168 | m_touchone = true; | ||
169 | setBackgroundColor( white ); | ||
170 | size_t endpos, endoffset; | ||
171 | endpos = startpos; | ||
172 | endoffset = startoffset; | ||
173 | size_t currentpos = locate(); | ||
174 | if (endpos >= m_startpos) | ||
175 | { | ||
176 | jumpto(m_startpos); | ||
177 | for (int i = 0; i < m_startoffset; i++) | ||
178 | { | ||
179 | getch(); | ||
180 | } | ||
181 | if (m_startpos == endpos) | ||
182 | { | ||
183 | for (int i = m_startoffset; i <= endoffset; i++) | ||
184 | { | ||
185 | wrd += QChar(getch()); | ||
186 | } | ||
187 | } | ||
188 | else | ||
189 | { | ||
190 | while (buffdoc.explocate() <= endpos) | ||
191 | { | ||
192 | wrd += QChar(getch()); | ||
193 | } | ||
194 | for (int i = 0; i < endoffset; i++) | ||
195 | { | ||
196 | wrd += QChar(getch()); | ||
197 | } | ||
198 | } | ||
199 | jumpto(currentpos); | ||
200 | } | ||
201 | } | ||
202 | } | ||
203 | else if (m_bMonoSpaced) | ||
204 | { | ||
87 | int chno = _e->x()/m_charWidth; | 205 | int chno = _e->x()/m_charWidth; |
88 | if (chno < ustrlen(textarray[lineno]->data())) | 206 | if (chno < ustrlen(textarray[lineno]->data())) |
89 | { | 207 | { |
@@ -92,19 +210,17 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e ) | |||
92 | } | 210 | } |
93 | else | 211 | else |
94 | { | 212 | { |
95 | CBuffer* t = textarray[lineno]; | 213 | CDrawBuffer* t = textarray[lineno]; |
96 | int first = 0; | 214 | int first = 0; |
97 | while (1) | 215 | while (1) |
98 | { | 216 | { |
99 | int i = first+1; | 217 | int i = first+1; |
100 | // while ((*t)[i] != ' ' && (*t)[i] != 0) i++; | ||
101 | while (QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++; | 218 | while (QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++; |
102 | if (m_fm->width(toQString(t->data()), i) > _e->x()) | 219 | if (t->width(i) > _e->x()) |
103 | { | 220 | { |
104 | wrd = toQString(t->data()+first, i - first); | 221 | wrd = toQString(t->data()+first, i - first); |
105 | break; | 222 | break; |
106 | } | 223 | } |
107 | // while ((*t)[i] == ' ' && (*t)[i] != 0) i++; | ||
108 | while (!QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++; | 224 | while (!QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++; |
109 | if ((*t)[i] == 0) break; | 225 | if ((*t)[i] == 0) break; |
110 | first = i; | 226 | first = i; |
@@ -112,14 +228,13 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e ) | |||
112 | } | 228 | } |
113 | if (!wrd.isEmpty()) | 229 | if (!wrd.isEmpty()) |
114 | { | 230 | { |
115 | QClipboard* cb = QApplication::clipboard(); | 231 | emit OnWordSelected(wrd, locnarray[lineno], (m_twotouch) ? wrd : toQString(textarray[lineno]->data())); |
116 | cb->setText(wrd); | 232 | } |
117 | Global::statusMessage(wrd); | 233 | } |
118 | if (!m_targetapp.isEmpty() && !m_targetmsg.isEmpty()) | ||
119 | { | ||
120 | QCopEnvelope e(("QPE/Application/"+m_targetapp).utf8(), (m_targetmsg+"(QString)").utf8()); | ||
121 | e << wrd; | ||
122 | } | 234 | } |
235 | else | ||
236 | { | ||
237 | mouseUpOn = true; | ||
123 | } | 238 | } |
124 | } | 239 | } |
125 | } | 240 | } |
@@ -135,7 +250,7 @@ void QTReader::focusOutEvent(QFocusEvent* e) | |||
135 | if (m_autoScroll) | 250 | if (m_autoScroll) |
136 | { | 251 | { |
137 | timer->stop(); | 252 | timer->stop(); |
138 | m_scrolldy = 0; | 253 | m_scrolldy1 = m_scrolldy2 = 0; |
139 | } | 254 | } |
140 | } | 255 | } |
141 | 256 | ||
@@ -245,15 +360,11 @@ void QTReader::keyPressEvent(QKeyEvent* e) | |||
245 | case Key_Right: | 360 | case Key_Right: |
246 | { | 361 | { |
247 | e->accept(); | 362 | e->accept(); |
248 | if (fontsizes[++m_textsize] == 0) | 363 | if (m_fontControl.increasesize()) |
249 | { | ||
250 | m_textsize--; | ||
251 | } | ||
252 | else | ||
253 | { | 364 | { |
254 | bool sc = m_autoScroll; | 365 | bool sc = m_autoScroll; |
366 | setfont(); | ||
255 | m_autoScroll = false; | 367 | m_autoScroll = false; |
256 | setfont(NULL); | ||
257 | locate(pagelocate()); | 368 | locate(pagelocate()); |
258 | update(); | 369 | update(); |
259 | m_autoScroll = sc; | 370 | m_autoScroll = sc; |
@@ -264,12 +375,11 @@ void QTReader::keyPressEvent(QKeyEvent* e) | |||
264 | case Key_Left: | 375 | case Key_Left: |
265 | { | 376 | { |
266 | e->accept(); | 377 | e->accept(); |
267 | if (m_textsize > 0) | 378 | if (m_fontControl.decreasesize()) |
268 | { | 379 | { |
269 | bool sc = m_autoScroll; | 380 | bool sc = m_autoScroll; |
270 | m_autoScroll = false; | 381 | m_autoScroll = false; |
271 | m_textsize--; | 382 | setfont(); |
272 | setfont(NULL); | ||
273 | locate(pagelocate()); | 383 | locate(pagelocate()); |
274 | update(); | 384 | update(); |
275 | m_autoScroll = sc; | 385 | m_autoScroll = sc; |
@@ -278,12 +388,10 @@ void QTReader::keyPressEvent(QKeyEvent* e) | |||
278 | } | 388 | } |
279 | break; | 389 | break; |
280 | case Key_Space: | 390 | case Key_Space: |
281 | // case Key_Enter: | ||
282 | case Key_Return: | 391 | case Key_Return: |
283 | { | 392 | { |
284 | e->accept(); | 393 | e->accept(); |
285 | setautoscroll(!m_autoScroll); | 394 | emit OnActionPressed(); |
286 | ((QTReaderApp*)parent()->parent())->setScrollState(m_autoScroll); | ||
287 | } | 395 | } |
288 | break; | 396 | break; |
289 | default: | 397 | default: |
@@ -297,15 +405,17 @@ void QTReader::setautoscroll(bool _sc) | |||
297 | if (m_autoScroll) | 405 | if (m_autoScroll) |
298 | { | 406 | { |
299 | m_autoScroll = false; | 407 | m_autoScroll = false; |
408 | QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; | ||
300 | } | 409 | } |
301 | else | 410 | else |
302 | { | 411 | { |
303 | m_autoScroll = true; | 412 | m_autoScroll = true; |
304 | autoscroll(); | 413 | autoscroll(); |
414 | QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Disable; // light is even not dimmed | ||
305 | } | 415 | } |
306 | } | 416 | } |
307 | 417 | ||
308 | bool QTReader::getline(CBuffer *buff) | 418 | bool QTReader::getline(CDrawBuffer *buff) |
309 | { | 419 | { |
310 | if (m_bMonoSpaced) | 420 | if (m_bMonoSpaced) |
311 | { | 421 | { |
@@ -330,48 +440,38 @@ void QTReader::doscroll() | |||
330 | bitBlt(this,0,0,this,0,1,width(),-1); | 440 | bitBlt(this,0,0,this,0,1,width(),-1); |
331 | qDrawPlainRect(&p,0,height() - 2,width(),2,white,1,&b); | 441 | qDrawPlainRect(&p,0,height() - 2,width(),2,white,1,&b); |
332 | 442 | ||
333 | if (++m_scrolldy == m_linespacing) | 443 | if (++m_scrolldy1 == textarray[0]->lineSpacing()) |
334 | { | 444 | { |
335 | setfont(&p); | 445 | CDrawBuffer* buff = textarray[0]; |
336 | m_scrolldy = 0; | 446 | for (int i = 1; i <= numlines; i++) |
337 | // qDrawPlainRect(&p,0,height() - m_linespacing,width(),m_linespacing,white,1,&b); | ||
338 | pagepos = locnarray[1]; | ||
339 | CBuffer* buff = textarray[0]; | ||
340 | for (int i = 1; i < numlines; i++) | ||
341 | { | 447 | { |
342 | textarray[i-1] = textarray[i]; | 448 | textarray[i-1] = textarray[i]; |
343 | locnarray[i-1] = locnarray[i]; | 449 | locnarray[i-1] = locnarray[i]; |
344 | } | 450 | } |
345 | locnarray[numlines-1] = locate(); | 451 | textarray[numlines] = buff; |
346 | if (getline(buff)) | 452 | --numlines; |
347 | { | 453 | m_scrolldy1 = 0; |
348 | textarray[numlines-1] = buff; | ||
349 | drawText( p, 0, height() - m_descent - 2, buff->data()); | ||
350 | mylastpos = locate(); | ||
351 | } | 454 | } |
352 | else | 455 | if (++m_scrolldy2 == textarray[numlines]->lineSpacing()) |
353 | { | 456 | { |
354 | // (*buff)[0] = '\0'; | 457 | m_scrolldy2 = 0; |
355 | textarray[numlines-1] = buff; | 458 | numlines++; |
356 | m_autoScroll = false; | ||
357 | ((QTReaderApp*)parent()->parent())->setScrollState(m_autoScroll); | ||
358 | } | ||
359 | } | ||
360 | } | ||
361 | 459 | ||
362 | void QTReader::drawText(QPainter& p, int x, int y, tchar* _text) | 460 | if (textarray[numlines] == NULL) |
363 | { | ||
364 | QString text = toQString(_text); | ||
365 | if (m_bMonoSpaced) | ||
366 | { | ||
367 | for (int i = 0; i < text.length(); i++) | ||
368 | { | 461 | { |
369 | p.drawText( x+i*m_charWidth, y, QString(text[i]) ); | 462 | textarray[numlines] = new CDrawBuffer; |
370 | } | 463 | } |
371 | } | 464 | locnarray[numlines] = locate(); |
372 | else | 465 | int ch = getline(textarray[numlines]); |
466 | textarray[numlines-1]->render(&p, height() - textarray[numlines]->descent() - 2, m_bMonoSpaced, m_charWidth, width()); | ||
467 | mylastpos = locate(); | ||
468 | if (!ch) | ||
373 | { | 469 | { |
374 | p.drawText( x, y, text ); | 470 | m_autoScroll = false; |
471 | ((QTReaderApp*)parent()->parent())->setScrollState(m_autoScroll); | ||
472 | emit OnRedraw(); | ||
473 | } | ||
474 | emit OnRedraw(); | ||
375 | } | 475 | } |
376 | } | 476 | } |
377 | 477 | ||
@@ -380,47 +480,36 @@ void QTReader::autoscroll() | |||
380 | timer->start(real_delay(), false); | 480 | timer->start(real_delay(), false); |
381 | } | 481 | } |
382 | 482 | ||
383 | void QTReader::setfont(QPainter* p) | 483 | void QTReader::setfont() |
384 | { | 484 | { |
385 | // qDebug("Fontsize = %u",fontsizes[m_textsize]); | 485 | // m_fontControl.Change |
386 | // qDebug("SetFont %x",p); | 486 | m_charWidth = (m_charpc*m_fontControl.currentsize())/100; |
387 | QFont font(m_fontname, fontsizes[m_textsize], (m_bBold) ? QFont::Bold : QFont::Normal ); | ||
388 | m_charWidth = (m_charpc*fontsizes[m_textsize])/100; | ||
389 | if (m_charWidth <= 0) m_charWidth = 1; | 487 | if (m_charWidth <= 0) m_charWidth = 1; |
390 | // font.setFixedPitch(m_bMonoSpaced); | 488 | m_ascent = m_fontControl.ascent(); |
391 | // qDebug("Raw name = %s", (const char*)font.rawName()); | 489 | m_descent = m_fontControl.descent(); |
392 | if (p != NULL) p->setFont( font ); | 490 | m_linespacing = m_fontControl.lineSpacing(); |
393 | if (m_fm == NULL) | ||
394 | { | ||
395 | m_fm = new QFontMetrics(font); | ||
396 | buffdoc.setfm(m_fm); | ||
397 | } | ||
398 | else | ||
399 | { | ||
400 | *m_fm = QFontMetrics(font); | ||
401 | } | ||
402 | m_ascent = m_fm->ascent(); | ||
403 | m_descent = m_fm->descent(); | ||
404 | m_linespacing = m_fm->lineSpacing(); | ||
405 | } | 491 | } |
406 | 492 | ||
407 | void QTReader::drawFonts( QPainter *p ) | 493 | void QTReader::drawFonts( QPainter *p ) |
408 | { | 494 | { |
409 | setfont(p); | 495 | setfont(); |
410 | if (m_lastwidth != width()) | 496 | if (m_lastwidth != width() || m_lastheight != height()) |
411 | { | 497 | { |
412 | m_lastwidth = width(); | 498 | m_lastwidth = width(); |
413 | locate(pagepos); | 499 | m_lastheight = height(); |
500 | locate(pagelocate()); | ||
414 | } | 501 | } |
415 | else | 502 | else |
416 | { | 503 | { |
504 | |||
505 | /* | ||
417 | int sl = screenlines(); | 506 | int sl = screenlines(); |
418 | if (sl < numlines) | 507 | if (sl < numlines) |
419 | { | 508 | { |
420 | // qDebug("df:<%u,%u>",sl,numlines); | 509 | // qDebug("df:<%u,%u>",sl,numlines); |
421 | 510 | ||
422 | size_t newpos = locnarray[sl]; | 511 | size_t newpos = locnarray[sl]; |
423 | CBuffer** nta = new CBuffer*[sl]; | 512 | CDrawBuffer** nta = new CDrawBuffer*[sl]; |
424 | size_t* nla = new size_t[sl]; | 513 | size_t* nla = new size_t[sl]; |
425 | for (int i = 0; i < sl; i++) | 514 | for (int i = 0; i < sl; i++) |
426 | { | 515 | { |
@@ -428,18 +517,17 @@ void QTReader::drawFonts( QPainter *p ) | |||
428 | nla[i] = locnarray[i]; | 517 | nla[i] = locnarray[i]; |
429 | } | 518 | } |
430 | for (int i = sl; i < numlines; i++) delete textarray[i]; | 519 | for (int i = sl; i < numlines; i++) delete textarray[i]; |
431 | delete [] textarray; | ||
432 | delete [] locnarray; | 520 | delete [] locnarray; |
521 | delete [] textarray; | ||
433 | textarray = nta; | 522 | textarray = nta; |
434 | locnarray = nla; | 523 | locnarray = nla; |
435 | numlines = sl; | 524 | numlines = sl; |
436 | jumpto(mylastpos = newpos); | 525 | jumpto(mylastpos = newpos); |
437 | // locate(pagepos); | ||
438 | } | 526 | } |
439 | if (sl > numlines) | 527 | if (sl > numlines) |
440 | { | 528 | { |
441 | // qDebug("df:<%u,%u>",sl,numlines); | 529 | // qDebug("df:<%u,%u>",sl,numlines); |
442 | CBuffer** nta = new CBuffer*[sl]; | 530 | CDrawBuffer** nta = new CDrawBuffer*[sl]; |
443 | size_t* nla = new size_t[sl]; | 531 | size_t* nla = new size_t[sl]; |
444 | for (int i = 0; i < numlines; i++) | 532 | for (int i = 0; i < numlines; i++) |
445 | { | 533 | { |
@@ -449,39 +537,33 @@ void QTReader::drawFonts( QPainter *p ) | |||
449 | if (locate() != mylastpos) jumpto(mylastpos); | 537 | if (locate() != mylastpos) jumpto(mylastpos); |
450 | for (int i = numlines; i < sl; i++) | 538 | for (int i = numlines; i < sl; i++) |
451 | { | 539 | { |
452 | nta[i] = new CBuffer; | 540 | nta[i] = new CDrawBuffer(&m_fontControl); |
453 | nla[i] = locate(); | 541 | nla[i] = locate(); |
454 | getline(nta[i]); | 542 | getline(nta[i]); |
455 | } | 543 | } |
456 | mylastpos = locate(); | 544 | mylastpos = locate(); |
457 | delete [] textarray; | ||
458 | delete [] locnarray; | 545 | delete [] locnarray; |
546 | delete [] textarray; | ||
459 | textarray = nta; | 547 | textarray = nta; |
460 | locnarray = nla; | 548 | locnarray = nla; |
461 | numlines = sl; | 549 | numlines = sl; |
462 | } | 550 | } |
463 | int ypos = (btight) ? 0 : m_ascent-m_linespacing; | 551 | */ |
464 | // int linespacing = (tight) ? m_ascent : m_ascent+m_descent; | 552 | if (numlines > 0) |
465 | for (int i = 0; i < numlines; i++) | ||
466 | { | 553 | { |
467 | drawText( *p, 0, ypos += m_linespacing, textarray[i]->data()); | 554 | int ypos = textarray[0]->ascent(); |
468 | } | 555 | textarray[0]->render( p, ypos, m_bMonoSpaced, m_charWidth, width()); |
469 | /* | 556 | for (int i = 1; i < numlines; i++) |
470 | |||
471 | |||
472 | |||
473 | int nlines = height()/(fontmetric.ascent()+fontmetric.descent()); | ||
474 | tchar buffer[1024]; | ||
475 | for (int i = 0; i < nlines; i++) | ||
476 | { | 557 | { |
477 | y += fontmetric.ascent(); | 558 | ypos += (textarray[i-1]->lineSpacing() + textarray[i]->lineSpacing())/2; |
478 | sprintf(buffer, "%d:%d:%s[%d]:Lines %d:%s", i+1, m_textfont, fonts[m_textfont], m_fs, nlines, (const tchar*)m_string); | 559 | textarray[i]->render( p, ypos, m_bMonoSpaced, m_charWidth, width()); |
479 | drawText( *p, 0, y, buffer ); | 560 | |
480 | y += fontmetric.descent(); | 561 | } |
562 | // mylastpos = locate(); | ||
481 | } | 563 | } |
482 | */ | ||
483 | } | 564 | } |
484 | m_scrolldy = 0; | 565 | m_scrolldy1 = m_scrolldy2 = 0; |
566 | emit OnRedraw(); | ||
485 | } | 567 | } |
486 | 568 | ||
487 | QString QTReader::firstword() | 569 | QString QTReader::firstword() |
@@ -516,44 +598,9 @@ QString QTReader::firstword() | |||
516 | // Construct the QTReader with buttons. | 598 | // Construct the QTReader with buttons. |
517 | // | 599 | // |
518 | 600 | ||
519 | void QTReader::ChangeFont(int tgt) | 601 | bool QTReader::ChangeFont(int tgt) |
520 | { | 602 | { |
521 | 603 | return m_fontControl.ChangeFont(m_fontname, tgt); | |
522 | QValueList<int>::Iterator it; | ||
523 | |||
524 | // QValueList<int> sizes = QFontDatabase::pointSizes(m_fontname, (m_bBold) ? QFont::Bold : QFont::Normal); | ||
525 | QFontDatabase fdb; | ||
526 | /* | ||
527 | QStringList styles = fdb.styles(m_fontname); | ||
528 | for ( QStringList::Iterator it = styles.begin(); it != styles.end(); ++it ) | ||
529 | { | ||
530 | printf( "%s \n", (*it).latin1() ); | ||
531 | } | ||
532 | */ | ||
533 | QValueList<int> sizes = fdb.pointSizes(m_fontname, (m_bBold) ? QString("Bold") : QString::null); | ||
534 | uint n = sizes.count(); | ||
535 | if (fontsizes != NULL) delete [] fontsizes; | ||
536 | fontsizes = new unsigned int[n+1]; | ||
537 | uint i = 0; | ||
538 | uint best = 0; | ||
539 | for (it = sizes.begin(); it != sizes.end(); it++) | ||
540 | { | ||
541 | fontsizes[i] = (*it)/10; | ||
542 | if (abs(tgt-fontsizes[i]) < abs(tgt-fontsizes[best])) | ||
543 | { | ||
544 | best = i; | ||
545 | } | ||
546 | i++; | ||
547 | } | ||
548 | m_textsize = best; | ||
549 | fontsizes[i] = 0; | ||
550 | setfont(NULL); | ||
551 | QFont font(m_fontname, fontsizes[m_textsize], (m_bBold) ? QFont::Bold : QFont::Normal ); | ||
552 | if (m_fm == NULL) | ||
553 | { | ||
554 | m_fm = new QFontMetrics(font); | ||
555 | buffdoc.setfm(m_fm); | ||
556 | } | ||
557 | } | 604 | } |
558 | 605 | ||
559 | void QTReader::init() | 606 | void QTReader::init() |
@@ -565,13 +612,15 @@ void QTReader::init() | |||
565 | // p.setBackgroundMode( Qt::OpaqueMode ); | 612 | // p.setBackgroundMode( Qt::OpaqueMode ); |
566 | buffdoc.setfilter(getfilter()); | 613 | buffdoc.setfilter(getfilter()); |
567 | ChangeFont(m_textsize); | 614 | ChangeFont(m_textsize); |
568 | // setFocusPolicy(QWidget::StrongFocus); | 615 | setFocusPolicy(QWidget::StrongFocus); |
569 | // resize( 240, 320 ); | 616 | // resize( 240, 320 ); |
570 | //setFocus(); | 617 | //setFocus(); |
571 | timer = new QTimer(this); | 618 | timer = new QTimer(this); |
572 | connect(timer, SIGNAL(timeout()), this, SLOT(doscroll())); | 619 | connect(timer, SIGNAL(timeout()), this, SLOT(doscroll())); |
573 | // QMessageBox::information(this, "init", m_lastfile, 1); | 620 | // QMessageBox::information(this, "init", m_lastfile, 1); |
574 | m_lastwidth = width(); | 621 | m_lastwidth = width(); |
622 | m_lastheight = height(); | ||
623 | setfont(); | ||
575 | if (!m_lastfile.isEmpty()) | 624 | if (!m_lastfile.isEmpty()) |
576 | { | 625 | { |
577 | m_string = DocLnk(m_lastfile).name(); | 626 | m_string = DocLnk(m_lastfile).name(); |
@@ -584,10 +633,6 @@ void QTReader::init() | |||
584 | // | 633 | // |
585 | QTReader::~QTReader() | 634 | QTReader::~QTReader() |
586 | { | 635 | { |
587 | if (fontsizes != NULL) delete [] fontsizes; | ||
588 | #ifndef QT_NO_PRINTER | ||
589 | // delete printer; | ||
590 | #endif | ||
591 | } | 636 | } |
592 | 637 | ||
593 | // | 638 | // |
@@ -672,76 +717,73 @@ unsigned int QTReader::screenlines() | |||
672 | return (height()-2)/(m_linespacing); | 717 | return (height()-2)/(m_linespacing); |
673 | }; | 718 | }; |
674 | 719 | ||
675 | bool QTReader::fillbuffer() { | 720 | bool QTReader::fillbuffer(int reuse, int ht) |
721 | { | ||
676 | if (buffdoc.empty()) return false; | 722 | if (buffdoc.empty()) return false; |
677 | //printf("Fillbuffer\n"); | 723 | m_scrolldy1 = m_scrolldy2 = 0; |
678 | m_scrolldy = 0; | ||
679 | int ch; | 724 | int ch; |
680 | bool ret = false; | 725 | bool ret = false; |
681 | int delta = screenlines(); | 726 | unsigned int oldpagepos = locnarray[reuse]; |
682 | // qDebug("fillbuffer:%u-%u",delta,numlines); | 727 | int ypos = ht; |
683 | if (delta != numlines) | 728 | numlines = reuse; |
729 | while (ypos < height()) | ||
684 | { | 730 | { |
685 | if (textarray != NULL) | 731 | if (textarray[numlines] == NULL) |
686 | { | 732 | { |
687 | for (int i = 0; i < numlines; i++) delete textarray[i]; | 733 | textarray[numlines] = new CDrawBuffer(&m_fontControl); |
688 | delete [] textarray; | ||
689 | delete [] locnarray; | ||
690 | } | 734 | } |
691 | numlines = delta; | 735 | locnarray[numlines] = locate(); |
692 | textarray = new CBuffer*[numlines]; | 736 | int ch = getline(textarray[numlines]); |
693 | locnarray = new size_t[numlines]; | 737 | ypos += textarray[numlines]->lineSpacing(); |
694 | for (int i = 0; i < numlines; i++) textarray[i] = new CBuffer; | 738 | numlines++; |
695 | } | ||
696 | // qDebug("fillbuffer:pagepos:%u",pagepos); | ||
697 | unsigned int oldpagepos = pagepos; | ||
698 | // if (textarray != NULL) | ||
699 | // pagepos = locnarray[0]; | ||
700 | // else | ||
701 | pagepos = locate(); | ||
702 | for (int i = 0; i < delta; i++) | ||
703 | { | ||
704 | locnarray[i] = locate(); | ||
705 | ch = getline(textarray[i]); | ||
706 | // if (ch == EOF) { | ||
707 | if (!ch) | 739 | if (!ch) |
708 | { | 740 | { |
709 | if (i == 0) | 741 | if (numlines - reuse == 1/* && locnarray[0] == buffdoc.locate()*/) |
710 | { | 742 | { |
711 | locate(oldpagepos); | 743 | locate(oldpagepos); |
712 | return false; | 744 | return false; |
713 | } | 745 | } |
714 | else | 746 | else |
715 | { | 747 | { |
716 | ret = true; | 748 | --numlines; |
717 | for (int j = i+1; j < delta; j++) | 749 | mylastpos = locate(); |
718 | { | 750 | return true; |
719 | locnarray[j] = locnarray[j-1]; | ||
720 | (*(textarray[j]))[0] = '\0'; | ||
721 | } | ||
722 | break; | ||
723 | } | 751 | } |
724 | } | 752 | } |
725 | if (ch == '\012') ret = true; | ||
726 | } | 753 | } |
754 | |||
755 | --numlines; | ||
727 | mylastpos = locate(); | 756 | mylastpos = locate(); |
728 | // qDebug("fillbuffer:lastpos:%u",mylastpos); | 757 | |
729 | return true; | 758 | return true; |
730 | } | 759 | } |
731 | 760 | ||
732 | 761 | ||
733 | void QTReader::dopagedn() | 762 | void QTReader::dopagedn() |
734 | { | 763 | { |
735 | if (m_overlap == 0) | 764 | int skip = 0, ypos = 0; |
765 | if (locate() != mylastpos) | ||
736 | { | 766 | { |
737 | if (locate() != mylastpos) jumpto(mylastpos); | 767 | //qDebug("Jumping to %u", mylastpos); |
768 | jumpto(mylastpos); | ||
738 | } | 769 | } |
739 | else | 770 | CDrawBuffer* reusebuffer = textarray[numlines]; |
771 | if (reusebuffer != NULL) | ||
772 | { | ||
773 | for (int i = 0; i <= m_overlap; i++) | ||
740 | { | 774 | { |
741 | if (m_overlap >= screenlines()) m_overlap = screenlines()/2; | 775 | int offset = numlines - m_overlap + i; |
742 | jumpto(locnarray[screenlines()-m_overlap]); | 776 | reusebuffer = textarray[offset]; |
777 | size_t reuselocn = locnarray[offset]; | ||
778 | textarray[offset] = textarray[i]; | ||
779 | textarray[i] = reusebuffer; | ||
780 | locnarray[offset] = locnarray[i]; | ||
781 | locnarray[i] = reuselocn; | ||
782 | ypos += textarray[i]->lineSpacing(); | ||
783 | skip++; | ||
743 | } | 784 | } |
744 | if (fillbuffer()) | 785 | } |
786 | if (fillbuffer(skip, ypos)) | ||
745 | { | 787 | { |
746 | update(); | 788 | update(); |
747 | } | 789 | } |
@@ -749,86 +791,82 @@ void QTReader::dopagedn() | |||
749 | 791 | ||
750 | void QTReader::dopageup() | 792 | void QTReader::dopageup() |
751 | { | 793 | { |
752 | CBuffer** buff = textarray; | 794 | CBufferFace<CDrawBuffer*> buff; |
753 | unsigned int *loc = new unsigned int[numlines]; | 795 | CBufferFace<size_t> loc; |
754 | int cbptr = 0; | 796 | unsigned int target = locnarray[(m_overlap < numlines) ? m_overlap : numlines/2]; |
755 | if (locate() != mylastpos) jumpto(mylastpos); | 797 | |
756 | if (m_overlap >= screenlines()) m_overlap = screenlines()/2; | 798 | size_t delta; |
757 | unsigned int target = locnarray[m_overlap]; | 799 | if (target < 2048) |
758 | if (buffdoc.hasrandomaccess()) | ||
759 | { | ||
760 | unsigned int delta = locate()-pagelocate(); | ||
761 | if (delta < 64) delta = 64; | ||
762 | if (delta % 2 != 0) delta++; | ||
763 | if (target % 2 != 0) target++; | ||
764 | do | ||
765 | { | ||
766 | delta <<= 1; | ||
767 | if (delta >= target) | ||
768 | { | 800 | { |
769 | delta = target; | 801 | delta = target; |
770 | jumpto(0); | 802 | jumpto(0); |
771 | for (int i = 0; i < numlines; i++) | ||
772 | { | ||
773 | loc[i] = locate(); | ||
774 | getline(buff[i]); | ||
775 | } | ||
776 | break; | ||
777 | } | 803 | } |
804 | else | ||
805 | { | ||
806 | delta = 2048; | ||
807 | |||
778 | jumpto(target-delta); | 808 | jumpto(target-delta); |
809 | |||
810 | buff[0] = new CDrawBuffer(&m_fontControl); | ||
811 | |||
779 | do | 812 | do |
780 | { | 813 | { |
781 | getline(buff[0]); | 814 | |
782 | #ifdef WS | 815 | if (!getline(buff[0])) break; |
783 | //printf("Trying:%s\n",buff[0]); | 816 | |
784 | #endif | ||
785 | if (locate() > target) continue; | 817 | if (locate() > target) continue; |
786 | } | 818 | } |
787 | while (!buffdoc.iseol()); | 819 | while (!buffdoc.iseol()); |
788 | for (int i = 0; i < numlines; i++) | ||
789 | { | ||
790 | loc[i] = locate(); | ||
791 | getline(buff[i]); | ||
792 | #ifdef WS | ||
793 | //printf("Filling:%s\n",buff[i]); | ||
794 | #endif | ||
795 | } | ||
796 | } | 820 | } |
797 | while (locate() >= target && delta < 4096); | 821 | int nbfl = 0; |
798 | #ifdef WS | 822 | |
799 | //printf("Delta:%u\n",delta); | 823 | bool ch = true; |
800 | #endif | 824 | int ypos = 0; |
825 | while (locate() < target) | ||
826 | { | ||
827 | if (buff[nbfl] == NULL) buff[nbfl] = new CDrawBuffer(&m_fontControl); | ||
828 | loc[nbfl] = locate(); | ||
829 | ch = getline(buff[nbfl]); | ||
830 | ypos += buff[nbfl]->lineSpacing(); | ||
831 | nbfl++; | ||
832 | if (!ch) break; | ||
801 | } | 833 | } |
802 | else | 834 | if (ypos < height()) |
803 | { | 835 | { |
804 | jumpto(0); | 836 | locate(0); |
805 | for (int i = 0; i < numlines; i++) | 837 | return; |
838 | } | ||
839 | if (ch) | ||
806 | { | 840 | { |
807 | loc[i] = locate(); | 841 | if (buff[nbfl] == NULL) buff[nbfl] = new CDrawBuffer(&m_fontControl); |
808 | getline(buff[i]); | 842 | loc[nbfl] = locate(); |
843 | int ch = getline(buff[nbfl]); | ||
844 | nbfl++; | ||
809 | } | 845 | } |
846 | ypos = 0; | ||
847 | numlines = 0; | ||
848 | while (ypos < height() && numlines <= nbfl-2) | ||
849 | { | ||
850 | ypos += buff[nbfl - numlines - 2]->lineSpacing(); | ||
851 | numlines++; | ||
810 | } | 852 | } |
811 | cbptr = 0; | 853 | --numlines; |
812 | while (locate() < target) | 854 | int offset = nbfl; |
855 | offset -= numlines+1; | ||
856 | for (int i = 0; i <= numlines; i++) | ||
813 | { | 857 | { |
814 | loc[cbptr] = locate(); | 858 | delete textarray[i]; |
815 | getline(buff[cbptr]); | 859 | textarray[i] = buff[offset+i]; |
816 | #ifdef WS | 860 | locnarray[i] = loc[offset + i]; |
817 | //printf("Adding:%s\n",buff[cbptr]->data()); | ||
818 | #endif | ||
819 | cbptr = (cbptr+1) % numlines; | ||
820 | } | 861 | } |
821 | pagepos = loc[cbptr]; | 862 | for (int i = 0; i < nbfl - numlines - 1; i++) |
822 | textarray = new CBuffer*[numlines]; | ||
823 | for (int i = 0; i < numlines; i++) | ||
824 | { | 863 | { |
825 | int j = (cbptr+i)%numlines; | 864 | delete buff[i]; |
826 | textarray[i] = buff[j]; | ||
827 | locnarray[i] = loc[j]; | ||
828 | } | 865 | } |
829 | delete [] buff; | 866 | |
830 | delete [] loc; | 867 | // --numlines; |
831 | mylastpos = locate(); | 868 | mylastpos = locate(); |
869 | |||
832 | update(); | 870 | update(); |
833 | } | 871 | } |
834 | 872 | ||
@@ -852,6 +890,7 @@ bool QTReader::load_file(const char *newfile, unsigned int _lcn) | |||
852 | locate(lcn); | 890 | locate(lcn); |
853 | // qDebug("buffdoc.locate done"); | 891 | // qDebug("buffdoc.locate done"); |
854 | } | 892 | } |
893 | setfilter(getfilter()); | ||
855 | update(); | 894 | update(); |
856 | // qDebug("Updated"); | 895 | // qDebug("Updated"); |
857 | return bRC; | 896 | return bRC; |
@@ -859,23 +898,33 @@ bool QTReader::load_file(const char *newfile, unsigned int _lcn) | |||
859 | 898 | ||
860 | void QTReader::lineDown() | 899 | void QTReader::lineDown() |
861 | { | 900 | { |
862 | pagepos = locnarray[1]; | 901 | int ypos = 0; |
863 | CBuffer* buff = textarray[0]; | 902 | int offset = numlines; |
864 | for (int i = 1; i < numlines; i++) | 903 | |
904 | for (int i = 0; i <= numlines; i++) | ||
865 | { | 905 | { |
866 | textarray[i-1] = textarray[i]; | 906 | if ((ypos += textarray[numlines-i]->lineSpacing()) > height()) |
867 | locnarray[i-1] = locnarray[i]; | 907 | { |
908 | offset = i-1; | ||
909 | break; | ||
910 | } | ||
868 | } | 911 | } |
869 | locnarray[numlines-1] = locate(); | 912 | offset = numlines - offset; |
870 | if (getline(buff)) | 913 | for (int i = offset; i <= numlines; i++) |
871 | { | 914 | { |
872 | textarray[numlines-1] = buff; | 915 | CDrawBuffer* buff = textarray[i-offset]; |
873 | mylastpos = locate(); | 916 | textarray[i-offset] = textarray[i]; |
917 | locnarray[i-offset] = locnarray[i]; | ||
918 | textarray[i] = buff; | ||
874 | } | 919 | } |
875 | else | 920 | numlines = numlines - offset + 1; |
921 | locnarray[numlines] = locate(); | ||
922 | if (textarray[numlines] == NULL) | ||
876 | { | 923 | { |
877 | textarray[numlines-1] = buff; | 924 | textarray[numlines] = new CDrawBuffer(&m_fontControl); |
878 | } | 925 | } |
926 | getline(textarray[numlines]); | ||
927 | mylastpos = locate(); | ||
879 | update(); | 928 | update(); |
880 | } | 929 | } |
881 | /* | 930 | /* |
@@ -963,12 +1012,13 @@ void QTReader::lineUp() | |||
963 | */ | 1012 | */ |
964 | void QTReader::lineUp() | 1013 | void QTReader::lineUp() |
965 | { | 1014 | { |
966 | CBuffer* buff = textarray[numlines-1]; | 1015 | CDrawBuffer* buff = textarray[numlines]; |
967 | unsigned int loc; | 1016 | unsigned int loc; |
968 | unsigned int end = locnarray[numlines-1]; | 1017 | unsigned int end = locnarray[numlines]; |
969 | int cbptr = 0; | 1018 | int cbptr = 0; |
970 | if (locate() != mylastpos) jumpto(mylastpos); | 1019 | if (locate() != mylastpos) jumpto(mylastpos); |
971 | unsigned int target = locnarray[0]; | 1020 | unsigned int target = locnarray[0]; |
1021 | if (target == 0) return; | ||
972 | if (buffdoc.hasrandomaccess()) | 1022 | if (buffdoc.hasrandomaccess()) |
973 | { | 1023 | { |
974 | unsigned int delta = locate()-pagelocate(); | 1024 | unsigned int delta = locate()-pagelocate(); |
@@ -980,11 +1030,8 @@ void QTReader::lineUp() | |||
980 | { | 1030 | { |
981 | delta = target; | 1031 | delta = target; |
982 | jumpto(0); | 1032 | jumpto(0); |
983 | for (int i = 0; i < numlines; i++) | ||
984 | { | ||
985 | loc = locate(); | 1033 | loc = locate(); |
986 | getline(buff); | 1034 | getline(buff); |
987 | } | ||
988 | break; | 1035 | break; |
989 | } | 1036 | } |
990 | jumpto(target-delta); | 1037 | jumpto(target-delta); |
@@ -1014,18 +1061,27 @@ void QTReader::lineUp() | |||
1014 | loc = locate(); | 1061 | loc = locate(); |
1015 | getline(buff); | 1062 | getline(buff); |
1016 | } | 1063 | } |
1017 | pagepos = loc; | 1064 | for (int i = numlines; i > 0; i--) |
1018 | for (int i = numlines-1; i > 0; i--) | ||
1019 | { | 1065 | { |
1020 | textarray[i] = textarray[i-1]; | 1066 | textarray[i] = textarray[i-1]; |
1021 | locnarray[i] = locnarray[i-1]; | 1067 | locnarray[i] = locnarray[i-1]; |
1022 | } | 1068 | } |
1023 | textarray[0] = buff; | 1069 | textarray[0] = buff; |
1024 | locnarray[0] = loc; | 1070 | locnarray[0] = loc; |
1025 | // delete [] buff; | 1071 | int start = numlines; |
1026 | // delete [] loc; | 1072 | int ypos = 0; |
1027 | mylastpos = locate(); | 1073 | for (int i = 0; i <= numlines; i++) |
1028 | jumpto(end); | 1074 | { |
1075 | ypos += textarray[i]->lineSpacing(); | ||
1076 | if (ypos > height()) | ||
1077 | { | ||
1078 | start = i; | ||
1079 | ypos -= textarray[i]->lineSpacing(); | ||
1080 | break; | ||
1081 | } | ||
1082 | } | ||
1083 | jumpto(locnarray[start]); | ||
1084 | fillbuffer(start, ypos); | ||
1029 | update(); | 1085 | update(); |
1030 | } | 1086 | } |
1031 | 1087 | ||
@@ -1033,3 +1089,21 @@ bool QTReader::empty() | |||
1033 | { | 1089 | { |
1034 | return buffdoc.empty(); | 1090 | return buffdoc.empty(); |
1035 | } | 1091 | } |
1092 | |||
1093 | MarkupType QTReader::PreferredMarkup() | ||
1094 | { | ||
1095 | MarkupType m = buffdoc.PreferredMarkup(); | ||
1096 | if (m == cTEXT) | ||
1097 | { | ||
1098 | int ext = m_lastfile.findRev('.'); | ||
1099 | if (ext >= 0) | ||
1100 | { | ||
1101 | QString ft = m_lastfile.right(m_lastfile.length()-ext-1).upper(); | ||
1102 | if (ft.left(3) == "HTM") | ||
1103 | { | ||
1104 | m = cHTML; | ||
1105 | } | ||
1106 | } | ||
1107 | } | ||
1108 | return m; | ||
1109 | } | ||
diff --git a/noncore/apps/opie-reader/QTReader.h b/noncore/apps/opie-reader/QTReader.h index 2efb988..78230b4 100644 --- a/noncore/apps/opie-reader/QTReader.h +++ b/noncore/apps/opie-reader/QTReader.h | |||
@@ -2,12 +2,17 @@ | |||
2 | #define __QTREADER_H | 2 | #define __QTREADER_H |
3 | 3 | ||
4 | #include <qwidget.h> | 4 | #include <qwidget.h> |
5 | #include <qpainter.h> | 5 | //#include <qpainter.h> |
6 | #include <qclipboard.h> | ||
7 | #include "CBuffer.h" | ||
8 | #include "my_list.h" | 6 | #include "my_list.h" |
9 | #include "BuffDoc.h" | 7 | #include "BuffDoc.h" |
10 | #include <qtimer.h> | 8 | #include "FontControl.h" |
9 | |||
10 | //#include <qtimer.h> | ||
11 | |||
12 | class CDrawBuffer; | ||
13 | //class CBuffer; | ||
14 | class QPainter; | ||
15 | class QTimer; | ||
11 | 16 | ||
12 | class QTReader : public QWidget | 17 | class QTReader : public QWidget |
13 | { | 18 | { |
@@ -20,13 +25,14 @@ class QTReader : public QWidget | |||
20 | bool m_autoScroll; | 25 | bool m_autoScroll; |
21 | void autoscroll(); | 26 | void autoscroll(); |
22 | QTimer* timer; | 27 | QTimer* timer; |
23 | int m_scrolldy, m_encd; | 28 | int m_scrolldy1, m_scrolldy2, m_encd; |
24 | void focusInEvent(QFocusEvent*); | 29 | void focusInEvent(QFocusEvent*); |
25 | void focusOutEvent(QFocusEvent*); | 30 | void focusOutEvent(QFocusEvent*); |
26 | void ChangeFont(int); | 31 | bool ChangeFont(int); |
27 | bool getline(CBuffer*); | 32 | bool getline(CDrawBuffer*); |
28 | int m_charWidth; | 33 | int m_charWidth; |
29 | int m_charpc; | 34 | int m_charpc; |
35 | FontControl m_fontControl; | ||
30 | public: | 36 | public: |
31 | QTReader( QWidget *parent=0, const char *name=0, WFlags f = 0); | 37 | QTReader( QWidget *parent=0, const char *name=0, WFlags f = 0); |
32 | // QTReader( const QString& filename, QWidget *parent=0, const tchar *name=0, WFlags f = 0); | 38 | // QTReader( const QString& filename, QWidget *parent=0, const tchar *name=0, WFlags f = 0); |
@@ -66,6 +72,37 @@ public: | |||
66 | } | 72 | } |
67 | }; | 73 | }; |
68 | */ | 74 | */ |
75 | void setpeanut(bool _b) | ||
76 | { | ||
77 | bpeanut = _b; | ||
78 | setfilter(getfilter()); | ||
79 | } | ||
80 | void setremap(bool _b) | ||
81 | { | ||
82 | bremap = _b; | ||
83 | setfilter(getfilter()); | ||
84 | } | ||
85 | void setmakebold(bool _b) | ||
86 | { | ||
87 | bmakebold = _b; | ||
88 | setfilter(getfilter()); | ||
89 | } | ||
90 | void setautofmt(bool _b) | ||
91 | { | ||
92 | bautofmt = _b; | ||
93 | if (bautofmt) | ||
94 | { | ||
95 | btextfmt = false; | ||
96 | bstriphtml = false;; | ||
97 | bpeanut = false; | ||
98 | } | ||
99 | setfilter(getfilter()); | ||
100 | } | ||
101 | void settextfmt(bool _b) | ||
102 | { | ||
103 | btextfmt = _b; | ||
104 | setfilter(getfilter()); | ||
105 | } | ||
69 | void setstripcr(bool _b) | 106 | void setstripcr(bool _b) |
70 | { | 107 | { |
71 | bstripcr = _b; | 108 | bstripcr = _b; |
@@ -113,14 +150,15 @@ public: | |||
113 | void setmono(bool _b) | 150 | void setmono(bool _b) |
114 | { | 151 | { |
115 | m_bMonoSpaced = _b; | 152 | m_bMonoSpaced = _b; |
116 | ChangeFont(fontsizes[m_textsize]); | 153 | ChangeFont(m_fontControl.currentsize()); |
117 | locate(pagepos); | 154 | locate(pagelocate()); |
118 | } | 155 | } |
119 | void setencoding(int _f) | 156 | void setencoding(int _f) |
120 | { | 157 | { |
121 | m_encd = _f; | 158 | m_encd = _f; |
122 | setfilter(getfilter()); | 159 | setfilter(getfilter()); |
123 | } | 160 | } |
161 | MarkupType PreferredMarkup(); | ||
124 | CEncoding* getencoding() | 162 | CEncoding* getencoding() |
125 | { | 163 | { |
126 | switch (m_encd) | 164 | switch (m_encd) |
@@ -144,12 +182,18 @@ public: | |||
144 | { | 182 | { |
145 | CFilterChain * filt = new CFilterChain(getencoding()); | 183 | CFilterChain * filt = new CFilterChain(getencoding()); |
146 | if (bstripcr) filt->addfilter(new stripcr); | 184 | if (bstripcr) filt->addfilter(new stripcr); |
147 | if (bstriphtml) filt->addfilter(new striphtml); | 185 | |
186 | if (btextfmt || (bautofmt && (PreferredMarkup() == cTEXT))) filt->addfilter(new textfmt); | ||
187 | if (bpeanut || (bautofmt && (PreferredMarkup() == cPML))) filt->addfilter(new PeanutFormatter); | ||
188 | if (bstriphtml || (bautofmt && (PreferredMarkup() == cHTML))) filt->addfilter(new striphtml); | ||
189 | |||
148 | if (bdehyphen) filt->addfilter(new dehyphen); | 190 | if (bdehyphen) filt->addfilter(new dehyphen); |
149 | if (bunindent) filt->addfilter(new unindent); | 191 | if (bunindent) filt->addfilter(new unindent); |
150 | if (brepara) filt->addfilter(new repara); | 192 | if (brepara) filt->addfilter(new repara); |
151 | if (bindenter) filt->addfilter(new indenter(bindenter)); | 193 | if (bindenter) filt->addfilter(new indenter(bindenter)); |
152 | if (bdblspce) filt->addfilter(new dblspce); | 194 | if (bdblspce) filt->addfilter(new dblspce); |
195 | if (bremap) filt->addfilter(new remap); | ||
196 | if (bmakebold) filt->addfilter(new embolden); | ||
153 | return filt; | 197 | return filt; |
154 | } | 198 | } |
155 | 199 | ||
@@ -162,26 +206,31 @@ private slots: | |||
162 | void keyPressEvent(QKeyEvent*); | 206 | void keyPressEvent(QKeyEvent*); |
163 | void drawFonts(QPainter*); | 207 | void drawFonts(QPainter*); |
164 | private: | 208 | private: |
209 | void setTwoTouch(bool _b); | ||
165 | void init(); | 210 | void init(); |
211 | void mousePressEvent( QMouseEvent* ); | ||
166 | void mouseReleaseEvent( QMouseEvent* ); | 212 | void mouseReleaseEvent( QMouseEvent* ); |
167 | // void mouseDoubleClickEvent( QMouseEvent* ); | 213 | // void mouseDoubleClickEvent( QMouseEvent* ); |
168 | QString m_string, m_fontname; | 214 | QString m_string, m_fontname; |
169 | void setfont(QPainter*); | 215 | void setfont(); |
170 | //myoutput stuff | 216 | //myoutput stuff |
171 | private: | 217 | private: |
218 | bool mouseUpOn; | ||
219 | bool getcurrentpos(int x, int y, size_t& start, size_t& offset, size_t& tgt); | ||
220 | bool m_twotouch, m_touchone; | ||
221 | size_t m_startpos, m_startoffset; | ||
172 | void dopageup(); | 222 | void dopageup(); |
173 | void lineDown(); | 223 | void lineDown(); |
174 | void lineUp(); | 224 | void lineUp(); |
175 | void dopagedn(); | 225 | void dopagedn(); |
176 | long real_delay(); | 226 | long real_delay(); |
177 | int m_textsize; | 227 | int m_textsize; |
178 | int m_lastwidth; | 228 | int m_lastwidth, m_lastheight; |
179 | CBuffer** textarray; | 229 | CBufferFace<CDrawBuffer*> textarray; |
180 | size_t* locnarray; | 230 | CBufferFace<size_t> locnarray; |
181 | unsigned int numlines; | 231 | unsigned int numlines; |
182 | bool bstripcr, bstriphtml, bdehyphen, bunindent, brepara, bdblspce, btight, m_bBold; | 232 | bool bstripcr, btextfmt, bstriphtml, bdehyphen, bunindent, brepara, bdblspce, btight, bmakebold, bremap, bpeanut, bautofmt; |
183 | bool m_bpagemode, m_bMonoSpaced; | 233 | bool m_bpagemode, m_bMonoSpaced; |
184 | QString m_targetapp, m_targetmsg; | ||
185 | unsigned char bindenter; | 234 | unsigned char bindenter; |
186 | QString m_lastfile; | 235 | QString m_lastfile; |
187 | size_t m_lastposn; | 236 | size_t m_lastposn; |
@@ -194,24 +243,30 @@ private slots: | |||
194 | bool locate(unsigned long n); | 243 | bool locate(unsigned long n); |
195 | void jumpto(unsigned long n) { buffdoc.locate(n); } | 244 | void jumpto(unsigned long n) { buffdoc.locate(n); } |
196 | unsigned long locate() { return buffdoc.locate(); } | 245 | unsigned long locate() { return buffdoc.locate(); } |
197 | unsigned long pagelocate() { return pagepos; } | 246 | unsigned long explocate() { return buffdoc.explocate(); } |
198 | unsigned long pagepos, mylastpos; | 247 | unsigned long pagelocate() { return locnarray[0]; } |
199 | void setfilter(CFilterChain *f) { buffdoc.setfilter(f); locate(pagepos); } | 248 | unsigned long mylastpos; |
249 | void setfilter(CFilterChain *f) { buffdoc.setfilter(f); locate(pagelocate()); } | ||
200 | void restore() { jumpto(mylastpos); } | 250 | void restore() { jumpto(mylastpos); } |
201 | void goUp(); | 251 | void goUp(); |
202 | void refresh() { locate(pagepos); } | 252 | void refresh() { locate(pagelocate()); } |
203 | void goDown(); | 253 | void goDown(); |
204 | // bool bold; | 254 | // bool bold; |
205 | int textsize() { return m_textsize; } | 255 | int textsize() { return m_textsize; } |
206 | void textsize(int ts) { m_textsize = ts; } | 256 | void textsize(int ts) { m_textsize = ts; } |
207 | bool fillbuffer(); | 257 | bool fillbuffer(int ru = 0, int ht = 0); |
208 | unsigned int screenlines(); | 258 | unsigned int screenlines(); |
209 | void sizes(unsigned long& fs, unsigned long& ts) { buffdoc.sizes(fs,ts); } | 259 | void sizes(unsigned long& fs, unsigned long& ts) { buffdoc.sizes(fs,ts); } |
210 | static const char *fonts[]; | 260 | static const char *fonts[]; |
211 | unsigned int *fontsizes; | 261 | // unsigned int *fontsizes; |
212 | int m_ascent, m_descent, m_linespacing; | 262 | int m_ascent, m_descent, m_linespacing; |
213 | QFontMetrics* m_fm; | 263 | QFontMetrics* m_fm; |
214 | QString firstword(); | 264 | QString firstword(); |
265 | |||
266 | signals: | ||
267 | void OnRedraw(); | ||
268 | void OnWordSelected(const QString&, size_t, const QString&); | ||
269 | void OnActionPressed(); | ||
215 | }; | 270 | }; |
216 | 271 | ||
217 | #endif | 272 | #endif |
diff --git a/noncore/apps/opie-reader/QTReaderApp.cpp b/noncore/apps/opie-reader/QTReaderApp.cpp index 68c80c1..0608b66 100644 --- a/noncore/apps/opie-reader/QTReaderApp.cpp +++ b/noncore/apps/opie-reader/QTReaderApp.cpp | |||
@@ -18,6 +18,7 @@ | |||
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include <qclipboard.h> | ||
21 | #include <qwidgetstack.h> | 22 | #include <qwidgetstack.h> |
22 | #include <qpe/qpemenubar.h> | 23 | #include <qpe/qpemenubar.h> |
23 | #include <qpe/qpetoolbar.h> | 24 | #include <qpe/qpetoolbar.h> |
@@ -38,10 +39,14 @@ | |||
38 | #include <qpe/config.h> | 39 | #include <qpe/config.h> |
39 | #include <qbuttongroup.h> | 40 | #include <qbuttongroup.h> |
40 | #include <qradiobutton.h> | 41 | #include <qradiobutton.h> |
42 | #include <qpe/qcopenvelope_qws.h> | ||
41 | 43 | ||
44 | #include "QTReader.h" | ||
45 | #include "Bkmks.h" | ||
42 | #include "cbkmkselector.h" | 46 | #include "cbkmkselector.h" |
43 | #include "infowin.h" | 47 | #include "infowin.h" |
44 | 48 | #include "CAnnoEdit.h" | |
49 | #include "QFloatBar.h" | ||
45 | //#include <qpe/fontdatabase.h> | 50 | //#include <qpe/fontdatabase.h> |
46 | 51 | ||
47 | #include <qpe/resource.h> | 52 | #include <qpe/resource.h> |
@@ -49,6 +54,7 @@ | |||
49 | 54 | ||
50 | #include "QTReaderApp.h" | 55 | #include "QTReaderApp.h" |
51 | #include "fileBrowser.h" | 56 | #include "fileBrowser.h" |
57 | #include "CDrawBuffer.h" | ||
52 | 58 | ||
53 | 59 | ||
54 | unsigned long QTReaderApp::m_uid = 0; | 60 | unsigned long QTReaderApp::m_uid = 0; |
@@ -84,7 +90,7 @@ void QTReaderApp::listBkmkFiles() | |||
84 | 90 | ||
85 | if (cnt > 0) | 91 | if (cnt > 0) |
86 | { | 92 | { |
87 | menu->hide(); | 93 | //tjw menu->hide(); |
88 | editBar->hide(); | 94 | editBar->hide(); |
89 | if (m_fontVisible) m_fontBar->hide(); | 95 | if (m_fontVisible) m_fontBar->hide(); |
90 | if (regVisible) regBar->hide(); | 96 | if (regVisible) regBar->hide(); |
@@ -97,7 +103,7 @@ void QTReaderApp::listBkmkFiles() | |||
97 | } | 103 | } |
98 | 104 | ||
99 | QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f ) | 105 | QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f ) |
100 | : QMainWindow( parent, name, f ), bFromDocView( FALSE ) | 106 | : QMainWindow( parent, name, f ), bFromDocView( FALSE ), m_dontSave(false) |
101 | { | 107 | { |
102 | // qDebug("Application directory = %s", (const tchar *)QPEApplication::documentDir()); | 108 | // qDebug("Application directory = %s", (const tchar *)QPEApplication::documentDir()); |
103 | // qDebug("Application directory = %s", (const tchar *)Global::applicationFileName("uqtreader","bkmks.xml")); | 109 | // qDebug("Application directory = %s", (const tchar *)Global::applicationFileName("uqtreader","bkmks.xml")); |
@@ -117,7 +123,7 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f ) | |||
117 | QPEToolBar *bar = new QPEToolBar( this ); | 123 | QPEToolBar *bar = new QPEToolBar( this ); |
118 | bar->setHorizontalStretchable( TRUE ); | 124 | bar->setHorizontalStretchable( TRUE ); |
119 | addToolBar(bar, "tool",QMainWindow::Top, true); | 125 | addToolBar(bar, "tool",QMainWindow::Top, true); |
120 | menu = bar; | 126 | //tjw menu = bar; |
121 | 127 | ||
122 | QPEMenuBar *mb = new QPEMenuBar( bar ); | 128 | QPEMenuBar *mb = new QPEMenuBar( bar ); |
123 | QPopupMenu *file = new QPopupMenu( this ); | 129 | QPopupMenu *file = new QPopupMenu( this ); |
@@ -144,6 +150,11 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f ) | |||
144 | pbar = new QProgressBar(this); | 150 | pbar = new QProgressBar(this); |
145 | pbar->hide(); | 151 | pbar->hide(); |
146 | 152 | ||
153 | m_annoWin = new CAnnoEdit(editorStack); | ||
154 | editorStack->addWidget(m_annoWin, get_unique_id()); | ||
155 | connect( m_annoWin, SIGNAL( finished(const QString&, const QString&) ), this, SLOT( addAnno(const QString&, const QString&) ) ); | ||
156 | connect( m_annoWin, SIGNAL( cancelled() ), this, SLOT( infoClose() ) ); | ||
157 | |||
147 | m_infoWin = new infowin(editorStack); | 158 | m_infoWin = new infowin(editorStack); |
148 | editorStack->addWidget(m_infoWin, get_unique_id()); | 159 | editorStack->addWidget(m_infoWin, get_unique_id()); |
149 | connect( m_infoWin, SIGNAL( Close() ), this, SLOT( infoClose() ) ); | 160 | connect( m_infoWin, SIGNAL( Close() ), this, SLOT( infoClose() ) ); |
@@ -166,18 +177,23 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f ) | |||
166 | */ | 177 | */ |
167 | 178 | ||
168 | reader = new QTReader( editorStack ); | 179 | reader = new QTReader( editorStack ); |
180 | |||
181 | ((QPEApplication*)qApp)->setStylusOperation(reader, QPEApplication::RightOnHold); | ||
182 | |||
169 | Config config( "uqtreader" ); | 183 | Config config( "uqtreader" ); |
170 | config.setGroup( "View" ); | 184 | config.setGroup( "View" ); |
171 | 185 | ||
172 | reader->bstripcr = config.readBoolEntry( "StripCr", true ); | 186 | reader->bstripcr = config.readBoolEntry( "StripCr", true ); |
187 | reader->btextfmt = config.readBoolEntry( "TextFmt", false ); | ||
188 | reader->bautofmt = config.readBoolEntry( "AutoFmt", true ); | ||
173 | reader->bstriphtml = config.readBoolEntry( "StripHtml", false ); | 189 | reader->bstriphtml = config.readBoolEntry( "StripHtml", false ); |
190 | reader->bpeanut = config.readBoolEntry( "Peanut", false ); | ||
174 | reader->bdehyphen = config.readBoolEntry( "Dehyphen", false ); | 191 | reader->bdehyphen = config.readBoolEntry( "Dehyphen", false ); |
175 | reader->bunindent = config.readBoolEntry( "Unindent", false ); | 192 | reader->bunindent = config.readBoolEntry( "Unindent", false ); |
176 | reader->brepara = config.readBoolEntry( "Repara", false ); | 193 | reader->brepara = config.readBoolEntry( "Repara", false ); |
177 | reader->bdblspce = config.readBoolEntry( "DoubleSpace", false ); | 194 | reader->bdblspce = config.readBoolEntry( "DoubleSpace", false ); |
178 | reader->bindenter = config.readNumEntry( "Indent", 0 ); | 195 | reader->bindenter = config.readNumEntry( "Indent", 0 ); |
179 | reader->m_textsize = config.readNumEntry( "FontSize", 12 ); | 196 | reader->m_textsize = config.readNumEntry( "FontSize", 12 ); |
180 | reader->m_bBold = config.readBoolEntry( "Bold", false ); | ||
181 | reader->m_delay = config.readNumEntry( "ScrollDelay", 5184); | 197 | reader->m_delay = config.readNumEntry( "ScrollDelay", 5184); |
182 | reader->m_lastfile = config.readEntry( "LastFile", QString::null ); | 198 | reader->m_lastfile = config.readEntry( "LastFile", QString::null ); |
183 | reader->m_lastposn = config.readNumEntry( "LastPosn", 0 ); | 199 | reader->m_lastposn = config.readNumEntry( "LastPosn", 0 ); |
@@ -187,9 +203,21 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f ) | |||
187 | reader->m_encd = config.readNumEntry( "Encoding", 0 ); | 203 | reader->m_encd = config.readNumEntry( "Encoding", 0 ); |
188 | reader->m_charpc = config.readNumEntry( "CharSpacing", 100 ); | 204 | reader->m_charpc = config.readNumEntry( "CharSpacing", 100 ); |
189 | reader->m_overlap = config.readNumEntry( "Overlap", 0 ); | 205 | reader->m_overlap = config.readNumEntry( "Overlap", 0 ); |
190 | reader->m_targetapp = config.readEntry( "TargetApp", QString::null ); | 206 | reader->bremap = config.readBoolEntry( "Remap", true ); |
191 | reader->m_targetmsg = config.readEntry( "TargetMsg", QString::null ); | 207 | reader->bmakebold = config.readBoolEntry( "MakeBold", false ); |
192 | reader->init(); | 208 | m_targetapp = config.readEntry( "TargetApp", QString::null ); |
209 | m_targetmsg = config.readEntry( "TargetMsg", QString::null ); | ||
210 | m_twoTouch = config.readBoolEntry( "TwoTouch", false); | ||
211 | m_doAnnotation = config.readBoolEntry( "Annotation", false); | ||
212 | m_doDictionary = config.readBoolEntry( "Dictionary", false); | ||
213 | m_doClipboard = config.readBoolEntry( "Clipboard", false); | ||
214 | m_spaceTarget = (ActionTypes)config.readNumEntry("SpaceTarget", cesAutoScroll); | ||
215 | setTwoTouch(m_twoTouch); | ||
216 | |||
217 | |||
218 | connect( reader, SIGNAL( OnRedraw() ), this, SLOT( OnRedraw() ) ); | ||
219 | connect( reader, SIGNAL( OnActionPressed() ), this, SLOT( OnActionPressed() ) ); | ||
220 | connect( reader, SIGNAL( OnWordSelected(const QString&, size_t, const QString&) ), this, SLOT( OnWordSelected(const QString&, size_t, const QString&) ) ); | ||
193 | editorStack->addWidget( reader, get_unique_id() ); | 221 | editorStack->addWidget( reader, get_unique_id() ); |
194 | 222 | ||
195 | QAction *a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); | 223 | QAction *a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); |
@@ -212,16 +240,22 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f ) | |||
212 | connect( a, SIGNAL( activated() ), this, SLOT( showinfo() ) ); | 240 | connect( a, SIGNAL( activated() ), this, SLOT( showinfo() ) ); |
213 | a->addTo( file ); | 241 | a->addTo( file ); |
214 | 242 | ||
215 | a = new QAction( tr( "Start Block" ), QString::null, 0, this, NULL); | 243 | QActionGroup* ag = new QActionGroup(this); |
216 | connect( a, SIGNAL( activated() ), this, SLOT( editMark() ) ); | 244 | QPopupMenu *spacemenu = new QPopupMenu(this); |
217 | file->insertSeparator(); | 245 | file->insertItem( tr( "On Action..." ), spacemenu ); |
218 | a->addTo( file ); | ||
219 | 246 | ||
220 | a = new QAction( tr( "Copy Block" ), QString::null, 0, this, NULL); | 247 | m_buttonAction[0] = new QAction( tr( "Open File" ), QString::null, 0, ag, NULL, true ); |
221 | connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) ); | 248 | |
222 | a->addTo( file ); | 249 | m_buttonAction[1] = new QAction( tr( "Autoscroll" ), QString::null, 0, ag, NULL, true ); |
250 | |||
251 | m_buttonAction[2] = new QAction( tr( "Mark" ), QString::null, 0, ag, NULL, true ); | ||
252 | |||
253 | ag->addTo(spacemenu); | ||
254 | |||
255 | connect(ag, SIGNAL( selected(QAction*) ), this, SLOT( buttonActionSelected(QAction*) ) ); | ||
223 | 256 | ||
224 | a = m_scrollButton = new QAction( tr( "Scroll" ), Resource::loadPixmap( "opie-reader/panel-arrow-down" ), QString::null, 0, this, 0, true ); | 257 | |
258 | a = m_scrollButton = new QAction( tr( "Scroll" ), Resource::loadPixmap( "panel-arrow-down" ), QString::null, 0, this, 0, true ); | ||
225 | // connect( a, SIGNAL( activated() ), this, SLOT( autoScroll() ) ); | 259 | // connect( a, SIGNAL( activated() ), this, SLOT( autoScroll() ) ); |
226 | a->setOn(false); | 260 | a->setOn(false); |
227 | connect( a, SIGNAL( toggled(bool) ), this, SLOT( autoScroll(bool) ) ); | 261 | connect( a, SIGNAL( toggled(bool) ), this, SLOT( autoScroll(bool) ) ); |
@@ -242,7 +276,7 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f ) | |||
242 | connect( a, SIGNAL( activated() ), this, SLOT( jump() ) ); | 276 | connect( a, SIGNAL( activated() ), this, SLOT( jump() ) ); |
243 | a->addTo( file ); | 277 | a->addTo( file ); |
244 | 278 | ||
245 | a = new QAction( tr( "Page/Line scroll" ), QString::null, 0, this, NULL, true ); | 279 | a = new QAction( tr( "Page/Line Scroll" ), QString::null, 0, this, NULL, true ); |
246 | connect( a, SIGNAL( toggled(bool) ), this, SLOT( pagemode(bool) ) ); | 280 | connect( a, SIGNAL( toggled(bool) ), this, SLOT( pagemode(bool) ) ); |
247 | a->setOn(reader->m_bpagemode); | 281 | a->setOn(reader->m_bpagemode); |
248 | a->addTo( file ); | 282 | a->addTo( file ); |
@@ -251,10 +285,37 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f ) | |||
251 | connect( a, SIGNAL( activated() ), this, SLOT( setoverlap() ) ); | 285 | connect( a, SIGNAL( activated() ), this, SLOT( setoverlap() ) ); |
252 | a->addTo( file ); | 286 | a->addTo( file ); |
253 | 287 | ||
288 | file->insertSeparator(); | ||
289 | |||
254 | a = new QAction( tr( "Set Dictionary" ), QString::null, 0, this, NULL); | 290 | a = new QAction( tr( "Set Dictionary" ), QString::null, 0, this, NULL); |
255 | connect( a, SIGNAL( activated() ), this, SLOT( settarget() ) ); | 291 | connect( a, SIGNAL( activated() ), this, SLOT( settarget() ) ); |
256 | a->addTo( file ); | 292 | a->addTo( file ); |
257 | 293 | ||
294 | a = new QAction( tr( "Two/One Touch" ), QString::null, 0, this, NULL, true ); | ||
295 | connect( a, SIGNAL( toggled(bool) ), this, SLOT( setTwoTouch(bool) ) ); | ||
296 | a->setOn(m_twoTouch); | ||
297 | a->addTo( file ); | ||
298 | |||
299 | ag = new QActionGroup(this); | ||
300 | ag->setExclusive(false); | ||
301 | QPopupMenu *encoding = new QPopupMenu(this); | ||
302 | file->insertItem( tr( "Target" ), encoding ); | ||
303 | |||
304 | a = new QAction( tr( "Annotation" ), QString::null, 0, ag, NULL, true ); | ||
305 | connect( a, SIGNAL( toggled(bool) ), this, SLOT( OnAnnotation(bool) ) ); | ||
306 | a->setOn(m_doAnnotation); | ||
307 | |||
308 | a = new QAction( tr( "Dictionary" ), QString::null, 0, ag, NULL, true ); | ||
309 | connect( a, SIGNAL( toggled(bool) ), this, SLOT( OnDictionary(bool) ) ); | ||
310 | a->setOn(m_doDictionary); | ||
311 | |||
312 | a = new QAction( tr( "Clipboard" ), QString::null, 0, ag, NULL, true ); | ||
313 | connect( a, SIGNAL( toggled(bool) ), this, SLOT( OnClipboard(bool) ) ); | ||
314 | a->setOn(m_doClipboard); | ||
315 | |||
316 | ag->addTo(encoding); | ||
317 | |||
318 | |||
258 | /* | 319 | /* |
259 | a = new QAction( tr( "Import" ), QString::null, 0, this, NULL ); | 320 | a = new QAction( tr( "Import" ), QString::null, 0, this, NULL ); |
260 | connect( a, SIGNAL( activated() ), this, SLOT( importFiles() ) ); | 321 | connect( a, SIGNAL( activated() ), this, SLOT( importFiles() ) ); |
@@ -276,56 +337,95 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f ) | |||
276 | a->addTo( edit ); | 337 | a->addTo( edit ); |
277 | */ | 338 | */ |
278 | 339 | ||
279 | a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 ); | 340 | // a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 ); |
341 | a = new QAction( tr( "Find..." ), QString::null, 0, this, NULL); | ||
280 | connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) ); | 342 | connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) ); |
281 | file->insertSeparator(); | 343 | file->insertSeparator(); |
282 | a->addTo( bar ); | 344 | // a->addTo( bar ); |
283 | a->addTo( file ); | 345 | a->addTo( file ); |
284 | 346 | ||
285 | 347 | ||
286 | a = new QAction( tr( "Strip CR" ), QString::null, 0, this, NULL, true ); | 348 | a = m_bkmkAvail = new QAction( tr( "Annotation" ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 ); |
287 | a->setOn(reader->bstripcr); | 349 | connect( a, SIGNAL( activated() ), this, SLOT( showAnnotation() ) ); |
288 | connect( a, SIGNAL( toggled(bool) ), this, SLOT( stripcr(bool) ) ); | 350 | a->addTo( bar ); |
289 | a->addTo( format ); | 351 | |
290 | // a->setOn(true); | 352 | m_bkmkAvail->setEnabled(false); |
353 | |||
354 | |||
355 | ag = new QActionGroup(this); | ||
356 | // ag->setExclusive(false); | ||
357 | encoding = new QPopupMenu(this); | ||
358 | format->insertItem( tr( "Markup" ), encoding ); | ||
359 | |||
360 | a = new QAction( tr( "Auto" ), QString::null, 0, ag, NULL, true ); | ||
361 | a->setOn(reader->bautofmt); | ||
362 | connect( a, SIGNAL( toggled(bool) ), this, SLOT( autofmt(bool) ) ); | ||
363 | |||
364 | a = new QAction( tr( "None" ), QString::null, 0, ag, NULL, true ); | ||
365 | a->setOn(!reader->bautofmt && !(reader->btextfmt || reader->bstriphtml || reader->bpeanut)); | ||
366 | // connect( a, SIGNAL( toggled(bool) ), this, SLOT( textfmt(bool) ) ); | ||
291 | 367 | ||
292 | a = new QAction( tr( "Strip HTML" ), QString::null, 0, this, NULL, true ); | 368 | a = new QAction( tr( "Text" ), QString::null, 0, ag, NULL, true ); |
369 | a->setOn(reader->btextfmt); | ||
370 | connect( a, SIGNAL( toggled(bool) ), this, SLOT( textfmt(bool) ) ); | ||
371 | |||
372 | a = new QAction( tr( "HTML" ), QString::null, 0, ag, NULL, true ); | ||
293 | a->setOn(reader->bstriphtml); | 373 | a->setOn(reader->bstriphtml); |
294 | connect( a, SIGNAL( toggled(bool) ), this, SLOT( striphtml(bool) ) ); | 374 | connect( a, SIGNAL( toggled(bool) ), this, SLOT( striphtml(bool) ) ); |
295 | a->addTo( format ); | ||
296 | 375 | ||
297 | a = new QAction( tr( "Dehyphen" ), QString::null, 0, this, NULL, true ); | 376 | a = new QAction( tr( "Peanut/PML" ), QString::null, 0, ag, NULL, true ); |
377 | a->setOn(reader->bpeanut); | ||
378 | connect( a, SIGNAL( toggled(bool) ), this, SLOT( peanut(bool) ) ); | ||
379 | |||
380 | ag->addTo(encoding); | ||
381 | |||
382 | |||
383 | |||
384 | ag = new QActionGroup(this); | ||
385 | ag->setExclusive(false); | ||
386 | encoding = new QPopupMenu(this); | ||
387 | format->insertItem( tr( "Layout" ), encoding ); | ||
388 | |||
389 | a = new QAction( tr( "Strip CR" ), QString::null, 0, ag, NULL, true ); | ||
390 | a->setOn(reader->bstripcr); | ||
391 | connect( a, SIGNAL( toggled(bool) ), this, SLOT( stripcr(bool) ) ); | ||
392 | |||
393 | a = new QAction( tr( "Dehyphen" ), QString::null, 0, ag, NULL, true ); | ||
298 | a->setOn(reader->bdehyphen); | 394 | a->setOn(reader->bdehyphen); |
299 | connect( a, SIGNAL( toggled(bool) ), this, SLOT( dehyphen(bool) ) ); | 395 | connect( a, SIGNAL( toggled(bool) ), this, SLOT( dehyphen(bool) ) ); |
300 | a->addTo( format ); | 396 | // a->addTo( format ); |
301 | 397 | ||
302 | a = new QAction( tr( "Unindent" ), QString::null, 0, this, NULL, true ); | 398 | a = new QAction( tr( "Unindent" ), QString::null, 0, ag, NULL, true ); |
303 | connect( a, SIGNAL( toggled(bool) ), this, SLOT( unindent(bool) ) ); | 399 | connect( a, SIGNAL( toggled(bool) ), this, SLOT( unindent(bool) ) ); |
304 | a->setOn(reader->bunindent); | 400 | a->setOn(reader->bunindent); |
305 | a->addTo( format ); | 401 | // a->addTo( format ); |
306 | 402 | ||
307 | a = new QAction( tr( "Re-paragraph" ), QString::null, 0, this, NULL, true ); | 403 | a = new QAction( tr( "Re-paragraph" ), QString::null, 0, ag, NULL, true ); |
308 | connect( a, SIGNAL( toggled(bool) ), this, SLOT( repara(bool) ) ); | 404 | connect( a, SIGNAL( toggled(bool) ), this, SLOT( repara(bool) ) ); |
309 | a->setOn(reader->brepara); | 405 | a->setOn(reader->brepara); |
310 | a->addTo( format ); | 406 | // a->addTo( format ); |
311 | 407 | ||
312 | a = new QAction( tr( "Double Space" ), QString::null, 0, this, NULL, true ); | 408 | a = new QAction( tr( "Double Space" ), QString::null, 0, ag, NULL, true ); |
313 | connect( a, SIGNAL( toggled(bool) ), this, SLOT( dblspce(bool) ) ); | 409 | connect( a, SIGNAL( toggled(bool) ), this, SLOT( dblspce(bool) ) ); |
314 | a->setOn(reader->bdblspce); | 410 | a->setOn(reader->bdblspce); |
315 | a->addTo( format ); | 411 | // a->addTo( format ); |
316 | 412 | ||
317 | a = new QAction( tr( "Indent+" ), QString::null, 0, this, NULL ); | 413 | a = new QAction( tr( "Indent+" ), QString::null, 0, ag, NULL ); |
318 | connect( a, SIGNAL( activated() ), this, SLOT( indentplus() ) ); | 414 | connect( a, SIGNAL( activated() ), this, SLOT( indentplus() ) ); |
319 | a->addTo( format ); | 415 | // a->addTo( format ); |
320 | 416 | ||
321 | a = new QAction( tr( "Indent-" ), QString::null, 0, this, NULL ); | 417 | a = new QAction( tr( "Indent-" ), QString::null, 0, ag, NULL ); |
322 | connect( a, SIGNAL( activated() ), this, SLOT( indentminus() ) ); | 418 | connect( a, SIGNAL( activated() ), this, SLOT( indentminus() ) ); |
323 | a->addTo( format ); | ||
324 | 419 | ||
325 | a = new QAction( tr( "Bold" ), QString::null, 0, this, NULL, true ); | 420 | a = new QAction( tr( "Remap" ), QString::null, 0, ag, NULL, true ); |
326 | a->setOn(reader->m_bBold); | 421 | connect( a, SIGNAL( toggled(bool) ), this, SLOT( remap(bool) ) ); |
327 | connect( a, SIGNAL( toggled(bool) ), this, SLOT( setbold(bool) ) ); | 422 | a->setOn(reader->bremap); |
328 | a->addTo( format ); | 423 | |
424 | a = new QAction( tr( "Embolden" ), QString::null, 0, ag, NULL, true ); | ||
425 | connect( a, SIGNAL( toggled(bool) ), this, SLOT( embolden(bool) ) ); | ||
426 | a->setOn(reader->bmakebold); | ||
427 | |||
428 | ag->addTo(encoding); | ||
329 | 429 | ||
330 | // a = new QAction( tr( "Zoom" ), QString::null, 0, this, NULL, true ); | 430 | // a = new QAction( tr( "Zoom" ), QString::null, 0, this, NULL, true ); |
331 | // a = new QAction( tr( "Zoom" ), Resource::loadPixmap( "mag" ), QString::null, 0, this, 0 ); | 431 | // a = new QAction( tr( "Zoom" ), Resource::loadPixmap( "mag" ), QString::null, 0, this, 0 ); |
@@ -346,11 +446,11 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f ) | |||
346 | connect( a, SIGNAL( activated() ), this, SLOT( setspacing() ) ); | 446 | connect( a, SIGNAL( activated() ), this, SLOT( setspacing() ) ); |
347 | a->addTo( format ); | 447 | a->addTo( format ); |
348 | 448 | ||
349 | QPopupMenu *encoding = new QPopupMenu(this); | 449 | encoding = new QPopupMenu(this); |
350 | format->insertSeparator(); | 450 | // format->insertSeparator(); |
351 | format->insertItem( tr( "Encoding" ), encoding ); | 451 | format->insertItem( tr( "Encoding" ), encoding ); |
352 | 452 | ||
353 | QActionGroup* ag = new QActionGroup(this); | 453 | ag = new QActionGroup(this); |
354 | 454 | ||
355 | m_EncodingAction[0] = new QAction( tr( "Ascii" ), QString::null, 0, ag, NULL, true ); | 455 | m_EncodingAction[0] = new QAction( tr( "Ascii" ), QString::null, 0, ag, NULL, true ); |
356 | 456 | ||
@@ -379,6 +479,10 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f ) | |||
379 | connect( a, SIGNAL( activated() ), this, SLOT( addbkmk() ) ); | 479 | connect( a, SIGNAL( activated() ), this, SLOT( addbkmk() ) ); |
380 | a->addTo( marks ); | 480 | a->addTo( marks ); |
381 | 481 | ||
482 | a = new QAction( tr( "Annotate" ), QString::null, 0, this, NULL); | ||
483 | connect( a, SIGNAL( activated() ), this, SLOT( addanno() ) ); | ||
484 | a->addTo( marks ); | ||
485 | |||
382 | a = new QAction( tr( "Goto" ), QString::null, 0, this, NULL, false ); | 486 | a = new QAction( tr( "Goto" ), QString::null, 0, this, NULL, false ); |
383 | connect( a, SIGNAL( activated() ), this, SLOT( do_gotomark() ) ); | 487 | connect( a, SIGNAL( activated() ), this, SLOT( do_gotomark() ) ); |
384 | a->addTo( marks ); | 488 | a->addTo( marks ); |
@@ -405,19 +509,32 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f ) | |||
405 | marks->insertSeparator(); | 509 | marks->insertSeparator(); |
406 | a->addTo( marks ); | 510 | a->addTo( marks ); |
407 | 511 | ||
512 | a = new QAction( tr( "Start Block" ), QString::null, 0, this, NULL); | ||
513 | connect( a, SIGNAL( activated() ), this, SLOT( editMark() ) ); | ||
514 | marks->insertSeparator(); | ||
515 | a->addTo( marks ); | ||
516 | |||
517 | a = new QAction( tr( "Copy Block" ), QString::null, 0, this, NULL); | ||
518 | connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) ); | ||
519 | a->addTo( marks ); | ||
520 | |||
521 | |||
408 | mb->insertItem( tr( "File" ), file ); | 522 | mb->insertItem( tr( "File" ), file ); |
409 | // mb->insertItem( tr( "Edit" ), edit ); | 523 | // mb->insertItem( tr( "Edit" ), edit ); |
410 | mb->insertItem( tr( "Format" ), format ); | 524 | mb->insertItem( tr( "Format" ), format ); |
411 | mb->insertItem( tr( "Marks" ), marks ); | 525 | mb->insertItem( tr( "Marks" ), marks ); |
412 | 526 | ||
413 | searchBar = new QToolBar( "Search", this, QMainWindow::Top, TRUE ); | 527 | searchBar = new QFloatBar( "Search", this, QMainWindow::Top, TRUE ); |
414 | 528 | ||
415 | searchBar->setHorizontalStretchable( TRUE ); | 529 | searchBar->setHorizontalStretchable( TRUE ); |
416 | 530 | ||
531 | connect(searchBar, SIGNAL( OnHide() ), this, SLOT( restoreFocus() )); | ||
532 | |||
417 | searchEdit = new QLineEdit( searchBar, "searchEdit" ); | 533 | searchEdit = new QLineEdit( searchBar, "searchEdit" ); |
418 | // QFont f("unifont", 16 /*, QFont::Bold*/); | 534 | // QFont f("unifont", 16 /*, QFont::Bold*/); |
419 | // searchEdit->setFont( f ); | 535 | // searchEdit->setFont( f ); |
420 | searchBar->setStretchableWidget( searchEdit ); | 536 | searchBar->setStretchableWidget( searchEdit ); |
537 | |||
421 | #ifdef __ISEARCH | 538 | #ifdef __ISEARCH |
422 | connect( searchEdit, SIGNAL( textChanged( const QString & ) ), | 539 | connect( searchEdit, SIGNAL( textChanged( const QString & ) ), |
423 | this, SLOT( search( const QString& ) ) ); | 540 | this, SLOT( search( const QString& ) ) ); |
@@ -435,7 +552,8 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f ) | |||
435 | 552 | ||
436 | searchBar->hide(); | 553 | searchBar->hide(); |
437 | 554 | ||
438 | regBar = new QToolBar( "Autogen", this, QMainWindow::Top, TRUE ); | 555 | regBar = new QFloatBar( "Autogen", this, QMainWindow::Top, TRUE ); |
556 | connect(regBar, SIGNAL( OnHide() ), this, SLOT( restoreFocus() )); | ||
439 | 557 | ||
440 | regBar->setHorizontalStretchable( TRUE ); | 558 | regBar->setHorizontalStretchable( TRUE ); |
441 | 559 | ||
@@ -465,8 +583,21 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f ) | |||
465 | m_fontBar->setStretchableWidget( m_fontSelector ); | 583 | m_fontBar->setStretchableWidget( m_fontSelector ); |
466 | { | 584 | { |
467 | FontDatabase f; | 585 | FontDatabase f; |
468 | m_fontSelector->insertStringList(f.families()); | 586 | QStringList flist = f.families(); |
587 | m_fontSelector->insertStringList(flist); | ||
588 | |||
589 | bool realfont = false; | ||
590 | for (QStringList::Iterator nm = flist.begin(); nm != flist.end(); nm++) | ||
591 | { | ||
592 | if (reader->m_fontname == *nm) | ||
593 | { | ||
594 | realfont = true; | ||
595 | break; | ||
596 | } | ||
597 | } | ||
598 | if (!realfont) reader->m_fontname = flist[0]; | ||
469 | } // delete the FontDatabase!!! | 599 | } // delete the FontDatabase!!! |
600 | |||
470 | connect( m_fontSelector, SIGNAL( activated(const QString& ) ), | 601 | connect( m_fontSelector, SIGNAL( activated(const QString& ) ), |
471 | this, SLOT( do_setfont(const QString&) ) ); | 602 | this, SLOT( do_setfont(const QString&) ) ); |
472 | 603 | ||
@@ -477,12 +608,14 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f ) | |||
477 | this, SLOT( msgHandler(const QCString&, const QByteArray&) ) ); | 608 | this, SLOT( msgHandler(const QCString&, const QByteArray&) ) ); |
478 | 609 | ||
479 | 610 | ||
611 | reader->init(); | ||
480 | if (!reader->m_lastfile.isEmpty()) | 612 | if (!reader->m_lastfile.isEmpty()) |
481 | { | 613 | { |
482 | openFile( reader->m_lastfile ); | 614 | openFile( reader->m_lastfile ); |
483 | doc = new DocLnk(reader->m_lastfile); | 615 | doc = new DocLnk(reader->m_lastfile); |
484 | } | 616 | } |
485 | m_EncodingAction[reader->m_encd]->setOn(true); | 617 | m_EncodingAction[reader->m_encd]->setOn(true); |
618 | m_buttonAction[m_spaceTarget]->setOn(true); | ||
486 | do_setfont(reader->m_fontname); | 619 | do_setfont(reader->m_fontname); |
487 | } | 620 | } |
488 | 621 | ||
@@ -498,12 +631,249 @@ void QTReaderApp::msgHandler(const QCString& _msg, const QByteArray& _data) | |||
498 | QString info; | 631 | QString info; |
499 | stream >> info; | 632 | stream >> info; |
500 | QMessageBox::information(this, "QTReader", info); | 633 | QMessageBox::information(this, "QTReader", info); |
501 | } else if ( msg == "warn(QString)" ) | 634 | } |
635 | else if ( msg == "warn(QString)" ) | ||
502 | { | 636 | { |
503 | QString info; | 637 | QString info; |
504 | stream >> info; | 638 | stream >> info; |
505 | QMessageBox::warning(this, "QTReader", info); | 639 | QMessageBox::warning(this, "QTReader", info); |
506 | } | 640 | } |
641 | |||
642 | |||
643 | else if ( msg == "exit()" ) | ||
644 | { | ||
645 | m_dontSave = true; | ||
646 | close(); | ||
647 | } | ||
648 | else if ( msg == "pageDown()" ) | ||
649 | { | ||
650 | reader->dopagedn(); | ||
651 | } | ||
652 | else if ( msg == "pageUp()" ) | ||
653 | { | ||
654 | reader->dopageup(); | ||
655 | } | ||
656 | else if ( msg == "lineDown()" ) | ||
657 | { | ||
658 | reader->lineDown(); | ||
659 | } | ||
660 | else if ( msg == "lineUp()" ) | ||
661 | { | ||
662 | reader->lineUp(); | ||
663 | } | ||
664 | else if ( msg == "showText()" ) | ||
665 | { | ||
666 | showEditTools(); | ||
667 | } | ||
668 | else if ( msg == "File/Open(QString)" ) | ||
669 | { | ||
670 | QString info; | ||
671 | stream >> info; | ||
672 | openFile( info ); | ||
673 | } | ||
674 | else if ( msg == "File/Info()" ) | ||
675 | { | ||
676 | showinfo(); | ||
677 | } | ||
678 | else if ( msg == "File/Start Block()" ) | ||
679 | { | ||
680 | editMark(); | ||
681 | } | ||
682 | else if ( msg == "File/Copy Block()" ) | ||
683 | { | ||
684 | editCopy(); | ||
685 | } | ||
686 | else if ( msg == "File/Scroll(int)" ) | ||
687 | { | ||
688 | int info; | ||
689 | stream >> info; | ||
690 | autoScroll(info); | ||
691 | } | ||
692 | else if ( msg == "File/Jump(int)" ) | ||
693 | { | ||
694 | int info; | ||
695 | stream >> info; | ||
696 | reader->locate(info); | ||
697 | } | ||
698 | else if ( msg == "File/Page/Line Scroll(int)" ) | ||
699 | { | ||
700 | int info; | ||
701 | stream >> info; | ||
702 | pagemode(info); | ||
703 | } | ||
704 | else if ( msg == "File/Set Overlap(int)" ) | ||
705 | { | ||
706 | int info; | ||
707 | stream >> info; | ||
708 | reader->m_overlap = info; | ||
709 | } | ||
710 | else if ( msg == "File/Set Dictionary(QString)" ) | ||
711 | { | ||
712 | QString info; | ||
713 | stream >> info; | ||
714 | do_settarget(info); | ||
715 | } | ||
716 | else if ( msg == "File/Two/One Touch(int)" ) | ||
717 | { | ||
718 | int info; | ||
719 | stream >> info; | ||
720 | setTwoTouch(info); | ||
721 | } | ||
722 | else if ( msg == "Target/Annotation(int)" ) | ||
723 | { | ||
724 | int info; | ||
725 | stream >> info; | ||
726 | OnAnnotation(info); | ||
727 | } | ||
728 | else if ( msg == "Target/Dictionary(int)" ) | ||
729 | { | ||
730 | int info; | ||
731 | stream >> info; | ||
732 | OnDictionary(info); | ||
733 | } | ||
734 | else if ( msg == "Target/Clipboard(int)" ) | ||
735 | { | ||
736 | int info; | ||
737 | stream >> info; | ||
738 | OnClipboard(info); | ||
739 | } | ||
740 | else if ( msg == "File/Find(QString)" ) | ||
741 | { | ||
742 | QString info; | ||
743 | stream >> info; | ||
744 | QRegExp arg(info); | ||
745 | size_t pos = reader->pagelocate(); | ||
746 | size_t start = pos; | ||
747 | CDrawBuffer test(&(reader->m_fontControl)); | ||
748 | reader->buffdoc.getline(&test,reader->width()); | ||
749 | while (arg.match(toQString(test.data())) == -1) | ||
750 | { | ||
751 | pos = reader->locate(); | ||
752 | if (!reader->buffdoc.getline(&test,reader->width())) | ||
753 | { | ||
754 | QMessageBox::information(this, "QTReader", QString("Can't find\n")+info); | ||
755 | pos = start; | ||
756 | break; | ||
757 | } | ||
758 | } | ||
759 | reader->locate(pos); | ||
760 | } | ||
761 | else if ( msg == "Layout/Strip CR(int)" ) | ||
762 | { | ||
763 | int info; | ||
764 | stream >> info; | ||
765 | stripcr(info); | ||
766 | } | ||
767 | else if ( msg == "Markup/Auto(int)" ) | ||
768 | { | ||
769 | int info; | ||
770 | stream >> info; | ||
771 | autofmt(info); | ||
772 | } | ||
773 | else if ( msg == "Markup/Text(int)" ) | ||
774 | { | ||
775 | int info; | ||
776 | stream >> info; | ||
777 | textfmt(info); | ||
778 | } | ||
779 | else if ( msg == "Markup/HTML(int)" ) | ||
780 | { | ||
781 | int info; | ||
782 | stream >> info; | ||
783 | striphtml(info); | ||
784 | } | ||
785 | else if ( msg == "Markup/Peanut(int)" ) | ||
786 | { | ||
787 | int info; | ||
788 | stream >> info; | ||
789 | peanut(info); | ||
790 | } | ||
791 | else if ( msg == "Layout/Dehyphen(int)" ) | ||
792 | { | ||
793 | int info; | ||
794 | stream >> info; | ||
795 | dehyphen(info); | ||
796 | } | ||
797 | else if ( msg == "Layout/Unindent(int)" ) | ||
798 | { | ||
799 | int info; | ||
800 | stream >> info; | ||
801 | unindent(info); | ||
802 | } | ||
803 | else if ( msg == "Layout/Re-paragraph(int)" ) | ||
804 | { | ||
805 | int info; | ||
806 | stream >> info; | ||
807 | repara(info); | ||
808 | } | ||
809 | else if ( msg == "Layout/Double Space(int)" ) | ||
810 | { | ||
811 | int info; | ||
812 | stream >> info; | ||
813 | dblspce(info); | ||
814 | } | ||
815 | else if ( msg == "Layout/Indent(int)" ) | ||
816 | { | ||
817 | int info; | ||
818 | stream >> info; | ||
819 | reader->bindenter = info; | ||
820 | reader->setfilter(reader->getfilter()); | ||
821 | } | ||
822 | else if ( msg == "Layout/Remap(int)" ) | ||
823 | { | ||
824 | int info; | ||
825 | stream >> info; | ||
826 | remap(info); | ||
827 | } | ||
828 | else if ( msg == "Layout/Embolden(int)" ) | ||
829 | { | ||
830 | int info; | ||
831 | stream >> info; | ||
832 | embolden(info); | ||
833 | } | ||
834 | else if ( msg == "Format/Ideogram/Word(int)" ) | ||
835 | { | ||
836 | int info; | ||
837 | stream >> info; | ||
838 | monospace(info); | ||
839 | } | ||
840 | else if ( msg == "Format/Set width(int)" ) | ||
841 | { | ||
842 | int info; | ||
843 | stream >> info; | ||
844 | reader->m_charpc = info; | ||
845 | reader->setfont(); | ||
846 | reader->refresh(); | ||
847 | } | ||
848 | else if ( msg == "Format/Encoding(QString)" ) | ||
849 | { | ||
850 | QString info; | ||
851 | stream >> info; | ||
852 | reader->setencoding(EncNameToInt(info)); | ||
853 | } | ||
854 | else if ( msg == "Format/Set Font(QString,int)" ) | ||
855 | { | ||
856 | QString fontname; | ||
857 | int size; | ||
858 | stream >> fontname; | ||
859 | stream >> size; | ||
860 | setfontHelper(fontname, size); | ||
861 | } | ||
862 | else if ( msg == "Marks/Autogen(QString)" ) | ||
863 | { | ||
864 | QString info; | ||
865 | stream >> info; | ||
866 | do_autogen(info); | ||
867 | } | ||
868 | } | ||
869 | |||
870 | ActionTypes QTReaderApp::ActNameToInt(const QString& _enc) | ||
871 | { | ||
872 | for (int i = 0; i < MAX_ACTIONS; i++) | ||
873 | { | ||
874 | if (m_buttonAction[i]->text() == _enc) return (ActionTypes)i; | ||
875 | } | ||
876 | return cesAutoScroll; | ||
507 | } | 877 | } |
508 | 878 | ||
509 | int QTReaderApp::EncNameToInt(const QString& _enc) | 879 | int QTReaderApp::EncNameToInt(const QString& _enc) |
@@ -527,6 +897,12 @@ void QTReaderApp::encodingSelected(QAction* _a) | |||
527 | reader->setencoding(EncNameToInt(_a->text())); | 897 | reader->setencoding(EncNameToInt(_a->text())); |
528 | } | 898 | } |
529 | 899 | ||
900 | void QTReaderApp::buttonActionSelected(QAction* _a) | ||
901 | { | ||
902 | // qDebug("es:%x : %s (%u)", _a, (const char *)(_a->text()), ActNameToInt(_a->text())); | ||
903 | m_spaceTarget = ActNameToInt(_a->text()); | ||
904 | } | ||
905 | |||
530 | QTReaderApp::~QTReaderApp() | 906 | QTReaderApp::~QTReaderApp() |
531 | { | 907 | { |
532 | } | 908 | } |
@@ -589,6 +965,7 @@ void QTReaderApp::fileOpen() | |||
589 | if (!fn.isEmpty() && QFileInfo(fn).isFile()) openFile(fn); | 965 | if (!fn.isEmpty() && QFileInfo(fn).isFile()) openFile(fn); |
590 | } | 966 | } |
591 | delete fb; | 967 | delete fb; |
968 | reader->setFocus(); | ||
592 | } | 969 | } |
593 | 970 | ||
594 | void QTReaderApp::showinfo() | 971 | void QTReaderApp::showinfo() |
@@ -612,6 +989,107 @@ void QTReaderApp::showinfo() | |||
612 | } | 989 | } |
613 | } | 990 | } |
614 | 991 | ||
992 | void QTReaderApp::addAnno(const QString& name, const QString& text, size_t posn) | ||
993 | { | ||
994 | if (pBkmklist == NULL) pBkmklist = new CList<Bkmk>; | ||
995 | #ifdef _UNICODE | ||
996 | CBuffer buff(name.length()+1); | ||
997 | int i; | ||
998 | for (i = 0; i < name.length(); i++) | ||
999 | { | ||
1000 | buff[i] = name[i].unicode(); | ||
1001 | } | ||
1002 | buff[i] = 0; | ||
1003 | CBuffer buff2(text.length()+1); | ||
1004 | for (i = 0; i < text.length(); i++) | ||
1005 | { | ||
1006 | buff2[i] = text[i].unicode(); | ||
1007 | } | ||
1008 | buff2[i] = 0; | ||
1009 | pBkmklist->push_front(Bkmk(buff.data(), buff2.data(), posn)); | ||
1010 | #else | ||
1011 | pBkmklist->push_front(Bkmk((const tchar*)text,posn)); | ||
1012 | #endif | ||
1013 | m_fBkmksChanged = true; | ||
1014 | pBkmklist->sort(); | ||
1015 | } | ||
1016 | |||
1017 | void QTReaderApp::addAnno(const QString& name, const QString& text) | ||
1018 | { | ||
1019 | if (m_annoIsEditing) | ||
1020 | { | ||
1021 | if (name.isEmpty()) | ||
1022 | { | ||
1023 | QMessageBox::information(this, "QTReader", "Need a name for the bookmark\nPlease try again", 1); | ||
1024 | } | ||
1025 | else | ||
1026 | { | ||
1027 | addAnno(name, text, m_annoWin->getPosn()); | ||
1028 | } | ||
1029 | showEditTools(); | ||
1030 | } | ||
1031 | else | ||
1032 | { | ||
1033 | if (m_annoWin->edited()) | ||
1034 | { | ||
1035 | CBuffer buff(text.length()+1); | ||
1036 | int i; | ||
1037 | for (i = 0; i < text.length(); i++) | ||
1038 | { | ||
1039 | buff[i] = text[i].unicode(); | ||
1040 | } | ||
1041 | buff[i] = 0; | ||
1042 | m_fBkmksChanged = true; | ||
1043 | m_anno->setAnno(buff.data()); | ||
1044 | } | ||
1045 | bool found = findNextBookmark(m_anno->value()+1); | ||
1046 | if (found) | ||
1047 | { | ||
1048 | m_annoWin->setName(toQString(m_anno->name())); | ||
1049 | m_annoWin->setAnno(toQString(m_anno->anno())); | ||
1050 | } | ||
1051 | else | ||
1052 | { | ||
1053 | showEditTools(); | ||
1054 | } | ||
1055 | } | ||
1056 | } | ||
1057 | |||
1058 | bool QTReaderApp::findNextBookmark(size_t start) | ||
1059 | { | ||
1060 | bool found = false; | ||
1061 | for (CList<Bkmk>::iterator iter = pBkmklist->begin(); iter != pBkmklist->end(); iter++) | ||
1062 | { | ||
1063 | if (iter->value() >= start) | ||
1064 | { | ||
1065 | if (iter->value() < reader->locate()) | ||
1066 | { | ||
1067 | found = true; | ||
1068 | m_anno = iter.pContent(); | ||
1069 | } | ||
1070 | break; | ||
1071 | } | ||
1072 | } | ||
1073 | return found; | ||
1074 | } | ||
1075 | |||
1076 | void QTReaderApp::addanno() | ||
1077 | { | ||
1078 | if (reader->empty()) | ||
1079 | { | ||
1080 | QMessageBox::information(this, "QTReader", "No file loaded", 1); | ||
1081 | } | ||
1082 | else | ||
1083 | { | ||
1084 | m_annoWin->setName(""); | ||
1085 | m_annoWin->setAnno(""); | ||
1086 | m_annoWin->setPosn(reader->pagelocate()); | ||
1087 | m_annoIsEditing = true; | ||
1088 | editorStack->raiseWidget( m_annoWin ); | ||
1089 | m_annoWin->setFocus(); | ||
1090 | } | ||
1091 | } | ||
1092 | |||
615 | void QTReaderApp::infoClose() | 1093 | void QTReaderApp::infoClose() |
616 | { | 1094 | { |
617 | showEditTools(); | 1095 | showEditTools(); |
@@ -644,19 +1122,12 @@ void QTReaderApp::editCopy() | |||
644 | unsigned long currentpos = reader->pagelocate(); | 1122 | unsigned long currentpos = reader->pagelocate(); |
645 | unsigned long endpos = reader->locate(); | 1123 | unsigned long endpos = reader->locate(); |
646 | reader->jumpto(m_savedpos); | 1124 | reader->jumpto(m_savedpos); |
647 | while (reader->locate() < endpos && (ch = reader->getch()) != UEOF) | 1125 | while (reader->explocate() < endpos && (ch = reader->getch()) != UEOF) |
648 | { | 1126 | { |
649 | text += ch; | 1127 | text += ch; |
650 | } | 1128 | } |
651 | cb->setText(text); | 1129 | cb->setText(text); |
652 | // text = cb->text(); | ||
653 | // if (text) | ||
654 | // qDebug("The clipboard contains: %s", (const tchar*)text); | ||
655 | reader->locate(currentpos); | 1130 | reader->locate(currentpos); |
656 | #ifndef QT_NO_CLIPBOARD | ||
657 | // TBD(); | ||
658 | // reader->copy(); | ||
659 | #endif | ||
660 | } | 1131 | } |
661 | 1132 | ||
662 | void QTReaderApp::pageup() | 1133 | void QTReaderApp::pageup() |
@@ -673,6 +1144,26 @@ void QTReaderApp::stripcr(bool _b) | |||
673 | { | 1144 | { |
674 | reader->setstripcr(_b); | 1145 | reader->setstripcr(_b); |
675 | } | 1146 | } |
1147 | void QTReaderApp::remap(bool _b) | ||
1148 | { | ||
1149 | reader->setremap(_b); | ||
1150 | } | ||
1151 | void QTReaderApp::peanut(bool _b) | ||
1152 | { | ||
1153 | reader->setpeanut(_b); | ||
1154 | } | ||
1155 | void QTReaderApp::embolden(bool _b) | ||
1156 | { | ||
1157 | reader->setmakebold(_b); | ||
1158 | } | ||
1159 | void QTReaderApp::autofmt(bool _b) | ||
1160 | { | ||
1161 | reader->setautofmt(_b); | ||
1162 | } | ||
1163 | void QTReaderApp::textfmt(bool _b) | ||
1164 | { | ||
1165 | reader->settextfmt(_b); | ||
1166 | } | ||
676 | void QTReaderApp::striphtml(bool _b) | 1167 | void QTReaderApp::striphtml(bool _b) |
677 | { | 1168 | { |
678 | reader->setstriphtml(_b); | 1169 | reader->setstriphtml(_b); |
@@ -689,12 +1180,6 @@ void QTReaderApp::repara(bool _b) | |||
689 | { | 1180 | { |
690 | reader->setrepara(_b); | 1181 | reader->setrepara(_b); |
691 | } | 1182 | } |
692 | void QTReaderApp::setbold(bool _b) | ||
693 | { | ||
694 | reader->m_bBold = _b; | ||
695 | reader->ChangeFont(reader->fontsizes[reader->m_textsize]); | ||
696 | reader->refresh(); | ||
697 | } | ||
698 | void QTReaderApp::dblspce(bool _b) | 1183 | void QTReaderApp::dblspce(bool _b) |
699 | { | 1184 | { |
700 | reader->setdblspce(_b); | 1185 | reader->setdblspce(_b); |
@@ -730,9 +1215,9 @@ void QTReaderApp::setoverlap() | |||
730 | void QTReaderApp::settarget() | 1215 | void QTReaderApp::settarget() |
731 | { | 1216 | { |
732 | m_nRegAction = cSetTarget; | 1217 | m_nRegAction = cSetTarget; |
733 | QString text = ((reader->m_targetapp.isEmpty()) ? QString("") : reader->m_targetapp) | 1218 | QString text = ((m_targetapp.isEmpty()) ? QString("") : m_targetapp) |
734 | + "/" | 1219 | + "/" |
735 | + ((reader->m_targetmsg.isEmpty()) ? QString("") : reader->m_targetmsg); | 1220 | + ((m_targetmsg.isEmpty()) ? QString("") : m_targetmsg); |
736 | regEdit->setText(text); | 1221 | regEdit->setText(text); |
737 | do_regedit(); | 1222 | do_regedit(); |
738 | } | 1223 | } |
@@ -756,6 +1241,8 @@ void QTReaderApp::do_mono(const QString& lcn) | |||
756 | if (ok) | 1241 | if (ok) |
757 | { | 1242 | { |
758 | reader->m_charpc = ulcn; | 1243 | reader->m_charpc = ulcn; |
1244 | reader->setfont(); | ||
1245 | reader->refresh(); | ||
759 | // reader->setmono(true); | 1246 | // reader->setmono(true); |
760 | } | 1247 | } |
761 | else | 1248 | else |
@@ -793,7 +1280,7 @@ void QTReaderApp::findNext() | |||
793 | #else | 1280 | #else |
794 | QRegExp arg = searchEdit->text(); | 1281 | QRegExp arg = searchEdit->text(); |
795 | #endif | 1282 | #endif |
796 | CBuffer test; | 1283 | CDrawBuffer test(&(reader->m_fontControl)); |
797 | size_t start = reader->pagelocate(); | 1284 | size_t start = reader->pagelocate(); |
798 | reader->jumpto(start); | 1285 | reader->jumpto(start); |
799 | reader->buffdoc.getline(&test,reader->width()); | 1286 | reader->buffdoc.getline(&test,reader->width()); |
@@ -825,13 +1312,13 @@ void QTReaderApp::regClose() | |||
825 | } | 1312 | } |
826 | 1313 | ||
827 | #ifdef __ISEARCH | 1314 | #ifdef __ISEARCH |
828 | bool QTReaderApp::dosearch(size_t start, CBuffer& test, const QString& arg) | 1315 | bool QTReaderApp::dosearch(size_t start, CDrawBuffer& test, const QString& arg) |
829 | #else | 1316 | #else |
830 | bool QTReaderApp::dosearch(size_t start, CBuffer& test, const QRegExp& arg) | 1317 | bool QTReaderApp::dosearch(size_t start, CDrawBuffer& test, const QRegExp& arg) |
831 | #endif | 1318 | #endif |
832 | { | 1319 | { |
833 | bool ret = true; | 1320 | bool ret = true; |
834 | size_t pos = start; | 1321 | size_t pos = reader->locate(); |
835 | reader->buffdoc.getline(&test,reader->width()); | 1322 | reader->buffdoc.getline(&test,reader->width()); |
836 | #ifdef __ISEARCH | 1323 | #ifdef __ISEARCH |
837 | while (strstr(test.data(),(const tchar*)arg) == NULL) | 1324 | while (strstr(test.data(),(const tchar*)arg) == NULL) |
@@ -895,11 +1382,7 @@ void QTReaderApp::search(const QString & arg) | |||
895 | #else | 1382 | #else |
896 | void QTReaderApp::search() | 1383 | void QTReaderApp::search() |
897 | { | 1384 | { |
898 | QRegExp arg = searchEdit->text(); | 1385 | findNext(); |
899 | CBuffer test; | ||
900 | size_t start = reader->pagelocate(); | ||
901 | // reader->jumpto(start); | ||
902 | dosearch(start, test, arg); | ||
903 | } | 1386 | } |
904 | #endif | 1387 | #endif |
905 | 1388 | ||
@@ -945,7 +1428,7 @@ void QTReaderApp::showEditTools() | |||
945 | if ( !doc ) | 1428 | if ( !doc ) |
946 | close(); | 1429 | close(); |
947 | // fileSelector->hide(); | 1430 | // fileSelector->hide(); |
948 | menu->show(); | 1431 | //tjw menu->show(); |
949 | editBar->show(); | 1432 | editBar->show(); |
950 | if ( searchVisible ) | 1433 | if ( searchVisible ) |
951 | searchBar->show(); | 1434 | searchBar->show(); |
@@ -1003,12 +1486,12 @@ void QTReaderApp::clear() | |||
1003 | void QTReaderApp::updateCaption() | 1486 | void QTReaderApp::updateCaption() |
1004 | { | 1487 | { |
1005 | if ( !doc ) | 1488 | if ( !doc ) |
1006 | setCaption( tr("Opie Reader") ); | 1489 | setCaption( tr("QTReader") ); |
1007 | else { | 1490 | else { |
1008 | QString s = doc->name(); | 1491 | QString s = doc->name(); |
1009 | if ( s.isEmpty() ) | 1492 | if ( s.isEmpty() ) |
1010 | s = tr( "Unnamed" ); | 1493 | s = tr( "Unnamed" ); |
1011 | setCaption( s + " - " + tr("Opie Reader") ); | 1494 | setCaption( s + " - " + tr("QTReader") ); |
1012 | } | 1495 | } |
1013 | } | 1496 | } |
1014 | 1497 | ||
@@ -1022,6 +1505,12 @@ void QTReaderApp::setDocument(const QString& fileref) | |||
1022 | 1505 | ||
1023 | void QTReaderApp::closeEvent( QCloseEvent *e ) | 1506 | void QTReaderApp::closeEvent( QCloseEvent *e ) |
1024 | { | 1507 | { |
1508 | if (m_dontSave) | ||
1509 | { | ||
1510 | e->accept(); | ||
1511 | } | ||
1512 | else | ||
1513 | { | ||
1025 | if (editorStack->visibleWidget() == reader) | 1514 | if (editorStack->visibleWidget() == reader) |
1026 | { | 1515 | { |
1027 | if (m_fontVisible) | 1516 | if (m_fontVisible) |
@@ -1058,6 +1547,7 @@ void QTReaderApp::closeEvent( QCloseEvent *e ) | |||
1058 | showEditTools(); | 1547 | showEditTools(); |
1059 | } | 1548 | } |
1060 | } | 1549 | } |
1550 | } | ||
1061 | 1551 | ||
1062 | void QTReaderApp::do_gotomark() | 1552 | void QTReaderApp::do_gotomark() |
1063 | { | 1553 | { |
@@ -1077,7 +1567,6 @@ void QTReaderApp::listbkmk() | |||
1077 | int cnt = 0; | 1567 | int cnt = 0; |
1078 | if (pBkmklist != NULL) | 1568 | if (pBkmklist != NULL) |
1079 | { | 1569 | { |
1080 | if (m_fBkmksChanged) pBkmklist->sort(); | ||
1081 | for (CList<Bkmk>::iterator i = pBkmklist->begin(); i != pBkmklist->end(); i++) | 1570 | for (CList<Bkmk>::iterator i = pBkmklist->begin(); i != pBkmklist->end(); i++) |
1082 | { | 1571 | { |
1083 | #ifdef _UNICODE | 1572 | #ifdef _UNICODE |
@@ -1090,7 +1579,7 @@ void QTReaderApp::listbkmk() | |||
1090 | } | 1579 | } |
1091 | if (cnt > 0) | 1580 | if (cnt > 0) |
1092 | { | 1581 | { |
1093 | menu->hide(); | 1582 | //tjw menu->hide(); |
1094 | editBar->hide(); | 1583 | editBar->hide(); |
1095 | if (m_fontVisible) m_fontBar->hide(); | 1584 | if (m_fontVisible) m_fontBar->hide(); |
1096 | if (regVisible) regBar->hide(); | 1585 | if (regVisible) regBar->hide(); |
@@ -1127,6 +1616,7 @@ void QTReaderApp::gotobkmk(int ind) | |||
1127 | // qDebug("Deleting:%s\n",(*pBkmklist)[ind]->name()); | 1616 | // qDebug("Deleting:%s\n",(*pBkmklist)[ind]->name()); |
1128 | pBkmklist->erase(ind); | 1617 | pBkmklist->erase(ind); |
1129 | m_fBkmksChanged = true; | 1618 | m_fBkmksChanged = true; |
1619 | // pBkmklist->sort(); | ||
1130 | break; | 1620 | break; |
1131 | case cRmBkmkFile: | 1621 | case cRmBkmkFile: |
1132 | unlink((const char *)Global::applicationFileName("uqtreader",bkmkselector->text(ind))); | 1622 | unlink((const char *)Global::applicationFileName("uqtreader",bkmkselector->text(ind))); |
@@ -1194,14 +1684,14 @@ void QTReaderApp::do_settarget(const QString& _txt) | |||
1194 | int ind = _txt.find('/'); | 1684 | int ind = _txt.find('/'); |
1195 | if (ind == -1) | 1685 | if (ind == -1) |
1196 | { | 1686 | { |
1197 | reader->m_targetapp = ""; | 1687 | m_targetapp = ""; |
1198 | reader->m_targetmsg = ""; | 1688 | m_targetmsg = ""; |
1199 | QMessageBox::information(this, "QTReader", "Format is\nappname/messagename"); | 1689 | QMessageBox::information(this, "QTReader", "Format is\nappname/messagename"); |
1200 | } | 1690 | } |
1201 | else | 1691 | else |
1202 | { | 1692 | { |
1203 | reader->m_targetapp = _txt.left(ind); | 1693 | m_targetapp = _txt.left(ind); |
1204 | reader->m_targetmsg = _txt.right(_txt.length()-ind-1); | 1694 | m_targetmsg = _txt.right(_txt.length()-ind-1); |
1205 | } | 1695 | } |
1206 | } | 1696 | } |
1207 | 1697 | ||
@@ -1219,20 +1709,30 @@ void QTReaderApp::setfont() | |||
1219 | m_fontVisible = true; | 1709 | m_fontVisible = true; |
1220 | } | 1710 | } |
1221 | 1711 | ||
1222 | void QTReaderApp::do_setfont(const QString& lcn) | 1712 | void QTReaderApp::setfontHelper(const QString& lcn, int size = 0) |
1223 | { | 1713 | { |
1714 | if (size == 0) size = reader->m_fontControl.currentsize(); | ||
1224 | QFont f(lcn, 10 /*, QFont::Bold*/); | 1715 | QFont f(lcn, 10 /*, QFont::Bold*/); |
1225 | bkmkselector->setFont( f ); | 1716 | bkmkselector->setFont( f ); |
1226 | regEdit->setFont( f ); | 1717 | regEdit->setFont( f ); |
1227 | searchEdit->setFont( f ); | 1718 | searchEdit->setFont( f ); |
1719 | m_annoWin->setFont( f ); | ||
1228 | reader->m_fontname = lcn; | 1720 | reader->m_fontname = lcn; |
1229 | reader->ChangeFont(reader->fontsizes[reader->m_textsize]); | 1721 | if (!reader->ChangeFont(size)) |
1722 | { | ||
1723 | reader->ChangeFont(size); | ||
1724 | } | ||
1230 | reader->refresh(); | 1725 | reader->refresh(); |
1231 | m_fontBar->hide(); | 1726 | m_fontBar->hide(); |
1232 | m_fontVisible = false; | 1727 | m_fontVisible = false; |
1233 | showEditTools(); | 1728 | showEditTools(); |
1234 | } | 1729 | } |
1235 | 1730 | ||
1731 | void QTReaderApp::do_setfont(const QString& lcn) | ||
1732 | { | ||
1733 | setfontHelper(lcn); | ||
1734 | } | ||
1735 | |||
1236 | void QTReaderApp::do_autogen(const QString& regText) | 1736 | void QTReaderApp::do_autogen(const QString& regText) |
1237 | { | 1737 | { |
1238 | unsigned long fs, ts; | 1738 | unsigned long fs, ts; |
@@ -1270,8 +1770,9 @@ pbar->resize(width(), editBar->height()); | |||
1270 | #else | 1770 | #else |
1271 | if (re.match(buff.data()) != -1) | 1771 | if (re.match(buff.data()) != -1) |
1272 | #endif | 1772 | #endif |
1273 | pBkmklist->push_back(Bkmk(buff.data(),lcn)); | 1773 | pBkmklist->push_back(Bkmk(buff.data(), NULL, lcn)); |
1274 | } | 1774 | } |
1775 | pBkmklist->sort(); | ||
1275 | pbar->setProgress(100); | 1776 | pbar->setProgress(100); |
1276 | qApp->processEvents(); | 1777 | qApp->processEvents(); |
1277 | pbar->hide(); | 1778 | pbar->hide(); |
@@ -1286,14 +1787,15 @@ void QTReaderApp::saveprefs() | |||
1286 | reader->m_lastposn = reader->pagelocate(); | 1787 | reader->m_lastposn = reader->pagelocate(); |
1287 | 1788 | ||
1288 | config.writeEntry( "StripCr", reader->bstripcr ); | 1789 | config.writeEntry( "StripCr", reader->bstripcr ); |
1790 | config.writeEntry( "AutoFmt", reader->bautofmt ); | ||
1791 | config.writeEntry( "TextFmt", reader->btextfmt ); | ||
1289 | config.writeEntry( "StripHtml", reader->bstriphtml ); | 1792 | config.writeEntry( "StripHtml", reader->bstriphtml ); |
1290 | config.writeEntry( "Dehyphen", reader->bdehyphen ); | 1793 | config.writeEntry( "Dehyphen", reader->bdehyphen ); |
1291 | config.writeEntry( "Unindent", reader->bunindent ); | 1794 | config.writeEntry( "Unindent", reader->bunindent ); |
1292 | config.writeEntry( "Repara", reader->brepara ); | 1795 | config.writeEntry( "Repara", reader->brepara ); |
1293 | config.writeEntry( "DoubleSpace", reader->bdblspce ); | 1796 | config.writeEntry( "DoubleSpace", reader->bdblspce ); |
1294 | config.writeEntry( "Indent", reader->bindenter ); | 1797 | config.writeEntry( "Indent", reader->bindenter ); |
1295 | config.writeEntry( "FontSize", (int)(reader->fontsizes[reader->m_textsize]) ); | 1798 | config.writeEntry( "FontSize", (int)(reader->m_fontControl.currentsize()) ); |
1296 | config.writeEntry( "Bold", reader->m_bBold ); | ||
1297 | config.writeEntry( "ScrollDelay", reader->m_delay); | 1799 | config.writeEntry( "ScrollDelay", reader->m_delay); |
1298 | config.writeEntry( "LastFile", reader->m_lastfile ); | 1800 | config.writeEntry( "LastFile", reader->m_lastfile ); |
1299 | config.writeEntry( "LastPosn", (int)(reader->pagelocate()) ); | 1801 | config.writeEntry( "LastPosn", (int)(reader->pagelocate()) ); |
@@ -1303,8 +1805,16 @@ void QTReaderApp::saveprefs() | |||
1303 | config.writeEntry( "Encoding", reader->m_encd ); | 1805 | config.writeEntry( "Encoding", reader->m_encd ); |
1304 | config.writeEntry( "CharSpacing", reader->m_charpc ); | 1806 | config.writeEntry( "CharSpacing", reader->m_charpc ); |
1305 | config.writeEntry( "Overlap", (int)(reader->m_overlap) ); | 1807 | config.writeEntry( "Overlap", (int)(reader->m_overlap) ); |
1306 | config.writeEntry( "TargetApp", reader->m_targetapp ); | 1808 | config.writeEntry( "TargetApp", m_targetapp ); |
1307 | config.writeEntry( "TargetMsg", reader->m_targetmsg ); | 1809 | config.writeEntry( "TargetMsg", m_targetmsg ); |
1810 | config.writeEntry( "TwoTouch", m_twoTouch ); | ||
1811 | config.writeEntry( "Annotation", m_doAnnotation); | ||
1812 | config.writeEntry( "Dictionary", m_doDictionary); | ||
1813 | config.writeEntry( "Clipboard", m_doClipboard); | ||
1814 | config.writeEntry( "SpaceTarget", m_spaceTarget); | ||
1815 | config.writeEntry( "Remap", reader->bremap ); | ||
1816 | config.writeEntry( "Peanut", reader->bpeanut ); | ||
1817 | config.writeEntry( "MakeBold", reader->bmakebold ); | ||
1308 | } | 1818 | } |
1309 | 1819 | ||
1310 | void QTReaderApp::indentplus() | 1820 | void QTReaderApp::indentplus() |
@@ -1391,7 +1901,7 @@ void QTReaderApp::readbkmks() | |||
1391 | } | 1901 | } |
1392 | BkmkFile bf((const char *)Global::applicationFileName("uqtreader",reader->m_string)); | 1902 | BkmkFile bf((const char *)Global::applicationFileName("uqtreader",reader->m_string)); |
1393 | pBkmklist = bf.readall(); | 1903 | pBkmklist = bf.readall(); |
1394 | m_fBkmksChanged = false; | 1904 | m_fBkmksChanged = bf.upgraded(); |
1395 | if (pBkmklist == NULL) | 1905 | if (pBkmklist == NULL) |
1396 | { | 1906 | { |
1397 | pBkmklist = reader->getbkmklist(); | 1907 | pBkmklist = reader->getbkmklist(); |
@@ -1424,10 +1934,96 @@ void QTReaderApp::do_addbkmk(const QString& text) | |||
1424 | buff[i] = text[i].unicode(); | 1934 | buff[i] = text[i].unicode(); |
1425 | } | 1935 | } |
1426 | buff[i] = 0; | 1936 | buff[i] = 0; |
1427 | pBkmklist->push_front(Bkmk(buff.data(), reader->pagelocate())); | 1937 | pBkmklist->push_front(Bkmk(buff.data(), NULL, reader->pagelocate())); |
1428 | #else | 1938 | #else |
1429 | pBkmklist->push_front(Bkmk((const tchar*)text,reader->pagelocate())); | 1939 | pBkmklist->push_front(Bkmk((const tchar*)text,reader->pagelocate())); |
1430 | #endif | 1940 | #endif |
1431 | m_fBkmksChanged = true; | 1941 | m_fBkmksChanged = true; |
1942 | pBkmklist->sort(); | ||
1432 | } | 1943 | } |
1433 | } | 1944 | } |
1945 | |||
1946 | void QTReaderApp::OnRedraw() | ||
1947 | { | ||
1948 | if (pBkmklist != NULL) | ||
1949 | { | ||
1950 | bool found = findNextBookmark(reader->pagelocate()); | ||
1951 | m_bkmkAvail->setEnabled(found); | ||
1952 | } | ||
1953 | } | ||
1954 | |||
1955 | void QTReaderApp::showAnnotation() | ||
1956 | { | ||
1957 | m_annoWin->setName(toQString(m_anno->name())); | ||
1958 | m_annoWin->setAnno(toQString(m_anno->anno())); | ||
1959 | m_annoIsEditing = false; | ||
1960 | editorStack->raiseWidget( m_annoWin ); | ||
1961 | m_annoWin->setFocus(); | ||
1962 | } | ||
1963 | |||
1964 | void QTReaderApp::OnWordSelected(const QString& wrd, size_t posn, const QString& line) | ||
1965 | { | ||
1966 | // qDebug("OnWordSelected(%u):%s", posn, (const char*)wrd); | ||
1967 | |||
1968 | if (m_doClipboard) | ||
1969 | { | ||
1970 | QClipboard* cb = QApplication::clipboard(); | ||
1971 | cb->setText(wrd); | ||
1972 | if (wrd.length() > 10) | ||
1973 | { | ||
1974 | Global::statusMessage(wrd.left(8) + ".."); | ||
1975 | } | ||
1976 | else | ||
1977 | { | ||
1978 | Global::statusMessage(wrd); | ||
1979 | } | ||
1980 | } | ||
1981 | if (m_doAnnotation) | ||
1982 | { | ||
1983 | //addAnno(wrd, "Need to be able to edit this", posn); | ||
1984 | m_annoWin->setName(line); | ||
1985 | m_annoWin->setAnno(""); | ||
1986 | m_annoWin->setPosn(posn); | ||
1987 | m_annoIsEditing = true; | ||
1988 | editorStack->raiseWidget( m_annoWin ); | ||
1989 | } | ||
1990 | if (m_doDictionary) | ||
1991 | { | ||
1992 | if (!m_targetapp.isEmpty() && !m_targetmsg.isEmpty()) | ||
1993 | { | ||
1994 | QCopEnvelope e(("QPE/Application/"+m_targetapp).utf8(), (m_targetmsg+"(QString)").utf8()); | ||
1995 | e << wrd; | ||
1996 | } | ||
1997 | } | ||
1998 | } | ||
1999 | |||
2000 | void QTReaderApp::OnActionPressed() | ||
2001 | { | ||
2002 | switch (m_spaceTarget) | ||
2003 | { | ||
2004 | case cesOpenFile: | ||
2005 | { | ||
2006 | fileOpen(); | ||
2007 | } | ||
2008 | break; | ||
2009 | case cesAutoScroll: | ||
2010 | { | ||
2011 | reader->setautoscroll(!reader->m_autoScroll); | ||
2012 | setScrollState(reader->m_autoScroll); | ||
2013 | } | ||
2014 | break; | ||
2015 | case cesActionMark: | ||
2016 | { | ||
2017 | addbkmk(); | ||
2018 | } | ||
2019 | break; | ||
2020 | default: | ||
2021 | { | ||
2022 | qDebug("Unknown ActionType:%u", m_spaceTarget); | ||
2023 | } | ||
2024 | break; | ||
2025 | } | ||
2026 | } | ||
2027 | |||
2028 | void QTReaderApp::setTwoTouch(bool _b) { reader->setTwoTouch(_b); } | ||
2029 | void QTReaderApp::restoreFocus() { reader->setFocus(); } | ||
diff --git a/noncore/apps/opie-reader/QTReaderApp.h b/noncore/apps/opie-reader/QTReaderApp.h index 48575e9..22c57e4 100644 --- a/noncore/apps/opie-reader/QTReaderApp.h +++ b/noncore/apps/opie-reader/QTReaderApp.h | |||
@@ -23,24 +23,37 @@ | |||
23 | //#define __ISEARCH | 23 | //#define __ISEARCH |
24 | 24 | ||
25 | #define MAX_ENCODING 6 | 25 | #define MAX_ENCODING 6 |
26 | #define MAX_ACTIONS 3 | ||
26 | 27 | ||
27 | #include <qmainwindow.h> | 28 | #include <qmainwindow.h> |
28 | #include "QTReader.h" | 29 | #include "CExpander.h" |
29 | #include <qlist.h> | 30 | #include <qlist.h> |
30 | #include <qpe/filemanager.h> | 31 | #include <qpe/filemanager.h> |
31 | #include <qmap.h> | 32 | #include <qmap.h> |
32 | #include <qlineedit.h> | 33 | #include <qlineedit.h> |
33 | #include <qstack.h> | 34 | #include <qstack.h> |
34 | #include <qlistbox.h> | 35 | #include <qlistbox.h> |
35 | #include "Queue.h" | 36 | //#include "Queue.h" |
36 | 37 | ||
37 | class QWidgetStack; | 38 | class QWidgetStack; |
38 | class QToolButton; | 39 | class QToolButton; |
39 | class QPopupMenu; | 40 | class QPopupMenu; |
40 | class QToolBar; | 41 | class QToolBar; |
42 | class QPEToolBar; | ||
41 | class CBkmkSelector; | 43 | class CBkmkSelector; |
42 | class QProgressBar; | 44 | class QProgressBar; |
43 | class QAction; | 45 | class QAction; |
46 | class CAnnoEdit; | ||
47 | class QFloatBar; | ||
48 | class CDrawBuffer; | ||
49 | class QTReader; | ||
50 | |||
51 | enum ActionTypes | ||
52 | { | ||
53 | cesOpenFile = 0, | ||
54 | cesAutoScroll, | ||
55 | cesActionMark | ||
56 | }; | ||
44 | 57 | ||
45 | #ifdef __ISEARCH | 58 | #ifdef __ISEARCH |
46 | struct searchrecord | 59 | struct searchrecord |
@@ -58,6 +71,7 @@ class QTReaderApp : public QMainWindow | |||
58 | Q_OBJECT | 71 | Q_OBJECT |
59 | 72 | ||
60 | unsigned long m_savedpos; | 73 | unsigned long m_savedpos; |
74 | bool m_annoIsEditing; | ||
61 | 75 | ||
62 | public: | 76 | public: |
63 | QTReaderApp( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); | 77 | QTReaderApp( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); |
@@ -68,6 +82,10 @@ class QTReaderApp : public QMainWindow | |||
68 | void setScrollState(bool _b); | 82 | void setScrollState(bool _b); |
69 | 83 | ||
70 | protected: | 84 | protected: |
85 | void setfontHelper(const QString& lcn, int size = 0); | ||
86 | QAction* m_bkmkAvail; | ||
87 | CAnnoEdit* m_annoWin; | ||
88 | Bkmk* m_anno; | ||
71 | void closeEvent( QCloseEvent *e ); | 89 | void closeEvent( QCloseEvent *e ); |
72 | void readbkmks(); | 90 | void readbkmks(); |
73 | void do_mono(const QString&); | 91 | void do_mono(const QString&); |
@@ -75,11 +93,36 @@ class QTReaderApp : public QMainWindow | |||
75 | void do_overlap(const QString&); | 93 | void do_overlap(const QString&); |
76 | void do_settarget(const QString&); | 94 | void do_settarget(const QString&); |
77 | int EncNameToInt(const QString&); | 95 | int EncNameToInt(const QString&); |
78 | void saveprefs(); | 96 | ActionTypes ActNameToInt(const QString&); |
97 | bool m_doAnnotation; | ||
98 | bool m_doDictionary; | ||
99 | bool m_doClipboard; | ||
79 | 100 | ||
101 | public: | ||
102 | void saveprefs(); | ||
80 | private slots: | 103 | private slots: |
104 | void setTwoTouch(bool _b); | ||
105 | void restoreFocus(); | ||
106 | void OnAnnotation(bool _b) | ||
107 | { | ||
108 | m_doAnnotation = _b; | ||
109 | } | ||
110 | void OnDictionary(bool _b) | ||
111 | { | ||
112 | m_doDictionary = _b; | ||
113 | } | ||
114 | void OnClipboard(bool _b) | ||
115 | { | ||
116 | m_doClipboard = _b; | ||
117 | } | ||
118 | void OnWordSelected(const QString&, size_t, const QString&); | ||
119 | void addAnno(const QString&, const QString&, size_t); | ||
120 | void addAnno(const QString&, const QString&); | ||
121 | void addanno(); | ||
122 | void showAnnotation(); | ||
81 | void do_setfont(const QString&); | 123 | void do_setfont(const QString&); |
82 | void encodingSelected(QAction*); | 124 | void encodingSelected(QAction*); |
125 | void buttonActionSelected(QAction*); | ||
83 | void msgHandler(const QCString&, const QByteArray&); | 126 | void msgHandler(const QCString&, const QByteArray&); |
84 | void monospace(bool); | 127 | void monospace(bool); |
85 | void jump(); | 128 | void jump(); |
@@ -127,11 +170,15 @@ private slots: | |||
127 | void showEditTools(); | 170 | void showEditTools(); |
128 | 171 | ||
129 | void stripcr(bool); | 172 | void stripcr(bool); |
173 | void peanut(bool _b); | ||
174 | void remap(bool); | ||
175 | void embolden(bool); | ||
176 | void autofmt(bool); | ||
177 | void textfmt(bool); | ||
130 | void striphtml(bool); | 178 | void striphtml(bool); |
131 | void dehyphen(bool); | 179 | void dehyphen(bool); |
132 | void unindent(bool); | 180 | void unindent(bool); |
133 | void repara(bool); | 181 | void repara(bool); |
134 | void setbold(bool); | ||
135 | void dblspce(bool); | 182 | void dblspce(bool); |
136 | void pagemode(bool); | 183 | void pagemode(bool); |
137 | // void gotobkmk(const QString& bm); | 184 | // void gotobkmk(const QString& bm); |
@@ -141,8 +188,11 @@ private slots: | |||
141 | void do_delmark(); | 188 | void do_delmark(); |
142 | void do_autogen(); | 189 | void do_autogen(); |
143 | void do_regaction(); | 190 | void do_regaction(); |
191 | void OnRedraw(); | ||
192 | void OnActionPressed(); | ||
144 | 193 | ||
145 | private: | 194 | private: |
195 | QString m_targetapp, m_targetmsg; | ||
146 | void listbkmk(); | 196 | void listbkmk(); |
147 | void do_regedit(); | 197 | void do_regedit(); |
148 | void colorChanged( const QColor &c ); | 198 | void colorChanged( const QColor &c ); |
@@ -150,6 +200,7 @@ private slots: | |||
150 | void updateCaption(); | 200 | void updateCaption(); |
151 | void do_autogen(const QString&); | 201 | void do_autogen(const QString&); |
152 | void do_addbkmk(const QString&); | 202 | void do_addbkmk(const QString&); |
203 | bool findNextBookmark(size_t start); | ||
153 | 204 | ||
154 | private: | 205 | private: |
155 | 206 | ||
@@ -157,24 +208,29 @@ private slots: | |||
157 | 208 | ||
158 | QAction* m_EncodingAction[MAX_ENCODING]; | 209 | QAction* m_EncodingAction[MAX_ENCODING]; |
159 | 210 | ||
211 | QAction* m_buttonAction[MAX_ACTIONS]; | ||
212 | |||
160 | CBkmkSelector* bkmkselector; | 213 | CBkmkSelector* bkmkselector; |
161 | 214 | ||
215 | ActionTypes m_spaceTarget; | ||
162 | size_t searchStart; | 216 | size_t searchStart; |
163 | #ifdef __ISEARCH | 217 | #ifdef __ISEARCH |
164 | QStack<searchrecord>* searchStack; | 218 | QStack<searchrecord>* searchStack; |
165 | bool dosearch(size_t start, CBuffer& test, const QString& arg); | 219 | bool dosearch(size_t start, CDrawBuffer& test, const QString& arg); |
166 | #else | 220 | #else |
167 | bool dosearch(size_t start, CBuffer& test, const QRegExp& arg); | 221 | bool dosearch(size_t start, CDrawBuffer& test, const QRegExp& arg); |
168 | #endif | 222 | #endif |
169 | QWidgetStack *editorStack; | 223 | QWidgetStack *editorStack; |
170 | QTReader* reader; | 224 | QTReader* reader; |
171 | QComboBox* m_fontSelector; | 225 | QComboBox* m_fontSelector; |
172 | QToolBar *menu, *editBar, *searchBar, *regBar, *m_fontBar; | 226 | QPEToolBar /* *menu,*/ *editBar; |
227 | QFloatBar *searchBar, *regBar/*, *m_fontBar*/; | ||
228 | QToolBar /* *searchBar, *regBar,*/ *m_fontBar; | ||
173 | QLineEdit *searchEdit, *regEdit; | 229 | QLineEdit *searchEdit, *regEdit; |
174 | DocLnk *doc; | 230 | DocLnk *doc; |
175 | bool searchVisible; | 231 | bool searchVisible; |
176 | bool regVisible; | 232 | bool regVisible; |
177 | bool m_fontVisible; | 233 | bool m_fontVisible, m_twoTouch; |
178 | bool bFromDocView; | 234 | bool bFromDocView; |
179 | static unsigned long m_uid; | 235 | static unsigned long m_uid; |
180 | long unsigned get_unique_id() { return m_uid++; } | 236 | long unsigned get_unique_id() { return m_uid++; } |
@@ -192,6 +248,7 @@ private slots: | |||
192 | bool m_fBkmksChanged; | 248 | bool m_fBkmksChanged; |
193 | int m_nRegAction; | 249 | int m_nRegAction; |
194 | QString m_autogenstr; | 250 | QString m_autogenstr; |
251 | bool m_dontSave; | ||
195 | }; | 252 | }; |
196 | 253 | ||
197 | const int cAutoGen = 0; | 254 | const int cAutoGen = 0; |
diff --git a/noncore/apps/opie-reader/StyleConsts.h b/noncore/apps/opie-reader/StyleConsts.h new file mode 100644 index 0000000..b6dd861 --- a/dev/null +++ b/noncore/apps/opie-reader/StyleConsts.h | |||
@@ -0,0 +1,113 @@ | |||
1 | #ifndef __STYLECONSTS_H | ||
2 | #define __STYLECONSTS_H | ||
3 | |||
4 | typedef unsigned short StyleType; | ||
5 | |||
6 | class CStyle | ||
7 | { | ||
8 | // 15 14 13-5 4 3 2 1 0 | ||
9 | //bold italic spare align align fs fs fs | ||
10 | static const StyleType m_Bold = 1 << 15; | ||
11 | static const StyleType m_Italic = 1 << 14; | ||
12 | static const StyleType m_FontMask = 7; | ||
13 | static const StyleType m_FontBase = 3; | ||
14 | |||
15 | static const StyleType m_AlignShift = 3; | ||
16 | static const StyleType m_AlignMask = 3 << m_AlignShift; | ||
17 | static const StyleType m_EveryBit = 0xffff; | ||
18 | |||
19 | |||
20 | StyleType sty; | ||
21 | |||
22 | void unjustify() { sty &= m_EveryBit ^ m_AlignMask; } | ||
23 | unsigned char red, green, blue; | ||
24 | unsigned long data; | ||
25 | bool isLink; | ||
26 | public: | ||
27 | unsigned char Red() { return red; } | ||
28 | unsigned char Green() { return green; } | ||
29 | unsigned char Blue() { return blue; } | ||
30 | void setColour(unsigned char r, unsigned char g, unsigned char b) | ||
31 | { | ||
32 | red = r; | ||
33 | green = g; | ||
34 | blue = b; | ||
35 | } | ||
36 | static const StyleType m_AlignLeft = 0; | ||
37 | static const StyleType m_AlignRight = 1 << m_AlignShift; | ||
38 | static const StyleType m_AlignCentre = 2 << m_AlignShift; | ||
39 | static const StyleType m_AlignJustify = 3 << m_AlignShift; | ||
40 | CStyle() | ||
41 | : | ||
42 | sty(m_FontBase), | ||
43 | red(0), green(0), blue(0), | ||
44 | data(0), isLink(false) | ||
45 | {} | ||
46 | // CStyle(const int _fs) : sty(m_FontBase+_fs) {} | ||
47 | |||
48 | void unset() | ||
49 | { | ||
50 | sty = m_FontBase; | ||
51 | red = green = blue = 0; | ||
52 | data = 0; | ||
53 | isLink = false; | ||
54 | } | ||
55 | |||
56 | void setBold() { sty |= m_Bold; } | ||
57 | void setItalic() { sty |= m_Italic; } | ||
58 | void unsetBold() { sty &= m_EveryBit ^ m_Bold; } | ||
59 | void unsetItalic() { sty &= m_EveryBit ^ m_Italic; } | ||
60 | bool isBold() { return ((sty & m_Bold) != 0); } | ||
61 | bool isItalic() { return ((sty & m_Italic) != 0); } | ||
62 | |||
63 | void setLeftJustify() | ||
64 | { | ||
65 | unjustify(); | ||
66 | sty |= m_AlignLeft; | ||
67 | } | ||
68 | void setRightJustify() | ||
69 | { | ||
70 | unjustify(); | ||
71 | sty |= m_AlignRight; | ||
72 | } | ||
73 | void setCentreJustify() | ||
74 | { | ||
75 | unjustify(); | ||
76 | sty |= m_AlignCentre; | ||
77 | } | ||
78 | void setFullJustify() | ||
79 | { | ||
80 | unjustify(); | ||
81 | sty |= m_AlignJustify; | ||
82 | } | ||
83 | StyleType getJustify() | ||
84 | { | ||
85 | return sty & m_AlignMask; | ||
86 | } | ||
87 | |||
88 | void setFontSize(int _fs) | ||
89 | { | ||
90 | sty &= m_EveryBit ^ m_FontMask; | ||
91 | sty |= m_FontBase + _fs; | ||
92 | } | ||
93 | int getFontSize() | ||
94 | { | ||
95 | return (sty & m_FontMask) - m_FontBase; | ||
96 | } | ||
97 | bool operator!=(const CStyle& rhs) | ||
98 | { | ||
99 | return | ||
100 | ( | ||
101 | (sty != rhs.sty) || (red != rhs.red) || (green != rhs.green) || | ||
102 | (blue != rhs.blue) || | ||
103 | (data != rhs.data) || | ||
104 | (isLink != rhs.isLink) | ||
105 | ); | ||
106 | } | ||
107 | void setLink(bool _l) { isLink = _l; } | ||
108 | bool getLink() { return isLink; } | ||
109 | void setData(unsigned long _d) { data = _d; } | ||
110 | unsigned long getData() { return data; } | ||
111 | }; | ||
112 | |||
113 | #endif | ||
diff --git a/noncore/apps/opie-reader/ZText.h b/noncore/apps/opie-reader/ZText.h index 4b1b96e..9e72161 100644 --- a/noncore/apps/opie-reader/ZText.h +++ b/noncore/apps/opie-reader/ZText.h | |||
@@ -1,8 +1,7 @@ | |||
1 | #ifndef __Text_h | 1 | #ifndef __Text_h |
2 | #define __Text_h | 2 | #define __Text_h |
3 | #include <stdio.h> | 3 | #include <stdio.h> |
4 | #include "zlib/zlib.h" | 4 | #include <zlib.h> |
5 | //#include <zlib.h> | ||
6 | #include <sys/stat.h> | 5 | #include <sys/stat.h> |
7 | 6 | ||
8 | #include "CExpander.h" | 7 | #include "CExpander.h" |
@@ -32,5 +31,9 @@ public: | |||
32 | { | 31 | { |
33 | _text = _file = fsize; | 32 | _text = _file = fsize; |
34 | } | 33 | } |
34 | virtual MarkupType PreferredMarkup() | ||
35 | { | ||
36 | return cTEXT; | ||
37 | } | ||
35 | }; | 38 | }; |
36 | #endif | 39 | #endif |
diff --git a/noncore/apps/opie-reader/fileBrowser.cpp b/noncore/apps/opie-reader/fileBrowser.cpp index def988f..b21d59d 100644 --- a/noncore/apps/opie-reader/fileBrowser.cpp +++ b/noncore/apps/opie-reader/fileBrowser.cpp | |||
@@ -17,7 +17,7 @@ Extensive modification by Tim Wentford to allow it to work in rotated mode | |||
17 | #include <qlayout.h> | 17 | #include <qlayout.h> |
18 | 18 | ||
19 | fileBrowser::fileBrowser( QWidget* parent, const char* name, bool modal, WFlags fl , const QString filter, const QString iPath ) | 19 | fileBrowser::fileBrowser( QWidget* parent, const char* name, bool modal, WFlags fl , const QString filter, const QString iPath ) |
20 | : QDialog( parent, name, modal, fl ) | 20 | : QDialog( parent, name, modal, fl ), filterspec(QDir::All) |
21 | { | 21 | { |
22 | // showMaximized(); | 22 | // showMaximized(); |
23 | if ( !name ) | 23 | if ( !name ) |
@@ -28,8 +28,16 @@ fileBrowser::fileBrowser( QWidget* parent, const char* name, bool modal, WFlags | |||
28 | 28 | ||
29 | buttonOk = new QPushButton( this, "buttonOk" ); | 29 | buttonOk = new QPushButton( this, "buttonOk" ); |
30 | buttonOk->setFixedSize( 25, 25 ); | 30 | buttonOk->setFixedSize( 25, 25 ); |
31 | buttonOk->setAutoDefault( false ); | ||
31 | buttonOk->setText( tr( "/" ) ); | 32 | buttonOk->setText( tr( "/" ) ); |
32 | 33 | ||
34 | buttonShowHidden = new QPushButton( this, "buttonShowHidden" ); | ||
35 | // buttonShowHidden->setFixedSize( 50, 25 ); | ||
36 | buttonShowHidden->setText( tr( "Hidden" ) ); | ||
37 | buttonShowHidden->setAutoDefault( false ); | ||
38 | buttonShowHidden->setToggleButton( true ); | ||
39 | buttonShowHidden->setOn( false ); | ||
40 | |||
33 | dirLabel = new QLabel(this, "DirLabel"); | 41 | dirLabel = new QLabel(this, "DirLabel"); |
34 | dirLabel->setText(currentDir.canonicalPath()); | 42 | dirLabel->setText(currentDir.canonicalPath()); |
35 | 43 | ||
@@ -38,10 +46,10 @@ fileBrowser::fileBrowser( QWidget* parent, const char* name, bool modal, WFlags | |||
38 | ListView->setSorting( 2, FALSE); | 46 | ListView->setSorting( 2, FALSE); |
39 | ListView->addColumn( tr( "Size" ) ); | 47 | ListView->addColumn( tr( "Size" ) ); |
40 | ListView->setSelectionMode(QListView::Single); | 48 | ListView->setSelectionMode(QListView::Single); |
41 | |||
42 | ListView->setAllColumnsShowFocus( TRUE ); | 49 | ListView->setAllColumnsShowFocus( TRUE ); |
43 | 50 | ||
44 | // signals and slots connections | 51 | // signals and slots connections |
52 | connect( buttonShowHidden, SIGNAL( toggled(bool) ), this, SLOT( setHidden(bool) ) ); | ||
45 | connect( buttonOk, SIGNAL( clicked() ), this, SLOT( OnRoot() ) ); | 53 | connect( buttonOk, SIGNAL( clicked() ), this, SLOT( OnRoot() ) ); |
46 | connect( ListView, SIGNAL(doubleClicked( QListViewItem*)), SLOT(listDoubleClicked(QListViewItem *)) ); | 54 | connect( ListView, SIGNAL(doubleClicked( QListViewItem*)), SLOT(listDoubleClicked(QListViewItem *)) ); |
47 | connect( ListView, SIGNAL(clicked( QListViewItem*)), SLOT(listClicked(QListViewItem *)) ); | 55 | connect( ListView, SIGNAL(clicked( QListViewItem*)), SLOT(listClicked(QListViewItem *)) ); |
@@ -52,6 +60,7 @@ fileBrowser::fileBrowser( QWidget* parent, const char* name, bool modal, WFlags | |||
52 | QVBoxLayout* grid = new QVBoxLayout(this); | 60 | QVBoxLayout* grid = new QVBoxLayout(this); |
53 | QHBoxLayout* hgrid = new QHBoxLayout(grid); | 61 | QHBoxLayout* hgrid = new QHBoxLayout(grid); |
54 | hgrid->addWidget(dirLabel,1); | 62 | hgrid->addWidget(dirLabel,1); |
63 | hgrid->addWidget(buttonShowHidden); | ||
55 | hgrid->addWidget(buttonOk); | 64 | hgrid->addWidget(buttonOk); |
56 | grid->addWidget(ListView,1); | 65 | grid->addWidget(ListView,1); |
57 | 66 | ||
@@ -85,14 +94,14 @@ void fileBrowser::populateList() | |||
85 | ListView->clear(); | 94 | ListView->clear(); |
86 | //qDebug(currentDir.canonicalPath()); | 95 | //qDebug(currentDir.canonicalPath()); |
87 | // currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::NoSymLinks ); | 96 | // currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::NoSymLinks ); |
88 | currentDir.setFilter( QDir::All ); | 97 | currentDir.setFilter( filterspec ); |
89 | currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); | 98 | currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); |
90 | currentDir.setMatchAllDirs(TRUE); | 99 | currentDir.setMatchAllDirs(TRUE); |
91 | 100 | ||
92 | currentDir.setNameFilter(filterStr); | 101 | currentDir.setNameFilter(filterStr); |
93 | // currentDir.setNameFilter("*.txt;*.etx"); | 102 | // currentDir.setNameFilter("*.txt;*.etx"); |
94 | QString fileL, fileS; | 103 | QString fileL, fileS; |
95 | const QFileInfoList *list = currentDir.entryInfoList(QDir::All); | 104 | const QFileInfoList *list = currentDir.entryInfoList(); |
96 | QFileInfoListIterator it(*list); | 105 | QFileInfoListIterator it(*list); |
97 | QFileInfo *fi; | 106 | QFileInfo *fi; |
98 | while ( (fi=it.current()) ) | 107 | while ( (fi=it.current()) ) |
@@ -115,6 +124,7 @@ void fileBrowser::populateList() | |||
115 | } | 124 | } |
116 | ListView->setSorting( 2, FALSE); | 125 | ListView->setSorting( 2, FALSE); |
117 | dirLabel->setText("Current Directory:\n"+currentDir.canonicalPath()); | 126 | dirLabel->setText("Current Directory:\n"+currentDir.canonicalPath()); |
127 | ListView->setFocus(); | ||
118 | } | 128 | } |
119 | 129 | ||
120 | void fileBrowser::upDir() | 130 | void fileBrowser::upDir() |
@@ -183,3 +193,12 @@ void fileBrowser::OnCancel() | |||
183 | { | 193 | { |
184 | reject(); | 194 | reject(); |
185 | } | 195 | } |
196 | |||
197 | void fileBrowser::setHidden(bool _hidden) | ||
198 | { | ||
199 | if (_hidden) | ||
200 | filterspec = QDir::All | QDir::Hidden; | ||
201 | else | ||
202 | filterspec = QDir::All; | ||
203 | populateList(); | ||
204 | } | ||
diff --git a/noncore/apps/opie-reader/fileBrowser.h b/noncore/apps/opie-reader/fileBrowser.h index d222791..5521383 100644 --- a/noncore/apps/opie-reader/fileBrowser.h +++ b/noncore/apps/opie-reader/fileBrowser.h | |||
@@ -40,6 +40,7 @@ public: | |||
40 | ~fileBrowser(); | 40 | ~fileBrowser(); |
41 | 41 | ||
42 | QPushButton* buttonOk; | 42 | QPushButton* buttonOk; |
43 | QPushButton* buttonShowHidden; | ||
43 | QtrListView* ListView; | 44 | QtrListView* ListView; |
44 | QPushButton* buttonCancel; | 45 | QPushButton* buttonCancel; |
45 | QLabel *dirLabel; | 46 | QLabel *dirLabel; |
@@ -47,6 +48,8 @@ public: | |||
47 | QDir currentDir; | 48 | QDir currentDir; |
48 | QFile file; | 49 | QFile file; |
49 | QStringList fileList; | 50 | QStringList fileList; |
51 | int filterspec; | ||
52 | // QDir::FilterSpec filterspec; | ||
50 | 53 | ||
51 | //QListViewItem * item; | 54 | //QListViewItem * item; |
52 | public slots: | 55 | public slots: |
@@ -59,6 +62,7 @@ private slots: | |||
59 | void listClicked(QListViewItem *); | 62 | void listClicked(QListViewItem *); |
60 | void OnRoot(); | 63 | void OnRoot(); |
61 | void OnCancel(); | 64 | void OnCancel(); |
65 | void setHidden(bool); | ||
62 | 66 | ||
63 | protected slots: | 67 | protected slots: |
64 | 68 | ||
diff --git a/noncore/apps/opie-reader/infowin.cpp b/noncore/apps/opie-reader/infowin.cpp index f9a6f5f..9637a62 100644 --- a/noncore/apps/opie-reader/infowin.cpp +++ b/noncore/apps/opie-reader/infowin.cpp | |||
@@ -1,7 +1,6 @@ | |||
1 | #include "infowin.h" | 1 | #include "infowin.h" |
2 | #include "version.h" | 2 | #include "version.h" |
3 | 3 | #include <stdio.h> | |
4 | #define VERSION_STRING "QT Reader v" ## MAJOR ## "." ## MINOR ## " (" ## RELEASE_TYPE ## ")\nA small e-text reader" | ||
5 | 4 | ||
6 | infowin::infowin( QWidget *parent=0, const char *name=0, WFlags f = 0) : | 5 | infowin::infowin( QWidget *parent=0, const char *name=0, WFlags f = 0) : |
7 | QWidget(parent, name, f) | 6 | QWidget(parent, name, f) |
@@ -33,7 +32,9 @@ infowin::infowin( QWidget *parent=0, const char *name=0, WFlags f = 0) : | |||
33 | read = new QLabel("0", this); | 32 | read = new QLabel("0", this); |
34 | read->setAlignment( AlignVCenter | AlignRight ); | 33 | read->setAlignment( AlignVCenter | AlignRight ); |
35 | grid->addWidget(read, 4, 1); | 34 | grid->addWidget(read, 4, 1); |
36 | l = new QLabel(VERSION_STRING, this); | 35 | char vstr[128]; |
36 | sprintf(vstr, "QT Reader v%u.%u%c (%s)\nA small e-text reader", MAJOR, BKMKTYPE, MINOR, RELEASE_TYPE); | ||
37 | l = new QLabel(vstr, this); | ||
37 | grid->addWidget(l, 5, 0); | 38 | grid->addWidget(l, 5, 0); |
38 | QPushButton* exitbutton = new QPushButton("Cancel", this); | 39 | QPushButton* exitbutton = new QPushButton("Cancel", this); |
39 | connect( exitbutton, SIGNAL( released() ), this, SLOT( infoClose() ) ); | 40 | connect( exitbutton, SIGNAL( released() ), this, SLOT( infoClose() ) ); |
diff --git a/noncore/apps/opie-reader/main.cpp b/noncore/apps/opie-reader/main.cpp index e37f12c..08f59a8 100644 --- a/noncore/apps/opie-reader/main.cpp +++ b/noncore/apps/opie-reader/main.cpp | |||
@@ -1,38 +1,30 @@ | |||
1 | #include <qpe/qpeapplication.h> | 1 | #include <qpe/qpeapplication.h> |
2 | //#include <qmainwindow.h> | ||
3 | #include "QTReaderApp.h" | 2 | #include "QTReaderApp.h" |
4 | 3 | ||
4 | #include "signal.h" | ||
5 | #include "stdio.h" | ||
6 | #include "time.h" | ||
5 | 7 | ||
8 | QTReaderApp* app = NULL; | ||
6 | 9 | ||
7 | 10 | void handler(int signum) | |
8 | |||
9 | /* | ||
10 | class myapp : public QPEApplication | ||
11 | { | ||
12 | public slots: | ||
13 | void receive( const QCString& msg, const QByteArray& data ) | ||
14 | { | 11 | { |
15 | 12 | if (app != NULL) app->saveprefs(); | |
16 | QDataStream stream( data, IO_ReadOnly ); | 13 | signal(signum, handler); |
17 | if ( msg == "someMessage(int,int,int)" ) { | ||
18 | int a,b,c; | ||
19 | stream >> a >> b >> c; | ||
20 | ... | ||
21 | } else if ( msg == "otherMessage(QString)" ) { | ||
22 | ... | ||
23 | } | ||
24 | |||
25 | } | ||
26 | } | 14 | } |
27 | */ | ||
28 | 15 | ||
29 | int main( int argc, char ** argv ) | 16 | int main( int argc, char ** argv ) |
30 | { | 17 | { |
18 | signal(SIGCONT, handler); | ||
19 | |||
31 | QPEApplication a( argc, argv ); | 20 | QPEApplication a( argc, argv ); |
32 | 21 | ||
33 | QTReaderApp m; | 22 | QTReaderApp m; |
23 | |||
34 | a.showMainDocumentWidget( &m ); | 24 | a.showMainDocumentWidget( &m ); |
35 | 25 | ||
26 | app = &m; | ||
27 | |||
36 | return a.exec(); | 28 | return a.exec(); |
37 | } | 29 | } |
38 | 30 | ||
diff --git a/noncore/apps/opie-reader/my_list.h b/noncore/apps/opie-reader/my_list.h index b3f0cc0..f180d3d 100644 --- a/noncore/apps/opie-reader/my_list.h +++ b/noncore/apps/opie-reader/my_list.h | |||
@@ -28,6 +28,8 @@ class CList | |||
28 | } | 28 | } |
29 | } | 29 | } |
30 | } | 30 | } |
31 | T& first() { return front->data; } | ||
32 | T& last() { return back->data; } | ||
31 | T* operator[](int n) | 33 | T* operator[](int n) |
32 | { | 34 | { |
33 | node* current = front; | 35 | node* current = front; |
@@ -61,6 +63,7 @@ class CList | |||
61 | back = n; | 63 | back = n; |
62 | } | 64 | } |
63 | } | 65 | } |
66 | bool isEmpty() { return (front == NULL); } | ||
64 | void erase(unsigned int n) | 67 | void erase(unsigned int n) |
65 | { | 68 | { |
66 | node* p = front; | 69 | node* p = front; |
@@ -155,10 +158,18 @@ class CList | |||
155 | { | 158 | { |
156 | return &(current->data); | 159 | return &(current->data); |
157 | } | 160 | } |
161 | T* pContent() | ||
162 | { | ||
163 | return &(current->data); | ||
164 | } | ||
158 | bool operator!=(iterator t) | 165 | bool operator!=(iterator t) |
159 | { | 166 | { |
160 | return (current != t.current); | 167 | return (current != t.current); |
161 | } | 168 | } |
169 | bool operator==(iterator t) | ||
170 | { | ||
171 | return (current == t.current); | ||
172 | } | ||
162 | }; | 173 | }; |
163 | iterator begin() | 174 | iterator begin() |
164 | { | 175 | { |
diff --git a/noncore/apps/opie-reader/opie-reader.pro b/noncore/apps/opie-reader/opie-reader.pro index 5d074c3..51849a3 100644 --- a/noncore/apps/opie-reader/opie-reader.pro +++ b/noncore/apps/opie-reader/opie-reader.pro | |||
@@ -3,11 +3,11 @@ CONFIG = qt warn_on release | |||
3 | HEADERS = Aportis.h \ | 3 | HEADERS = Aportis.h \ |
4 | BuffDoc.h \ | 4 | BuffDoc.h \ |
5 | CBuffer.h \ | 5 | CBuffer.h \ |
6 | CDrawBuffer.h \ | ||
6 | CExpander.h \ | 7 | CExpander.h \ |
7 | CFilter.h \ | 8 | CFilter.h \ |
8 | QTReader.h \ | 9 | QTReader.h \ |
9 | QTReaderApp.h \ | 10 | QTReaderApp.h \ |
10 | Text.h \ | ||
11 | ZText.h \ | 11 | ZText.h \ |
12 | arith.h \ | 12 | arith.h \ |
13 | my_list.h \ | 13 | my_list.h \ |
@@ -23,10 +23,18 @@ HEADERS = Aportis.h \ | |||
23 | utypes.h \ | 23 | utypes.h \ |
24 | ustring.h \ | 24 | ustring.h \ |
25 | CEncoding.h \ | 25 | CEncoding.h \ |
26 | CAnnoEdit.h \ | ||
27 | QFloatBar.h \ | ||
28 | StyleConsts.h \ | ||
29 | FontControl.h \ | ||
30 | plucker.h \ | ||
31 | Markups.h \ | ||
32 | Bkmks.h \ | ||
26 | config.h | 33 | config.h |
27 | SOURCES = Aportis.cpp \ | 34 | SOURCES = Aportis.cpp \ |
28 | BuffDoc.cpp \ | 35 | BuffDoc.cpp \ |
29 | CBuffer.cpp \ | 36 | CBuffer.cpp \ |
37 | CDrawBuffer.cpp \ | ||
30 | QTReader.cpp \ | 38 | QTReader.cpp \ |
31 | QTReaderApp.cpp \ | 39 | QTReaderApp.cpp \ |
32 | arith_d.cpp \ | 40 | arith_d.cpp \ |
@@ -38,8 +46,10 @@ SOURCES = Aportis.cpp \ | |||
38 | infowin.cpp \ | 46 | infowin.cpp \ |
39 | pdb.cpp \ | 47 | pdb.cpp \ |
40 | CEncoding.cpp \ | 48 | CEncoding.cpp \ |
49 | CFilter.cpp \ | ||
50 | plucker.cpp \ | ||
51 | Bkmks.cpp \ | ||
41 | fileBrowser.cpp | 52 | fileBrowser.cpp |
42 | INTERFACES= | ||
43 | DESTDIR = $(OPIEDIR)/bin | 53 | DESTDIR = $(OPIEDIR)/bin |
44 | INCLUDEPATH+= $(OPIEDIR)/include | 54 | INCLUDEPATH+= $(OPIEDIR)/include |
45 | DEPENDPATH+= $(OPIEDIR)/include | 55 | DEPENDPATH+= $(OPIEDIR)/include |
diff --git a/noncore/apps/opie-reader/pdb.h b/noncore/apps/opie-reader/pdb.h index 143c5cb..41649bd 100644 --- a/noncore/apps/opie-reader/pdb.h +++ b/noncore/apps/opie-reader/pdb.h | |||
@@ -17,6 +17,7 @@ | |||
17 | /* Normal Palm typedefs */ | 17 | /* Normal Palm typedefs */ |
18 | typedef unsigned char UInt8; | 18 | typedef unsigned char UInt8; |
19 | typedef unsigned short UInt16; | 19 | typedef unsigned short UInt16; |
20 | typedef signed short Int16; | ||
20 | typedef unsigned long UInt32; | 21 | typedef unsigned long UInt32; |
21 | typedef UInt32 LocalID; | 22 | typedef UInt32 LocalID; |
22 | 23 | ||
diff --git a/noncore/apps/opie-reader/plucker.h b/noncore/apps/opie-reader/plucker.h new file mode 100644 index 0000000..84e855c --- a/dev/null +++ b/noncore/apps/opie-reader/plucker.h | |||
@@ -0,0 +1,86 @@ | |||
1 | #ifndef __plucker_h | ||
2 | #define __plucker_h | ||
3 | |||
4 | #include "CExpander.h" | ||
5 | #include <zlib.h> | ||
6 | #include "ztxt.h" | ||
7 | #include "pdb.h" | ||
8 | #include "CBuffer.h" | ||
9 | |||
10 | struct CPlucker_dataRecord | ||
11 | { | ||
12 | UInt16 uid; | ||
13 | UInt16 nParagraphs; | ||
14 | UInt16 size; | ||
15 | UInt8 type; | ||
16 | UInt8 reserved; | ||
17 | }; | ||
18 | |||
19 | struct CPlucker_record0 | ||
20 | { | ||
21 | UInt16 uid; | ||
22 | UInt16 version; | ||
23 | UInt16 nRecords; | ||
24 | }; | ||
25 | |||
26 | struct CPluckerbkmk | ||
27 | { | ||
28 | UInt32 offset; | ||
29 | tchar title[MAX_BMRK_LENGTH]; | ||
30 | }; | ||
31 | |||
32 | |||
33 | const UInt32 CPLUCKER_ID = 0x5458547a; | ||
34 | |||
35 | class CPlucker : public CExpander, Cpdb | ||
36 | { | ||
37 | size_t textlength; | ||
38 | UInt16 uid; | ||
39 | int m_nextPara, m_nextParaIndex; | ||
40 | CBufferFace<UInt16> m_ParaOffsets; | ||
41 | CBufferFace<UInt16> m_ParaAttrs; | ||
42 | UInt16 m_nParas; | ||
43 | CStyle mystyle; | ||
44 | // bool bInit; | ||
45 | UInt32 buffersize; | ||
46 | UInt32 buffercontent; | ||
47 | UInt8* expandedtextbuffer; | ||
48 | UInt8* compressedtextbuffer; | ||
49 | size_t bufferpos; | ||
50 | UInt16 bufferrec; | ||
51 | CPlucker_record0 hdr0; | ||
52 | size_t currentpos; | ||
53 | bool expand(int); | ||
54 | void UnZip(size_t, UInt8*, UInt16); | ||
55 | void UnDoc(size_t, UInt8*, UInt16); | ||
56 | void expandimg(UInt16 tgt); | ||
57 | void home(); | ||
58 | int bgetch(); | ||
59 | public: | ||
60 | virtual void sizes(unsigned long& _file, unsigned long& _text) | ||
61 | { | ||
62 | _file = file_length; | ||
63 | _text = textlength; | ||
64 | //ntohl(hdr0.size); | ||
65 | } | ||
66 | virtual bool hasrandomaccess() { return true; } | ||
67 | virtual ~CPlucker() | ||
68 | { | ||
69 | if (expandedtextbuffer != NULL) delete [] expandedtextbuffer; | ||
70 | if (compressedtextbuffer != NULL) delete [] compressedtextbuffer; | ||
71 | } | ||
72 | CPlucker(); | ||
73 | virtual int openfile(const char *src); | ||
74 | virtual int getch(); | ||
75 | virtual void getch(int&, CStyle&); | ||
76 | virtual unsigned int locate(); | ||
77 | virtual void locate(unsigned int n); | ||
78 | virtual CList<Bkmk>* getbkmklist(); | ||
79 | virtual bool hyperlink(unsigned int n); | ||
80 | virtual MarkupType PreferredMarkup() | ||
81 | { | ||
82 | return cNONE; | ||
83 | } | ||
84 | }; | ||
85 | |||
86 | #endif | ||
diff --git a/noncore/apps/opie-reader/ppm_expander.h b/noncore/apps/opie-reader/ppm_expander.h index ce95db7..115988d 100644 --- a/noncore/apps/opie-reader/ppm_expander.h +++ b/noncore/apps/opie-reader/ppm_expander.h | |||
@@ -41,6 +41,10 @@ class ppm_expander : public CExpander { | |||
41 | virtual void locate(unsigned int n); | 41 | virtual void locate(unsigned int n); |
42 | virtual bool hasrandomaccess() { return (numblocks > 1); } | 42 | virtual bool hasrandomaccess() { return (numblocks > 1); } |
43 | virtual void sizes(unsigned long& file, unsigned long& text); | 43 | virtual void sizes(unsigned long& file, unsigned long& text); |
44 | virtual MarkupType PreferredMarkup() | ||
45 | { | ||
46 | return cTEXT; | ||
47 | } | ||
44 | }; | 48 | }; |
45 | 49 | ||
46 | #endif | 50 | #endif |
diff --git a/noncore/apps/opie-reader/version.h b/noncore/apps/opie-reader/version.h index bd32e4d..8b6c756 100644 --- a/noncore/apps/opie-reader/version.h +++ b/noncore/apps/opie-reader/version.h | |||
@@ -1,3 +1,5 @@ | |||
1 | #define MAJOR "0" | 1 | |
2 | #define MINOR "3r" | 2 | #define MAJOR 0 |
3 | #define RELEASE_TYPE "beta(U)" | 3 | #define BKMKTYPE 5 |
4 | #define MINOR 'a' | ||
5 | #define RELEASE_TYPE "beta" | ||
diff --git a/noncore/apps/opie-reader/ztxt.cpp b/noncore/apps/opie-reader/ztxt.cpp index c30e4fd..289b13a 100644 --- a/noncore/apps/opie-reader/ztxt.cpp +++ b/noncore/apps/opie-reader/ztxt.cpp | |||
@@ -1,6 +1,8 @@ | |||
1 | #include <stdio.h> | 1 | #include <stdio.h> |
2 | #include <string.h> | 2 | #include <string.h> |
3 | #include "ztxt.h" | 3 | #include "ztxt.h" |
4 | #include "my_list.h" | ||
5 | #include "Bkmks.h" | ||
4 | 6 | ||
5 | ztxt::ztxt() : bInit(false), expandedtextbuffer(NULL), compressedtextbuffer(NULL) { /*printf("constructing:%x\n",fin);*/ } | 7 | ztxt::ztxt() : bInit(false), expandedtextbuffer(NULL), compressedtextbuffer(NULL) { /*printf("constructing:%x\n",fin);*/ } |
6 | 8 | ||
@@ -152,7 +154,7 @@ CList<Bkmk>* ztxt::getbkmklist() | |||
152 | zTXTbkmk bkmk; | 154 | zTXTbkmk bkmk; |
153 | if (fread(&bkmk, sizeof(bkmk), 1, fin) != 1) break; | 155 | if (fread(&bkmk, sizeof(bkmk), 1, fin) != 1) break; |
154 | // printf("Bookmark number:%d:%.20s\n", i, bkmk.title); | 156 | // printf("Bookmark number:%d:%.20s\n", i, bkmk.title); |
155 | t->push_back(Bkmk(bkmk.title, ntohl(bkmk.offset))); | 157 | t->push_back(Bkmk(bkmk.title, NULL, ntohl(bkmk.offset))); |
156 | } | 158 | } |
157 | fseek(fin, cur, SEEK_SET); | 159 | fseek(fin, cur, SEEK_SET); |
158 | return t; | 160 | return t; |
diff --git a/noncore/apps/opie-reader/ztxt.h b/noncore/apps/opie-reader/ztxt.h index 6352cfc..7be45c0 100644 --- a/noncore/apps/opie-reader/ztxt.h +++ b/noncore/apps/opie-reader/ztxt.h | |||
@@ -2,8 +2,7 @@ | |||
2 | #define __ztxt_h | 2 | #define __ztxt_h |
3 | 3 | ||
4 | #include "CExpander.h" | 4 | #include "CExpander.h" |
5 | #include "zlib/zlib.h" | 5 | #include <zlib.h> |
6 | //#include <zlib.h> | ||
7 | #include "pdb.h" | 6 | #include "pdb.h" |
8 | /* | 7 | /* |
9 | * Stuff common to both Weasel Reader and makeztxt | 8 | * Stuff common to both Weasel Reader and makeztxt |
@@ -97,7 +96,10 @@ class ztxt : public CExpander, Cpdb | |||
97 | virtual unsigned int locate(); | 96 | virtual unsigned int locate(); |
98 | virtual void locate(unsigned int n); | 97 | virtual void locate(unsigned int n); |
99 | virtual CList<Bkmk>* getbkmklist(); | 98 | virtual CList<Bkmk>* getbkmklist(); |
99 | virtual MarkupType PreferredMarkup() | ||
100 | { | ||
101 | return cTEXT; | ||
102 | } | ||
100 | }; | 103 | }; |
101 | 104 | ||
102 | #endif | 105 | #endif |
103 | |||