-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathand1.cpp
executable file
·365 lines (256 loc) · 8.03 KB
/
and1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
#include "and1.h"
#include "ui_and1.h"
//https://groups.google.com/forum/?fromgroups=#!topic/android-qt/PYHwZSCZvCo per lo scroll
and1::and1(QWidget *parent) : QMainWindow(parent), ui(new Ui::and1){
g=globalish::getInstance ();
v=verse::getInstance ();
//Setto l'immagine di sfondo
QPalette* palette = new QPalette();
palette->setBrush(QPalette::Background,*(new QBrush(*(new QPixmap(PATH "body_bg.png")))));
setPalette(*palette);
//E creo la UI, altrimenti non posso caricare il testo ecc...
ui->setupUi(this);
ui->popup_view->hide ();
ui->book_name->hide ();
ui->opt_frame->hide();
//Configuro UTF - 8 per tutti gli stream testuali
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
//Appendo una stringa per controllare che siano ok gli utf 8...
//str.append(QString::fromUtf8 ("是下記 @#[!£$%&/ #[éé+ùÆæø] ﬖﬓſtשׁהּמּשּקּनऩझऑसॐ३ॻປຜຝນᚓᚔⰇⰆⱙΏΛΜϢϮϫᚣᚻᛓᛟᛞრ⣩❺❮❢ϭמשק "));
//Modifico il frame principale per delegare i link
QWebPage *page=new QWebPage();
// QUrl url = QUrl("http://localhost");
// ui->main_view->load (url);
ui->main_view->setPage (page);
ui->main_view->page ()->setLinkDelegationPolicy (ui->main_view->page ()->DelegateAllLinks);
QWebPage *page2=new QWebPage();
ui->popup_view->setPage (page2);
ui->popup_view->page ()->setLinkDelegationPolicy (ui->main_view->page ()->DelegateAllLinks);
//Configuro l'event filter
KeyPressEater *keyPressEater = new KeyPressEater();
keyPressEater->w=null;
ui->main_view->installEventFilter(keyPressEater);
//ui->->installEventFilter(keyPressEater);
//Intanto inizializzo la home
init_text ();
//Qualche static
aresx=ui->main_view->width ()/2;
aresy=ui->main_view->height ()/2;
}
and1::~and1()
{
delete ui;
}
/** Se faccio click su uno dei link
*/
void and1::on_main_view_linkClicked(const QUrl &arg1)
{
capitolibox (arg1.path ());
}
//Il boxino coi capitoli
void and1::capitolibox(QString libro){
//farewell cookies
id_book=libro.toInt ();
int cc=v->chapter_count (id_book);
str.clear ();
str.append (head);
str.append ("<body><div id=\"bla\"><br>");
int i=0;
int sizx = 0,sizy;
int j,f=0;
if (cc>100){
//Ma sono i salmi!
f=1;
}
for ( j = 1; j < cc+1; ++j) {
i++;
if (i>10){
i=1;
str.append("<br>");
}
str.append("<a href=\"");
str.append(QString::number(j));
str.append("\">");
if (f==1 && j < 100){
str.append(" ");
}
if (j<10){
str.append(" ");
}else{
str.append("");
}
str.append(QString::number(j));
str.append(" ");
str.append("</a>");
}
j--;
if (f==1){
sizy=755;
sizx=670;
}else{
sizy=(ceil((j/10)-1))*50+200;
if (j<10){
sizx=j*50+15;
}
if(j==10){
sizx=500;
}
if(j>10){
sizx=510;
}
}
ui->popup_view->setFixedWidth (sizx);
ui->popup_view->setFixedHeight (sizy);
str.append ("</div></body>");
//qDebug (str.toAscii ());
ui->popup_view->setHtml (str.toAscii ());
ui->popup_view->move (aresx - sizx/2 , aresy - sizy/2 +25 );
ui->popup_view->show();
}
//Inizializza il testo e altre cosine
void and1::init_text(){
//Apro il file con l'head
file.setFileName(PATH "/1.css");
//TODO check se il file è aperto per davvero o no
file.open(QIODevice::ReadOnly | QIODevice::Text);
//Leggo il file in head ed home
QTextStream in(&file);
home_html.append (in.readAll ());
head.append (home_html);
file.close ();
/******************************************/
//Apro il file con l'html della home page
file.setFileName(PATH "/1");
//TODO check se il file è aperto per davvero o no
file.open(QIODevice::ReadOnly | QIODevice::Text);
//Leggo il file in str
QTextStream in2(&file);
home_html.append (in.readAll ());
file.close ();
/******************************************/
//Apro il file con il css di versetti
file.setFileName(PATH "/2.css");
//TODO check se il file è aperto per davvero o no
file.open(QIODevice::ReadOnly | QIODevice::Text);
//Leggo il file in str
QTextStream in3(&file);
css_versetti.append (in.readAll ());
file.close ();
str.clear ();
str.append ("<style> a{color: #5BB6E4; text-decoration:none} </style> <a href=\"some\">");
str.append("Homizzah !");
str.append ("</a>");
ui->homizzah->setText (str.toAscii ());
home();
}
void and1::home(){
//Scrivo la "index"
ui->main_view->setHtml (home_html.toAscii ());
//Nascondo due cosine
ui->homizzah->hide ();
ui->book_name->hide();
//Forzo a non vedersi la barra di scroll
ui->main_view->page ()->mainFrame ()->setScrollBarPolicy ( Qt::Horizontal, Qt::ScrollBarAlwaysOff);
}
/** Se faccio click sulla FINESTRA (non il frame web) NON sui link
*nascondo il popino
*/
bool and1::event(QEvent *event) {
if (event->type() == QEvent::MouseButtonPress) {
ui->popup_view->hide();
return true;
}
return QWidget::event(event);
}
bool KeyPressEater::eventFilter(QObject *obj, QEvent *event) {
if(w == null){
w = and1::getInstance();
}
switch (event->type()) {
case QEvent::KeyPress: {
//QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
//qDebug("Ate key press %d", keyEvent->key());
return true;
break;
}
/*
case QEvent::MouseButtonPress: {
// QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
w->ui->hint->hide();
qDebug("Ate mouse press!!");
return true;
break;
}
*/
//TODO meglio on release
//case QEvent::MouseButtonPress: {
case QEvent::MouseButtonRelease: {
// QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
if (w->ui->popup_view->isVisible()) {
w->ui->popup_view->hide();
//qDebug("Ate mouse press!!");
return QObject::eventFilter(obj, event);
} else {
return QObject::eventFilter(obj, event);
}
break;
}
default:
return QObject::eventFilter(obj, event);
break;
}
}
/** Click su un link del popino, alias scelgo un capitolo da leggere
*/
void and1::on_popup_view_linkClicked(const QUrl &arg1)
{
verse* v=verse::getInstance ();
ui->popup_view->hide();
str.clear ();
str.append ("<style> a{color: #5BB6E4; text-decoration:none} </style> <a href=\"some\">");
str.append(v->book_name (id_book));
str.append(" : ");
str.append(arg1.path ());
str.append ("</a>");
ui->book_name->setText (str.toAscii ());
ui->book_name->show ();
ui->homizzah->show();
str.clear ();
str.append (css_versetti);
str.append (v->chapter(id_book,arg1.path ().toInt ()));
// qDebug (str.toAscii ());
ui->main_view->page ()->mainFrame ()->setScrollBarPolicy ( Qt::Horizontal, Qt::ScrollBarAlwaysOff);
ui->main_view->setHtml (str);
}
//Faccio click sul nome di un libro
void and1::on_book_name_linkActivated(const QString &link)
{
str.clear ();
str.append (QString::number(id_book));
capitolibox (str);
}
void and1::on_homizzah_linkActivated(const QString &link)
{
home();
ui->main_view->show();
ui->opt_frame->hide();
}
void and1::on_options_clicked()
{
ui->main_view->hide();
ui->homizzah->show();
ui->book_name->hide();
ui->opt_frame->show();
}
void and1::on_opt_salva_clicked()
{
//ui->opt_lang1
//ui->opt_lang2
if (ui->opt_interlinear->checkState() == Qt::Unchecked){
g->interlinear=false;
}
if (ui->opt_interlinear->checkState() == Qt::Checked){
g->interlinear=true;
}
}