38 #define TAG_BOLD_OFF 5
39 #define TAG_ITALIC_ON 6
40 #define TAG_ITALIC_OFF 7
43 #define TAG_LINK_END 10
44 #define TAG_LIST_ON 11
45 #define TAG_LIST_OFF 12
46 #define TAG_LIST_ITEM 13
48 #define PIX_HEIGHT 2000
50 char names[14][40] = {
51 "text", "other", "link", "anchor", "bold on",
52 "bold off", "italic on", "italic off", "break",
53 "line", "end link", "list on", "list off", "list item"
61 strcpy(tag_label, "");
83 void AnalyzeTag(QString*);
86 Tag *CheckTag(int, int);
87 Tag *FindAnchor(char*);
90 HTMLAnalyzer::HTMLAnalyzer()
97 bool HTMLAnalyzer::LoadFile(char *fname)
106 if (!f.open(IO_ReadOnly))
112 poms = fs.readLine();
113 while (poms.length()>0) {
117 poms1 = poms.left(i);
119 pomt->tag_type = TAG_TEXT;
121 poms1 = poms1.simplifyWhiteSpace();
124 sprintf(pomt->tag_text, " %s",
128 poms = poms.right(poms.length() - i);
132 poms1 = poms.mid(1, i - 1);
134 poms = poms.right(poms.length() - i -1);
141 pomt->tag_type = TAG_TEXT;
143 poms=poms.simplifyWhiteSpace();
145 sprintf(pomt->tag_text, " %s", poms.data());
149 }/* while length>0 */
152 pomt->tag_type = TAG_BREAK;
160 void HTMLAnalyzer::AnalyzeTag(QString *t)
166 *t = t->simplifyWhiteSpace();
169 if ((t->data()[0] != 'A') && (t->data()[0] != 'a')) {
171 if (strcmp(t->data(), "B") ==0 ) {
172 pom->tag_type = TAG_BOLD_ON;
174 else if (strcmp(t->data(), "/B") == 0) {
175 pom->tag_type = TAG_BOLD_OFF;
177 else if (strcmp(t->data(), "I") == 0) {
178 pom->tag_type = TAG_ITALIC_ON;
180 else if (strcmp(t->data(), "/I") == 0) {
181 pom->tag_type = TAG_ITALIC_OFF;
183 else if (strcmp(t->data(), "BR") == 0) {
184 pom->tag_type = TAG_BREAK;
186 else if (strcmp(t->data(), "HR") == 0) {
187 pom->tag_type = TAG_LINE;
189 else if (strcmp(t->data(), "/A") == 0) {
190 pom->tag_type = TAG_LINK_END;
192 else if (strcmp(t->data(), "UL") == 0) {
193 pom->tag_type = TAG_LIST_ON;
195 else if (strcmp(t->data(), "/UL") == 0) {
196 pom->tag_type = TAG_LIST_OFF;
198 else if (strcmp(t->data(), "LI") == 0) {
199 pom->tag_type = TAG_LIST_ITEM;
201 else if (strcmp(t->data(), "PRE") == 0) {
204 else if (strcmp(t->data(),"/PRE") == 0) {
214 poms = t->mid(2, i - 2);
215 poms = poms.simplifyWhiteSpace();
217 poms1 = t->right(t->length() - i - 1);
218 poms1 = poms1.simplifyWhiteSpace();
220 if (strcmp(poms.data(),"HREF") == 0) {
221 pom->tag_type = TAG_LINK;
222 strcpy(pom->tag_link,poms1.data());
224 else if (strcmp(poms.data(), "NAME") == 0) {
225 pom->tag_type = TAG_ANCHOR;
226 if (poms1.data()[0] == '"')
227 poms1=poms1.right(poms1.length() - 1);
228 if (poms1.data()[poms1.length() - 1] == '"')
229 poms1=poms1.left(poms1.length() - 1);
230 strcpy(pom->tag_label, poms1.data());
237 void HTMLAnalyzer::DumpList()
241 while (pom != NULL) {
242 fprintf(stderr, "%s:%s,%s,%s\n", names[pom->tag_type],
243 pom->tag_text, pom->tag_link, pom->tag_label);
248 void HTMLAnalyzer::PackLinks()
255 if ((pom->tag_type == TAG_LINK) ||
256 (pom->tag_type == TAG_ANCHOR)) {
259 while ((pom1 != NULL) &&
260 (pom1->tag_type != TAG_LINK_END)) {
261 if (pom1->tag_type == TAG_TEXT)
262 strcat(s,pom1->tag_text);
264 pom1 = tags.current();
266 strcpy(pom->tag_text,s);
268 pom = tags.current();
276 Tag *HTMLAnalyzer::CheckTag(int x,int y)
280 while (pom != NULL) {
281 if (pom->tag_type==TAG_LINK)
282 if ((x >= pom->x) && (x <= pom->x + pom->w) &&
283 (y >= pom->y) && (y <= pom->y + pom->h)) {
291 Tag *HTMLAnalyzer::FindAnchor(char *name)
295 while (pom != NULL) {
296 if ((pom->tag_type == TAG_ANCHOR) &&
297 (strcmp(pom->tag_label, name) == 0)) {
304 /********************************/
306 class QHTML: public QFrame {
311 HTMLAnalyzer *analyzer;
313 int cx,cy,oy,lstep,pstep;
315 QFont *normal,*bold,*italic,*bold_italic,*actual_font;
320 virtual void paintEvent(QPaintEvent *ev);
321 virtual void resizeEvent(QResizeEvent *ev);
322 virtual void mousePressEvent(QMouseEvent *ev);
335 QHTML::QHTML(char *d)
340 QFont f("Helvetica", 12, QFont::Bold);
341 normal = new QFont("Helvetica", 12, QFont::Normal);
342 bold = new QFont("Helvetica", 12, QFont::Bold);
343 italic = new QFont("Helvetica", 12, QFont::Normal, TRUE);
344 bold_italic = new QFont("Helvetica", 12, QFont::Bold, TRUE);
347 actual_font = normal;
348 bar = new QMenuBar(this);
350 pp->insertItem("Index", this, SLOT(contents()));
351 pp->insertItem("User Guide", this, SLOT(user_guide()));
352 pp->insertItem("Language reference", this, SLOT(lang_guide()));
354 /*pp->setStyle(WindowsStyle);*/
355 bar->insertItem("File", this, SLOT(load()));
356 bar->insertItem("Contents", pp);
357 bar->insertItem("Quit", app, SLOT(quit()));
359 setCaption("LOGLAN Help");
360 setBackgroundColor(gray);
361 analyzer = new HTMLAnalyzer;
362 map = new QPixmap(500, PIX_HEIGHT);
363 map->fill(backgroundColor());
364 resize(500, height());
365 setFixedSize(width(), height());
368 pstep = height() - bar->height();
369 vscroll = new QScrollBar(0, PIX_HEIGHT, lstep, pstep, 0,
370 QScrollBar::Vertical, this);
371 vscroll->setTracking(TRUE);
372 vscroll->setGeometry(width() - 16, bar->height(), 16,
373 height()-bar->height());
374 connect(vscroll, SIGNAL(valueChanged(int)), this, SLOT(vscrolled(int)));
375 sprintf(s, "%s/index.html", homedir);
376 analyzer->LoadFile(s);
377 analyzer->PackLinks();
381 void QHTML::vscrolled(int v)
389 QString s(QFileDialog::getOpenFileName(homedir, "*", this));
391 vscroll->setValue(0);
392 analyzer->LoadFile((char*)s.ascii());
393 analyzer->PackLinks();
398 void QHTML::contents()
401 sprintf(ss, "%s/index.html", homedir);
402 analyzer->LoadFile(ss);
403 analyzer->PackLinks();
407 void QHTML::user_guide()
410 sprintf(ss, "%s/userg.html", homedir);
411 analyzer->LoadFile(ss);
412 analyzer->PackLinks();
416 void QHTML::lang_guide()
419 sprintf(ss, "%s/langg.html", homedir);
420 analyzer->LoadFile(ss);
421 analyzer->PackLinks();
425 void QHTML::paintEvent(QPaintEvent *ev)
428 bitBlt(this, 0, bar->height(), map, 0, oy,
429 width() - 16, height() - 16);
433 void QHTML::resizeEvent(QResizeEvent *ev)
438 void QHTML::mousePressEvent(QMouseEvent *ev)
444 pom = analyzer->CheckTag(ev->x(), ev->y() + oy);
446 poms.sprintf(pom->tag_link);
447 if (poms.data()[0] == '"')
448 poms = poms.right(poms.length() - 1);
449 if (poms.data()[poms.length() - 1] == '"')
450 poms=poms.left(poms.length() - 1);
451 if (poms.data()[0] == '#') {
452 poms = poms.right(poms.length() - 1);
453 pom1 = analyzer->FindAnchor((char*)poms.ascii());
455 vscroll->setValue(pom1->y);
458 sprintf(ss, "%s/%s", homedir, poms.data());
459 analyzer->LoadFile(ss);
460 analyzer->PackLinks();
470 void QHTML::DrawList()
475 if (!analyzer->tags.isEmpty()) {
478 map->fill(backgroundColor());
481 pom = analyzer->tags.first();
482 while (pom != NULL) {
483 switch(pom->tag_type) {
485 p.setFont(*actual_font);
486 if (cx + p.fontMetrics().width(pom->tag_text) >
489 cy = cy + p.fontMetrics().height();
491 p.drawText(cx, cy, pom->tag_text);
492 cx = cx + p.fontMetrics().width(pom->tag_text);
495 p.setFont(*actual_font);
496 cy = cy + p.fontMetrics().height();
500 if (actual_font == bold)
501 actual_font = bold_italic;
503 actual_font = italic;
507 if (actual_font == bold_italic)
510 actual_font = normal;
514 if (actual_font == italic)
515 actual_font = bold_italic;
521 if (actual_font == bold_italic)
522 actual_font = italic;
524 actual_font = normal;
528 p.setFont(*actual_font);
529 if (cx + p.fontMetrics().width(pom->tag_text) >
532 cy = cy + p.fontMetrics().height();
534 p.setPen(QColor(255, 0, 0));
535 p.drawText(cx, cy, pom->tag_text);
537 pom->y = cy + p.fontMetrics().height();
538 pom->w = p.fontMetrics().width(pom->tag_text);
539 pom->h = p.fontMetrics().height();
540 p.setPen(QColor(0, 0, 0));
541 cx = cx + p.fontMetrics().width(pom->tag_text);
544 p.setFont(*actual_font);
545 if (cx + p.fontMetrics().width(pom->tag_text) >
548 cy = cy + p.fontMetrics().height();
550 //p.setPen(QColor(0,255,0));
551 p.drawText(cx, cy, pom->tag_text);
553 pom->y = cy - p.fontMetrics().height();
554 pom->w = p.fontMetrics().width(pom->tag_text);
555 pom->h = p.fontMetrics().height();
556 p.setPen(QColor(0, 0, 0));
557 cx=cx + p.fontMetrics().width(pom->tag_text);
561 p.setFont(*actual_font);
563 cy = cy + p.fontMetrics().height();
565 case TAG_LIST_ITEM:p.setFont(*actual_font);
566 p.setBrush(QBrush(QColor(0, 0, 255)));
568 cy = cy + p.fontMetrics().height();
569 p.drawPie(cx, cy - 5, 5, 5, 0, 5760);
573 p.setFont(*actual_font);
575 cy = cy + p.fontMetrics().height();
577 (int)(p.fontMetrics().height() / 2),
578 width() - 16 - 5, cy -
579 (int)(p.fontMetrics().height() / 2));
581 cy = cy + p.fontMetrics().height();
584 pom = analyzer->tags.next();
593 int main( int argc, char **argv )
597 app = new QApplication(argc, argv);
602 QHTML cfg((char*)ps.ascii());
603 //app->setStyle(WindowsStyle);
604 app->setMainWidget(&cfg);