/
HelpBrowser.cpp
65 lines (50 loc) · 2.05 KB
/
HelpBrowser.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
#include "HelpBrowser.h"
#include <QDir>
HelpBrowser::HelpBrowser(const QString &path,
const QString &page,
QWidget *parent)
: QWidget(parent)
{
setAttribute(Qt::WA_DeleteOnClose);
setAttribute(Qt::WA_GroupLeader);
textBrowser = new QTextBrowser;
homeAction = new QAction(this);
homeAction->setText(tr("&Home"));
homeAction->setToolTip(tr("Go back to home"));
homeAction->setIcon(QIcon("://icons/others_icons/help_home_32x32.png"));
backAction = new QAction(this);
backAction->setText(tr("&Back"));
backAction->setToolTip(tr("Back"));
backAction->setIcon(QIcon("://icons/others_icons/help_back_32x32.png"));
closeAction = new QAction(this);
closeAction->setText(tr("&Close"));
closeAction->setToolTip(tr("Close"));
closeAction->setIcon(QIcon("://icons/others_icons/help_close_32x32.png"));
toolBar = new QToolBar;
toolBar->addAction(homeAction);
toolBar->addAction(backAction);
toolBar->addSeparator();
toolBar->addAction(closeAction);
toolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
mainLayout = new QVBoxLayout;
mainLayout->addWidget(toolBar);
mainLayout->addWidget(textBrowser);
setLayout(mainLayout);
connect(homeAction, SIGNAL(triggered()), textBrowser, SLOT(home()));
connect(backAction, SIGNAL(triggered()), textBrowser, SLOT(backward()));
connect(closeAction, SIGNAL(triggered()), this, SLOT(close()));
connect(textBrowser, SIGNAL(sourceChanged(QUrl)), this, SLOT(updateWindowTitle()));
textBrowser->setSearchPaths(QStringList() << path << "images");
textBrowser->setSource(page);
}
void HelpBrowser::showPage(const QString &page)
{
QString path = QDir("doc").absolutePath();
HelpBrowser *showTextBrowser = new HelpBrowser(path, page);
showTextBrowser->resize(500, 400);
showTextBrowser->show();
}
void HelpBrowser::updateWindowTitle()
{
setWindowTitle(tr("Help: %1").arg(textBrowser->documentTitle()));
}