summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorkh1 <qt-info@nokia.com>2009-11-09 10:50:10 (GMT)
committerkh1 <qt-info@nokia.com>2009-11-09 10:52:28 (GMT)
commitb183a1d916b42e174da1d4ee71d387b6b8c48f72 (patch)
treec61729f34a642bcd8304cd4b3b659a65cd418c90 /tools
parent46a9b3e8e627b63b6d2ffe89311c00b2a1a5434d (diff)
downloadQt-b183a1d916b42e174da1d4ee71d387b6b8c48f72.zip
Qt-b183a1d916b42e174da1d4ee71d387b6b8c48f72.tar.gz
Qt-b183a1d916b42e174da1d4ee71d387b6b8c48f72.tar.bz2
Fix Assistant losing font settings across invocations.
Task-number: QTBUG-5333 Reviewed-by: ck
Diffstat (limited to 'tools')
-rw-r--r--tools/assistant/tools/assistant/centralwidget.cpp120
-rw-r--r--tools/assistant/tools/assistant/centralwidget.h9
2 files changed, 67 insertions, 62 deletions
diff --git a/tools/assistant/tools/assistant/centralwidget.cpp b/tools/assistant/tools/assistant/centralwidget.cpp
index 62b4736..67d803d 100644
--- a/tools/assistant/tools/assistant/centralwidget.cpp
+++ b/tools/assistant/tools/assistant/centralwidget.cpp
@@ -666,34 +666,16 @@ void CentralWidget::setSourceInNewTab(const QUrl &url, qreal zoom)
tabWidget->setCurrentIndex(tabWidget->addTab(viewer,
quoteTabTitle(viewer->documentTitle())));
- QFont font = qApp->font();
- bool userFont = helpEngine->customValue(QLatin1String("useBrowserFont")).toBool();
- if (userFont) {
- font = qVariantValue<QFont>(helpEngine->customValue(
- QLatin1String("browserFont")));
- }
-
-#if !defined(QT_NO_WEBKIT)
- QWebSettings *settings = QWebSettings::globalSettings();
- if (!userFont) {
- int fontSize = settings->fontSize(QWebSettings::DefaultFontSize);
- QString fontFamily = settings->fontFamily(QWebSettings::StandardFont);
- font = QFont(fontFamily, fontSize);
- }
+ QFont font;
+ getBrowserFontFor(viewer, &font);
- QWebView *view = qobject_cast<QWebView*> (viewer);
- if (view) {
- settings = view->settings();
- settings->setFontFamily(QWebSettings::StandardFont, font.family());
- settings->setFontSize(QWebSettings::DefaultFontSize, font.pointSize());
- } else if (viewer) {
- viewer->setFont(font);
- }
- viewer->setTextSizeMultiplier(zoom == 0.0 ? 1.0 : zoom);
-#else
+#if defined(QT_NO_WEBKIT)
font.setPointSize((int)(font.pointSize() + zoom));
- viewer->setFont(font);
+ setBrowserFontFor(viewer, font);
viewer->setZoom((int)zoom);
+#else
+ setBrowserFontFor(viewer, font);
+ viewer->setTextSizeMultiplier(zoom == 0.0 ? 1.0 : zoom);
#endif
connectSignals();
@@ -1011,41 +993,17 @@ bool CentralWidget::findInTextBrowser(QTextBrowser* browser, const QString &ttf,
void CentralWidget::updateBrowserFont()
{
- QFont font = qApp->font();
- bool userFont = helpEngine->customValue(QLatin1String("useBrowserFont")).toBool();
- if (userFont) {
- font = qVariantValue<QFont>(helpEngine->customValue(
- QLatin1String("browserFont")));
- }
-
-#if !defined(QT_NO_WEBKIT)
- QWebSettings *settings = QWebSettings::globalSettings();
- if (!userFont) {
- int fontSize = settings->fontSize(QWebSettings::DefaultFontSize);
- QString fontFamily = settings->fontFamily(QWebSettings::StandardFont);
- font = QFont(fontFamily, fontSize);
+ QFont font;
+ bool searchAttached = searchWidgetAttached();
+ if (searchAttached) {
+ getBrowserFontFor(m_searchWidget, &font);
+ setBrowserFontFor(m_searchWidget, font);
}
-#endif
- QWidget *widget = 0;
- for (int i = 0; i < tabWidget->count(); ++i) {
- widget = tabWidget->widget(i);
-#if !defined(QT_NO_WEBKIT)
- QWebView *view = qobject_cast<QWebView*> (widget);
- if (view) {
- settings = view->settings();
- settings->setFontFamily(QWebSettings::StandardFont, font.family());
- settings->setFontSize(QWebSettings::DefaultFontSize, font.pointSize());
- } else if (widget) {
- if (!userFont)
- font = qApp->font();
- widget->setFont(font);
- }
-#else
- if (widget && widget->font() != font)
- widget->setFont(font);
-#endif
- }
+ int i = searchAttached ? 1 : 0;
+ getBrowserFontFor(tabWidget->widget(i), &font);
+ for (i; i < tabWidget->count(); ++i)
+ setBrowserFontFor(tabWidget->widget(i), font);
}
void CentralWidget::createSearchWidget(QHelpSearchEngine *searchEngine)
@@ -1058,6 +1016,10 @@ void CentralWidget::createSearchWidget(QHelpSearchEngine *searchEngine)
SLOT(setSourceFromSearch(QUrl)));
connect(m_searchWidget, SIGNAL(requestShowLinkInNewTab(QUrl)), this,
SLOT(setSourceFromSearchInNewTab(QUrl)));
+
+ QFont font;
+ getBrowserFontFor(m_searchWidget, &font);
+ setBrowserFontFor(m_searchWidget, font);
}
void CentralWidget::activateSearchWidget(bool updateLastTabPage)
@@ -1079,7 +1041,7 @@ void CentralWidget::activateSearchWidget(bool updateLastTabPage)
void CentralWidget::removeSearchWidget()
{
- if (m_searchWidget && m_searchWidget->isAttached()) {
+ if (searchWidgetAttached()) {
tabWidget->removeTab(0);
m_searchWidget->setAttached(false);
}
@@ -1088,7 +1050,7 @@ void CentralWidget::removeSearchWidget()
int CentralWidget::availableHelpViewer() const
{
int count = tabWidget->count();
- if (m_searchWidget && m_searchWidget->isAttached())
+ if (searchWidgetAttached())
count--;
return count;
}
@@ -1096,7 +1058,7 @@ int CentralWidget::availableHelpViewer() const
bool CentralWidget::enableTabCloseAction() const
{
int minTabCount = 1;
- if (m_searchWidget && m_searchWidget->isAttached())
+ if (searchWidgetAttached())
minTabCount = 2;
return (tabWidget->count() > minTabCount);
@@ -1199,4 +1161,40 @@ QMap<int, QString> CentralWidget::currentSourceFileList() const
return sourceList;
}
+void CentralWidget::getBrowserFontFor(QWidget *viewer, QFont *font)
+{
+ const QLatin1String key("useBrowserFont");
+ if (!helpEngine->customValue(key, false).toBool()) {
+ *font = qApp->font(); // case for QTextBrowser and SearchWidget
+#if !defined(QT_NO_WEBKIT)
+ QWebView *view = qobject_cast<QWebView*> (viewer);
+ if (view) {
+ QWebSettings *settings = QWebSettings::globalSettings();
+ *font = QFont(settings->fontFamily(QWebSettings::StandardFont),
+ settings->fontSize(QWebSettings::DefaultFontSize));
+ }
+#endif
+ } else {
+ *font = qVariantValue<QFont>(helpEngine->customValue(
+ QLatin1String("browserFont")));
+ }
+}
+
+void CentralWidget::setBrowserFontFor(QWidget *widget, const QFont &font)
+{
+#if !defined(QT_NO_WEBKIT)
+ QWebView *view = qobject_cast<QWebView*> (widget);
+ if (view) {
+ QWebSettings *settings = view->settings();
+ settings->setFontFamily(QWebSettings::StandardFont, font.family());
+ settings->setFontSize(QWebSettings::DefaultFontSize, font.pointSize());
+ } else if (widget && widget->font() != font) {
+ widget->setFont(font);
+ }
+#else
+ if (widget && widget->font() != font)
+ widget->setFont(font);
+#endif
+}
+
QT_END_NAMESPACE
diff --git a/tools/assistant/tools/assistant/centralwidget.h b/tools/assistant/tools/assistant/centralwidget.h
index 7ae8ee5..8c186f0 100644
--- a/tools/assistant/tools/assistant/centralwidget.h
+++ b/tools/assistant/tools/assistant/centralwidget.h
@@ -48,6 +48,8 @@
#include <QtGui/QWidget>
+#include "searchwidget.h"
+
QT_BEGIN_NAMESPACE
class QEvent;
@@ -65,7 +67,6 @@ class CentralWidget;
class PrintHelper;
class MainWindow;
-class SearchWidget;
class QHelpSearchEngine;
class FindWidget : public QWidget
@@ -123,6 +124,9 @@ public:
HelpViewer *currentHelpViewer() const;
void activateTab(bool onlyHelpViewer = false);
+ bool searchWidgetAttached() const {
+ return m_searchWidget && m_searchWidget->isAttached();
+ }
void createSearchWidget(QHelpSearchEngine *searchEngine);
void activateSearchWidget(bool updateLastTabPage = false);
void removeSearchWidget();
@@ -190,6 +194,9 @@ private:
void highlightSearchTerms();
void setLastShownPages();
+ void getBrowserFontFor(QWidget* viewer, QFont *font);
+ void setBrowserFontFor(QWidget *widget, const QFont &font);
+
private:
int lastTabPage;
QString collectionFile;