forked from qt-creator/qt-creator
Add "Zoom" setting to the Help font settings
If the scrollWheelZooming is enabled, this setting will get updated when using scroll wheel. It will also be used when zooming in/out by using keyboard shortcuts. Fixes: QTCREATORBUG-25109 Fixes: QTCREATORBUG-25230 Fixes: QTCREATORBUG-23731 Change-Id: I9d22632b4c034ce236fa39dba074df4a2746ff84 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -70,6 +70,8 @@ QWidget *GeneralSettingsPage::widget()
|
||||
m_ui->styleComboBox->setEditable(false);
|
||||
|
||||
m_font = LocalHelpManager::fallbackFont();
|
||||
m_fontZoom = LocalHelpManager::fontZoom();
|
||||
m_ui->zoomSpinBox->setValue(m_fontZoom);
|
||||
|
||||
updateFontSizeSelector();
|
||||
updateFontStyleSelector();
|
||||
@@ -92,6 +94,9 @@ QWidget *GeneralSettingsPage::widget()
|
||||
connect(m_ui->sizeComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
|
||||
this, &GeneralSettingsPage::updateFont);
|
||||
|
||||
connect(m_ui->zoomSpinBox, QOverload<int>::of(&QSpinBox::valueChanged),
|
||||
this, [this](int value) { m_fontZoom = value; });
|
||||
|
||||
m_homePage = LocalHelpManager::homePage();
|
||||
m_ui->homePageLineEdit->setText(m_homePage);
|
||||
|
||||
@@ -150,10 +155,11 @@ void GeneralSettingsPage::apply()
|
||||
if (!m_ui) // page was never shown
|
||||
return;
|
||||
|
||||
if (m_font != LocalHelpManager::fallbackFont()) {
|
||||
if (m_font != LocalHelpManager::fallbackFont())
|
||||
LocalHelpManager::setFallbackFont(m_font);
|
||||
emit fontChanged();
|
||||
}
|
||||
|
||||
if (m_fontZoom != LocalHelpManager::fontZoom())
|
||||
LocalHelpManager::setFontZoom(m_fontZoom);
|
||||
|
||||
QString homePage = QUrl::fromUserInput(m_ui->homePageLineEdit->text()).toString();
|
||||
if (homePage.isEmpty())
|
||||
|
@@ -44,9 +44,6 @@ public:
|
||||
void apply() override;
|
||||
void finish() override;
|
||||
|
||||
signals:
|
||||
void fontChanged();
|
||||
|
||||
private:
|
||||
void setCurrentPage();
|
||||
void setBlankPage();
|
||||
@@ -61,6 +58,7 @@ private:
|
||||
int closestPointSizeIndex(int desiredPointSize) const;
|
||||
|
||||
QFont m_font;
|
||||
int m_fontZoom = 100;
|
||||
QFontDatabase m_fontDatabase;
|
||||
|
||||
QString m_homePage;
|
||||
|
@@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>695</width>
|
||||
<height>472</height>
|
||||
<width>706</width>
|
||||
<height>594</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@@ -19,22 +19,22 @@
|
||||
<property name="title">
|
||||
<string>Font</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_5">
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="familyLabel">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Family:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="familyLabel">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Family:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFontComboBox" name="familyComboBox"/>
|
||||
</item>
|
||||
@@ -123,7 +123,7 @@
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<width>13</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
@@ -131,16 +131,65 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<item row="1" column="0" colspan="2">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Note: This setting takes effect only if the HTML file does not use a style sheet.</string>
|
||||
<string>Note: The above setting takes effect only if the HTML file does not use a style sheet.</string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="zoomLabel">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Zoom:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<widget class="QSpinBox" name="zoomSpinBox">
|
||||
<property name="suffix">
|
||||
<string>%</string>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>3000</number>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>100</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="spacer3_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>13</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
@@ -412,7 +412,7 @@ HelpViewer *HelpPluginPrivate::externalHelpViewer()
|
||||
return m_externalWindow->currentViewer();
|
||||
}
|
||||
|
||||
HelpViewer *HelpPlugin::createHelpViewer(qreal zoom)
|
||||
HelpViewer *HelpPlugin::createHelpViewer()
|
||||
{
|
||||
const HelpViewerFactory factory = LocalHelpManager::viewerBackend();
|
||||
QTC_ASSERT(factory.create, return nullptr);
|
||||
@@ -424,7 +424,10 @@ HelpViewer *HelpPlugin::createHelpViewer(qreal zoom)
|
||||
viewer, &HelpViewer::setViewerFont);
|
||||
|
||||
// initialize zoom
|
||||
viewer->setScale(zoom);
|
||||
viewer->setFontZoom(LocalHelpManager::fontZoom());
|
||||
connect(LocalHelpManager::instance(), &LocalHelpManager::fontZoomChanged,
|
||||
viewer, &HelpViewer::setFontZoom);
|
||||
|
||||
viewer->setScrollWheelZoomingEnabled(LocalHelpManager::isScrollWheelZoomingEnabled());
|
||||
connect(LocalHelpManager::instance(), &LocalHelpManager::scrollWheelZoomingEnabledChanged,
|
||||
viewer, &HelpViewer::setScrollWheelZoomingEnabled);
|
||||
|
@@ -48,7 +48,7 @@ public:
|
||||
~HelpPlugin() final;
|
||||
|
||||
static void showHelpUrl(const QUrl &url, Core::HelpManager::HelpViewerLocation location);
|
||||
static HelpViewer *createHelpViewer(qreal zoom);
|
||||
static HelpViewer *createHelpViewer();
|
||||
static HelpWidget *modeHelpWidget();
|
||||
|
||||
private:
|
||||
|
@@ -29,6 +29,7 @@
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
#include <utils/fadingindicator.h>
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/temporarydirectory.h>
|
||||
|
||||
@@ -91,6 +92,11 @@ HelpViewer::~HelpViewer()
|
||||
restoreOverrideCursor();
|
||||
}
|
||||
|
||||
void HelpViewer::setFontZoom(int percentage)
|
||||
{
|
||||
setScale(percentage / 100.0);
|
||||
}
|
||||
|
||||
void HelpViewer::setScrollWheelZoomingEnabled(bool enabled)
|
||||
{
|
||||
m_scrollWheelZoomingEnabled = enabled;
|
||||
@@ -172,14 +178,45 @@ void HelpViewer::home()
|
||||
setSource(LocalHelpManager::homePage());
|
||||
}
|
||||
|
||||
void HelpViewer::scaleUp()
|
||||
{
|
||||
incrementZoom(1);
|
||||
}
|
||||
|
||||
void HelpViewer::scaleDown()
|
||||
{
|
||||
incrementZoom(-1);
|
||||
}
|
||||
|
||||
void HelpViewer::resetScale()
|
||||
{
|
||||
applyZoom(100);
|
||||
}
|
||||
|
||||
void HelpViewer::wheelEvent(QWheelEvent *event)
|
||||
{
|
||||
if (m_scrollWheelZoomingEnabled && event->modifiers() == Qt::ControlModifier) {
|
||||
event->accept();
|
||||
event->angleDelta().y() > 0 ? scaleUp() : scaleDown();
|
||||
} else {
|
||||
QWidget::wheelEvent(event);
|
||||
const int deltaY = event->angleDelta().y();
|
||||
if (deltaY != 0)
|
||||
incrementZoom(deltaY / 120);
|
||||
return;
|
||||
}
|
||||
QWidget::wheelEvent(event);
|
||||
}
|
||||
|
||||
void HelpViewer::incrementZoom(int steps)
|
||||
{
|
||||
const int incrementPercentage = 10 * steps; // 10 percent increase by single step
|
||||
const int previousZoom = LocalHelpManager::fontZoom();
|
||||
applyZoom(previousZoom + incrementPercentage);
|
||||
}
|
||||
|
||||
void HelpViewer::applyZoom(int percentage)
|
||||
{
|
||||
const int newZoom = LocalHelpManager::setFontZoom(percentage);
|
||||
Utils::FadingIndicator::showText(this, QCoreApplication::translate("Help::HelpViewer",
|
||||
"Zoom: %1%").arg(newZoom), Utils::FadingIndicator::SmallText);
|
||||
}
|
||||
|
||||
void HelpViewer::slotLoadStarted()
|
||||
|
@@ -54,9 +54,9 @@ public:
|
||||
virtual QFont viewerFont() const = 0;
|
||||
virtual void setViewerFont(const QFont &font) = 0;
|
||||
|
||||
virtual qreal scale() const = 0;
|
||||
virtual void setScale(qreal scale) = 0;
|
||||
|
||||
void setFontZoom(int percentage);
|
||||
void setScrollWheelZoomingEnabled(bool enabled);
|
||||
bool isScrollWheelZoomingEnabled() const;
|
||||
|
||||
@@ -87,9 +87,9 @@ public:
|
||||
|
||||
void home();
|
||||
|
||||
virtual void scaleUp() = 0;
|
||||
virtual void scaleDown() = 0;
|
||||
virtual void resetScale() = 0;
|
||||
void scaleUp();
|
||||
void scaleDown();
|
||||
void resetScale();
|
||||
virtual void copy() = 0;
|
||||
virtual void stop() = 0;
|
||||
virtual void forward() = 0;
|
||||
@@ -117,6 +117,9 @@ protected:
|
||||
Actions m_visibleActions;
|
||||
bool m_scrollWheelZoomingEnabled = true;
|
||||
int m_loadOverrideStack = 0;
|
||||
private:
|
||||
void incrementZoom(int steps);
|
||||
void applyZoom(int percentage);
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
@@ -490,7 +490,7 @@ HelpWidget::HelpWidget(const Core::Context &context, WidgetStyle style, QWidget
|
||||
connect(reload, &QAction::triggered, this, [this]() {
|
||||
const int index = m_viewerStack->currentIndex();
|
||||
HelpViewer *previous = currentViewer();
|
||||
insertViewer(index, previous->source(), previous->scale());
|
||||
insertViewer(index, previous->source());
|
||||
removeViewerAt(index + 1);
|
||||
setCurrentIndex(index);
|
||||
});
|
||||
@@ -711,15 +711,15 @@ void HelpWidget::setCurrentIndex(int index)
|
||||
emit currentIndexChanged(index);
|
||||
}
|
||||
|
||||
HelpViewer *HelpWidget::addViewer(const QUrl &url, qreal zoom)
|
||||
HelpViewer *HelpWidget::addViewer(const QUrl &url)
|
||||
{
|
||||
return insertViewer(m_viewerStack->count(), url, zoom);
|
||||
return insertViewer(m_viewerStack->count(), url);
|
||||
}
|
||||
|
||||
HelpViewer *HelpWidget::insertViewer(int index, const QUrl &url, qreal zoom)
|
||||
HelpViewer *HelpWidget::insertViewer(int index, const QUrl &url)
|
||||
{
|
||||
m_model.beginInsertRows({}, index, index);
|
||||
HelpViewer *viewer = HelpPlugin::createHelpViewer(zoom);
|
||||
HelpViewer *viewer = HelpPlugin::createHelpViewer();
|
||||
m_viewerStack->insertWidget(index, viewer);
|
||||
viewer->setFocus(Qt::OtherFocusReason);
|
||||
viewer->setActionVisible(HelpViewer::Action::NewPage, supportsPages());
|
||||
@@ -900,19 +900,16 @@ void HelpWidget::saveState() const
|
||||
{
|
||||
// TODO generalize
|
||||
if (m_style == ModeWidget) {
|
||||
QList<qreal> zoomFactors;
|
||||
QStringList currentPages;
|
||||
for (int i = 0; i < viewerCount(); ++i) {
|
||||
const HelpViewer *const viewer = viewerAt(i);
|
||||
const QUrl &source = viewer->source();
|
||||
if (source.isValid()) {
|
||||
currentPages.append(source.toString());
|
||||
zoomFactors.append(viewer->scale());
|
||||
}
|
||||
}
|
||||
|
||||
LocalHelpManager::setLastShownPages(currentPages);
|
||||
LocalHelpManager::setLastShownPagesZoom(zoomFactors);
|
||||
LocalHelpManager::setLastSelectedTab(currentIndex());
|
||||
}
|
||||
}
|
||||
|
@@ -87,7 +87,7 @@ public:
|
||||
HelpViewer *currentViewer() const;
|
||||
int currentIndex() const;
|
||||
void setCurrentIndex(int index);
|
||||
HelpViewer *addViewer(const QUrl &url, qreal zoom = 0);
|
||||
HelpViewer *addViewer(const QUrl &url);
|
||||
void removeViewerAt(int index);
|
||||
|
||||
int viewerCount() const;
|
||||
@@ -118,7 +118,7 @@ signals:
|
||||
|
||||
private:
|
||||
int indexOf(HelpViewer *viewer) const;
|
||||
HelpViewer *insertViewer(int index, const QUrl &url, qreal zoom);
|
||||
HelpViewer *insertViewer(int index, const QUrl &url);
|
||||
void updateBackMenu();
|
||||
void updateForwardMenu();
|
||||
void updateWindowTitle();
|
||||
|
@@ -99,26 +99,6 @@ void LiteHtmlHelpViewer::setViewerFont(const QFont &newFont)
|
||||
m_viewer->setDefaultFont(newFont);
|
||||
}
|
||||
|
||||
void LiteHtmlHelpViewer::scaleUp()
|
||||
{
|
||||
setScale(scale() * 1.1);
|
||||
}
|
||||
|
||||
void LiteHtmlHelpViewer::scaleDown()
|
||||
{
|
||||
setScale(scale() * .9);
|
||||
}
|
||||
|
||||
void LiteHtmlHelpViewer::resetScale()
|
||||
{
|
||||
m_viewer->setZoomFactor(1);
|
||||
}
|
||||
|
||||
qreal LiteHtmlHelpViewer::scale() const
|
||||
{
|
||||
return m_viewer->zoomFactor();
|
||||
}
|
||||
|
||||
void LiteHtmlHelpViewer::setScale(qreal scale)
|
||||
{
|
||||
// interpret 0 as "default"
|
||||
|
@@ -48,7 +48,6 @@ public:
|
||||
QFont viewerFont() const override;
|
||||
void setViewerFont(const QFont &font) override;
|
||||
|
||||
qreal scale() const override;
|
||||
void setScale(qreal scale) override;
|
||||
|
||||
QString title() const override;
|
||||
@@ -67,9 +66,6 @@ public:
|
||||
bool findText(const QString &text, Core::FindFlags flags,
|
||||
bool incremental, bool fromSearch, bool *wrapped = nullptr) override;
|
||||
|
||||
void scaleUp() override;
|
||||
void scaleDown() override;
|
||||
void resetScale() override;
|
||||
void copy() override;
|
||||
void stop() override;
|
||||
void forward() override;
|
||||
|
@@ -83,16 +83,17 @@ static const char kHelpHomePageKey[] = "Help/HomePage";
|
||||
static const char kFontFamilyKey[] = "Help/FallbackFontFamily";
|
||||
static const char kFontStyleNameKey[] = "Help/FallbackFontStyleName";
|
||||
static const char kFontSizeKey[] = "Help/FallbackFontSize";
|
||||
static const char kFontZoomKey[] = "Help/FontZoom";
|
||||
static const char kStartOptionKey[] = "Help/StartOption";
|
||||
static const char kContextHelpOptionKey[] = "Help/ContextHelpOption";
|
||||
static const char kReturnOnCloseKey[] = "Help/ReturnOnClose";
|
||||
static const char kUseScrollWheelZooming[] = "Help/UseScrollWheelZooming";
|
||||
static const char kLastShownPagesKey[] = "Help/LastShownPages";
|
||||
static const char kLastShownPagesZoomKey[] = "Help/LastShownPagesZoom";
|
||||
static const char kLastSelectedTabKey[] = "Help/LastSelectedTab";
|
||||
static const char kViewerBackend[] = "Help/ViewerBackend";
|
||||
|
||||
static const int kDefaultFallbackFontSize = 14;
|
||||
static const int kDefaultFontZoom = 100;
|
||||
const int kDefaultStartOption = LocalHelpManager::ShowLastPages;
|
||||
const int kDefaultContextHelpOption = Core::HelpManager::SideBySideIfPossible;
|
||||
const bool kDefaultReturnOnClose = false;
|
||||
@@ -185,6 +186,22 @@ void LocalHelpManager::setFallbackFont(const QFont &font)
|
||||
emit m_instance->fallbackFontChanged(font);
|
||||
}
|
||||
|
||||
int LocalHelpManager::fontZoom()
|
||||
{
|
||||
return Core::ICore::settings()->value(kFontZoomKey, kDefaultFontZoom).toInt();
|
||||
}
|
||||
|
||||
int LocalHelpManager::setFontZoom(int percentage)
|
||||
{
|
||||
const int newZoom = qBound(10, percentage, 3000);
|
||||
if (newZoom == fontZoom())
|
||||
return newZoom;
|
||||
|
||||
Core::ICore::settings()->setValueWithDefault(kFontZoomKey, newZoom, kDefaultFontZoom);
|
||||
emit m_instance->fontZoomChanged(newZoom);
|
||||
return newZoom;
|
||||
}
|
||||
|
||||
LocalHelpManager::StartOption LocalHelpManager::startOption()
|
||||
{
|
||||
const QVariant value = Core::ICore::settings()->value(kStartOptionKey, kDefaultStartOption);
|
||||
@@ -284,22 +301,6 @@ void LocalHelpManager::setLastShownPages(const QStringList &pages)
|
||||
pages.join(Constants::ListSeparator));
|
||||
}
|
||||
|
||||
QList<float> LocalHelpManager::lastShownPagesZoom()
|
||||
{
|
||||
const QVariant value = Core::ICore::settings()->value(kLastShownPagesZoomKey, QVariant());
|
||||
const QStringList stringValues = value.toString().split(Constants::ListSeparator,
|
||||
Qt::SkipEmptyParts);
|
||||
return Utils::transform(stringValues, [](const QString &str) { return str.toFloat(); });
|
||||
}
|
||||
|
||||
void LocalHelpManager::setLastShownPagesZoom(const QList<qreal> &zoom)
|
||||
{
|
||||
const QStringList stringValues = Utils::transform(zoom,
|
||||
[](qreal z) { return QString::number(z); });
|
||||
Core::ICore::settings()->setValueWithDefault(kLastShownPagesZoomKey,
|
||||
stringValues.join(Constants::ListSeparator));
|
||||
}
|
||||
|
||||
int LocalHelpManager::lastSelectedTab()
|
||||
{
|
||||
const QVariant value = Core::ICore::settings()->value(kLastSelectedTabKey, 0);
|
||||
|
@@ -83,6 +83,9 @@ public:
|
||||
static QFont fallbackFont();
|
||||
static void setFallbackFont(const QFont &font);
|
||||
|
||||
static int fontZoom();
|
||||
static int setFontZoom(int percentage);
|
||||
|
||||
static StartOption startOption();
|
||||
static void setStartOption(StartOption option);
|
||||
|
||||
@@ -98,9 +101,6 @@ public:
|
||||
static QStringList lastShownPages();
|
||||
static void setLastShownPages(const QStringList &pages);
|
||||
|
||||
static QList<float> lastShownPagesZoom();
|
||||
static void setLastShownPagesZoom(const QList<qreal> &zoom);
|
||||
|
||||
static int lastSelectedTab();
|
||||
static void setLastSelectedTab(int index);
|
||||
|
||||
@@ -137,6 +137,7 @@ signals:
|
||||
void filterIndexChanged(int index);
|
||||
#endif
|
||||
void fallbackFontChanged(const QFont &font);
|
||||
void fontZoomChanged(int percentage);
|
||||
void returnOnCloseChanged();
|
||||
void scrollWheelZoomingEnabledChanged(bool enabled);
|
||||
void contextHelpOptionChanged(Core::HelpManager::HelpViewerLocation option);
|
||||
|
@@ -73,7 +73,6 @@ public:
|
||||
QFont viewerFont() const override;
|
||||
void setViewerFont(const QFont &font) override;
|
||||
|
||||
qreal scale() const override;
|
||||
void setScale(qreal scale) override;
|
||||
|
||||
QString title() const override;
|
||||
@@ -97,9 +96,6 @@ public:
|
||||
MacWebKitHelpWidget *widget() const { return m_widget; }
|
||||
|
||||
public:
|
||||
void scaleUp() override;
|
||||
void scaleDown() override;
|
||||
void resetScale() override;
|
||||
void copy() override;
|
||||
void stop() override;
|
||||
void forward() override;
|
||||
|
@@ -553,34 +553,6 @@ void MacWebKitHelpViewer::setViewerFont(const QFont &font)
|
||||
}
|
||||
}
|
||||
|
||||
void MacWebKitHelpViewer::scaleUp()
|
||||
{
|
||||
@autoreleasepool {
|
||||
m_widget->webView().textSizeMultiplier += 0.1f;
|
||||
}
|
||||
}
|
||||
|
||||
void MacWebKitHelpViewer::scaleDown()
|
||||
{
|
||||
@autoreleasepool {
|
||||
m_widget->webView().textSizeMultiplier = qMax(0.1f, m_widget->webView().textSizeMultiplier - 0.1f);
|
||||
}
|
||||
}
|
||||
|
||||
void MacWebKitHelpViewer::resetScale()
|
||||
{
|
||||
@autoreleasepool {
|
||||
m_widget->webView().textSizeMultiplier = 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
qreal MacWebKitHelpViewer::scale() const
|
||||
{
|
||||
@autoreleasepool {
|
||||
return m_widget->webView().textSizeMultiplier;
|
||||
}
|
||||
}
|
||||
|
||||
void MacWebKitHelpViewer::setScale(qreal scale)
|
||||
{
|
||||
m_widget->webView().textSizeMultiplier = (scale <= 0.0 ? 1.0 : scale);
|
||||
|
@@ -137,15 +137,11 @@ void OpenPagesManager::setupInitialPages()
|
||||
const int pageCount = lastShownPageList.count();
|
||||
|
||||
if (pageCount > 0) {
|
||||
QList<float> zoomFactors = LocalHelpManager::lastShownPagesZoom();
|
||||
while (zoomFactors.count() < pageCount)
|
||||
zoomFactors.append(0.);
|
||||
|
||||
initialPage = LocalHelpManager::lastSelectedTab();
|
||||
for (int curPage = 0; curPage < pageCount; ++curPage) {
|
||||
const QString &curFile = lastShownPageList.at(curPage);
|
||||
if (engine.findFile(curFile).isValid() || curFile == Help::Constants::AboutBlank) {
|
||||
m_helpWidget->addViewer(curFile, zoomFactors.at(curPage));
|
||||
m_helpWidget->addViewer(curFile);
|
||||
} else if (curPage <= initialPage && initialPage > 0) {
|
||||
--initialPage;
|
||||
}
|
||||
|
@@ -82,54 +82,22 @@ QFont TextBrowserHelpViewer::viewerFont() const
|
||||
|
||||
void TextBrowserHelpViewer::setViewerFont(const QFont &newFont)
|
||||
{
|
||||
m_textBrowser->forceFont = true;
|
||||
m_textBrowser->setFont(newFont);
|
||||
m_textBrowser->forceFont = false;
|
||||
setFontAndScale(newFont, LocalHelpManager::fontZoom() / 100.0);
|
||||
}
|
||||
|
||||
void TextBrowserHelpViewer::scaleUp()
|
||||
void TextBrowserHelpViewer::setFontAndScale(const QFont &font, qreal scale)
|
||||
{
|
||||
m_textBrowser->scaleUp();
|
||||
}
|
||||
|
||||
void TextBrowserHelpViewer::scaleDown()
|
||||
{
|
||||
m_textBrowser->scaleDown();
|
||||
}
|
||||
|
||||
void TextBrowserHelpViewer::resetScale()
|
||||
{
|
||||
m_textBrowser->withFixedTopPosition([this] {
|
||||
if (m_textBrowser->zoomCount != 0) {
|
||||
m_textBrowser->forceFont = true;
|
||||
m_textBrowser->zoomOut(m_textBrowser->zoomCount);
|
||||
m_textBrowser->forceFont = false;
|
||||
}
|
||||
m_textBrowser->zoomCount = 0;
|
||||
m_textBrowser->withFixedTopPosition([this, &font, scale] {
|
||||
QFont newFont = font;
|
||||
const float newSize = font.pointSizeF() * scale;
|
||||
newFont.setPointSizeF(newSize);
|
||||
m_textBrowser->setFont(newFont);
|
||||
});
|
||||
}
|
||||
|
||||
qreal TextBrowserHelpViewer::scale() const
|
||||
{
|
||||
return m_textBrowser->zoomCount;
|
||||
}
|
||||
|
||||
void TextBrowserHelpViewer::setScale(qreal scale)
|
||||
{
|
||||
m_textBrowser->withFixedTopPosition([this, &scale] {
|
||||
m_textBrowser->forceFont = true;
|
||||
if (scale > 10)
|
||||
scale = 10;
|
||||
else if (scale < -5)
|
||||
scale = -5;
|
||||
int diff = int(scale) - m_textBrowser->zoomCount;
|
||||
if (diff > 0)
|
||||
m_textBrowser->zoomIn(diff);
|
||||
else if (diff < 0)
|
||||
m_textBrowser->zoomOut(-diff);
|
||||
m_textBrowser->zoomCount = int(scale);
|
||||
m_textBrowser->forceFont = false;
|
||||
});
|
||||
setFontAndScale(LocalHelpManager::fallbackFont(), scale);
|
||||
}
|
||||
|
||||
QString TextBrowserHelpViewer::title() const
|
||||
@@ -302,8 +270,6 @@ void TextBrowserHelpViewer::goToHistoryItem()
|
||||
|
||||
TextBrowserHelpWidget::TextBrowserHelpWidget(TextBrowserHelpViewer *parent)
|
||||
: QTextBrowser(parent)
|
||||
, zoomCount(0)
|
||||
, forceFont(false)
|
||||
, m_parent(parent)
|
||||
{
|
||||
installEventFilter(this);
|
||||
@@ -350,30 +316,6 @@ void TextBrowserHelpWidget::scrollToTextPosition(int position)
|
||||
}
|
||||
}
|
||||
|
||||
void TextBrowserHelpWidget::scaleUp()
|
||||
{
|
||||
withFixedTopPosition([this] {
|
||||
if (zoomCount < 10) {
|
||||
zoomCount++;
|
||||
forceFont = true;
|
||||
zoomIn();
|
||||
forceFont = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void TextBrowserHelpWidget::scaleDown()
|
||||
{
|
||||
withFixedTopPosition([this] {
|
||||
if (zoomCount > -5) {
|
||||
zoomCount--;
|
||||
forceFont = true;
|
||||
zoomOut();
|
||||
forceFont = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void TextBrowserHelpWidget::contextMenuEvent(QContextMenuEvent *event)
|
||||
{
|
||||
QMenu menu("", nullptr);
|
||||
@@ -409,10 +351,7 @@ void TextBrowserHelpWidget::contextMenuEvent(QContextMenuEvent *event)
|
||||
bool TextBrowserHelpWidget::eventFilter(QObject *obj, QEvent *event)
|
||||
{
|
||||
if (obj == this) {
|
||||
if (event->type() == QEvent::FontChange) {
|
||||
if (!forceFont)
|
||||
return true;
|
||||
} else if (event->type() == QEvent::KeyPress) {
|
||||
if (event->type() == QEvent::KeyPress) {
|
||||
auto keyEvent = static_cast<QKeyEvent *>(event);
|
||||
if (keyEvent->key() == Qt::Key_Slash) {
|
||||
keyEvent->accept();
|
||||
@@ -428,6 +367,21 @@ bool TextBrowserHelpWidget::eventFilter(QObject *obj, QEvent *event)
|
||||
return QTextBrowser::eventFilter(obj, event);
|
||||
}
|
||||
|
||||
void TextBrowserHelpWidget::wheelEvent(QWheelEvent *e)
|
||||
{
|
||||
// These two conditions should match those defined in QTextEdit::wheelEvent()
|
||||
if (!(textInteractionFlags() & Qt::TextEditable)) {
|
||||
if (e->modifiers() & Qt::ControlModifier) {
|
||||
// Don't handle wheelEvent by the QTextEdit superclass, which zooms the
|
||||
// view in a broken way. We handle it properly through the sequence:
|
||||
// HelpViewer::wheelEvent() -> LocalHelpManager::setFontZoom() ->
|
||||
// HelpViewer::setFontZoom() -> TextBrowserHelpViewer::setFontAndScale().
|
||||
return;
|
||||
}
|
||||
}
|
||||
QTextBrowser::wheelEvent(e);
|
||||
}
|
||||
|
||||
void TextBrowserHelpWidget::mousePressEvent(QMouseEvent *e)
|
||||
{
|
||||
if (Utils::HostOsInfo::isLinuxHost() && m_parent->handleForwardBackwardMouseButtons(e))
|
||||
|
@@ -46,7 +46,6 @@ public:
|
||||
QFont viewerFont() const override;
|
||||
void setViewerFont(const QFont &font) override;
|
||||
|
||||
qreal scale() const override;
|
||||
void setScale(qreal scale) override;
|
||||
|
||||
QString title() const override;
|
||||
@@ -65,9 +64,6 @@ public:
|
||||
bool findText(const QString &text, Core::FindFlags flags,
|
||||
bool incremental, bool fromSearch, bool *wrapped = nullptr) override;
|
||||
|
||||
void scaleUp() override;
|
||||
void scaleDown() override;
|
||||
void resetScale() override;
|
||||
void copy() override;
|
||||
void stop() override;
|
||||
void forward() override;
|
||||
@@ -76,6 +72,7 @@ public:
|
||||
|
||||
private:
|
||||
void goToHistoryItem();
|
||||
void setFontAndScale(const QFont &font, qreal scale);
|
||||
|
||||
TextBrowserHelpWidget *m_textBrowser;
|
||||
};
|
||||
@@ -89,14 +86,12 @@ public:
|
||||
|
||||
QVariant loadResource(int type, const QUrl &name) override;
|
||||
|
||||
void scaleUp();
|
||||
void scaleDown();
|
||||
|
||||
void withFixedTopPosition(const std::function<void()> &action);
|
||||
|
||||
protected:
|
||||
void contextMenuEvent(QContextMenuEvent *event) override;
|
||||
bool eventFilter(QObject *obj, QEvent *event) override;
|
||||
void wheelEvent(QWheelEvent *e) override;
|
||||
void mousePressEvent(QMouseEvent *e) override;
|
||||
void mouseReleaseEvent(QMouseEvent *e) override;
|
||||
void resizeEvent(QResizeEvent *e) override;
|
||||
@@ -105,8 +100,6 @@ private:
|
||||
QString linkAt(const QPoint &pos);
|
||||
void scrollToTextPosition(int position);
|
||||
|
||||
int zoomCount;
|
||||
bool forceFont;
|
||||
TextBrowserHelpViewer *m_parent;
|
||||
friend class Help::Internal::TextBrowserHelpViewer;
|
||||
};
|
||||
|
@@ -173,11 +173,6 @@ void WebEngineHelpViewer::setViewerFont(const QFont &font)
|
||||
webSettings->setFontSize(QWebEngineSettings::DefaultFontSize, font.pointSize());
|
||||
}
|
||||
|
||||
qreal WebEngineHelpViewer::scale() const
|
||||
{
|
||||
return m_widget->zoomFactor();
|
||||
}
|
||||
|
||||
void WebEngineHelpViewer::setScale(qreal scale)
|
||||
{
|
||||
m_widget->setZoomFactor(scale);
|
||||
@@ -277,21 +272,6 @@ WebEngineHelpPage *WebEngineHelpViewer::page() const
|
||||
return static_cast<WebEngineHelpPage *>(m_widget->page());
|
||||
}
|
||||
|
||||
void WebEngineHelpViewer::scaleUp()
|
||||
{
|
||||
m_widget->setZoomFactor(m_widget->zoomFactor() + 0.1);
|
||||
}
|
||||
|
||||
void WebEngineHelpViewer::scaleDown()
|
||||
{
|
||||
m_widget->setZoomFactor(qMax(qreal(0.1), m_widget->zoomFactor() - qreal(0.1)));
|
||||
}
|
||||
|
||||
void WebEngineHelpViewer::resetScale()
|
||||
{
|
||||
m_widget->setZoomFactor(1.0);
|
||||
}
|
||||
|
||||
void WebEngineHelpViewer::copy()
|
||||
{
|
||||
m_widget->triggerPageAction(QWebEnginePage::Copy);
|
||||
|
@@ -84,7 +84,6 @@ public:
|
||||
|
||||
QFont viewerFont() const override;
|
||||
void setViewerFont(const QFont &font) override;
|
||||
qreal scale() const override;
|
||||
void setScale(qreal scale) override;
|
||||
QString title() const override;
|
||||
QUrl source() const override;
|
||||
@@ -99,9 +98,6 @@ public:
|
||||
|
||||
WebEngineHelpPage *page() const;
|
||||
|
||||
void scaleUp() override;
|
||||
void scaleDown() override;
|
||||
void resetScale() override;
|
||||
void copy() override;
|
||||
void stop() override;
|
||||
void forward() override;
|
||||
|
Reference in New Issue
Block a user