Commit 3cd98b33 authored by kh1's avatar kh1

Make use of the core engine in the general settings page.

Reviewed-by: ck
parent 24c36c17
......@@ -28,41 +28,39 @@
**************************************************************************/
#include "generalsettingspage.h"
#include "helpconstants.h"
#include "bookmarkmanager.h"
#include "centralwidget.h"
#include "helpconstants.h"
#include "helpmanager.h"
#include "helpviewer.h"
#include "xbelsupport.h"
#include <coreplugin/coreconstants.h>
#include <QtCore/QCoreApplication>
#include <QtCore/QTextStream>
#if defined(QT_NO_WEBKIT)
#include <QtGui/QApplication>
#else
#include <QtWebKit/QWebSettings>
#endif
#include <QtCore/QCoreApplication>
#include <QtCore/QDebug>
#include <QtGui/QFileDialog>
#include <QtHelp/QHelpEngine>
#include <coreplugin/coreconstants.h>
#include <QtHelp/QHelpEngineCore>
using namespace Help::Internal;
GeneralSettingsPage::GeneralSettingsPage(QHelpEngine *helpEngine,
CentralWidget *centralWidget, BookmarkManager *bookmarkManager)
: m_currentPage(0)
, m_helpEngine(helpEngine)
, m_centralWidget(centralWidget)
, m_bookmarkManager(bookmarkManager)
GeneralSettingsPage::GeneralSettingsPage(BookmarkManager *bookmarkManager)
: m_bookmarkManager(bookmarkManager)
{
#if !defined(QT_NO_WEBKIT)
QWebSettings* webSettings = QWebSettings::globalSettings();
font.setFamily(webSettings->fontFamily(QWebSettings::StandardFont));
font.setPointSize(webSettings->fontSize(QWebSettings::DefaultFontSize));
m_font.setFamily(webSettings->fontFamily(QWebSettings::StandardFont));
m_font.setPointSize(webSettings->fontSize(QWebSettings::DefaultFontSize));
#else
font = qApp->font();
m_font = qApp->font();
#endif
}
......@@ -88,40 +86,37 @@ QString GeneralSettingsPage::displayCategory() const
QWidget *GeneralSettingsPage::createPage(QWidget *parent)
{
m_currentPage = new QWidget(parent);
QWidget *widget = new QWidget(parent);
m_ui.setupUi(m_currentPage);
m_ui.setupUi(widget);
m_ui.sizeComboBox->setEditable(false);
m_ui.styleComboBox->setEditable(false);
font = qVariantValue<QFont>(m_helpEngine->customValue(QLatin1String("font"),
font));
const QHelpEngineCore &engine = HelpManager::helpEngineCore();
m_font = qVariantValue<QFont>(engine.customValue(QLatin1String("font"), m_font));
updateFontSize();
updateFontStyle();
updateFontFamily();
QString homePage = m_helpEngine->customValue(QLatin1String("HomePage"),
QString()).toString();
if (homePage.isEmpty()) {
homePage = m_helpEngine->customValue(QLatin1String("DefaultHomePage"),
m_homePage = engine.customValue(QLatin1String("HomePage"), QString()).toString();
if (m_homePage.isEmpty()) {
m_homePage = engine.customValue(QLatin1String("DefaultHomePage"),
QLatin1String("about:blank")).toString();
}
m_ui.homePageLineEdit->setText(homePage);
m_ui.homePageLineEdit->setText(m_homePage);
int index = m_helpEngine->customValue(QLatin1String("StartOption"), 2).toInt();
m_ui.helpStartComboBox->setCurrentIndex(index);
index = m_helpEngine->customValue(QLatin1String("ContextHelpOption"), 0).toInt();
m_ui.contextHelpComboBox->setCurrentIndex(index);
m_startOption = engine.customValue(QLatin1String("StartOption"), 2).toInt();
m_ui.helpStartComboBox->setCurrentIndex(m_startOption);
m_helpOption = engine.customValue(QLatin1String("ContextHelpOption"), 0).toInt();
m_ui.contextHelpComboBox->setCurrentIndex(m_helpOption);
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();
HelpViewer *viewer = CentralWidget::instance()->currentHelpViewer();
if (viewer == 0)
m_ui.currentPageButton->setEnabled(false);
......@@ -135,42 +130,50 @@ QWidget *GeneralSettingsPage::createPage(QWidget *parent)
<< ' ' << m_ui.bookmarkGroupBox->title();
m_searchKeywords.remove(QLatin1Char('&'));
}
return m_currentPage;
return widget;
}
void GeneralSettingsPage::apply()
{
emit dialogAccepted();
}
bool GeneralSettingsPage::applyChanges()
{
QFont newFont;
const QString &family = m_ui.familyComboBox->currentFont().family();
font.setFamily(family);
newFont.setFamily(family);
int fontSize = 14;
int currentIndex = m_ui.sizeComboBox->currentIndex();
if (currentIndex != -1)
fontSize = m_ui.sizeComboBox->itemData(currentIndex).toInt();
font.setPointSize(fontSize);
newFont.setPointSize(fontSize);
QString fontStyle = QLatin1String("Normal");
currentIndex = m_ui.styleComboBox->currentIndex();
if (currentIndex != -1)
fontStyle = m_ui.styleComboBox->itemText(currentIndex);
font.setBold(fontDatabase.bold(family, fontStyle));
newFont.setBold(m_fontDatabase.bold(family, fontStyle));
if (fontStyle.contains(QLatin1String("Italic")))
font.setStyle(QFont::StyleItalic);
newFont.setStyle(QFont::StyleItalic);
else if (fontStyle.contains(QLatin1String("Oblique")))
font.setStyle(QFont::StyleOblique);
newFont.setStyle(QFont::StyleOblique);
else
font.setStyle(QFont::StyleNormal);
newFont.setStyle(QFont::StyleNormal);
const int weight = fontDatabase.weight(family, fontStyle);
const int weight = m_fontDatabase.weight(family, fontStyle);
if (weight >= 0) // Weight < 0 asserts...
font.setWeight(weight);
newFont.setWeight(weight);
m_helpEngine->setCustomValue(QLatin1String("font"), font);
QHelpEngineCore *engine = &HelpManager::helpEngineCore();
engine->setCustomValue(QLatin1String("font"), newFont);
bool needsUpdate = newFont != m_font;
#if !defined(QT_NO_WEBKIT)
QWebSettings* webSettings = QWebSettings::globalSettings();
webSettings->setFontFamily(QWebSettings::StandardFont, font.family());
webSettings->setFontSize(QWebSettings::DefaultFontSize, font.pointSize());
webSettings->setFontFamily(QWebSettings::StandardFont, m_font.family());
webSettings->setFontSize(QWebSettings::DefaultFontSize, m_font.pointSize());
#else
emit fontChanged();
#endif
......@@ -178,23 +181,23 @@ void GeneralSettingsPage::apply()
QString homePage = m_ui.homePageLineEdit->text();
if (homePage.isEmpty())
homePage = QLatin1String("about:blank");
m_helpEngine->setCustomValue(QLatin1String("HomePage"), homePage);
engine->setCustomValue(QLatin1String("HomePage"), homePage);
needsUpdate |= homePage != m_homePage;
int startOption = m_ui.helpStartComboBox->currentIndex();
m_helpEngine->setCustomValue(QLatin1String("StartOption"), startOption);
const int startOption = m_ui.helpStartComboBox->currentIndex();
engine->setCustomValue(QLatin1String("StartOption"), startOption);
needsUpdate |= startOption != m_startOption;
int contextHelpOption = m_ui.contextHelpComboBox->currentIndex();
m_helpEngine->setCustomValue(QLatin1String("ContextHelpOption"), contextHelpOption);
}
const int helpOption = m_ui.contextHelpComboBox->currentIndex();
engine->setCustomValue(QLatin1String("ContextHelpOption"), helpOption);
needsUpdate |= helpOption != m_helpOption;
void GeneralSettingsPage::finish()
{
// Hmm, what to do here?
return needsUpdate;
}
void GeneralSettingsPage::setCurrentPage()
{
HelpViewer *viewer = m_centralWidget->currentHelpViewer();
HelpViewer *viewer = CentralWidget::instance()->currentHelpViewer();
if (viewer)
m_ui.homePageLineEdit->setText(viewer->source().toString());
}
......@@ -206,10 +209,9 @@ void GeneralSettingsPage::setBlankPage()
void GeneralSettingsPage::setDefaultPage()
{
const QString &homePage =
m_helpEngine->customValue(QLatin1String("DefaultHomePage"),
QString()).toString();
m_ui.homePageLineEdit->setText(homePage);
const QString &defaultHomePage = HelpManager::helpEngineCore()
.customValue(QLatin1String("DefaultHomePage"), QString()).toString();
m_ui.homePageLineEdit->setText(defaultHomePage);
}
void GeneralSettingsPage::importBookmarks()
......@@ -254,10 +256,10 @@ void GeneralSettingsPage::exportBookmarks()
void GeneralSettingsPage::updateFontSize()
{
const QString &family = font.family();
const QString &fontStyle = fontDatabase.styleString(font);
const QString &family = m_font.family();
const QString &fontStyle = m_fontDatabase.styleString(m_font);
QList<int> pointSizes = fontDatabase.pointSizes(family, fontStyle);
QList<int> pointSizes = m_fontDatabase.pointSizes(family, fontStyle);
if (pointSizes.empty())
pointSizes = QFontDatabase::standardSizes();
......@@ -270,7 +272,7 @@ void GeneralSettingsPage::updateFontSize()
QString n;
foreach (int pointSize, pointSizes)
m_ui.sizeComboBox->addItem(n.setNum(pointSize), QVariant(pointSize));
const int closestIndex = closestPointSizeIndex(font.pointSize());
const int closestIndex = closestPointSizeIndex(m_font.pointSize());
if (closestIndex != -1)
m_ui.sizeComboBox->setCurrentIndex(closestIndex);
}
......@@ -278,8 +280,8 @@ void GeneralSettingsPage::updateFontSize()
void GeneralSettingsPage::updateFontStyle()
{
const QString &fontStyle = fontDatabase.styleString(font);
const QStringList &styles = fontDatabase.styles(font.family());
const QString &fontStyle = m_fontDatabase.styleString(m_font);
const QStringList &styles = m_fontDatabase.styles(m_font.family());
m_ui.styleComboBox->clear();
m_ui.styleComboBox->setCurrentIndex(-1);
......@@ -306,7 +308,7 @@ void GeneralSettingsPage::updateFontStyle()
void GeneralSettingsPage::updateFontFamily()
{
m_ui.familyComboBox->setCurrentFont(font);
m_ui.familyComboBox->setCurrentFont(m_font);
}
int GeneralSettingsPage::closestPointSizeIndex(int desiredPointSize) const
......
......@@ -30,18 +30,11 @@
#ifndef GENERALSETTINGSPAGE_H
#define GENERALSETTINGSPAGE_H
#include <QtGui/QWidget>
#include <QtGui/QFontDatabase>
#include <coreplugin/dialogs/ioptionspage.h>
#include "ui_generalsettingspage.h"
#include <coreplugin/dialogs/ioptionspage.h>
class BookmarkManager;
QT_FORWARD_DECLARE_CLASS(QFont)
QT_FORWARD_DECLARE_CLASS(QHelpEngine)
namespace Help {
namespace Internal {
......@@ -52,8 +45,7 @@ class GeneralSettingsPage : public Core::IOptionsPage
Q_OBJECT
public:
GeneralSettingsPage(QHelpEngine *helpEngine, CentralWidget *centralWidget,
BookmarkManager *bookmarkManager);
GeneralSettingsPage(BookmarkManager *bookmarkManager);
QString id() const;
virtual QString displayName() const;
......@@ -62,11 +54,14 @@ public:
QWidget *createPage(QWidget *parent);
void apply();
void finish();
void finish() {}
virtual bool matches(const QString &s) const;
bool applyChanges();
signals:
void fontChanged();
void dialogAccepted();
private slots:
void setCurrentPage();
......@@ -82,16 +77,17 @@ private:
int closestPointSizeIndex(int desiredPointSize) const;
private:
QWidget *m_currentPage;
QHelpEngine *m_helpEngine;
CentralWidget *m_centralWidget;
BookmarkManager *m_bookmarkManager;
QFont m_font;
QFontDatabase m_fontDatabase;
QFont font;
QFontDatabase fontDatabase;
int m_helpOption;
int m_startOption;
QString m_homePage;
Ui::GeneralSettingsPage m_ui;
QString m_searchKeywords;
Ui::GeneralSettingsPage m_ui;
BookmarkManager *m_bookmarkManager;
};
} // Internal
......
......@@ -400,11 +400,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, m_bookmarkManager);
addAutoReleasedObject(generalSettings);
connect(generalSettings, SIGNAL(fontChanged()), this, SLOT(fontChanged()));
generalSettingsPage = new GeneralSettingsPage(m_bookmarkManager);
addAutoReleasedObject(generalSettingsPage);
connect(generalSettingsPage, SIGNAL(fontChanged()), this, SLOT(fontChanged()));
connect(generalSettingsPage, SIGNAL(dialogAccepted()), this,
SLOT(checkForGeneralChanges()));
return true;
}
......@@ -980,6 +980,12 @@ void HelpPlugin::checkForHelpChanges()
m_helpEngine->setupData();
}
void HelpPlugin::checkForGeneralChanges()
{
if (generalSettingsPage->applyChanges())
m_helpEngine->setupData();
}
void HelpPlugin::filterDocumentation(const QString &customFilter)
{
m_helpEngine->setCurrentFilter(customFilter);
......
......@@ -73,6 +73,7 @@ class CentralWidget;
class DocSettingsPage;
class FilterSettingsPage;
class HelpMode;
class GeneralSettingsPage;
class SearchWidget;
class HelpPlugin : public ExtensionSystem::IPlugin
......@@ -106,6 +107,7 @@ private slots:
void activateContents();
void activateSearch();
void checkForHelpChanges();
void checkForGeneralChanges();
void updateFilterComboBox();
void filterDocumentation(const QString &customFilter);
void addBookmark();
......@@ -159,6 +161,7 @@ private:
DocSettingsPage *m_docSettingsPage;
FilterSettingsPage *m_filterSettingsPage;
GeneralSettingsPage *generalSettingsPage;
QComboBox *m_documentsCombo;
QComboBox *m_filterComboBox;
......
Markdown is supported
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