00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <QtGui>
00026
00027 #include "helpbrowser.h"
00028
00029 HelpBrowser::HelpBrowser(const QString &path,
00030 const QString &page,
00031 QWidget *parent)
00032 : QWidget(parent)
00033 {
00034 setAttribute(Qt::WA_DeleteOnClose);
00035 setAttribute(Qt::WA_GroupLeader);
00036
00037 textBrowser = new QTextBrowser;
00038
00039 homeButton = new QPushButton(tr("&Home"));
00040 backButton = new QPushButton(tr("&Back"));
00041 closeButton = new QPushButton(tr("Close"));
00042 closeButton->setShortcut(tr("Esc"));
00043
00044 QHBoxLayout *buttonLayout = new QHBoxLayout;
00045 buttonLayout->addWidget(homeButton);
00046 buttonLayout->addWidget(backButton);
00047 buttonLayout->addStretch();
00048 buttonLayout->addWidget(closeButton);
00049
00050 QVBoxLayout *mainLayout = new QVBoxLayout;
00051 mainLayout->addLayout(buttonLayout);
00052 mainLayout->addWidget(textBrowser);
00053 setLayout(mainLayout);
00054
00055 connect(homeButton, SIGNAL(clicked()), textBrowser, SLOT(home()));
00056 connect(backButton, SIGNAL(clicked()), textBrowser, SLOT(backward()));
00057 connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
00058 connect(textBrowser, SIGNAL(sourceChanged(QUrl)),
00059 this, SLOT(updateWindowTitle()));
00060
00061 textBrowser->setSearchPaths(QStringList() << path << ":/ourstyle");
00062 textBrowser->setSource(page);
00063 }
00064
00065 void HelpBrowser::updateWindowTitle()
00066 {
00067 setWindowTitle(tr("Help: %1").arg(textBrowser->documentTitle()));
00068 }
00069
00070 void HelpBrowser::showPage(const QString& page)
00071 {
00072 QString path = QApplication::applicationDirPath() + "/doc";
00073 HelpBrowser *browser = new HelpBrowser(path, page);
00074 browser->resize(500,400);
00075 browser->show();
00076 }