Commit a175a5f6 authored by kh's avatar kh
Browse files

Implement home page settings and help startup options.

parent 319720f4
......@@ -239,18 +239,20 @@ void CentralWidget::setLastShownPages()
QString()).toString();
const QStringList lastShownPageList = value.split(QLatin1Char('|'),
QString::SkipEmptyParts);
const int pageCount = lastShownPageList.count();
if (pageCount <= 0) {
QUrl url = helpEngine->findFile(QString::fromLatin1("qthelp://com."
"trolltech.qt.440/qdoc/index.html"));
if (!url.isValid()) {
url.setUrl(QString("qthelp://com.nokia.qtcreator.%1%2/doc/index.html").
arg(IDE_VERSION_MAJOR).arg(IDE_VERSION_MINOR));
url.setUrl(QString::fromLatin1("qthelp://com.nokia.qtcreator.%1%2/"
"doc/index.html").arg(IDE_VERSION_MAJOR).arg(IDE_VERSION_MINOR));
QString homePage = helpEngine->customValue(QLatin1String("DefaultHomePage"),
QLatin1String("about:blank")).toString();
int option = helpEngine->customValue(QLatin1String("StartOption"), 2).toInt();
if (option == 0 || option == 1 || pageCount <= 0) {
if (option == 0) {
homePage = helpEngine->customValue(QLatin1String("HomePage"),
homePage).toString();
} else if (option == 1) {
homePage = QLatin1String("about:blank");
}
setSource(url);
setSource(homePage);
return;
}
......
......@@ -29,7 +29,8 @@
#include "generalsettingspage.h"
#include <QtHelp/QHelpEngine>
#include "centralwidget.h"
#include "helpviewer.h"
#if defined(QT_NO_WEBKIT)
#include <QtGui/QApplication>
......@@ -37,11 +38,17 @@
#include <QtWebKit/QWebSettings>
#endif
#include <QtHelp/QHelpEngine>
#include <coreplugin/coreconstants.h>
using namespace Help::Internal;
GeneralSettingsPage::GeneralSettingsPage(QHelpEngine *helpEngine)
GeneralSettingsPage::GeneralSettingsPage(QHelpEngine *helpEngine,
CentralWidget *centralWidget)
: m_currentPage(0)
, m_helpEngine(helpEngine)
, m_centralWidget(centralWidget)
{
#if !defined(QT_NO_WEBKIT)
QWebSettings* webSettings = QWebSettings::globalSettings();
......@@ -87,6 +94,26 @@ QWidget *GeneralSettingsPage::createPage(QWidget *parent)
updateFontStyle();
updateFontFamily();
QString homePage = m_helpEngine->customValue(QLatin1String("HomePage"),
QString()).toString();
if (homePage.isEmpty()) {
homePage = m_helpEngine->customValue(QLatin1String("DefaultHomePage"),
QLatin1String("about:blank")).toString();
}
m_ui.homePageLineEdit->setText(homePage);
int index = m_helpEngine->customValue(QLatin1String("StartOption"), 2).toInt();
m_ui.helpStartComboBox->setCurrentIndex(index);
connect(m_ui.currentPageButton, SIGNAL(clicked()), this, SLOT(setCurrentPage()));
connect(m_ui.blankPageButton, SIGNAL(clicked()), this, SLOT(setBlankPage()));
connect(m_ui.defaultPageButton, SIGNAL(clicked()), this, SLOT(setDefaultPage()));
HelpViewer *viewer = m_centralWidget->currentHelpViewer();
if (viewer == 0)
m_ui.currentPageButton->setEnabled(false);
return m_currentPage;
}
......@@ -121,6 +148,14 @@ void GeneralSettingsPage::apply()
#else
emit fontChanged();
#endif
QString homePage = m_ui.homePageLineEdit->text();
if (homePage.isEmpty())
homePage = QLatin1String("about:blank");
m_helpEngine->setCustomValue(QLatin1String("HomePage"), homePage);
int startOption = m_ui.helpStartComboBox->currentIndex();
m_helpEngine->setCustomValue(QLatin1String("StartOption"), startOption);
}
void GeneralSettingsPage::finish()
......@@ -128,6 +163,26 @@ void GeneralSettingsPage::finish()
// Hmm, what to do here?
}
void GeneralSettingsPage::setCurrentPage()
{
HelpViewer *viewer = m_centralWidget->currentHelpViewer();
if (viewer)
m_ui.homePageLineEdit->setText(viewer->source().toString());
}
void GeneralSettingsPage::setBlankPage()
{
m_ui.homePageLineEdit->setText(QLatin1String("about:blank"));
}
void GeneralSettingsPage::setDefaultPage()
{
const QString &homePage =
m_helpEngine->customValue(QLatin1String("DefaultHomePage"),
QString()).toString();
m_ui.homePageLineEdit->setText(homePage);
}
void GeneralSettingsPage::updateFontSize()
{
const QString &family = font.family();
......
......@@ -43,12 +43,14 @@ QT_FORWARD_DECLARE_CLASS(QHelpEngine)
namespace Help {
namespace Internal {
class CentralWidget;
class GeneralSettingsPage : public Core::IOptionsPage
{
Q_OBJECT
public:
GeneralSettingsPage(QHelpEngine *helpEngine);
GeneralSettingsPage(QHelpEngine *helpEngine, CentralWidget *centralWidget);
QString id() const;
virtual QString trName() const;
......@@ -62,6 +64,11 @@ public:
signals:
void fontChanged();
private slots:
void setCurrentPage();
void setBlankPage();
void setDefaultPage();
private:
void updateFontSize();
void updateFontStyle();
......@@ -71,6 +78,7 @@ private:
private:
QWidget *m_currentPage;
QHelpEngine *m_helpEngine;
CentralWidget *m_centralWidget;
QFont font;
QFontDatabase fontDatabase;
......
......@@ -133,7 +133,7 @@
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="title">
<string>Startup</string>
......@@ -155,7 +155,7 @@
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox">
<widget class="QComboBox" name="helpStartComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
......@@ -209,7 +209,7 @@
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
......@@ -224,22 +224,25 @@
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="currentPageButton">
<property name="text">
<string>Current Page</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="restoreDefaultHomePageButton">
<property name="text">
<string>Restore to default</string>
</property>
</widget>
</item>
</layout>
<widget class="QPushButton" name="currentPageButton">
<property name="text">
<string>Use &amp;Current Page</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="blankPageButton">
<property name="text">
<string>Use &amp;Blank Page</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="defaultPageButton">
<property name="text">
<string>Restore to Default</string>
</property>
</widget>
</item>
</layout>
</item>
......
......@@ -188,10 +188,6 @@ bool HelpPlugin::initialize(const QStringList &arguments, QString *error)
connect(m_docSettingsPage, SIGNAL(dialogAccepted()), this,
SLOT(checkForHelpChanges()));
GeneralSettingsPage *generalSettings = new GeneralSettingsPage(m_helpEngine);
addAutoReleasedObject(generalSettings);
connect(generalSettings, SIGNAL(fontChanged()), this, SLOT(fontChanged()));
m_contentWidget = new ContentWindow(m_helpEngine);
m_contentWidget->setWindowTitle(tr("Contents"));
m_indexWidget = new IndexWindow(m_helpEngine);
......@@ -421,6 +417,11 @@ bool HelpPlugin::initialize(const QStringList &arguments, QString *error)
advancedMenu->addAction(cmd, Core::Constants::G_EDIT_FONT);
}
GeneralSettingsPage *generalSettings =
new GeneralSettingsPage(m_helpEngine, m_centralWidget);
addAutoReleasedObject(generalSettings);
connect(generalSettings, SIGNAL(fontChanged()), this, SLOT(fontChanged()));
return true;
}
......@@ -628,6 +629,14 @@ void HelpPlugin::extensionsInitialized()
webSettings->setFontFamily(QWebSettings::StandardFont, font.family());
webSettings->setFontSize(QWebSettings::DefaultFontSize, font.pointSize());
#endif
QUrl url = m_helpEngine->findFile(QString::fromLatin1("qthelp://com."
"trolltech.qt.440/qdoc/index.html"));
if (!url.isValid()) {
url.setUrl(QString::fromLatin1("qthelp://com.nokia.qtcreator.%1%2/doc/"
"index.html").arg(IDE_VERSION_MAJOR).arg(IDE_VERSION_MINOR));
}
m_helpEngine->setCustomValue(QLatin1String("DefaultHomePage"), url.toString());
}
void HelpPlugin::shutdown()
......
......@@ -295,8 +295,15 @@ int HelpViewer::zoom() const
void HelpViewer::home()
{
if (homeUrl.isValid())
setSource(homeUrl);
QString homepage = helpEngine->customValue(QLatin1String("HomePage"),
QLatin1String("")).toString();
if (homepage.isEmpty()) {
homepage = helpEngine->customValue(QLatin1String("DefaultHomePage"),
QLatin1String("about:blank")).toString();
}
setSource(homepage);
}
void HelpViewer::wheelEvent(QWheelEvent *e)
......@@ -552,8 +559,15 @@ void HelpViewer::keyPressEvent(QKeyEvent *e)
void HelpViewer::home()
{
if (homeUrl.isValid())
setSource(homeUrl);
QString homepage = helpEngine->customValue(QLatin1String("HomePage"),
QLatin1String("")).toString();
if (homepage.isEmpty()) {
homepage = helpEngine->customValue(QLatin1String("DefaultHomePage"),
QLatin1String("about:blank")).toString();
}
setSource(homepage);
}
void HelpViewer::wheelEvent(QWheelEvent *e)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment