From 4d6b7bea2e4a98e978d76cd2d4f7a48be390952f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 25 Aug 2010 20:08:07 +0200 Subject: [PATCH] GUI: some fixes of help * moved the help file to the application folder * use absolute path instead of relative path for helpfile * show warning messages if help file doesn't exist or fails to be loaded --- gui/helpwindow.cpp | 48 ++++++++++++++++++++++++++-------------------- gui/helpwindow.h | 6 ++++++ gui/mainwindow.cpp | 16 ++++++++++++++++ 3 files changed, 49 insertions(+), 21 deletions(-) diff --git a/gui/helpwindow.cpp b/gui/helpwindow.cpp index 6f603d455..484887c83 100644 --- a/gui/helpwindow.cpp +++ b/gui/helpwindow.cpp @@ -52,30 +52,36 @@ HelpWindow::HelpWindow(QWidget *parent) : m_ui(new Ui::HelpWindow) { m_ui->setupUi(this); + helpEngine = NULL; +} - setVisible(true); - - helpEngine = new QHelpEngine("help/online-help.qhc", this); - if (helpEngine->setupData()) +bool HelpWindow::load(const QString &helpFile) +{ + helpEngine = new QHelpEngine(helpFile, this); + if (!helpEngine->setupData()) { - QSplitter *helpPanel = new QSplitter(Qt::Horizontal); - HelpBrowser *helpBrowser = new HelpBrowser(helpEngine, this); - - helpPanel->insertWidget(0, helpEngine->contentWidget()); - helpPanel->insertWidget(1, helpBrowser); - helpPanel->setStretchFactor(1, 1); - - m_ui->mainLayout->addWidget(helpPanel); - - connect(helpEngine->contentWidget(), SIGNAL(linkActivated(const QUrl &)), - helpBrowser, SLOT(setSource(const QUrl &))); - - connect(m_ui->backButton, SIGNAL(clicked()), helpBrowser, SLOT(backward())); - connect(m_ui->forwardButton, SIGNAL(clicked()), helpBrowser, SLOT(forward())); - connect(m_ui->homeButton, SIGNAL(clicked()), helpBrowser, SLOT(home())); - //connect(m_ui->zoomInButton, SIGNAL(clicked()), helpBrowser, SLOT(zoomIn())); - //connect(m_ui->zoomOutButton, SIGNAL(clicked()), helpBrowser, SLOT(zoomOut())); + return false; } + + QSplitter *helpPanel = new QSplitter(Qt::Horizontal); + HelpBrowser *helpBrowser = new HelpBrowser(helpEngine, this); + + helpPanel->insertWidget(0, helpEngine->contentWidget()); + helpPanel->insertWidget(1, helpBrowser); + helpPanel->setStretchFactor(1, 1); + + m_ui->mainLayout->addWidget(helpPanel); + + connect(helpEngine->contentWidget(), SIGNAL(linkActivated(const QUrl &)), + helpBrowser, SLOT(setSource(const QUrl &))); + + connect(m_ui->backButton, SIGNAL(clicked()), helpBrowser, SLOT(backward())); + connect(m_ui->forwardButton, SIGNAL(clicked()), helpBrowser, SLOT(forward())); + connect(m_ui->homeButton, SIGNAL(clicked()), helpBrowser, SLOT(home())); + //connect(m_ui->zoomInButton, SIGNAL(clicked()), helpBrowser, SLOT(zoomIn())); + //connect(m_ui->zoomOutButton, SIGNAL(clicked()), helpBrowser, SLOT(zoomOut())); + + return true; } HelpWindow::~HelpWindow() diff --git a/gui/helpwindow.h b/gui/helpwindow.h index 5d3ddb073..1b9067477 100644 --- a/gui/helpwindow.h +++ b/gui/helpwindow.h @@ -41,6 +41,12 @@ public: HelpWindow(QWidget *parent = 0); ~HelpWindow(); + /** + * load a *.qhc file and setup GUI. the file must exist. + * @return false if loading failed + */ + bool load(const QString &helpFile); + private: Ui::HelpWindow *m_ui; diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index ce6874da5..422174147 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -684,7 +684,23 @@ void MainWindow::OpenHelpContents() void MainWindow::OpenHtmlHelpContents() { if (mHelpWindow == NULL) + { + const QString fname = qApp->applicationDirPath() + "/online-help.qhc"; + if (!QFileInfo(fname).exists()) + { + QMessageBox::warning(this, tr("Cppcheck Help"), tr("Failed to load help file (not found)")); + return; + } + mHelpWindow = new HelpWindow; + if (!mHelpWindow->load(fname)) + { + delete mHelpWindow; + mHelpWindow = NULL; + QMessageBox::warning(this, tr("Cppcheck Help"), tr("Failed to load help file")); + return; + } + } mHelpWindow->show(); if (!mHelpWindow->isActiveWindow())