X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=src%2Fhelp%2Fhelp.cpp;h=9645f411e9559827b554d7e5020b70c330e72b80;hb=refs%2Ftags%2F3.4-b1;hp=d2cf4f0de5ef139ad48c42c146848c884a83e940;hpb=c93d8517f5609af29641b70460f61fb1363f468e;p=vlp.git diff --git a/src/help/help.cpp b/src/help/help.cpp index d2cf4f0..9645f41 100644 --- a/src/help/help.cpp +++ b/src/help/help.cpp @@ -1,32 +1,31 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +// #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #define TAG_TEXT 0 @@ -73,7 +72,7 @@ public: class HTMLAnalyzer { public: - QList tags; + QList tags; bool verbatim; HTMLAnalyzer(); @@ -106,7 +105,7 @@ bool HTMLAnalyzer::LoadFile(char *fname) QTextStream fs(&f); - while (!fs.eof()) { + while (!fs.atEnd()) { poms = fs.readLine(); while (poms.length()>0) { i = poms.find('<'); @@ -119,8 +118,7 @@ bool HTMLAnalyzer::LoadFile(char *fname) poms1 = poms1.simplifyWhiteSpace(); } - sprintf(pomt->tag_text, " %s", - poms1.data()); + sprintf(pomt->tag_text, " %s", poms1.toStdString().c_str()); tags.append(pomt); } poms = poms.right(poms.length() - i); @@ -140,7 +138,7 @@ bool HTMLAnalyzer::LoadFile(char *fname) if (!verbatim) poms=poms.simplifyWhiteSpace(); - sprintf(pomt->tag_text, " %s", poms.data()); + sprintf(pomt->tag_text, " %s", poms.toStdString().c_str()); tags.append(pomt); break; } @@ -164,42 +162,42 @@ void HTMLAnalyzer::AnalyzeTag(QString *t) *t = t->simplifyWhiteSpace(); pom = new Tag; - if ((t->data()[0] != 'A') && (t->data()[0] != 'a')) { + if ((t->toStdString().c_str()[0] != 'A') && (t->toStdString().c_str()[0] != 'a')) { *t = t->upper(); - if (strcmp(t->data(), "B") ==0 ) { + if (strcmp(t->toStdString().c_str(), "B") ==0 ) { pom->tag_type = TAG_BOLD_ON; } - else if (strcmp(t->data(), "/B") == 0) { + else if (strcmp(t->toStdString().c_str(), "/B") == 0) { pom->tag_type = TAG_BOLD_OFF; } - else if (strcmp(t->data(), "I") == 0) { + else if (strcmp(t->toStdString().c_str(), "I") == 0) { pom->tag_type = TAG_ITALIC_ON; } - else if (strcmp(t->data(), "/I") == 0) { + else if (strcmp(t->toStdString().c_str(), "/I") == 0) { pom->tag_type = TAG_ITALIC_OFF; } - else if (strcmp(t->data(), "BR") == 0) { + else if (strcmp(t->toStdString().c_str(), "BR") == 0) { pom->tag_type = TAG_BREAK; } - else if (strcmp(t->data(), "HR") == 0) { + else if (strcmp(t->toStdString().c_str(), "HR") == 0) { pom->tag_type = TAG_LINE; } - else if (strcmp(t->data(), "/A") == 0) { + else if (strcmp(t->toStdString().c_str(), "/A") == 0) { pom->tag_type = TAG_LINK_END; } - else if (strcmp(t->data(), "UL") == 0) { + else if (strcmp(t->toStdString().c_str(), "UL") == 0) { pom->tag_type = TAG_LIST_ON; } - else if (strcmp(t->data(), "/UL") == 0) { + else if (strcmp(t->toStdString().c_str(), "/UL") == 0) { pom->tag_type = TAG_LIST_OFF; } - else if (strcmp(t->data(), "LI") == 0) { + else if (strcmp(t->toStdString().c_str(), "LI") == 0) { pom->tag_type = TAG_LIST_ITEM; } - else if (strcmp(t->data(), "PRE") == 0) { + else if (strcmp(t->toStdString().c_str(), "PRE") == 0) { verbatim=TRUE; } - else if (strcmp(t->data(),"/PRE") == 0) { + else if (strcmp(t->toStdString().c_str(),"/PRE") == 0) { verbatim=FALSE; } } else { @@ -215,17 +213,17 @@ void HTMLAnalyzer::AnalyzeTag(QString *t) poms1 = t->right(t->length() - i - 1); poms1 = poms1.simplifyWhiteSpace(); - if (strcmp(poms.data(),"HREF") == 0) { + if (poms == "HREF") { pom->tag_type = TAG_LINK; - strcpy(pom->tag_link,poms1.data()); + strcpy(pom->tag_link,poms1.toStdString().c_str()); } - else if (strcmp(poms.data(), "NAME") == 0) { + else if (poms == "NAME") { pom->tag_type = TAG_ANCHOR; - if (poms1.data()[0] == '"') + if (poms1[0] == '"') poms1=poms1.right(poms1.length() - 1); - if (poms1.data()[poms1.length() - 1] == '"') + if (poms1[poms1.length() - 1] == '"') poms1=poms1.left(poms1.length() - 1); - strcpy(pom->tag_label, poms1.data()); + strcpy(pom->tag_label, poms1.toStdString().c_str()); } } } @@ -235,11 +233,12 @@ void HTMLAnalyzer::AnalyzeTag(QString *t) void HTMLAnalyzer::DumpList() { Tag *pom; - pom = tags.first(); - while (pom != NULL) { + QListIterator tagsIterator(tags); + + while (tagsIterator.hasNext()) { + pom = tagsIterator.next(); fprintf(stderr, "%s:%s,%s,%s\n", names[pom->tag_type], pom->tag_text, pom->tag_link, pom->tag_label); - pom=tags.next(); } } @@ -247,25 +246,26 @@ void HTMLAnalyzer::PackLinks() { Tag *pom,*pom1; char s[255]; + QListIterator tagsIterator(tags); - pom = tags.first(); - while (pom!=NULL) { + while (tagsIterator.hasNext()) { + pom = tagsIterator.next(); if ((pom->tag_type == TAG_LINK) || (pom->tag_type == TAG_ANCHOR)) { - pom1 = tags.next(); + pom1 = tagsIterator.next(); strcpy(s, ""); while ((pom1 != NULL) && (pom1->tag_type != TAG_LINK_END)) { if (pom1->tag_type == TAG_TEXT) strcat(s,pom1->tag_text); - tags.remove(pom1); + tags.removeOne(pom1); pom1 = tags.current(); } strcpy(pom->tag_text,s); - tags.remove(pom1); + tags.removeOne(pom1); pom = tags.current(); } else { - pom = tags.next(); + pom = tagsIterator.next(); } } } @@ -274,14 +274,15 @@ void HTMLAnalyzer::PackLinks() Tag *HTMLAnalyzer::CheckTag(int x,int y) { Tag *pom; - pom=tags.first(); - while (pom != NULL) { + QListIterator tagsIterator(tags); + + while (tagsIterator.hasNext()) { + pom = tagsIterator.next(); if (pom->tag_type==TAG_LINK) if ((x >= pom->x) && (x <= pom->x + pom->w) && (y >= pom->y) && (y <= pom->y + pom->h)) { return pom; } - pom=tags.next(); } return NULL; } @@ -289,19 +290,20 @@ Tag *HTMLAnalyzer::CheckTag(int x,int y) Tag *HTMLAnalyzer::FindAnchor(char *name) { Tag *pom; - pom = tags.first(); - while (pom != NULL) { + QListIterator tagsIterator(tags); + + while (tagsIterator.hasNext()) { + pom = tagsIterator.next(); if ((pom->tag_type == TAG_ANCHOR) && (strcmp(pom->tag_label, name) == 0)) { return(pom); } - pom=tags.next(); } return pom; } /********************************/ -class QHTML: public QFrame { +class QHTML: public QMainWindow { Q_OBJECT public: QScrollBar *vscroll; @@ -332,7 +334,6 @@ QApplication *app; QHTML::QHTML(char *d) { - QPopupMenu *pp; char s[255]; QFont f("Helvetica", 12, QFont::Bold); @@ -343,19 +344,18 @@ QHTML::QHTML(char *d) strcpy(homedir, d); actual_font = normal; - bar = new QMenuBar(this); - pp = new QPopupMenu; - pp->insertItem("Index", this, SLOT(contents())); - pp->insertItem("User Guide", this, SLOT(user_guide())); - pp->insertItem("Language reference", this, SLOT(lang_guide())); - pp->setFont(f); - /*pp->setStyle(WindowsStyle);*/ - bar->insertItem("File", this, SLOT(load())); - bar->insertItem("Contents", pp); - bar->insertItem("Quit", app, SLOT(quit())); - bar->setFont(f); - setCaption("LOGLAN Help"); - setBackgroundColor(gray); + + setWindowTitle("LOGLAN Help"); + + QMenu * contentsMenu = NULL; + menuBar()->addAction("File", this, SLOT(load())); + contentsMenu = menuBar()->addMenu("&Contents"); + contentsMenu->addAction("Index", this, SLOT(contents())); + contentsMenu->addAction("User Guide", this, SLOT(user_guide())); + contentsMenu->addAction("Language reference", this, SLOT(lang_guide())); + + menuBar()->addAction("Quit", app, SLOT(quit())); + analyzer = new HTMLAnalyzer; map = new QPixmap(500, PIX_HEIGHT); map->fill(backgroundColor()); @@ -364,12 +364,10 @@ QHTML::QHTML(char *d) oy = 0; lstep = 10; pstep = height() - bar->height(); - vscroll = new QScrollBar(0, PIX_HEIGHT, lstep, pstep, 0, - QScrollBar::Vertical, this); + vscroll = new QScrollBar(0, PIX_HEIGHT, lstep, pstep, 0, QScrollBar::Vertical, this); vscroll->setTracking(TRUE); - vscroll->setGeometry(width() - 16, bar->height(), 16, - height()-bar->height()); - connect(vscroll, SIGNAL(valueChanged(int)), this, SLOT(vscrolled(int))); + vscroll->setGeometry(width() - 16, bar->height(), 16, height()-bar->height()); + connect(vscroll, SIGNAL(valueChanged(int)), this, SLOT(vscrolled(int))); sprintf(s, "%s/index.html", homedir); analyzer->LoadFile(s); analyzer->PackLinks(); @@ -442,18 +440,18 @@ void QHTML::mousePressEvent(QMouseEvent *ev) pom = analyzer->CheckTag(ev->x(), ev->y() + oy); if (pom != NULL) { poms.sprintf(pom->tag_link); - if (poms.data()[0] == '"') + if (poms[0] == '"') poms = poms.right(poms.length() - 1); - if (poms.data()[poms.length() - 1] == '"') + if (poms[poms.length() - 1] == '"') poms=poms.left(poms.length() - 1); - if (poms.data()[0] == '#') { + if (poms[0] == '#') { poms = poms.right(poms.length() - 1); pom1 = analyzer->FindAnchor((char*)poms.ascii()); if (pom1 != NULL) { vscroll->setValue(pom1->y); } } else { - sprintf(ss, "%s/%s", homedir, poms.data()); + sprintf(ss, "%s/%s", homedir, poms.toStdString().c_str()); analyzer->LoadFile(ss); analyzer->PackLinks(); DrawList(); @@ -479,8 +477,10 @@ void QHTML::DrawList() map->fill(backgroundColor()); p.begin(map); - pom = analyzer->tags.first(); - while (pom != NULL) { + QListIterator tagsIterator(tags); + + while (tagsIterator.hasNext()) { + pom = tagsIterator.next(); switch(pom->tag_type) { case TAG_TEXT: p.setFont(*actual_font); @@ -582,7 +582,6 @@ void QHTML::DrawList() cy = cy + p.fontMetrics().height(); break; } - pom = analyzer->tags.next(); } p.end(); repaint(); @@ -602,7 +601,7 @@ int main( int argc, char **argv ) ps.sprintf("."); QHTML cfg((char*)ps.ascii()); //app->setStyle(WindowsStyle); - app->setMainWidget(&cfg); +// app->setMainWidget(&cfg); cfg.show(); return app->exec(); }